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>
70 lines
2.6 KiB
Bash
Executable File
70 lines
2.6 KiB
Bash
Executable File
#!/usr/bin/env bash
|
|
set -euo pipefail
|
|
|
|
# CASAN H1 context validator.
|
|
# Before a sub-agent trusts pipeline-context.yaml, verify every referenced
|
|
# artifact / trace file actually exists on disk, and (optionally) is not
|
|
# staler than CASAN_CONTEXT_TTL_SECONDS relative to the context file itself.
|
|
# Catches renamed/deleted/missing artifacts before they cause a silent bad read.
|
|
#
|
|
# Usage: context-validate.sh <pipeline-context.yaml>
|
|
# Exit: 0 all good, 2 a referenced path is missing, 3 a referenced path is stale.
|
|
|
|
CTX="${1:-}"
|
|
if [[ -z "$CTX" || ! -f "$CTX" ]]; then
|
|
echo "Usage: context-validate.sh <pipeline-context.yaml>" >&2
|
|
exit 64
|
|
fi
|
|
|
|
CTX_DIR="$(cd "$(dirname "$CTX")" && pwd)"
|
|
# Resolve paths relative to the repo root (3 levels up from this script).
|
|
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
|
source "$SCRIPT_DIR/casan-paths.sh"
|
|
PROJECT_ROOT="$CASAN_APP_ROOT"
|
|
|
|
python - "$CTX" "$PROJECT_ROOT" "${CASAN_CONTEXT_TTL_SECONDS:-0}" <<'PY'
|
|
import os, re, sys, subprocess
|
|
|
|
ctx, root, ttl = sys.argv[1], sys.argv[2], int(sys.argv[3])
|
|
ctx_mtime = os.path.getmtime(ctx)
|
|
missing, stale, checked = [], [], 0
|
|
|
|
def path_exists(p):
|
|
"""Check existence using both Python and bash (handles MSYS2/Windows path mismatch)."""
|
|
if os.path.exists(p):
|
|
return True
|
|
# On Windows+MSYS2, /tmp maps to AppData/Local/Temp but Windows Python resolves it as C:\tmp.
|
|
# Fall back to bash test for absolute paths that Python can't find.
|
|
try:
|
|
r = subprocess.run(["bash", "-c", f"test -e {repr(p)}"], capture_output=True, timeout=3)
|
|
return r.returncode == 0
|
|
except Exception:
|
|
return False
|
|
|
|
with open(ctx, encoding="utf-8") as fh:
|
|
for line in fh:
|
|
m = re.match(r"\s*(?:artifact|trace_file|path|data-model|spec|plan):\s*(\S+)", line)
|
|
if not m:
|
|
continue
|
|
ref = m.group(1).strip().strip('"').strip("'")
|
|
if ref in ("", "null", "<from", "pipeline-context>"):
|
|
continue
|
|
if "<" in ref or ref.endswith(">"):
|
|
continue # unresolved template placeholder, not a concrete path
|
|
cand = ref if os.path.isabs(ref) else os.path.join(root, ref)
|
|
checked += 1
|
|
if not path_exists(cand):
|
|
missing.append(ref)
|
|
continue
|
|
if ttl > 0 and (ctx_mtime - os.path.getmtime(cand)) > ttl:
|
|
stale.append(ref)
|
|
|
|
if missing:
|
|
sys.stderr.write("CONTEXT_INVALID missing=%d: %s\n" % (len(missing), ", ".join(missing)))
|
|
raise SystemExit(2)
|
|
if stale:
|
|
sys.stderr.write("CONTEXT_STALE stale=%d: %s\n" % (len(stale), ", ".join(stale)))
|
|
raise SystemExit(3)
|
|
print(f"CONTEXT_VALID checked={checked} all referenced artifacts present")
|
|
PY
|