Physically move the pure-code subtrees out of .specify into the package, leaving compat symlinks at the old .specify/<dir> paths so every existing reference (internal CASAN_HARNESS_ROOT + external CI/docker/mjs) keeps resolving. Runtime state stays put. Moved (git mv): scripts/ tests/ security/ templates/ config/ governance/ memory/ .specify/<dir> -> packages/casan-harness/<dir> (+ .specify/<dir> symlink) Stays in .specify (state/governance/domain, handled later): logs/ agentops/ level5/ init-options.json traceability-map.json Python `.resolve()` self-location followed the compat symlink into packages and lost the app root; generate-casan-demo-context.py, generate-agentops-dashboard.py and dashboard-server.py now walk UP for the `.specify` state marker instead of a fixed parent depth (fixes "missing trace files" in run-casan4). Full gate: PASS=64 FAIL=0 SKIP=3 (CASAN_CI_STEP_TIMEOUT_SEC=1200 — track-a ~450s runs close to the 600s default and can tip over under load; this is timing variance, not a regression — it passed cleanly with headroom). Runtime log/audit artifacts kept unstaged. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
96 lines
3.9 KiB
Bash
Executable File
96 lines
3.9 KiB
Bash
Executable File
#!/usr/bin/env bash
|
|
set -uo pipefail
|
|
|
|
# CASAN Plan-10 — Traceability REQ→code→test MVP tests.
|
|
#
|
|
# Proves the matrix is generated from the real requirement document and the gate
|
|
# fails when any FR loses test coverage.
|
|
|
|
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
|
source "$SCRIPT_DIR/../scripts/bash/casan-paths.sh"
|
|
PROJECT_ROOT="$(cd "$SCRIPT_DIR/../.." && pwd)"
|
|
S="$CASAN_HARNESS_ROOT/scripts/bash"
|
|
WORK="$(mktemp -d)"
|
|
trap 'rm -rf "$WORK"' EXIT
|
|
|
|
PASS=0; FAIL=0
|
|
pass() { echo "PASS: $1"; PASS=$((PASS + 1)); }
|
|
fail() { echo "FAIL: $1"; FAIL=$((FAIL + 1)); }
|
|
|
|
REQ="$PROJECT_ROOT/docs/input/okr-requirement.md"
|
|
MAP="$CASAN_HARNESS_ROOT/traceability-map.json"
|
|
OUT="$WORK/traceability-matrix.json"
|
|
|
|
echo "===== Plan-10 traceability matrix ====="
|
|
if python3 "$S/traceability-matrix.py" --requirements "$REQ" --map "$MAP" --out "$OUT" --gate >/dev/null 2>"$WORK/pass.err"; then
|
|
pass "complete FR→code→test matrix passes gate"
|
|
else
|
|
cat "$WORK/pass.err"
|
|
fail "complete traceability matrix rejected"
|
|
fi
|
|
|
|
COUNT="$(python3 -c "import json;d=json.load(open('$OUT'));print(d['summary']['requirements'])" 2>/dev/null)"
|
|
FAILED="$(python3 -c "import json;d=json.load(open('$OUT'));print(d['summary']['failed'])" 2>/dev/null)"
|
|
[[ "$COUNT" == "5" && "$FAILED" == "0" ]] \
|
|
&& pass "matrix captures all 5 FRs with zero failures" \
|
|
|| fail "matrix summary unexpected (requirements=$COUNT failed=$FAILED)"
|
|
|
|
BROKEN="$WORK/traceability-map-broken.json"
|
|
python3 - "$MAP" "$BROKEN" <<'PY'
|
|
import json, sys
|
|
d = json.load(open(sys.argv[1]))
|
|
d["FR-04"]["tests"] = []
|
|
json.dump(d, open(sys.argv[2], "w"), indent=2)
|
|
PY
|
|
set +e
|
|
python3 "$S/traceability-matrix.py" --requirements "$REQ" --map "$BROKEN" --out "$WORK/broken.json" --gate >/dev/null 2>"$WORK/broken.err"
|
|
RC=$?
|
|
set -e 2>/dev/null || true
|
|
[[ "$RC" -eq 1 ]] && grep -q "TRACEABILITY_FAIL FR-04" "$WORK/broken.err" \
|
|
&& pass "missing FR test coverage fails the gate" \
|
|
|| fail "missing test coverage did not fail as expected (rc=$RC)"
|
|
|
|
echo ""
|
|
echo "===== Plan-10 symbol/line-level traceability ====="
|
|
# The real map carries symbol refs for FR-01 (AuthService, login); the passing
|
|
# run above wrote $OUT from the real map, so those symbols must resolve.
|
|
SYM_FOUND="$(python3 -c "import json;print(json.load(open('$OUT'))['summary']['symbols_found'])" 2>/dev/null)"
|
|
SYM_MISS="$(python3 -c "import json;print(json.load(open('$OUT'))['summary']['symbols_missing'])" 2>/dev/null)"
|
|
[[ "${SYM_FOUND:-0}" -ge 2 && "${SYM_MISS:-1}" -eq 0 ]] \
|
|
&& pass "real map symbol refs resolved (found=$SYM_FOUND missing=$SYM_MISS)" \
|
|
|| fail "real map symbol refs unexpected (found=$SYM_FOUND missing=$SYM_MISS)"
|
|
|
|
SYMBROKEN="$WORK/map-badsym.json"
|
|
python3 - "$MAP" "$SYMBROKEN" <<'PY'
|
|
import json, sys
|
|
d = json.load(open(sys.argv[1]))
|
|
d["FR-01"]["code"] = [{"file": "backend/src/auth/auth.service.ts", "symbols": ["NoSuchSymbolXYZ"]}]
|
|
json.dump(d, open(sys.argv[2], "w"), indent=2)
|
|
PY
|
|
set +e
|
|
python3 "$S/traceability-matrix.py" --requirements "$REQ" --map "$SYMBROKEN" --out "$WORK/badsym.json" --gate >/dev/null 2>"$WORK/badsym.err"
|
|
RC=$?
|
|
set -e 2>/dev/null || true
|
|
[[ "$RC" -eq 1 ]] && grep -q "missing_symbols=1" "$WORK/badsym.err" \
|
|
&& pass "missing symbol fails the gate (symbol-level)" \
|
|
|| fail "missing symbol did not fail as expected (rc=$RC)"
|
|
|
|
LINEBROKEN="$WORK/map-badline.json"
|
|
python3 - "$MAP" "$LINEBROKEN" <<'PY'
|
|
import json, sys
|
|
d = json.load(open(sys.argv[1]))
|
|
d["FR-01"]["code"] = [{"file": "backend/src/auth/auth.service.ts", "lines": [999999]}]
|
|
json.dump(d, open(sys.argv[2], "w"), indent=2)
|
|
PY
|
|
set +e
|
|
python3 "$S/traceability-matrix.py" --requirements "$REQ" --map "$LINEBROKEN" --out "$WORK/badline.json" --gate >/dev/null 2>"$WORK/badline.err"
|
|
RC=$?
|
|
set -e 2>/dev/null || true
|
|
[[ "$RC" -eq 1 ]] && grep -q "missing_lines=1" "$WORK/badline.err" \
|
|
&& pass "out-of-range line ref fails the gate (line-level)" \
|
|
|| fail "line ref did not fail as expected (rc=$RC)"
|
|
|
|
echo ""
|
|
echo "===== TRACEABILITY SUMMARY: PASS=$PASS FAIL=$FAIL ====="
|
|
[[ "$FAIL" -eq 0 ]] || exit 1
|