Files
CASAN/AINative_OKR_CASAN5/packages/casan-harness/tests/phase-sec19-tests.sh
T
thanhnvandClaude Opus 4.8 3adc48ed82 feat(plan-01): Phase 4a — make harness location-independent (facade-free capable)
Resolve every root by marker walk-up instead of a fixed depth that only lands on the
app via the .specify compat symlink, so the harness runs correctly when invoked by its
real packages/casan-harness path — proven by a full gate run via that path: 64/0/0.

- 95 scripts/tests: PROJECT_ROOT/ROOT "$SCRIPT_DIR/../.."-style computations -> $CASAN_APP_ROOT.
- 6 leaf scripts (infra-lab, context-validate, secrets-scan, path-guard, toolchain-verify,
  phase2-sourcegen) now source casan-paths + use CASAN_APP_ROOT.
- run-casan4: source casan-paths as a package sibling (facade-independent), PROJECT_ROOT=CASAN_APP_ROOT.
- 8 Python files: project_root()/REPO_ROOT/bundle_root walk UP for the .specify marker
  (control-plane-settings, loop_common, model-call, context-compress, test-integrity,
  bundle-integrity, traceability-matrix; generate-* fixed earlier).
- evidence-pack-build.py + traceability-matrix.py: domain refs -> apps/okr/domain
  (input/, corpus/redteam-vectors.jsonl, traceability-map.json).
- ci-harness-gate.sh: export CASAN_TESTS_DIR/CASAN_TEST_MANIFEST/CASAN_BUNDLE_ROOT so the
  integrity Python resolves via the harness root regardless of invocation path; ROOT=CASAN_APP_ROOT.
- Remove the domain compat symlinks from packages/casan-harness/security (redteam-corpus,
  redteam-vectors, benign-corpus) — packages now holds NO domain data.

Both invocation paths pass (compat facade still present): .specify/... and packages/...

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2026-07-08 10:50:50 +09:00

60 lines
2.4 KiB
Bash

#!/usr/bin/env bash
set -uo pipefail
# CASAN Plan-16 SEC-19 (ARCH-05) — atomic + locked control-plane writes.
#
# The control-plane store did an unlocked, non-atomic load→modify→save, so two
# concurrent `set`/`rollback` runs could lose a write or fork the audit hash chain.
# Now the critical section holds a POSIX flock and the store is written atomically
# (tmp + rename). Proves concurrent writes on distinct keys all survive and the
# chain still verifies, with no torn/partial store file.
#
# Deterministic; hermetic (temp store + temp keys).
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
source "$SCRIPT_DIR/../scripts/bash/casan-paths.sh"
PROJECT_ROOT="$CASAN_APP_ROOT"
CP="$CASAN_HARNESS_ROOT/scripts/bash/control-plane-settings.py"
WORK="$(mktemp -d)"
trap 'rm -rf "$WORK"' EXIT
export CASAN_CP_STORE_FILE="$WORK/store.json"
export CASAN_CP_KEY_DIR="$WORK/keys"
export CASAN_CP_PUB="$WORK/pub.pem"
PASS=0; FAIL=0
pass() { echo "PASS: $1"; PASS=$((PASS + 1)); }
fail() { echo "FAIL: $1"; FAIL=$((FAIL + 1)); }
echo "===== Plan-16 SEC-19: atomic + locked control-plane writes ====="
# Fire four concurrent writers on distinct non-sensitive keys.
python3 "$CP" set compression.enabled true --actor a --reason r >/dev/null 2>&1 &
python3 "$CP" set compression.mode structural --actor a --reason r >/dev/null 2>&1 &
python3 "$CP" set cost.absolute_cap_usd 5 --actor a --reason r >/dev/null 2>&1 &
python3 "$CP" set model.primary "ollama:ornith" --actor a --reason r >/dev/null 2>&1 &
wait
COUNT="$(python3 "$CP" get-all | python3 -c 'import json,sys; print(len(json.load(sys.stdin)))' 2>/dev/null)"
[[ "$COUNT" == "4" ]] \
&& pass "all 4 concurrent writes survived (no lost update)" \
|| fail "lost update under concurrency (only $COUNT/4 keys present)"
python3 "$CP" verify-audit >/dev/null 2>&1 \
&& pass "audit chain intact after concurrent writes" \
|| fail "audit chain forked/broken under concurrency"
# The store must always be valid JSON (atomic rename ⇒ never torn) and no tmp left.
python3 -c "import json; json.load(open('$CASAN_CP_STORE_FILE'))" 2>/dev/null \
&& pass "store file is valid JSON (atomic write, not torn)" \
|| fail "store file torn / invalid JSON"
if ls "$WORK"/*.tmp >/dev/null 2>&1; then
fail "leftover .tmp file (atomic rename incomplete)"
else
pass "no leftover .tmp file"
fi
echo ""
echo "===== SEC-19 SUMMARY: PASS=$PASS FAIL=$FAIL ====="
[[ "$FAIL" -eq 0 ]] || exit 1