Task 1.2: introduce a single path resolver so no harness script hardcodes `.specify/...` scattered across the tree. casan-paths.sh resolves four roots (HARNESS/STATE/GOVERNANCE/APP) by marker-based walk-up from its own location — never `git rev-parse` (git root is the repo PARENT here, not the app dir). - 101 bash scripts/tests: 238 hardcoded `$PROJECT_ROOT/.specify/...` refs rewritten to CASAN_HARNESS_ROOT (code) / CASAN_STATE_ROOT (logs,state) / CASAN_GOVERNANCE_ROOT. Sandbox test vars ($WORK/$TP/$FP/$T1_WORK) left untouched. - Roots are NOT exported: each script/subprocess self-resolves from its own tree, matching the original per-script semantics and preserving hermetic sandbox isolation (node casan-step.mjs, copied telemetry/rollback scripts must not inherit real roots). - Sandbox tests that copy a harness script now also copy casan-paths.sh (its new sibling dependency): adversarial (verify-audit-chain/verify-tool-audit/rollback) + track-a (security-check/telemetry-integrity). - control-plane-settings.json reclassified as STATE (untracked runtime store). Roots all still resolve to `.specify` in this monolithic layout, so behavior is unchanged. Full gate: PASS=64 FAIL=0 SKIP=3 (adversarial 44/0, track-a 25/0). Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
56 lines
2.5 KiB
Bash
56 lines
2.5 KiB
Bash
#!/usr/bin/env bash
|
|
set -uo pipefail
|
|
|
|
# CASAN Plan-15/13 — harness preflight enforcement tests.
|
|
# Deterministic & offline: the BLOCK path short-circuits before any model call,
|
|
# so no Ollama/cloud is needed. Proves governance cores actually gate a run.
|
|
|
|
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"
|
|
PF="$S/harness-preflight.sh"
|
|
ROUTER="$S/model-router.sh"
|
|
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)); }
|
|
|
|
printf 'Please summarize; contact alice@example.com about the account.\n' > "$WORK/pii.txt"
|
|
printf 'Please refactor the dashboard grid layout.\n' > "$WORK/benign.txt"
|
|
|
|
echo "===== harness preflight (governance enforced before model call) ====="
|
|
|
|
# 1) preflight blocks PII → cloud without approval
|
|
set +e
|
|
bash "$PF" "$WORK/pii.txt" "$WORK/out.json" --model openai:gpt-4o >/dev/null 2>"$WORK/1.err"; RC=$?
|
|
set -e 2>/dev/null || true
|
|
[[ "$RC" -ne 0 ]] && grep -q "PREFLIGHT_BLOCK" "$WORK/1.err" \
|
|
&& pass "preflight blocks PII→cloud without approval" || fail "preflight did not block (rc=$RC)"
|
|
|
|
# 2) preflight allows PII → cloud WITH approval
|
|
CASAN_MODEL_APPROVAL=human-ok bash "$PF" "$WORK/pii.txt" "$WORK/out.json" --model anthropic:claude >/dev/null 2>&1 \
|
|
&& pass "preflight allows PII→cloud with approval" || fail "approved cloud send blocked"
|
|
|
|
# 3) preflight allows benign → cloud
|
|
bash "$PF" "$WORK/benign.txt" "$WORK/out.json" --model openai:gpt-4o >/dev/null 2>&1 \
|
|
&& pass "preflight allows benign→cloud" || fail "benign cloud send blocked"
|
|
|
|
# 4) preflight ignores local model (no cloud data-gov gate)
|
|
bash "$PF" "$WORK/pii.txt" "$WORK/out.json" --model ollama:ornith:9b >/dev/null 2>&1 \
|
|
&& pass "preflight passes local model" || fail "local model wrongly blocked"
|
|
|
|
# 5) WIRED into router: CASAN_PREFLIGHT=1 blocks a cloud PII call BEFORE model-call
|
|
# (short-circuits, so no live model is required to prove enforcement)
|
|
set +e
|
|
CASAN_PREFLIGHT=1 bash "$ROUTER" "$WORK/pii.txt" "$WORK/out.json" --model openai:gpt-4o >/dev/null 2>"$WORK/5.err"; RC=$?
|
|
set -e 2>/dev/null || true
|
|
[[ "$RC" -ne 0 ]] && grep -q "PREFLIGHT_BLOCK" "$WORK/5.err" \
|
|
&& pass "model-router honors CASAN_PREFLIGHT and blocks before model call" || fail "router preflight not enforced (rc=$RC)"
|
|
|
|
echo ""
|
|
echo "===== PREFLIGHT SUMMARY: PASS=$PASS FAIL=$FAIL ====="
|
|
[[ "$FAIL" -eq 0 ]] || exit 1
|