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>
72 lines
2.6 KiB
Bash
Executable File
72 lines
2.6 KiB
Bash
Executable File
#!/usr/bin/env bash
|
|
set -euo pipefail
|
|
|
|
# CASAN H2 tool-input validation.
|
|
# Validates a tool-call input JSON against a JSON-Schema-style spec
|
|
# (required fields + property types + additionalProperties:false).
|
|
# Stdlib-only — supports type, required, properties, additionalProperties,
|
|
# enum. NOT a full JSON Schema engine (no $ref, no nested object recursion
|
|
# beyond one level); scoped deliberately and labeled as such.
|
|
#
|
|
# Usage: validate-tool-input.sh <schema.json> <input.json>
|
|
# Exit: 0 valid, 2 invalid, 64 usage error.
|
|
|
|
SCHEMA="${1:-}"
|
|
INPUT="${2:-}"
|
|
if [[ -z "$SCHEMA" || -z "$INPUT" || ! -f "$SCHEMA" || ! -f "$INPUT" ]]; then
|
|
echo "Usage: validate-tool-input.sh <schema.json> <input.json>" >&2
|
|
exit 64
|
|
fi
|
|
|
|
python - "$SCHEMA" "$INPUT" <<'PY'
|
|
import json, sys
|
|
|
|
schema = json.load(open(sys.argv[1], encoding="utf-8"))
|
|
data = json.load(open(sys.argv[2], encoding="utf-8"))
|
|
|
|
TYPES = {
|
|
"string": str, "integer": int, "number": (int, float),
|
|
"boolean": bool, "object": dict, "array": list,
|
|
}
|
|
errors = []
|
|
|
|
|
|
# SEC-15: validate RECURSIVELY. Previously only the top level was checked, so a
|
|
# nested object could smuggle wrong types / unexpected fields past the gate.
|
|
def validate(schema, data, path):
|
|
expected = schema.get("type")
|
|
py = TYPES.get(expected)
|
|
if py and (not isinstance(data, py)
|
|
or (expected in ("integer", "number") and isinstance(data, bool))):
|
|
errors.append(f"{path or 'root'}: expected {expected}")
|
|
return
|
|
if "enum" in schema and data not in schema["enum"]:
|
|
errors.append(f"{path or 'root'}: not in enum {schema['enum']}")
|
|
|
|
if expected == "object" and isinstance(data, dict):
|
|
props = schema.get("properties", {})
|
|
for field in schema.get("required", []):
|
|
if field not in data:
|
|
errors.append(f"{path or 'root'}: missing required field: {field}")
|
|
if schema.get("additionalProperties") is False:
|
|
for key in data:
|
|
if key not in props:
|
|
errors.append(f"{path or 'root'}: unexpected field: {key}")
|
|
for key, spec in props.items():
|
|
if key in data:
|
|
validate(spec, data[key], f"{path}.{key}" if path else key)
|
|
elif expected == "array" and isinstance(data, list):
|
|
item_spec = schema.get("items")
|
|
if isinstance(item_spec, dict):
|
|
for i, item in enumerate(data):
|
|
validate(item_spec, item, f"{path}[{i}]")
|
|
|
|
|
|
validate(schema, data, "")
|
|
|
|
if errors:
|
|
sys.stderr.write("TOOL_INPUT_INVALID " + "; ".join(errors) + "\n")
|
|
raise SystemExit(2)
|
|
print("TOOL_INPUT_VALID")
|
|
PY
|