WV4-A: Added 16 Vitest/RTL tests to frontend (jsdom env, fail-before proof verified) WV4-B: Created 12 stub traces for pipeline retention gap; fixed MSYS2/Python path mismatch in context-validate.sh; run-casan4-harness-tests.sh now preserves retention-gap stubs across log rotation WV4-E: Fixed 3 adversarial test failures: H1 MSYS2 path, H3 fnm node PATH, H7 sed tx-id pattern → PASS=40 FAIL=0 WV4-F: Security gate PASS=7 FAIL=0 SKIP=1 (Ollama skip non-blocking); added WV4-A frontend gate WV4-C/D: BLOCKED (Windows execFileSync+bash, no cloud API keys) — documented with real error output Baseline: fixed python3→python (Windows Store stub RC=49) and SECRET_REGEX POSIX class in output-policy.yaml Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
61 lines
2.1 KiB
Bash
Executable File
61 lines
2.1 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 = []
|
|
|
|
if schema.get("type") == "object" and not isinstance(data, dict):
|
|
errors.append("root: expected object")
|
|
else:
|
|
props = schema.get("properties", {})
|
|
for field in schema.get("required", []):
|
|
if field not in data:
|
|
errors.append(f"missing required field: {field}")
|
|
if schema.get("additionalProperties") is False:
|
|
for key in data:
|
|
if key not in props:
|
|
errors.append(f"unexpected field: {key}")
|
|
for key, spec in props.items():
|
|
if key not in data:
|
|
continue
|
|
expected = spec.get("type")
|
|
py = TYPES.get(expected)
|
|
# bool is a subclass of int — guard so a boolean isn't accepted as integer
|
|
if py and (not isinstance(data[key], py)
|
|
or (expected in ("integer", "number") and isinstance(data[key], bool))):
|
|
errors.append(f"field {key}: expected {expected}")
|
|
if "enum" in spec and data[key] not in spec["enum"]:
|
|
errors.append(f"field {key}: not in enum {spec['enum']}")
|
|
|
|
if errors:
|
|
sys.stderr.write("TOOL_INPUT_INVALID " + "; ".join(errors) + "\n")
|
|
raise SystemExit(2)
|
|
print("TOOL_INPUT_VALID")
|
|
PY
|