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>
64 lines
3.0 KiB
Bash
64 lines
3.0 KiB
Bash
#!/usr/bin/env bash
|
|
set -uo pipefail
|
|
|
|
# CASAN Plan-04 — self-improve core (harness-owned) tests.
|
|
# Deterministic. Proves proposals are generated from telemetry (dry-run, no writes),
|
|
# apply is refused without approval, and an approved apply goes through the governed
|
|
# settings store (audited).
|
|
|
|
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
|
source "$SCRIPT_DIR/../scripts/bash/casan-paths.sh"
|
|
PROJECT_ROOT="$(cd "$SCRIPT_DIR/../.." && pwd)"
|
|
SI="$CASAN_HARNESS_ROOT/scripts/bash/self-improve.py"
|
|
CPS="$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"
|
|
|
|
PASS=0; FAIL=0
|
|
pass() { echo "PASS: $1"; PASS=$((PASS + 1)); }
|
|
fail() { echo "FAIL: $1"; FAIL=$((FAIL + 1)); }
|
|
|
|
echo "===== Plan-04 self-improve core (harness) ====="
|
|
|
|
# metrics telemetry
|
|
cat > "$WORK/metrics.jsonl" <<'JSON'
|
|
{"step":"01-srs","cost_usd":0.02,"status":"ok"}
|
|
{"step":"10-impl","cost_usd":0.08,"status":"ok"}
|
|
JSON
|
|
cat > "$WORK/drift.json" <<'JSON'
|
|
{"drift": true, "entries": ["golden mismatch on 03-spec"]}
|
|
JSON
|
|
|
|
# 1) propose is dry-run (no store write) and yields a cost-cap proposal
|
|
python3 "$SI" propose --metrics "$WORK/metrics.jsonl" --drift "$WORK/drift.json" > "$WORK/props.json" 2>/dev/null
|
|
grep -q "P-COST-CAP" "$WORK/props.json" && pass "propose emits cost-cap proposal from telemetry" || fail "no cost-cap proposal"
|
|
[[ ! -f "$CASAN_CP_STORE_FILE" ]] && pass "propose is dry-run (no store written)" || fail "propose wrote store (not dry-run)"
|
|
|
|
# 2) drift → security-sensitive golden proposal present
|
|
grep -q "P-GOLDEN" "$WORK/props.json" && pass "drift yields review-required golden proposal" || fail "no golden proposal"
|
|
|
|
# 3) apply WITHOUT approval => deny (fail-able: proposal != application)
|
|
set +e
|
|
python3 "$SI" apply --proposals "$WORK/props.json" --id P-COST-CAP >/dev/null 2>"$WORK/3.err"; RC=$?
|
|
set -e 2>/dev/null || true
|
|
[[ "$RC" -eq 1 ]] && grep -q "APPROVAL_REQUIRED" "$WORK/3.err" \
|
|
&& pass "apply refused without approval" || fail "apply not refused without approval (rc=$RC)"
|
|
|
|
# 4) apply WITH approval => governed set recorded in store
|
|
python3 "$SI" apply --proposals "$WORK/props.json" --id P-COST-CAP --approval human-ok >/dev/null 2>&1 \
|
|
&& pass "approved apply succeeds" || fail "approved apply failed"
|
|
VAL="$(python3 "$CPS" get cost.absolute_cap_usd 2>/dev/null | python3 -c 'import json,sys;print(json.load(sys.stdin)["value"])' 2>/dev/null)"
|
|
[[ "$VAL" == "0.12" ]] && pass "applied change persisted via governed store (value=$VAL)" || fail "governed store value unexpected (value=$VAL)"
|
|
|
|
# 5) security-sensitive golden proposal without approval => deny
|
|
set +e
|
|
python3 "$SI" apply --proposals "$WORK/props.json" --id P-GOLDEN >/dev/null 2>"$WORK/5.err"; RC=$?
|
|
set -e 2>/dev/null || true
|
|
[[ "$RC" -eq 1 ]] && grep -q "APPROVAL_REQUIRED" "$WORK/5.err" \
|
|
&& pass "sensitive proposal refused without approval" || fail "sensitive proposal not refused (rc=$RC)"
|
|
|
|
echo ""
|
|
echo "===== SELF-IMPROVE SUMMARY: PASS=$PASS FAIL=$FAIL ====="
|
|
[[ "$FAIL" -eq 0 ]] || exit 1
|