Files
CASAN/packages/casan-harness/tests/phase-preflight-tests.sh
T
thanhnvandClaude Opus 4.8 36a4812ef3 refactor(structure): promote app to repo root + remove redundant workspace cruft
Standard production layout: the OKR app (was nested under AINative_OKR_CASAN5/) is now
the repository root. No more wrapper directory.

- Promote AINative_OKR_CASAN5/* -> repo root (backend/ frontend/ packages/ apps/
  .specify/ docs/ infra/ nginx/ scripts/ + configs). Merge tool dirs: .gitea (kept the
  active deploy ci.yml, added harness-ci.yml + runbooks), .claude (agents/commands +
  launch.json), .github moved up.
- Remove redundant: 00_SUBMISSION_PACKAGE, scattered root notes (FPT_CASAN_Full.md,
  tu-tuong-casan.md, casan-tu-sinh..., casan_harness_assessment.md, source-review...,
  README_CASAN5_REFINED.md), casan-next-plans/ and optimize-docs/ (competition/planning
  artifacts — roadmap + design history preserved in git log / commit messages).
- Update all references to the old layout:
  - .gitea/workflows/{ci,harness-ci}.yml, .github/workflows/{ci,deploy}.yml:
    working-directory .; drop AINative_OKR_CASAN5/ prefix; .specify/{tests,scripts}
    -> packages/casan-harness/... (.specify/logs state kept)
  - .claude/launch.json, .gitea/*-runbook.md: path prefixes
  - CLAUDE.md, README.md: docs/input -> apps/okr/domain/input
  - policy-bundle.yaml: 8 policy paths -> packages/casan-harness/...; manifest re-signed
- secrets-scan.sh: fixture excludes -> new package/domain paths.

Full gate from the new root: PASS=64 FAIL=0 SKIP=3.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2026-07-08 13:26:36 +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="$CASAN_APP_ROOT"
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