feat(plan-01): Phase 1 — relocate harness code to packages/casan-harness (symlink facade)
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>
This commit is contained in:
co-authored by
Claude Opus 4.8
parent
2c765c9a45
commit
664bd1f00c
+82
@@ -0,0 +1,82 @@
|
||||
#!/usr/bin/env bash
|
||||
set -uo pipefail
|
||||
|
||||
# CASAN C7 — Incident response + kill-switch tests (V23).
|
||||
#
|
||||
# Proves: a detected event is graded (severity map), recorded, and for HIGH/CRIT
|
||||
# the scoped kill-switch auto-engages (gates honoring it then stop); MED/LOW only
|
||||
# record. Kill-switch check/clear and global scope work. Deterministic, no infra.
|
||||
|
||||
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
|
||||
export CASAN_KILLSWITCH_DIR="$WORK/ks" # isolate the kill-switch state
|
||||
PASS=0; FAIL=0
|
||||
pass() { echo "PASS: $1"; PASS=$((PASS + 1)); }
|
||||
fail() { echo "FAIL: $1"; FAIL=$((FAIL + 1)); }
|
||||
expect_rc() {
|
||||
local want="$1" desc="$2"; shift 2
|
||||
local got=0; { "$@" >/dev/null 2>&1; } || got=$?
|
||||
[[ "$got" -eq "$want" ]] && pass "$desc (rc=$got)" || fail "$desc (got rc=$got, want $want)"
|
||||
}
|
||||
|
||||
INC() { bash "$S/incident.sh" "$@"; }
|
||||
KS() { bash "$S/kill-switch.sh" "$@"; }
|
||||
|
||||
echo "===== C7: severity classification + auto kill-switch ====="
|
||||
# CRIT event -> exit 2 + kill-switch engaged for its scope
|
||||
OUT="$(INC raise secret-to-cloud "key in prompt" --scope model --id m1 2>/dev/null)"; RC=$?
|
||||
{ [[ "$RC" -eq 2 ]] && printf '%s' "$OUT" | grep -q "sev=CRIT" && printf '%s' "$OUT" | grep -q "kill_switch_engaged"; } \
|
||||
&& pass "CRIT event (secret-to-cloud) → exit 2 + kill-switch engaged" \
|
||||
|| fail "CRIT handling wrong (rc=$RC out=$OUT)"
|
||||
expect_rc 2 "kill-switch now blocks that scope (model/m1)" KS check model m1
|
||||
|
||||
# HIGH event also engages
|
||||
expect_rc 2 "HIGH event (audit-chain-broken) → exit 2" INC raise audit-chain-broken "line 1" --scope project --id p1
|
||||
expect_rc 2 "kill-switch blocks project/p1 after HIGH" KS check project p1
|
||||
|
||||
# MED event: recorded only, no kill-switch
|
||||
expect_rc 0 "MED event (cost-budget-exceeded) → exit 0 (recorded, no kill)" INC raise cost-budget-exceeded "3x budget" --scope model --id m2
|
||||
expect_rc 0 "kill-switch stays clear for a MED-only scope (model/m2)" KS check model m2
|
||||
|
||||
# Unknown event → default severity (MED) → recorded, no kill
|
||||
expect_rc 0 "unknown event → default MED (recorded, no kill)" INC raise some-unmapped-thing --scope model --id m3
|
||||
|
||||
echo "===== C7: kill-switch lifecycle + global scope ====="
|
||||
expect_rc 0 "clear an engaged switch" KS clear model m1 "resolved-in-test"
|
||||
expect_rc 0 "cleared scope is unblocked again" KS check model m1
|
||||
KS engage global all "org-wide freeze" >/dev/null 2>&1
|
||||
expect_rc 2 "global kill-switch blocks ANY scope" KS check model brand-new
|
||||
KS clear global all "unfreeze" >/dev/null 2>&1
|
||||
expect_rc 0 "after clearing global, scopes flow again" KS check model brand-new
|
||||
|
||||
echo "===== C7: incident record is structured (severity + owner) ====="
|
||||
REC="$(INC raise private-key-exposure "id_rsa in output" --scope provider --id prov1 2>/dev/null)" || true
|
||||
LOGF="$CASAN_STATE_ROOT/logs/level5/incidents.jsonl"
|
||||
if tail -5 "$LOGF" 2>/dev/null | grep -qE '"severity": ?"CRIT"' && tail -5 "$LOGF" 2>/dev/null | grep -qE '"owner": ?"security-oncall"'; then
|
||||
pass "incident recorded with severity + owner (routable)"
|
||||
else
|
||||
fail "incident record missing severity/owner"
|
||||
fi
|
||||
KS clear provider prov1 "test-cleanup" >/dev/null 2>&1 || true
|
||||
|
||||
echo "===== C7: production wrapper honors the kill-switch ====="
|
||||
printf 'benign task input\n' > "$WORK/w.txt"
|
||||
# switch clear → wrapper runs normally
|
||||
expect_rc 0 "wrapper runs when kill-switch is clear (enforce on)" \
|
||||
env CASAN_KILLSWITCH_ENFORCE=1 CASAN_KILLSWITCH_SCOPE=project CASAN_KILLSWITCH_ID=wf1 \
|
||||
bash "$S/casan-harness.sh" "$WORK/w.txt" "$WORK/wo.txt" agent_step
|
||||
KS engage project wf1 "drill" >/dev/null 2>&1
|
||||
expect_rc 2 "wrapper REFUSES to run when kill-switch engaged" \
|
||||
env CASAN_KILLSWITCH_ENFORCE=1 CASAN_KILLSWITCH_SCOPE=project CASAN_KILLSWITCH_ID=wf1 \
|
||||
bash "$S/casan-harness.sh" "$WORK/w.txt" "$WORK/wo.txt" agent_step
|
||||
expect_rc 0 "wrapper ignores engaged switch when enforcement is OFF (backward compat)" \
|
||||
env CASAN_KILLSWITCH_SCOPE=project CASAN_KILLSWITCH_ID=wf1 \
|
||||
bash "$S/casan-harness.sh" "$WORK/w.txt" "$WORK/wo.txt" agent_step
|
||||
KS clear project wf1 "cleanup" >/dev/null 2>&1
|
||||
|
||||
echo ""
|
||||
echo "===== C7 INCIDENT SUMMARY: PASS=$PASS FAIL=$FAIL ====="
|
||||
[[ "$FAIL" -eq 0 ]] || exit 1
|
||||
Reference in New Issue
Block a user