#!/usr/bin/env sh # selftest.sh – Funktionspruefung fuer copilot-bootstrap.{sh,fish}. # # Baut ein isoliertes Fake-Template-Verzeichnis und ein Ziel-Repo in einem # temporaeren HOME und prueft, dass Bootstrap die erwartete Struktur erzeugt. # Veraendert weder das echte HOME noch ein echtes Repo. Lokal und in CI nutzbar: # sh scripts/selftest.sh set -eu REPO_DIR="$(cd "$(dirname "$0")/.." && pwd)" WORK="$(mktemp -d)" trap 'rm -rf "$WORK"' EXIT build_template() { tpl="$1" mkdir -p "$tpl/.github" "$tpl/.vscode" "$tpl/hooks" "$tpl/docs" "$tpl/docs/history/summary" # Realistische copilot-instructions.md inkl. Default-Shell-Zeile (Projekt-Sektion) printf '# Instr\n\n---\n\n## Entwicklungsumgebung\n\n- **Default-Shell:** fish\n\n## Project\n' \ > "$tpl/.github/copilot-instructions.md" echo '{}' > "$tpl/.vscode/settings.json" echo '{}' > "$tpl/.vscode/extensions.json" printf '#!/bin/sh\nexit 0\n' > "$tpl/hooks/pre-commit" printf '#!/bin/sh\nexit 0\n' > "$tpl/hooks/post-commit" for d in USER ADMIN MAINTAINER; do echo "$d" > "$tpl/docs/$d.md" done echo ctx > "$tpl/docs/history/summary/PROJECT_CONTEXT.md" } assert_file() { if [ ! -f "$1" ]; then echo "FAIL: erwartete Datei fehlt: $1" >&2 exit 1 fi } run_case() { label="$1" runner="$2" # sh | fish script="$3" home="$WORK/home_$label" target="$WORK/target_$label" mkdir -p "$home/.git-templates" "$target" build_template "$home/.git-templates" git -C "$target" init -q HOME="$home" "$runner" "$REPO_DIR/scripts/$script" "$target" >/dev/null assert_file "$target/.github/copilot-instructions.md" assert_file "$target/.vscode/settings.json" assert_file "$target/.vscode/extensions.json" assert_file "$target/docs/USER.md" assert_file "$target/docs/ADMIN.md" assert_file "$target/docs/MAINTAINER.md" assert_file "$target/docs/history/summary/PROJECT_CONTEXT.md" assert_file "$target/.git/hooks/pre-commit" assert_file "$target/.git/hooks/post-commit" assert_file "$target/data/.gitkeep" if ! grep -q ':Zone.Identifier' "$target/.gitignore"; then echo "FAIL: $label – .gitignore enthaelt kein Zone.Identifier-Muster" >&2 exit 1 fi if ! grep -q '^- \*\*Default-Shell:\*\*' "$target/.github/copilot-instructions.md"; then echo "FAIL: $label – Default-Shell-Zeile fehlt in copilot-instructions.md" >&2 exit 1 fi echo "PASS: $label ($script)" } # Prueft, dass die erkannte $SHELL korrekt in die copilot-instructions.md # geschrieben wird (deterministisch ueber explizit gesetztes SHELL). run_shell_case() { label="$1" runner="$2" script="$3" shellval="$4" expected="$5" home="$WORK/home_$label" target="$WORK/target_$label" mkdir -p "$home/.git-templates" "$target" build_template "$home/.git-templates" git -C "$target" init -q HOME="$home" SHELL="$shellval" "$runner" "$REPO_DIR/scripts/$script" "$target" >/dev/null got=$(sed -n 's|^- \*\*Default-Shell:\*\* ||p' "$target/.github/copilot-instructions.md") if [ "$got" != "$expected" ]; then echo "FAIL: $label – Default-Shell '$got' != erwartet '$expected'" >&2 exit 1 fi echo "PASS: $label (SHELL='$shellval' → $expected)" } run_case sh_bootstrap sh copilot-bootstrap.sh # Shell-Erkennung: expliziter Wert wird uebernommen, leeres SHELL faellt auf fish zurueck. run_shell_case sh_shell_zsh sh copilot-bootstrap.sh /usr/bin/zsh zsh run_shell_case sh_shell_empty sh copilot-bootstrap.sh "" fish if command -v fish >/dev/null 2>&1; then run_case fish_bootstrap fish copilot-bootstrap.fish run_shell_case fish_shell_zsh fish copilot-bootstrap.fish /usr/bin/zsh zsh run_shell_case fish_shell_empty fish copilot-bootstrap.fish "" fish else echo "SKIP: fish nicht installiert – fish-Bootstrap uebersprungen" fi echo "selftest OK"