Files
LithosAnanke/scripts/test_check_protocol.sh
T
Claude 7a43cc3514 ci: check_protocol.sh -- a commit carries passing protocol evidence for its tree (#135)
scripts/check_protocol.sh [<rev>]: refused (exit 1) unless <rev> carries a
logs/<TS>/PROTOCOL.md naming a commit whose protocol passed on a clean tree,
and that commit differs from <rev> only in the evidence (logs/ and
experiments/bare_metal/runs/, committed after the run). Any other change since
makes the evidence stale: the protocol is run again.

scripts/test_check_protocol.sh, written first and seen to fail (8 of 8, and
tightened so a missing script is not taken for a refusal): no protocol, stale,
failed, dirty, unknown commit -- refused; fresh, fresh among stale ones, other
files in logs/ -- passes. 8 of 8 pass.

Not yet wired into acceptance.yml: that comes with nightly.sh protocol.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_017RzZgrf7V7Zk2iczBXDRbm
2026-11-12 00:07:04 +00:00

68 lines
3.0 KiB
Bash
Executable File

#!/usr/bin/env bash
# SPDX-License-Identifier: LicenseRef-Starship-1.0
# Copyright (c) 2023-2026 Robert A. James
# test_check_protocol.sh -- the tests of scripts/check_protocol.sh (#135), in a scratch git
# repository: a commit is refused without a PROTOCOL.md for its tree, and passes with one.
#
# Prints PASS:/FAIL: per check and RESULT:; exits 0 only if every check passes.
set -uo pipefail
CHECK="$(cd "$(dirname "$0")" && pwd)/check_protocol.sh"
T=$(mktemp -d)
trap 'rm -rf "$T"' EXIT
ok=1
expect() { # expect <pass|refuse> "what" -- runs the check on HEAD of the scratch repository
local want="$1" what="$2" out rc
out=$(cd "$T" && bash "$CHECK" HEAD 2>&1); rc=$?
# a refusal is exit 1 and says so -- any other failure (no script, a crash) is not a refusal
if { [ "$want" = pass ] && [ $rc -eq 0 ]; } ||
{ [ "$want" = refuse ] && [ $rc -eq 1 ] && grep -q "refused" <<<"$out"; }; then
echo "PASS: $what"
else
echo "FAIL: $what (exit $rc)"; printf ' %s\n' "$out" | head -5; ok=0
fi
}
protocol() { # protocol <dir> <commit> <clean|dirty> <PASS|FAIL> -- a PROTOCOL.md as nightly.sh writes it
mkdir -p "$T/logs/$1"
printf '%s\n' "# Protocol for ${2:0:8}" "" "- Commit: $2" "- Tree: $3" "- Result: $4" > "$T/logs/$1/PROTOCOL.md"
}
commit() { (cd "$T" && git add -A && git commit -q -m "$1"); }
(cd "$T" && git init -q && git config user.email t@example.invalid && git config user.name test &&
git config commit.gpgsign false)
echo "int main(void) { return 0; }" > "$T/main.c"; commit "the code"
tested=$(cd "$T" && git rev-parse HEAD)
expect refuse "no PROTOCOL.md: refused"
protocol 20261112-010000 "$tested" clean PASS
mkdir -p "$T/logs/20261112-010000/amd64" "$T/experiments/bare_metal/runs"
echo "serial" > "$T/logs/20261112-010000/amd64/qemu-amd64.log"
: > "$T/experiments/bare_metal/runs/doe-amd64-20261112-010000.csv"
commit "the evidence"
expect pass "the evidence for the code, committed after it (logs/ and runs/ only): passes"
echo "/* a change */" >> "$T/main.c"; commit "a change after the run"
expect refuse "a change outside the evidence after the run: refused as stale"
newer=$(cd "$T" && git rev-parse HEAD)
protocol 20261112-020000 "$newer" clean FAIL; commit "a failed protocol"
expect refuse "the protocol for the head failed: refused"
protocol 20261112-030000 "$newer" dirty PASS; commit "a protocol run on a dirty tree"
expect refuse "the protocol ran on a dirty tree: refused"
protocol 20261112-040000 0123456789abcdef0123456789abcdef01234567 clean PASS; commit "a protocol for no commit"
expect refuse "the protocol names a commit this repository does not have: refused"
protocol 20261112-050000 "$newer" clean PASS; commit "the evidence for the change"
expect pass "a fresh protocol among stale and failed ones: passes"
printf '%s\n' "# not a protocol" > "$T/logs/20261112-060000.md"; commit "an unrelated note in logs/"
expect pass "files in logs/ that are not PROTOCOL.md do not matter: passes"
echo "RESULT: $([ $ok = 1 ] && echo PASS || echo FAIL)"
[ $ok = 1 ]