ms-ai-architect/tests/test-hooks.sh
Kjell Tore Guttormsen 039b61ca24 chore(ms-ai-architect): Sesjon 22 — rydd stale pre-edit-secrets-testreferanser [skip-docs]
pre-edit-secrets.mjs-hooken ble bevisst fjernet i v1.7.0 (secrets scanning
consolidated to llm-security, CHANGELOG l.413), men 2 testfiler refererte den
fortsatt og ga falske feil.

- tests/test-hooks.sh: fjernet pre-edit-secrets-testblokk (5 tester) → 6/6 grønn.
- tests/test-plugin-discovery.sh: fjernet pre-edit-secrets fra CLAUDE.md-dok-loop.

Separat funn (IKKE fikset, scope-guard): test-plugin-discovery.sh har 1
gjenværende feil `auto_discover is not true` — plugin.json mangler feltet; ikke
hook-relatert, krever søk-først (gjeldende felt vs stale test). Flagget → task #44.

De 4 sporede suitene uendret (validate 239 · kb-update 155 · kb-eval 100 · kb-integrity 192/192).

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2026-06-20 23:08:11 +02:00

95 lines
2.6 KiB
Bash

#!/bin/bash
# test-hooks.sh — Unit tests for ms-ai-architect hook scripts
# Usage: bash tests/test-hooks.sh
set -euo pipefail
PLUGIN_ROOT="$(cd "$(dirname "$0")/.." && pwd)"
SCRIPTS_DIR="$PLUGIN_ROOT/hooks/scripts"
PASS=0
FAIL=0
pass() { echo -e "\033[0;32m ✓ $1\033[0m"; PASS=$((PASS + 1)); }
fail() { echo -e "\033[0;31m ✗ $1\033[0m"; FAIL=$((FAIL + 1)); }
echo "=== Hook Script Tests ==="
echo ""
# NB: the pre-edit-secrets.mjs hook was removed in v1.7.0 (secrets scanning
# consolidated to the llm-security plugin — see CHANGELOG). Its tests were
# removed with it; secrets-scanning coverage now lives in llm-security.
# -------------------------------------------------------
# session-start-context.mjs
# -------------------------------------------------------
echo "--- session-start-context.mjs ---"
OUTPUT=$(CLAUDE_PLUGIN_ROOT="$PLUGIN_ROOT" node "$SCRIPTS_DIR/session-start-context.mjs" 2>/dev/null)
EXIT_CODE=$?
if [ $EXIT_CODE -eq 0 ]; then
pass "Runs without error (exit 0)"
else
fail "Expected exit 0, got $EXIT_CODE"
fi
if echo "$OUTPUT" | grep -q "Architect:"; then
pass "Output contains 'Architect:' prefix"
else
fail "Output missing 'Architect:' prefix"
fi
echo ""
# -------------------------------------------------------
# stop-assessment-reminder.mjs
# -------------------------------------------------------
echo "--- stop-assessment-reminder.mjs ---"
# Test from a temp dir without .work/
TMPDIR_TEST=$(mktemp -d)
OUTPUT=$(cd "$TMPDIR_TEST" && node "$SCRIPTS_DIR/stop-assessment-reminder.mjs" 2>/dev/null)
EXIT_CODE=$?
if [ $EXIT_CODE -eq 0 ]; then
pass "No .work/: exit 0"
else
fail "No .work/: expected exit 0, got $EXIT_CODE"
fi
if [ "$OUTPUT" = "{}" ]; then
pass "No .work/: returns {}"
else
fail "No .work/: expected {}, got: $OUTPUT"
fi
# Test with a fresh .work/ session
mkdir -p "$TMPDIR_TEST/.work/test-session"
touch "$TMPDIR_TEST/.work/test-session/state.json"
OUTPUT=$(cd "$TMPDIR_TEST" && node "$SCRIPTS_DIR/stop-assessment-reminder.mjs" 2>/dev/null)
if echo "$OUTPUT" | grep -q "systemMessage"; then
pass "Fresh .work/: returns systemMessage"
else
fail "Fresh .work/: expected systemMessage in output"
fi
if echo "$OUTPUT" | grep -q "architect:adr"; then
pass "Fresh .work/: suggests /architect:adr"
else
fail "Fresh .work/: missing /architect:adr suggestion"
fi
rm -rf "$TMPDIR_TEST"
echo ""
# -------------------------------------------------------
# Summary
# -------------------------------------------------------
TOTAL=$((PASS + FAIL))
echo "=== Results: $PASS/$TOTAL passed, $FAIL failed ==="
if [ "$FAIL" -gt 0 ]; then
exit 1
fi