syntaxai/tdd.md · main · tools / sama-cli / cross-verify.sh
#!/usr/bin/env bash
# cross-verify.sh — run both SAMA v2 verifiers (TS via Bun, shell
# via this directory's `sama check`) and assert their verdicts
# agree. The /goal demands "verdicts identical" — comparing the
# overall pass-count per check is the right granularity: violation
# strings differ in wording but the agreement claim is about which
# checks pass/fail.
#
# Exit 0 if both produce 7/7 ✓ (or any identical N/7 verdict);
# exit 1 if they diverge. Designed for CI hook + manual use.
#
# Usage:
# tools/sama-cli/cross-verify.sh # verify the main repo
# tools/sama-cli/cross-verify.sh --self # verify tools/sama-cli/src
set -u
REPO_ROOT="$(cd "$(dirname "${BASH_SOURCE[0]:-$0}")/../.." && pwd)"
SAMA_CLI_DIR="$REPO_ROOT/tools/sama-cli"
mode="main"
if [ "${1:-}" = "--self" ]; then
mode="self"
fi
echo "── cross-verify: SAMA v2 (TS vs shell) — target: $mode ──"
ts_verdict=""
sh_verdict=""
if [ "$mode" = "main" ]; then
# Main repo: TS verifier runs against ./src with ./sama.profile.toml.
cd "$REPO_ROOT" || exit 2
ts_verdict="$(bun run "$SAMA_CLI_DIR/run-ts-verifier.ts" 2>&1 | tail -1)"
sh_verdict="$("$SAMA_CLI_DIR/sama" check --summary 2>&1 | grep -oE '[0-9]+ / 7' | tail -1)"
else
# Self mode: only the shell verifier can verify its own .sh tree —
# the TS verifier hard-codes .ts. So "agreement" here is one-sided
# (shell vs spec). We still emit the verdict for the record.
ts_verdict="(n/a — TS verifier is .ts-only)"
sh_verdict="$("$SAMA_CLI_DIR/sama" check \
--profile="$SAMA_CLI_DIR/sama.profile.toml" \
--src="$SAMA_CLI_DIR/src" --summary 2>&1 \
| grep -oE '[0-9]+ / 7' | tail -1)"
fi
# Extract just the verdict line from main mode if it has extra text.
sh_pass_count="$(echo "$sh_verdict" | grep -oE '^[0-9]+' | head -1)"
ts_pass_count="$(echo "$ts_verdict" | grep -oE '^[0-9]+' | head -1)"
printf " TS verifier : %s\n" "$ts_verdict"
printf " Shell verifier: %s\n" "$sh_verdict"
echo
if [ "$mode" = "self" ]; then
if [ "$sh_pass_count" = "7" ]; then
echo "✓ self-conformance: shell verifier 7/7 against its own source tree"
exit 0
else
echo "✗ self-conformance: shell verifier ${sh_verdict} — should be 7/7"
exit 1
fi
fi
if [ -z "$ts_pass_count" ] || [ -z "$sh_pass_count" ]; then
echo "✗ cross-verify: one verdict missing — TS=\`$ts_verdict\` shell=\`$sh_verdict\`"
exit 1
fi
if [ "$ts_pass_count" = "$sh_pass_count" ]; then
echo "✓ empirical agreement: both verifiers report ${sh_pass_count}/7"
if [ "$sh_pass_count" = "7" ]; then
echo " — two independent implementations of the SAMA v2 §4 spec agree on 7/7 ✓"
fi
exit 0
fi
echo "✗ DISAGREEMENT — TS says $ts_pass_count/7, shell says $sh_pass_count/7"
echo " This is a §6 evolution-policy pressure point: the spec admits"
echo " multiple readings here. Resolve via prose, update both verifiers,"
echo " re-run. See /sama/v2 §6 for the evolution mechanism."
exit 1