Files
CASAN/AINative_OKR_CASAN5/packages/casan-harness/tests/phase-preflight-tests.sh
T
thanhnvandClaude Opus 4.8 664bd1f00c 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>
2026-07-08 00:06:00 +09:00

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