From d0dd048667bc49f8e569da68d58d18f853323d5e Mon Sep 17 00:00:00 2001 From: Drake Stapleton Date: Thu, 1 Oct 2026 22:14:28 -0500 Subject: [PATCH 1/5] chip_run: shared chip-run module + refusal self-test [host NOT_RUN] Co-Authored-By: Claude Sonnet 5.5 --- Makefile | 6 ++ tests/test_chip_run.sh | 189 +++++++++++++++++++++++++++++++++++++++++ tools/chip_run.sh | 178 ++++++++++++++++++++++++++++++++++++++ 3 files changed, 373 insertions(+) create mode 100755 tests/test_chip_run.sh create mode 100755 tools/chip_run.sh diff --git a/Makefile b/Makefile index 248d9da70..4e8a5fdf8 100644 --- a/Makefile +++ b/Makefile @@ -166,6 +166,12 @@ test-m19r-qualify: test-gate14-combine: tools/test_gate14_combine.sh +# Host-only self-test of the shared chip-run module (tools/chip_run.sh): every +# refusal path with fake binaries. No GPU. +.PHONY: test-chip-run +test-chip-run: + tests/test_chip_run.sh + # Gate 5 (OMEGA-NUMERIC-0), CPU tiers only: reference, CPU parity, provenance # and negative tests. Opens no device. The GB10 tier and the receipt come # from tests/run_numeric_gates.sh on the chip. Exits nonzero while any gate diff --git a/tests/test_chip_run.sh b/tests/test_chip_run.sh new file mode 100755 index 000000000..52e80aff0 --- /dev/null +++ b/tests/test_chip_run.sh @@ -0,0 +1,189 @@ +#!/bin/bash +# tests/test_chip_run.sh -- host-only self-test of tools/chip_run.sh. No GPU, no chip sources. +# Builds a throwaway fake omega and fake physics (git repos) in a mktemp dir and runs the module +# against tiny fake chip binaries (compiled with host gcc from 3-20 line C files, because the +# module's nm check needs real ELF files). Prints one line per case and a final +# "CHIP_RUN_SELFTEST: PASS" or "CHIP_RUN_SELFTEST: FAIL"; exits nonzero on any failure. +# tests/test_chip_run.sh run every case +# tests/test_chip_run.sh --mutants mutation check: for each "# REFUSAL:" line in the +# module, delete that line in a temp copy and require this test to report "FAIL :" +# (MODULE=path runs the test against any copy of the module; do this by hand to try a mutant) +# Needs: bash git jq gcc nm flock coreutils. +set -u +TESTS_DIR=$(cd -P "$(dirname "${BASH_SOURCE[0]}")" && pwd) +SRC_MODULE=${MODULE:-$TESTS_DIR/../tools/chip_run.sh} + +if [ "${1:-}" = --mutants ]; then + M=$(mktemp -d) || exit 1; trap 'rm -rf "$M"' EXIT; bad=0; n=0 + for id in $(grep -o '# REFUSAL:[a-z_]*$' "$SRC_MODULE" | sed 's/.*://' | sort -u); do + n=$((n + 1)) + sed "s/^.*# REFUSAL:$id\$/:/" "$SRC_MODULE" > "$M/chip_run.sh" + cmp -s "$M/chip_run.sh" "$SRC_MODULE" && { echo "NOCHANGE $id"; bad=1; continue; } + MODULE="$M/chip_run.sh" bash "${BASH_SOURCE[0]}" > "$M/out" 2>&1 + if grep -q "^FAIL $id:" "$M/out"; then echo "killed $id"; else echo "SURVIVED $id"; bad=1; fi + done + [ "$n" -gt 0 ] || bad=1 + [ "$bad" = 0 ] && { echo "CHIP_RUN_MUTANTS: PASS ($n mutants killed)"; exit 0; } + echo "CHIP_RUN_MUTANTS: FAIL"; exit 1 +fi + +T=$(mktemp -d) || exit 1 +trap 'rm -rf "$T"' EXIT +mkdir -p "$T/tmp" "$T/bin" +PHYS=$T/physics; OM=$T/omega; FLAG=$T/flag; LOCK=$T/gpu.lock; OUT=$T/out.txt; BAD=0; RC=0 +g() { local d=$1; shift; git -C "$d" -c user.email=t@t -c user.name=t -c commit.gpgsign=false "$@"; } + +# fake binaries +cat > "$T/ok.c" <<'EOC' +#include +#include +#include +int main(int argc, char **argv) { + const char *m = getenv("FAKE_MODE"); if (!m) m = "pass"; + printf("fake chip args=%d\n", argc - 1); + if (getenv("FAKE_CMD") && system(getenv("FAKE_CMD")) != 0) return 9; + if (!strcmp(m, "silent")) return 0; + if (!strcmp(m, "fail")) { printf("RESULT chip x ok=false\nVERDICT FAIL\n"); return 0; } + if (!strcmp(m, "passrc")) { printf("VERDICT PASS\n"); return 3; } + printf("RESULT chip x ok=true\nVERDICT PASS\n"); + return 0; +} +EOC +printf '#include \n#include \nint main(void){ volatile float x = 2.0f; printf("VERDICT PASS %%f\\n", expf(x)); return 0; }\n' > "$T/libm.c" +printf 'extern int cuInit(unsigned) __attribute__((weak));\n#include \nint main(void){ if (cuInit) cuInit(0); puts("VERDICT PASS"); return 0; }\n' > "$T/cuda.c" +gcc -O0 -o "$T/bin/ok" "$T/ok.c" && gcc -O0 -fno-builtin -o "$T/bin/libm" "$T/libm.c" -lm && gcc -O0 -o "$T/bin/cuda" "$T/cuda.c" \ + || { echo "FAIL setup: host gcc could not build the fake binaries"; echo "CHIP_RUN_SELFTEST: FAIL"; exit 1; } +printf '#!/bin/sh\necho VERDICT PASS\n' > "$T/bin/script"; chmod +x "$T/bin/script" + +# fake physics (pinned) and fake omega (clean, with the module under test) +mkdir -p "$PHYS/nvrm" "$OM/tools" "$OM/src" +git init -q "$PHYS" && echo "/* fake */" > "$PHYS/nvrm/nvrm.c" && g "$PHYS" add -A && g "$PHYS" commit -q -m physics +PIN=$(git -C "$PHYS" rev-parse HEAD) +git init -q "$OM" && cp "$SRC_MODULE" "$OM/tools/chip_run.sh" && echo "$PIN" > "$OM/physics.lock" && echo "/* fake */" > "$OM/src/a.c" \ + && g "$OM" add -A && g "$OM" commit -q -m omega +OM_HEAD=$(git -C "$OM" rev-parse HEAD) + +mkman() { cat > "$1" <&- +} +# cr ID [NAME=VALUE ...] -- [module args]: run the module from outside both trees +cr() { + local id=$1; shift; local extra=() + while [ "$1" != -- ]; do extra+=("$1"); shift; done; shift + ( cd "$T" && env -u PHYSICS_DIR -u PHYSICS CHIPRUN_SELFTEST=1 CHIPRUN_PREBUILT_BIN="$T/bin/ok" CHIPRUN_QUIET_FLAG="$FLAG" \ + CHIPRUN_GPU_LOCK="$LOCK" CHIPRUN_EST_LOAD_CMD=true FAKE_MODE=pass TMPDIR="$T/tmp" "${extra[@]}" \ + bash "$OM/tools/chip_run.sh" "$CRMAN" --evidence-dir "$T/ev-$id" "$@" ) > "$OUT" 2>&1 + RC=$? +} +bad() { echo "FAIL $1: $2"; sed 's/^/ | /' "$OUT" | head -8; BAD=$((BAD + 1)); } +# expect ID RC REGEX: exit code and a matching output line +expect() { + if [ "$RC" = "$2" ] && grep -Eq -- "$3" "$OUT"; then echo "ok $1 (exit $RC)"; else bad "$1" "exit $RC, wanted $2 and /$3/"; fi +} +# assert ID DESC cmd...: extra condition for a case +assert() { local id=$1 d=$2; shift 2; if "$@"; then echo "ok $id: $d"; else bad "$id" "$d"; fi; } +no_flag() { [ ! -e "$FLAG" ]; } +flag_is_other() { [ "$(cat "$FLAG" 2>/dev/null)" = other ]; } +receipt_verdict() { [ "$(jq -r .verdict "$T"/ev-"$1"/*.json 2>/dev/null)" = "$2" ]; } + +reset_world; cr selftest_override CHIPRUN_SELFTEST=0 -- "${PD[@]}" +expect selftest_override 2 '^REFUSED: .*self-test override' +reset_world; cr no_physics -- --physics-dir "$T/nonexistent" +expect no_physics 2 '^REFUSED: no physics checkout' +reset_world; CRMAN=$T/m-map.sh cr refuse_map -- --physics-dir "$T/nonexistent" +expect refuse_map 1 '^VERDICT NOT_RUN$'; CRMAN=$T/m.sh +reset_world; g "$PHYS" commit -q --allow-empty -m moved; cr physics_pin -- "${PD[@]}" +expect physics_pin 2 '^REFUSED: physics checkout is at .*physics.lock pins' +reset_world; echo x > "$PHYS/junk"; cr physics_dirty -- "${PD[@]}" +expect physics_dirty 2 '^REFUSED: physics checkout .* is dirty' +reset_world; echo x > "$OM/junk"; cr omega_dirty -- "${PD[@]}" +expect omega_dirty 2 '^REFUSED: omega tree .* is dirty' +reset_world; cr evidence_inside -- "${PD[@]}" --evidence-dir "$OM/evid" +expect evidence_inside 2 '^REFUSED: evidence dir .* inside a candidate tree' +reset_world; cr evidence_inside_physics -- "${PD[@]}" --evidence-dir "$PHYS/evid" +expect evidence_inside_physics 2 '^REFUSED: evidence dir .* inside a candidate tree' +reset_world; echo other > "$FLAG"; cr quiet_flag -- "${PD[@]}" +expect quiet_flag 2 '^REFUSED: quiet flag is up: other' +assert quiet_flag "a flag that is not ours is left alone" flag_is_other +reset_world; cr est_load CHIPRUN_EST_LOAD_CMD='echo 4242' -- "${PD[@]}" +expect est_load 2 '^REFUSED: an est_load process is running' +reset_world; exec 8> "$LOCK"; flock -x 8; cr gpu_lock -- "${PD[@]}"; exec 8>&- +expect gpu_lock 2 '^REFUSED: GPU lock .* is held' +assert gpu_lock "the quiet flag we raised is dropped on refusal" no_flag +reset_world; CRMAN=$T/m-hostfail.sh cr host_tier -- "${PD[@]}" +expect host_tier 2 '^REFUSED: host tier failed'; CRMAN=$T/m.sh +reset_world; cr nm_unreadable CHIPRUN_PREBUILT_BIN="$T/bin/script" -- "${PD[@]}" +expect nm_unreadable 2 '^REFUSED: nm cannot read' +reset_world; cr libm CHIPRUN_PREBUILT_BIN="$T/bin/libm" -- "${PD[@]}" +expect libm 2 '^REFUSED: libm math symbols' +reset_world; cr cuda CHIPRUN_PREBUILT_BIN="$T/bin/cuda" -- "${PD[@]}" +expect cuda 2 '^REFUSED: CUDA symbols' +reset_world; cr rc_nonzero FAKE_MODE=passrc -- "${PD[@]}" +expect rc_nonzero 1 '^CHIP_RUN: FAIL binary exit status 3' +reset_world; cr no_verdict FAKE_MODE=silent -- "${PD[@]}" +expect no_verdict 1 '^CHIP_RUN: FAIL no verdict line' +reset_world; cr fail_verdict FAKE_MODE=fail -- "${PD[@]}" +expect fail_verdict 1 '^CHIP_RUN: FAIL last verdict line does not match PASS_LINE' +assert fail_verdict "a FAIL receipt is still written" receipt_verdict fail_verdict FAIL +reset_world; cr omega_dirty_after FAKE_CMD="touch $OM/dirt" -- "${PD[@]}" +expect omega_dirty_after 1 '^CHIP_RUN: FAIL omega tree dirty after run' +reset_world; cr physics_dirty_after FAKE_CMD="touch $PHYS/dirt" -- "${PD[@]}" +expect physics_dirty_after 1 '^CHIP_RUN: FAIL physics tree dirty after run' +reset_world; cr head_moved FAKE_CMD="git -C $OM -c user.email=t@t -c user.name=t -c commit.gpgsign=false commit -q --allow-empty -m x" -- "${PD[@]}" +expect head_moved 1 '^CHIP_RUN: FAIL a HEAD moved' + +# physics dir resolution order: flag, PHYSICS_DIR, PHYSICS +reset_world; cr order_env_dir PHYSICS="$T/nonexistent" PHYSICS_DIR="$PHYS" -- +expect order_env_dir 0 '^CHIP_RUN: PASS' +reset_world; cr order_flag PHYSICS_DIR="$T/nonexistent" -- "${PD[@]}" +expect order_flag 0 '^CHIP_RUN: PASS' +reset_world; cr order_env_physics PHYSICS="$PHYS" -- +expect order_env_physics 0 '^CHIP_RUN: PASS' +# optional steps off: flag up and lock held do not matter +reset_world; echo other > "$FLAG"; exec 8> "$LOCK"; flock -x 8; CRMAN=$T/m-off.sh cr optional_off -- "${PD[@]}"; exec 8>&-; CRMAN=$T/m.sh +expect optional_off 0 '^CHIP_RUN: PASS' +assert optional_off "a flag we never raised is untouched" flag_is_other + +# happy path and receipt +reset_world; cr happy -- "${PD[@]}" -- --x 1 +expect happy 0 '^VERDICT PASS$' +grep -q '^CHIP_RUN: PASS$' "$OUT" || bad happy "no final CHIP_RUN: PASS line" +assert happy "quiet flag dropped after the run" no_flag +R=$(ls "$T"/ev-happy/*.json 2>/dev/null | head -1) +assert happy "exactly one receipt" test "$(ls "$T"/ev-happy/*.json 2>/dev/null | wc -l)" = 1 +assert happy "receipt mode is 0444" test "$(stat -c %a "$R" 2>/dev/null)" = 444 +assert happy "receipt name is the sha256 of its content" test "$(sha256sum "$R" 2>/dev/null | cut -d' ' -f1).json" = "$(basename "$R")" +for f in gate owner omega_commit omega_tree_clean_before omega_tree_clean_after omega_commit_unchanged_after physics_commit physics_lock_pin \ + physics_tree_clean_before physics_tree_clean_after physics_commit_unchanged_after binary_sha256 chip_log_sha256 run_args host_tier \ + verdict_lines chip_exit_status started_utc finished_utc verdict reason extra_marker; do + assert happy "receipt has field $f" jq -e --arg f "$f" 'has($f)' "$R" > /dev/null +done +assert happy "receipt verdict PASS, run_args from the command line" jq -e '.verdict == "PASS" and .run_args == ["--x","1"] and .host_tier == "host-tier-ok" and .omega_commit == "'"$OM_HEAD"'"' "$R" > /dev/null +LS=$(jq -r .chip_log_sha256 "$R" 2>/dev/null) +assert happy "log blob exists, mode 0444, named by its sha256" test "$(stat -c %a "$T/ev-happy/blobs/$LS.log" 2>/dev/null)" = 444 -a "$(sha256sum "$T/ev-happy/blobs/$LS.log" 2>/dev/null | cut -d' ' -f1)" = "$LS" + +if [ "$BAD" = 0 ]; then echo "CHIP_RUN_SELFTEST: PASS"; exit 0; fi +echo "CHIP_RUN_SELFTEST: FAIL ($BAD)"; exit 1 diff --git a/tools/chip_run.sh b/tools/chip_run.sh new file mode 100755 index 000000000..7b2c8a67f --- /dev/null +++ b/tools/chip_run.sh @@ -0,0 +1,178 @@ +#!/bin/bash +# chip_run.sh MANIFEST [--physics-dir DIR] [--evidence-dir DIR] [-- gate args] +# Run one chip binary under evidence. The one place that knows how (ground truth: +# tools/run_numeric_transc_gate.sh, tools/run_unwritten_trap.sh, tests/run_reduce_chip.sh). +# MANIFEST is shell syntax setting: GATE TEST_SOURCE SOURCES EXTRA_BUILD_SOURCES (relative +# to the omega root, may use $PHYSICS and $HERE) RUN_ARGS VERDICT_RE PASS_LINE OWNER +# EVIDENCE_DIR RAISE_QUIET TAKE_GPU_LOCK REFUSE_DIRTY_OMEGA (default 1) REFUSE_EXIT +# (default 2) REFUSE_VERDICT_LINE (default "CHIP_RUN: NOT_RUN"), hooks HOST_TIER_CMD +# (run first; nonzero refuses) and RECEIPT_EXTRA_JQ (jq filter on the receipt, $log = chip log). +# Physics dir, first match wins: --physics-dir, $PHYSICS_DIR, $PHYSICS, ~/workspace/physics. +# Exit: 0 PASS; 1 FAIL (binary ran, verdict not PASS or tree changed); REFUSE_EXIT (default 2, +# as run_unwritten_trap.sh) after printing "REFUSED: why" and REFUSE_VERDICT_LINE. A gate that +# keeps transc semantics sets REFUSE_EXIT=1 REFUSE_VERDICT_LINE="VERDICT NOT_RUN". +# REFUSES (nothing is run): bad usage or manifest; test override env without CHIPRUN_SELFTEST=1; +# no physics checkout; physics not at the physics.lock pin; physics dirty; omega dirty (if +# REFUSE_DIRTY_OMEGA=1); evidence dir inside omega or physics; quiet flag already up (if +# RAISE_QUIET=1); an est_load process; the GPU lock held (if TAKE_GPU_LOCK=1); HOST_TIER_CMD +# failing; a missing source; gcc failing; nm unreadable; libm math or CUDA symbols in the binary. +# FAILS (ran to the end, receipt written): nonzero exit; no line matching VERDICT_RE; last such +# line not matching PASS_LINE; omega (if REFUSE_DIRTY_OMEGA=1) or physics dirty after the run; +# either HEAD moved. Never killed, never timed out. Quiet flag dropped only if still ours. +# RECEIPT /.json, mode 0444, noclobber, plus blobs/.log. +# Fields: gate owner omega_commit omega_tree_clean_before omega_tree_clean_after +# omega_commit_unchanged_after physics_commit physics_lock_pin physics_tree_clean_before +# physics_tree_clean_after physics_commit_unchanged_after binary_sha256 chip_log_sha256 +# run_args host_tier verdict_lines chip_exit_status started_utc finished_utc verdict reason +# (plus whatever RECEIPT_EXTRA_JQ adds). +# Test seam (only with CHIPRUN_SELFTEST=1): CHIPRUN_PREBUILT_BIN CHIPRUN_QUIET_FLAG +# CHIPRUN_GPU_LOCK CHIPRUN_EST_LOAD_CMD. Mutation check: each refusal line ends in +# "# REFUSAL:"; tests/test_chip_run.sh --mutants deletes each one and needs case to FAIL. +# Shell + coreutils + git + jq + gcc + nm + flock. No Python. +set -u +HERE=$(cd -P "$(dirname "${BASH_SOURCE[0]}")/.." && pwd) +NVDIR=third_party/nvidia-open-580.173.02 # the one definition of the NVIDIA header tree +QUIET_FLAG=${CHIPRUN_QUIET_FLAG:-$HOME/workspace/.spark-quiet} +GPU_LOCK=${CHIPRUN_GPU_LOCK:-/tmp/aien-gb10.lock} +EST_LOAD_CMD=${CHIPRUN_EST_LOAD_CMD:-pgrep est_load} +FLAG_MINE=0; FLAG_TEXT=""; FAIL_REASON="" +REFUSE_EXIT=2; REFUSE_VERDICT_LINE="CHIP_RUN: NOT_RUN" +refuse() { echo "REFUSED: $*"; echo "$REFUSE_VERDICT_LINE"; exit "$REFUSE_EXIT"; } +fatal() { echo "CHIP_RUN: FAIL $*"; exit 1; } +fail() { FAIL_REASON=${FAIL_REASON:-$*}; } +cleanup() { [ "$FLAG_MINE" = 1 ] && [ "$(cat "$QUIET_FLAG" 2>/dev/null)" = "$FLAG_TEXT" ] && rm -f "$QUIET_FLAG"; return 0; } +trap cleanup EXIT +sha() { sha256sum "$1" | cut -d' ' -f1; } +clean() { [ -z "$(git -C "$1" status --porcelain 2>/dev/null)" ] && echo true || echo false; } +head_of() { git -C "$1" rev-parse HEAD 2>/dev/null; } + +[ $# -ge 1 ] || refuse "usage: chip_run.sh MANIFEST [--physics-dir DIR] [--evidence-dir DIR] [-- gate args]" +MANIFEST=$1; shift +PHYS_FLAG=""; EVID_FLAG="" +while [ $# -gt 0 ]; do + case $1 in + --physics-dir) [ $# -ge 2 ] || refuse "--physics-dir needs a value"; PHYS_FLAG=$2; shift 2 ;; + --evidence-dir) [ $# -ge 2 ] || refuse "--evidence-dir needs a value"; EVID_FLAG=$2; shift 2 ;; + --) shift; break ;; + *) refuse "unknown argument $1" ;; + esac +done +GATE_ARGS=("$@") +for v in CHIPRUN_PREBUILT_BIN CHIPRUN_QUIET_FLAG CHIPRUN_GPU_LOCK CHIPRUN_EST_LOAD_CMD; do [ -z "${!v:-}" ] || [ "${CHIPRUN_SELFTEST:-}" = 1 ] || refuse "$v is a self-test override; set CHIPRUN_SELFTEST=1"; done # REFUSAL:selftest_override + +# Physics dir resolution lives here and nowhere else. +PHYSICS=${PHYS_FLAG:-${PHYSICS_DIR:-${PHYSICS:-$HOME/workspace/physics}}} +PHYSICS=$(realpath -m "$PHYSICS") + +GATE=""; TEST_SOURCE=""; SOURCES=""; EXTRA_BUILD_SOURCES=""; RUN_ARGS=""; VERDICT_RE=""; PASS_LINE="" +OWNER=""; EVIDENCE_DIR=""; RAISE_QUIET=1; TAKE_GPU_LOCK=1; REFUSE_DIRTY_OMEGA=1; HOST_TIER_CMD=""; RECEIPT_EXTRA_JQ="" +[ -f "$MANIFEST" ] || refuse "no manifest at $MANIFEST" +. "$MANIFEST" || refuse "manifest $MANIFEST failed to load" +for v in GATE TEST_SOURCE VERDICT_RE PASS_LINE OWNER; do [ -n "${!v}" ] || refuse "manifest does not set $v"; done +case $GATE in *[!A-Za-z0-9_.-]*) refuse "GATE $GATE has characters outside A-Za-z0-9_.-" ;; esac +EVID=${EVID_FLAG:-$EVIDENCE_DIR} +[ -n "$EVID" ] || refuse "no evidence dir (manifest EVIDENCE_DIR or --evidence-dir)" +EVID=$(realpath -m "$EVID") +if [ "${#GATE_ARGS[@]}" -eq 0 ]; then read -ra GATE_ARGS <<< "$RUN_ARGS"; fi + +[ -d "$PHYSICS/nvrm" ] || refuse "no physics checkout at $PHYSICS" # REFUSAL:no_physics +case "$EVID/" in "$HERE"/*|"$PHYSICS"/*) refuse "evidence dir $EVID is inside a candidate tree" ;; esac # REFUSAL:evidence_inside +OMEGA_COMMIT=$(head_of "$HERE") || refuse "cannot read omega HEAD" +[ "$REFUSE_DIRTY_OMEGA" != 1 ] || [ "$(clean "$HERE")" = true ] || refuse "omega tree $HERE is dirty" # REFUSAL:omega_dirty +PIN=$(tr -d '[:space:]' < "$HERE/physics.lock") || refuse "cannot read physics.lock" +PHYS_COMMIT=$(head_of "$PHYSICS") || refuse "cannot read physics HEAD at $PHYSICS" +[ "$PHYS_COMMIT" = "$PIN" ] || refuse "physics checkout is at $PHYS_COMMIT, physics.lock pins $PIN" # REFUSAL:physics_pin +[ "$(clean "$PHYSICS")" = true ] || refuse "physics checkout $PHYSICS is dirty" # REFUSAL:physics_dirty +OMEGA_CLEAN_BEFORE=$(clean "$HERE"); PHYS_CLEAN_BEFORE=true +[ "$RAISE_QUIET" != 1 ] || [ ! -e "$QUIET_FLAG" ] || refuse "quiet flag is up: $(cat "$QUIET_FLAG")" # REFUSAL:quiet_flag +[ -z "$(bash -c "$EST_LOAD_CMD" 2>/dev/null)" ] || refuse "an est_load process is running" # REFUSAL:est_load + +RUN=$(mktemp -d "${TMPDIR:-/tmp}/chip-run.XXXXXX") || refuse "cannot create a run directory" +if [ -n "$HOST_TIER_CMD" ]; then + (cd "$HERE" && CHIPRUN_RUN_DIR="$RUN" bash -c "$HOST_TIER_CMD") > "$RUN/host.log" 2>&1; HRC=$? + tail -n 3 "$RUN/host.log" + [ "$HRC" = 0 ] || refuse "host tier failed (exit $HRC); no chip run" # REFUSAL:host_tier +fi +HOST_TIER=$(tail -n 1 "$RUN/host.log" 2>/dev/null) + +START=$(date -u +%Y-%m-%dT%H:%M:%SZ) +if [ "$RAISE_QUIET" = 1 ]; then + FLAG_TEXT="$OWNER start=$START expected_end=$(date -u -d '+2 hours' +%Y-%m-%dT%H:%M:%SZ) pid=$$" + set -o noclobber + echo "$FLAG_TEXT" > "$QUIET_FLAG" 2>/dev/null || { set +o noclobber; refuse "could not create the quiet flag"; } + set +o noclobber + FLAG_MINE=1 +fi +if [ "$TAKE_GPU_LOCK" = 1 ]; then + exec 9> "$GPU_LOCK" || refuse "cannot open $GPU_LOCK" + flock -n 9 || refuse "GPU lock $GPU_LOCK is held" # REFUSAL:gpu_lock +fi + +if [ -n "${CHIPRUN_PREBUILT_BIN:-}" ]; then + BIN=$CHIPRUN_PREBUILT_BIN + [ -x "$BIN" ] || refuse "CHIPRUN_PREBUILT_BIN $BIN is not executable" +else + echo "== chip build" + BIN=$RUN/$GATE.bin + read -ra SRCS <<< "$TEST_SOURCE $SOURCES $EXTRA_BUILD_SOURCES" + for s in "${SRCS[@]}"; do case $s in /*) f=$s ;; *) f=$HERE/$s ;; esac; [ -f "$f" ] || refuse "missing source $s"; done + NV=$PHYSICS/$NVDIR + (cd "$HERE" && gcc -std=gnu11 -O2 -Wall -Wextra -Werror -ffp-contract=off -fno-fast-math -pthread \ + -Isrc -I"$PHYSICS/nvrm" -I"$PHYSICS/m16" \ + -I"$NV/src/common/sdk/nvidia/inc" -I"$NV/kernel-open/common/inc" \ + -I"$NV/kernel-open/nvidia-uvm" -I"$NV/src/nvidia/arch/nvalloc/unix/include" \ + -o "$BIN" "${SRCS[@]}") > "$RUN/chip-build.log" 2>&1 || { cat "$RUN/chip-build.log"; refuse "chip build failed"; } +fi +SYMS=$(nm -u "$BIN" 2>&1) || refuse "nm cannot read $BIN" # REFUSAL:nm_unreadable +if printf '%s\n' "$SYMS" | grep -Eq '\b(sqrtf?|expf?|exp2f?|logf?|log2f?|powf?|fmaf?|sinf?|cosf?|tanhf?|erff?|roundf?|fabsf?)\b'; then refuse "libm math symbols in $BIN"; fi # REFUSAL:libm +if printf '%s\n' "$SYMS" | grep -Eiq 'cuda|cuInit|cuLaunch|nvrtc|cublas'; then refuse "CUDA symbols in $BIN"; fi # REFUSAL:cuda +BIN_SHA=$(sha "$BIN") + +echo "== chip run (not killed, not timed out): ${GATE_ARGS[*]}" +(cd "$HERE" && "$BIN" "${GATE_ARGS[@]}") > "$RUN/chip.log" 2>&1; CHIP_RC=$? +END=$(date -u +%Y-%m-%dT%H:%M:%SZ) +exec 9>&- +mapfile -t VLINES < <(grep -E -- "$VERDICT_RE" "$RUN/chip.log") +printf '%s\n' "${VLINES[@]}" + +OMEGA_CLEAN_AFTER=$(clean "$HERE"); PHYS_CLEAN_AFTER=$(clean "$PHYSICS") +OMEGA_SAME=$([ "$(head_of "$HERE")" = "$OMEGA_COMMIT" ] && echo true || echo false) +PHYS_SAME=$([ "$(head_of "$PHYSICS")" = "$PHYS_COMMIT" ] && echo true || echo false) +[ "$CHIP_RC" = 0 ] || fail "binary exit status $CHIP_RC" # REFUSAL:rc_nonzero +[ "${#VLINES[@]}" -gt 0 ] || fail "no verdict line matching $VERDICT_RE" # REFUSAL:no_verdict +[ "${#VLINES[@]}" -eq 0 ] || printf '%s\n' "${VLINES[$((${#VLINES[@]} - 1))]}" | grep -Eq -- "$PASS_LINE" || fail "last verdict line does not match PASS_LINE" # REFUSAL:fail_verdict +[ "$REFUSE_DIRTY_OMEGA" != 1 ] || [ "$OMEGA_CLEAN_AFTER" = true ] || fail "omega tree dirty after run" # REFUSAL:omega_dirty_after +[ "$PHYS_CLEAN_AFTER" = true ] || fail "physics tree dirty after run" # REFUSAL:physics_dirty_after +[ "$OMEGA_SAME" = true ] && [ "$PHYS_SAME" = true ] || fail "a HEAD moved during the run" # REFUSAL:head_moved +VERDICT=PASS; [ -z "$FAIL_REASON" ] || VERDICT=FAIL + +LOG_SHA=$(sha "$RUN/chip.log") +mkdir -p "$EVID/blobs" || fatal "cannot create $EVID/blobs" +if [ ! -e "$EVID/blobs/$LOG_SHA.log" ]; then + TMPB=$(mktemp "$EVID/blobs/.tmp.XXXXXX") && cp "$RUN/chip.log" "$TMPB" && chmod 0444 "$TMPB" && mv -n "$TMPB" "$EVID/blobs/$LOG_SHA.log" || fatal "could not store the log blob" + rm -f "$TMPB" +fi +[ "$(sha "$EVID/blobs/$LOG_SHA.log")" = "$LOG_SHA" ] || fatal "log blob does not match its digest" +BODY=$(jq -n --arg gate "$GATE" --arg owner "$OWNER" --arg omega "$OMEGA_COMMIT" --arg phys "$PHYS_COMMIT" --arg pin "$PIN" \ + --argjson oclean "$OMEGA_CLEAN_BEFORE" --argjson pclean "$PHYS_CLEAN_BEFORE" \ + --argjson oafter "$OMEGA_CLEAN_AFTER" --argjson pafter "$PHYS_CLEAN_AFTER" --argjson osame "$OMEGA_SAME" --argjson psame "$PHYS_SAME" \ + --arg bin "$BIN_SHA" --arg log "$LOG_SHA" --arg host "$HOST_TIER" --argjson rc "$CHIP_RC" \ + --arg start "$START" --arg end "$END" --arg verdict "$VERDICT" --arg reason "$FAIL_REASON" \ + --argjson run_args "$(jq -n '$ARGS.positional' --args "${GATE_ARGS[@]}")" \ + --argjson vlines "$(jq -n '$ARGS.positional' --args "${VLINES[@]}")" '{ + gate: $gate, owner: $owner, omega_commit: $omega, omega_tree_clean_before: $oclean, omega_tree_clean_after: $oafter, + omega_commit_unchanged_after: $osame, physics_commit: $phys, physics_lock_pin: $pin, physics_tree_clean_before: $pclean, + physics_tree_clean_after: $pafter, physics_commit_unchanged_after: $psame, binary_sha256: $bin, chip_log_sha256: $log, + run_args: $run_args, host_tier: $host, verdict_lines: $vlines, chip_exit_status: $rc, started_utc: $start, + finished_utc: $end, verdict: $verdict, reason: $reason }') || fatal "receipt JSON could not be built" +if [ -n "$RECEIPT_EXTRA_JQ" ]; then BODY=$(printf '%s' "$BODY" | jq --rawfile log "$RUN/chip.log" "$RECEIPT_EXTRA_JQ") || fatal "RECEIPT_EXTRA_JQ failed"; fi +printf '%s\n' "$BODY" > "$RUN/receipt.json" +jq -e '.gate and .verdict and .binary_sha256' "$RUN/receipt.json" > /dev/null || fatal "receipt lost its required fields" +RSHA=$(sha "$RUN/receipt.json"); OUT=$EVID/$RSHA.json +if [ ! -e "$OUT" ]; then + set -o noclobber; { cat "$RUN/receipt.json" > "$OUT" && chmod 0444 "$OUT"; } || { set +o noclobber; fatal "could not write receipt $OUT"; }; set +o noclobber +fi +cmp -s "$RUN/receipt.json" "$OUT" || fatal "receipt $OUT does not match what was built" +echo "RECEIPT $OUT" +echo "CHIP_RUN: $VERDICT${FAIL_REASON:+ $FAIL_REASON}" +[ "$VERDICT" = PASS ] From 341cba7d13321da4d4302e39ea45115a6212c53d Mon Sep 17 00:00:00 2001 From: Drake Stapleton Date: Thu, 1 Oct 2026 22:20:55 -0500 Subject: [PATCH 2/5] chip_run: fix PR 205 review (seam recheck, REQUIRE_ALL_PASS, REFUSE_EXIT check, tags + cases) [host NOT_RUN] Co-Authored-By: Claude Sonnet 5.5 --- tests/test_chip_run.sh | 120 +++++++++++++++++++++++++++++++++++++++-- tools/chip_run.sh | 114 ++++++++++++++++++++++++++++----------- 2 files changed, 199 insertions(+), 35 deletions(-) diff --git a/tests/test_chip_run.sh b/tests/test_chip_run.sh index 52e80aff0..e54f323fc 100755 --- a/tests/test_chip_run.sh +++ b/tests/test_chip_run.sh @@ -44,6 +44,7 @@ int main(int argc, char **argv) { if (getenv("FAKE_CMD") && system(getenv("FAKE_CMD")) != 0) return 9; if (!strcmp(m, "silent")) return 0; if (!strcmp(m, "fail")) { printf("RESULT chip x ok=false\nVERDICT FAIL\n"); return 0; } + if (!strcmp(m, "failpass")) { printf("VERDICT FAIL\nVERDICT PASS\n"); return 0; } if (!strcmp(m, "passrc")) { printf("VERDICT PASS\n"); return 3; } printf("RESULT chip x ok=true\nVERDICT PASS\n"); return 0; @@ -59,7 +60,8 @@ printf '#!/bin/sh\necho VERDICT PASS\n' > "$T/bin/script"; chmod +x "$T/bin/scri mkdir -p "$PHYS/nvrm" "$OM/tools" "$OM/src" git init -q "$PHYS" && echo "/* fake */" > "$PHYS/nvrm/nvrm.c" && g "$PHYS" add -A && g "$PHYS" commit -q -m physics PIN=$(git -C "$PHYS" rev-parse HEAD) -git init -q "$OM" && cp "$SRC_MODULE" "$OM/tools/chip_run.sh" && echo "$PIN" > "$OM/physics.lock" && echo "/* fake */" > "$OM/src/a.c" \ +git init -q "$OM" && cp "$SRC_MODULE" "$OM/tools/chip_run.sh" && echo "$PIN" > "$OM/physics.lock" && echo "/* fake */" > "$OM/src/a.c" && echo "int main(void){ return undefined_thing; }" > "$OM/src/bad.c" \ + && printf "#include \\nint main(void){ puts(\"VERDICT PASS\"); return 0; }\\n" > "$OM/src/okchip.c" \ && g "$OM" add -A && g "$OM" commit -q -m omega OM_HEAD=$(git -C "$OM" rev-parse HEAD) @@ -82,6 +84,7 @@ EOM mkman "$T/m.sh"; mkman "$T/m-hostfail.sh" "HOST_TIER_CMD=false" mkman "$T/m-map.sh" "REFUSE_EXIT=1; REFUSE_VERDICT_LINE='VERDICT NOT_RUN'" mkman "$T/m-off.sh" "RAISE_QUIET=0; TAKE_GPU_LOCK=0" +mkman "$T/m-all.sh" "REQUIRE_ALL_PASS=1; VERDICT_RE='^VERDICT'" CRMAN=$T/m.sh; PD=(--physics-dir "$PHYS") reset_world() { @@ -91,11 +94,11 @@ reset_world() { } # cr ID [NAME=VALUE ...] -- [module args]: run the module from outside both trees cr() { - local id=$1; shift; local extra=() + local id=$1; shift; local extra=() ev=(--evidence-dir "$T/ev-$id"); [ -z "${NOEVID:-}" ] || ev=() while [ "$1" != -- ]; do extra+=("$1"); shift; done; shift ( cd "$T" && env -u PHYSICS_DIR -u PHYSICS CHIPRUN_SELFTEST=1 CHIPRUN_PREBUILT_BIN="$T/bin/ok" CHIPRUN_QUIET_FLAG="$FLAG" \ CHIPRUN_GPU_LOCK="$LOCK" CHIPRUN_EST_LOAD_CMD=true FAKE_MODE=pass TMPDIR="$T/tmp" "${extra[@]}" \ - bash "$OM/tools/chip_run.sh" "$CRMAN" --evidence-dir "$T/ev-$id" "$@" ) > "$OUT" 2>&1 + bash "${RAWMOD:-$OM/tools/chip_run.sh}" "$CRMAN" "${ev[@]}" "$@" ) > "$OUT" 2>&1 RC=$? } bad() { echo "FAIL $1: $2"; sed 's/^/ | /' "$OUT" | head -8; BAD=$((BAD + 1)); } @@ -155,6 +158,117 @@ expect physics_dirty_after 1 '^CHIP_RUN: FAIL physics tree dirty after run' reset_world; cr head_moved FAKE_CMD="git -C $OM -c user.email=t@t -c user.name=t -c commit.gpgsign=false commit -q --allow-empty -m x" -- "${PD[@]}" expect head_moved 1 '^CHIP_RUN: FAIL a HEAD moved' +# raw ENV=VALUE... -- args: run the module with every seam variable unset (no CHIPRUN_SELFTEST) +raw() { + local extra=(); while [ "$1" != -- ]; do extra+=("$1"); shift; done; shift + ( cd "$T" && env -u PHYSICS_DIR -u PHYSICS -u CHIPRUN_SELFTEST -u CHIPRUN_PREBUILT_BIN -u CHIPRUN_QUIET_FLAG -u CHIPRUN_GPU_LOCK \ + -u CHIPRUN_EST_LOAD_CMD TMPDIR="$T/tmp" "${extra[@]}" bash "${RAWMOD:-$OM/tools/chip_run.sh}" "$@" ) > "$OUT" 2>&1 + RC=$? +} +# test seam: each of the four variables ALONE, without CHIPRUN_SELFTEST=1, is refused (manifest is m-off: no real flag or lock) +for sv in "seam_prebuilt CHIPRUN_PREBUILT_BIN $T/bin/ok" "seam_quiet CHIPRUN_QUIET_FLAG $FLAG" "seam_gpu CHIPRUN_GPU_LOCK $LOCK" "seam_est CHIPRUN_EST_LOAD_CMD true"; do + read -r sid svar sval <<< "$sv" + reset_world; raw "$svar=$sval" -- "$T/m-off.sh" --evidence-dir "$T/ev-$sid" "${PD[@]}" + expect "$sid" 2 "^REFUSED: $svar is a self-test override" +done +# checked before the manifest is read: a missing manifest still gets the seam message +reset_world; raw CHIPRUN_PREBUILT_BIN="$T/bin/ok" -- "$T/nope.sh" --evidence-dir "$T/ev-seam_before" "${PD[@]}" +expect seam_before 2 '^REFUSED: CHIPRUN_PREBUILT_BIN is a self-test override' +# checked after the manifest is read: a manifest that sets the variable cannot slip it in +mkman "$T/m-seamset.sh" "RAISE_QUIET=0; TAKE_GPU_LOCK=0; CHIPRUN_PREBUILT_BIN=$T/bin/ok" +reset_world; raw -- "$T/m-seamset.sh" --evidence-dir "$T/ev-seam_after" "${PD[@]}" +expect seam_after 2 '^REFUSED: CHIPRUN_PREBUILT_BIN is a self-test override' +# even with CHIPRUN_SELFTEST=1 in the environment, a manifest cannot change a seam variable or set CHIPRUN_SELFTEST +mkman "$T/m-seamchg.sh" "RAISE_QUIET=0; TAKE_GPU_LOCK=0; CHIPRUN_PREBUILT_BIN=$T/bin/libm" +reset_world; raw CHIPRUN_SELFTEST=1 CHIPRUN_PREBUILT_BIN="$T/bin/ok" -- "$T/m-seamchg.sh" --evidence-dir "$T/ev-seam_changed" "${PD[@]}" +expect seam_changed 2 '^REFUSED: manifest changed CHIPRUN_PREBUILT_BIN' +mkman "$T/m-selfset.sh" "RAISE_QUIET=0; TAKE_GPU_LOCK=0; CHIPRUN_SELFTEST=1" +reset_world; raw -- "$T/m-selfset.sh" --evidence-dir "$T/ev-seam_selftest" "${PD[@]}" +expect seam_selftest 2 '^REFUSED: manifest changed CHIPRUN_SELFTEST' + +# usage, arguments, manifest +reset_world; raw -- +expect usage 2 '^REFUSED: usage' +reset_world; cr bad_arg -- "${PD[@]}" --bogus +expect bad_arg 2 '^REFUSED: unknown argument --bogus' +reset_world; cr arg_value -- --physics-dir +expect arg_value 2 '^REFUSED: --physics-dir needs a value' +reset_world; CRMAN=$T/nope.sh cr no_manifest -- "${PD[@]}" +expect no_manifest 2 '^REFUSED: no manifest at' +mkman "$T/m-loadfail.sh" "false" +reset_world; CRMAN=$T/m-loadfail.sh cr manifest_load -- "${PD[@]}" +expect manifest_load 2 '^REFUSED: manifest .* failed to load' +mkman "$T/m-novars.sh" 'OWNER=""' +reset_world; CRMAN=$T/m-novars.sh cr manifest_vars -- "${PD[@]}" +expect manifest_vars 2 '^REFUSED: manifest does not set OWNER' +mkman "$T/m-gate.sh" 'GATE="bad/gate"' +reset_world; CRMAN=$T/m-gate.sh cr gate_chars -- "${PD[@]}" +expect gate_chars 2 '^REFUSED: GATE .* characters' +mkman "$T/m-noevid.sh" 'EVIDENCE_DIR=""' +reset_world; NOEVID=1; CRMAN=$T/m-noevid.sh cr no_evidence -- "${PD[@]}"; unset NOEVID +expect no_evidence 2 '^REFUSED: no evidence dir' +# REFUSE_EXIT must be an integer 1..125; REQUIRE_ALL_PASS must be 0 or 1 +for rx in "refuse_exit 0" "refuse_exit_text abc" "refuse_exit_big 126" "refuse_exit_empty ''"; do + read -r rid rval <<< "$rx"; mkman "$T/m-$rid.sh" "REFUSE_EXIT=$rval" + reset_world; CRMAN=$T/m-$rid.sh cr "$rid" -- "${PD[@]}" + expect "$rid" 1 '^CHIP_RUN: BAD_MANIFEST REFUSE_EXIT=' +done +mkman "$T/m-rx125.sh" "REFUSE_EXIT=125" +reset_world; CRMAN=$T/m-rx125.sh cr refuse_exit_125 -- --physics-dir "$T/nonexistent" +expect refuse_exit_125 125 '^REFUSED: no physics checkout' +mkman "$T/m-rap-bad.sh" "REQUIRE_ALL_PASS=yes" +reset_world; CRMAN=$T/m-rap-bad.sh cr require_all_value -- "${PD[@]}" +expect require_all_value 1 '^CHIP_RUN: BAD_MANIFEST REQUIRE_ALL_PASS=' + +# refusals that need a special world +mkdir -p "$T/nogit-om/tools" "$T/nogit/nvrm"; cp "$SRC_MODULE" "$T/nogit-om/tools/chip_run.sh" +reset_world; RAWMOD=$T/nogit-om/tools/chip_run.sh cr omega_head -- "${PD[@]}" +expect omega_head 2 '^REFUSED: cannot read omega HEAD' +mkman "$T/m-nolock.sh" "REFUSE_DIRTY_OMEGA=0" +reset_world; rm -f "$OM/physics.lock"; CRMAN=$T/m-nolock.sh cr physics_lock -- "${PD[@]}" +expect physics_lock 2 '^REFUSED: cannot read physics.lock' +reset_world; cr physics_head -- --physics-dir "$T/nogit" +expect physics_head 2 '^REFUSED: cannot read physics HEAD' +reset_world; cr mktemp TMPDIR="$T/nonexistent" -- "${PD[@]}" +expect mktemp 2 '^REFUSED: cannot create a run directory' +mkman "$T/m-race.sh" "HOST_TIER_CMD='echo other > $FLAG'" +reset_world; CRMAN=$T/m-race.sh cr flag_create -- "${PD[@]}" +expect flag_create 2 '^REFUSED: could not create the quiet flag' +assert flag_create "a flag created by someone else in the race is left alone" flag_is_other +reset_world; cr gpu_open CHIPRUN_GPU_LOCK="$T/nodir/x.lock" -- "${PD[@]}" +expect gpu_open 2 '^REFUSED: cannot open' +assert gpu_open "the quiet flag we raised is dropped on refusal" no_flag +reset_world; cr prebuilt_not_exec CHIPRUN_PREBUILT_BIN="$T/nonexistent" -- "${PD[@]}" +expect prebuilt_not_exec 2 '^REFUSED: CHIPRUN_PREBUILT_BIN .* is not executable' +mkman "$T/m-nosrc.sh" "TEST_SOURCE=src/nope.c" +reset_world; CRMAN=$T/m-nosrc.sh cr missing_source CHIPRUN_PREBUILT_BIN= -- "${PD[@]}" +expect missing_source 2 '^REFUSED: missing source src/nope.c' +mkman "$T/m-badsrc.sh" "TEST_SOURCE=src/bad.c" +reset_world; CRMAN=$T/m-badsrc.sh cr build_failed CHIPRUN_PREBUILT_BIN= -- "${PD[@]}" +expect build_failed 2 '^REFUSED: chip build failed' +mkman "$T/m-oksrc.sh" "TEST_SOURCE=src/okchip.c" +reset_world; CRMAN=$T/m-oksrc.sh cr build_ok CHIPRUN_PREBUILT_BIN= -- "${PD[@]}" +expect build_ok 0 '^CHIP_RUN: PASS' +# quiet flag: dropped only if still ours +reset_world; cr flag_not_ours FAKE_CMD="echo other > $FLAG" -- "${PD[@]}" +expect flag_not_ours 0 '^CHIP_RUN: PASS' +assert flag_not_ours "a flag someone else rewrote during the run is left alone" flag_is_other +# verdict logic: FAIL line then PASS line +reset_world; cr last_line_default FAKE_MODE=failpass -- "${PD[@]}" +expect last_line_default 0 '^CHIP_RUN: PASS' +reset_world; CRMAN=$T/m-all.sh cr fail_any_verdict FAKE_MODE=failpass -- "${PD[@]}" +expect fail_any_verdict 1 '^CHIP_RUN: FAIL a verdict line does not match PASS_LINE' +assert fail_any_verdict "a FAIL receipt is still written" receipt_verdict fail_any_verdict FAIL +reset_world; CRMAN=$T/m-all.sh cr all_pass_ok FAKE_MODE=pass -- "${PD[@]}" +expect all_pass_ok 0 '^CHIP_RUN: PASS' +# evidence reuse: a second run keeps one log blob; a tampered blob is caught +reset_world; cr reuse -- "${PD[@]}"; cr reuse -- "${PD[@]}" +expect reuse 0 '^CHIP_RUN: PASS' +assert reuse "one log blob for two identical logs" test "$(ls "$T"/ev-reuse/blobs/*.log 2>/dev/null | wc -l)" = 1 +RB=$(ls "$T"/ev-reuse/blobs/*.log 2>/dev/null | head -1); chmod u+w "$RB" 2>/dev/null; echo tamper >> "$RB" +reset_world; cr reuse -- "${PD[@]}" +expect blob_tamper 1 '^CHIP_RUN: FAIL log blob does not match its digest' + # physics dir resolution order: flag, PHYSICS_DIR, PHYSICS reset_world; cr order_env_dir PHYSICS="$T/nonexistent" PHYSICS_DIR="$PHYS" -- expect order_env_dir 0 '^CHIP_RUN: PASS' diff --git a/tools/chip_run.sh b/tools/chip_run.sh index 7b2c8a67f..73fc3eda3 100755 --- a/tools/chip_run.sh +++ b/tools/chip_run.sh @@ -5,29 +5,49 @@ # MANIFEST is shell syntax setting: GATE TEST_SOURCE SOURCES EXTRA_BUILD_SOURCES (relative # to the omega root, may use $PHYSICS and $HERE) RUN_ARGS VERDICT_RE PASS_LINE OWNER # EVIDENCE_DIR RAISE_QUIET TAKE_GPU_LOCK REFUSE_DIRTY_OMEGA (default 1) REFUSE_EXIT -# (default 2) REFUSE_VERDICT_LINE (default "CHIP_RUN: NOT_RUN"), hooks HOST_TIER_CMD -# (run first; nonzero refuses) and RECEIPT_EXTRA_JQ (jq filter on the receipt, $log = chip log). +# (default 2; must be an integer 1..125, else exit 1 "CHIP_RUN: BAD_MANIFEST") REFUSE_VERDICT_LINE +# (default "CHIP_RUN: NOT_RUN") REQUIRE_ALL_PASS (default 0; 0 or 1; when 1 EVERY line matching +# VERDICT_RE must also match PASS_LINE, so set VERDICT_RE to verdict lines only), hooks +# HOST_TIER_CMD (run first; nonzero refuses) and RECEIPT_EXTRA_JQ (jq filter on the receipt, +# $log = chip log). The manifest cannot change the test seam variables below, QUIET_FLAG, +# GPU_LOCK or EST_LOAD_CMD (checked and restored after it is sourced). # Physics dir, first match wins: --physics-dir, $PHYSICS_DIR, $PHYSICS, ~/workspace/physics. # Exit: 0 PASS; 1 FAIL (binary ran, verdict not PASS or tree changed); REFUSE_EXIT (default 2, # as run_unwritten_trap.sh) after printing "REFUSED: why" and REFUSE_VERDICT_LINE. A gate that # keeps transc semantics sets REFUSE_EXIT=1 REFUSE_VERDICT_LINE="VERDICT NOT_RUN". -# REFUSES (nothing is run): bad usage or manifest; test override env without CHIPRUN_SELFTEST=1; -# no physics checkout; physics not at the physics.lock pin; physics dirty; omega dirty (if -# REFUSE_DIRTY_OMEGA=1); evidence dir inside omega or physics; quiet flag already up (if -# RAISE_QUIET=1); an est_load process; the GPU lock held (if TAKE_GPU_LOCK=1); HOST_TIER_CMD -# failing; a missing source; gcc failing; nm unreadable; libm math or CUDA symbols in the binary. +# REFUSES (nothing is run): bad usage, argument or manifest; missing manifest variables or GATE +# characters; no evidence dir; test override env without CHIPRUN_SELFTEST=1 (checked before and +# after the manifest is sourced; a manifest that changes one is refused); no physics checkout; +# unreadable omega or physics HEAD or physics.lock; physics not at the physics.lock pin; +# physics dirty; omega dirty (if REFUSE_DIRTY_OMEGA=1); evidence dir inside omega or physics; +# quiet flag already up or lost in a create race (if RAISE_QUIET=1); an est_load process; the +# GPU lock unopenable or held (if TAKE_GPU_LOCK=1); no temp dir; HOST_TIER_CMD failing; a +# missing source; gcc failing; nm unreadable; libm math or CUDA symbols in the binary. # FAILS (ran to the end, receipt written): nonzero exit; no line matching VERDICT_RE; last such -# line not matching PASS_LINE; omega (if REFUSE_DIRTY_OMEGA=1) or physics dirty after the run; -# either HEAD moved. Never killed, never timed out. Quiet flag dropped only if still ours. +# line not matching PASS_LINE (any such line, if REQUIRE_ALL_PASS=1); omega (if +# REFUSE_DIRTY_OMEGA=1) or physics dirty after the run; either HEAD moved. Never killed, never +# timed out. Quiet flag dropped only if still ours. # RECEIPT /.json, mode 0444, noclobber, plus blobs/.log. # Fields: gate owner omega_commit omega_tree_clean_before omega_tree_clean_after # omega_commit_unchanged_after physics_commit physics_lock_pin physics_tree_clean_before # physics_tree_clean_after physics_commit_unchanged_after binary_sha256 chip_log_sha256 # run_args host_tier verdict_lines chip_exit_status started_utc finished_utc verdict reason # (plus whatever RECEIPT_EXTRA_JQ adds). +# NOT COVERED by this module (a gate that needs one adds it, or does not use this module yet): +# - transc's KDIG kernel-digest field and its unknown-op check: use RECEIPT_EXTRA_JQ. +# - transc's nvdisasm check: use HOST_TIER_CMD. +# - transc locks with fuser (refuses if ANY process holds the lock file); this module uses +# flock -n (refuses only if another flock holder has it). Not the same test. +# - reduce WAITS for the lock and the quiet flag; this module REFUSES at once. +# - binary blob storage: reduce stores blobs/.bin and refuses a PASS with no digests; +# this module stores only the log blob, and records binary_sha256 without keeping the binary. +# - REQUIRE_ALL_PASS checks lines that appear, not that a particular line appears: reduce's +# SUM, MAX, MIN, MEAN, RED_GB10_PARITY and E1 lines are not each demanded. +# - receipt reuse (an existing receipt with the same name is compared, not rewritten) has no case. # Test seam (only with CHIPRUN_SELFTEST=1): CHIPRUN_PREBUILT_BIN CHIPRUN_QUIET_FLAG # CHIPRUN_GPU_LOCK CHIPRUN_EST_LOAD_CMD. Mutation check: each refusal line ends in # "# REFUSAL:"; tests/test_chip_run.sh --mutants deletes each one and needs case to FAIL. +# Not tagged: the "fatal" exits after the run (receipt and blob writing). # Shell + coreutils + git + jq + gcc + nm + flock. No Python. set -u HERE=$(cd -P "$(dirname "${BASH_SOURCE[0]}")/.." && pwd) @@ -38,56 +58,83 @@ EST_LOAD_CMD=${CHIPRUN_EST_LOAD_CMD:-pgrep est_load} FLAG_MINE=0; FLAG_TEXT=""; FAIL_REASON="" REFUSE_EXIT=2; REFUSE_VERDICT_LINE="CHIP_RUN: NOT_RUN" refuse() { echo "REFUSED: $*"; echo "$REFUSE_VERDICT_LINE"; exit "$REFUSE_EXIT"; } +bad_manifest() { echo "CHIP_RUN: BAD_MANIFEST $*"; exit 1; } fatal() { echo "CHIP_RUN: FAIL $*"; exit 1; } fail() { FAIL_REASON=${FAIL_REASON:-$*}; } -cleanup() { [ "$FLAG_MINE" = 1 ] && [ "$(cat "$QUIET_FLAG" 2>/dev/null)" = "$FLAG_TEXT" ] && rm -f "$QUIET_FLAG"; return 0; } +cleanup() { + [ "$FLAG_MINE" = 1 ] || return 0 + [ "$(cat "$QUIET_FLAG" 2>/dev/null)" = "$FLAG_TEXT" ] || return 0 # REFUSAL:flag_not_ours + rm -f "$QUIET_FLAG"; return 0 +} trap cleanup EXIT sha() { sha256sum "$1" | cut -d' ' -f1; } clean() { [ -z "$(git -C "$1" status --porcelain 2>/dev/null)" ] && echo true || echo false; } head_of() { git -C "$1" rev-parse HEAD 2>/dev/null; } -[ $# -ge 1 ] || refuse "usage: chip_run.sh MANIFEST [--physics-dir DIR] [--evidence-dir DIR] [-- gate args]" +# Test seam: snapshot before the manifest is sourced, check before and after, restore after. +SEAM_VARS=(CHIPRUN_SELFTEST CHIPRUN_PREBUILT_BIN CHIPRUN_QUIET_FLAG CHIPRUN_GPU_LOCK CHIPRUN_EST_LOAD_CMD) +declare -A SEAM0; for v in "${SEAM_VARS[@]}"; do SEAM0[$v]=${!v:-}; done +SELFTEST0=${CHIPRUN_SELFTEST:-}; QUIET0=$QUIET_FLAG; GPU0=$GPU_LOCK; EST0=$EST_LOAD_CMD +seam_check() { + [ -z "${CHIPRUN_PREBUILT_BIN:-}" ] || [ "$SELFTEST0" = 1 ] || refuse "CHIPRUN_PREBUILT_BIN is a self-test override; set CHIPRUN_SELFTEST=1" # REFUSAL:seam_prebuilt + [ -z "${CHIPRUN_QUIET_FLAG:-}" ] || [ "$SELFTEST0" = 1 ] || refuse "CHIPRUN_QUIET_FLAG is a self-test override; set CHIPRUN_SELFTEST=1" # REFUSAL:seam_quiet + [ -z "${CHIPRUN_GPU_LOCK:-}" ] || [ "$SELFTEST0" = 1 ] || refuse "CHIPRUN_GPU_LOCK is a self-test override; set CHIPRUN_SELFTEST=1" # REFUSAL:seam_gpu + [ -z "${CHIPRUN_EST_LOAD_CMD:-}" ] || [ "$SELFTEST0" = 1 ] || refuse "CHIPRUN_EST_LOAD_CMD is a self-test override; set CHIPRUN_SELFTEST=1" # REFUSAL:seam_est +} + +[ $# -ge 1 ] || refuse "usage: chip_run.sh MANIFEST [--physics-dir DIR] [--evidence-dir DIR] [-- gate args]" # REFUSAL:usage MANIFEST=$1; shift -PHYS_FLAG=""; EVID_FLAG="" +PHYS_FLAG=""; EVID_FLAG=""; BAD_ARG="" while [ $# -gt 0 ]; do + case $1 in --physics-dir|--evidence-dir) [ $# -ge 2 ] || refuse "$1 needs a value" ;; esac # REFUSAL:arg_value case $1 in - --physics-dir) [ $# -ge 2 ] || refuse "--physics-dir needs a value"; PHYS_FLAG=$2; shift 2 ;; - --evidence-dir) [ $# -ge 2 ] || refuse "--evidence-dir needs a value"; EVID_FLAG=$2; shift 2 ;; + --physics-dir) PHYS_FLAG=$2; shift 2 ;; + --evidence-dir) EVID_FLAG=$2; shift 2 ;; --) shift; break ;; - *) refuse "unknown argument $1" ;; + *) BAD_ARG=$1; break ;; esac done +[ -z "$BAD_ARG" ] || refuse "unknown argument $BAD_ARG" # REFUSAL:bad_arg GATE_ARGS=("$@") -for v in CHIPRUN_PREBUILT_BIN CHIPRUN_QUIET_FLAG CHIPRUN_GPU_LOCK CHIPRUN_EST_LOAD_CMD; do [ -z "${!v:-}" ] || [ "${CHIPRUN_SELFTEST:-}" = 1 ] || refuse "$v is a self-test override; set CHIPRUN_SELFTEST=1"; done # REFUSAL:selftest_override +seam_check # REFUSAL:seam_before # Physics dir resolution lives here and nowhere else. PHYSICS=${PHYS_FLAG:-${PHYSICS_DIR:-${PHYSICS:-$HOME/workspace/physics}}} PHYSICS=$(realpath -m "$PHYSICS") GATE=""; TEST_SOURCE=""; SOURCES=""; EXTRA_BUILD_SOURCES=""; RUN_ARGS=""; VERDICT_RE=""; PASS_LINE="" -OWNER=""; EVIDENCE_DIR=""; RAISE_QUIET=1; TAKE_GPU_LOCK=1; REFUSE_DIRTY_OMEGA=1; HOST_TIER_CMD=""; RECEIPT_EXTRA_JQ="" -[ -f "$MANIFEST" ] || refuse "no manifest at $MANIFEST" -. "$MANIFEST" || refuse "manifest $MANIFEST failed to load" -for v in GATE TEST_SOURCE VERDICT_RE PASS_LINE OWNER; do [ -n "${!v}" ] || refuse "manifest does not set $v"; done -case $GATE in *[!A-Za-z0-9_.-]*) refuse "GATE $GATE has characters outside A-Za-z0-9_.-" ;; esac +OWNER=""; EVIDENCE_DIR=""; RAISE_QUIET=1; TAKE_GPU_LOCK=1; REFUSE_DIRTY_OMEGA=1; HOST_TIER_CMD=""; RECEIPT_EXTRA_JQ=""; REQUIRE_ALL_PASS=0 +[ -f "$MANIFEST" ] || refuse "no manifest at $MANIFEST" # REFUSAL:no_manifest +. "$MANIFEST"; MRC=$? +REX_BAD="" +case $REFUSE_EXIT in ''|*[!0-9]*) REX_BAD=1 ;; *) { [ "${#REFUSE_EXIT}" -le 3 ] && [ "$((10#$REFUSE_EXIT))" -ge 1 ] && [ "$((10#$REFUSE_EXIT))" -le 125 ]; } || REX_BAD=1 ;; esac +[ -z "$REX_BAD" ] || bad_manifest "REFUSE_EXIT=$REFUSE_EXIT is not an integer from 1 to 125" # REFUSAL:refuse_exit +case $REQUIRE_ALL_PASS in 0|1) ;; *) bad_manifest "REQUIRE_ALL_PASS=$REQUIRE_ALL_PASS is not 0 or 1" ;; esac # REFUSAL:require_all_value +seam_check # REFUSAL:seam_after +for v in "${SEAM_VARS[@]}"; do [ "${!v:-}" = "${SEAM0[$v]}" ] || refuse "manifest changed $v, a test seam variable"; done # REFUSAL:seam_changed +QUIET_FLAG=$QUIET0; GPU_LOCK=$GPU0; EST_LOAD_CMD=$EST0 +[ "$MRC" = 0 ] || refuse "manifest $MANIFEST failed to load" # REFUSAL:manifest_load +for v in GATE TEST_SOURCE VERDICT_RE PASS_LINE OWNER; do [ -n "${!v}" ] || refuse "manifest does not set $v"; done # REFUSAL:manifest_vars +case $GATE in *[!A-Za-z0-9_.-]*) refuse "GATE $GATE has characters outside A-Za-z0-9_.-" ;; esac # REFUSAL:gate_chars EVID=${EVID_FLAG:-$EVIDENCE_DIR} -[ -n "$EVID" ] || refuse "no evidence dir (manifest EVIDENCE_DIR or --evidence-dir)" +[ -n "$EVID" ] || refuse "no evidence dir (manifest EVIDENCE_DIR or --evidence-dir)" # REFUSAL:no_evidence EVID=$(realpath -m "$EVID") if [ "${#GATE_ARGS[@]}" -eq 0 ]; then read -ra GATE_ARGS <<< "$RUN_ARGS"; fi [ -d "$PHYSICS/nvrm" ] || refuse "no physics checkout at $PHYSICS" # REFUSAL:no_physics -case "$EVID/" in "$HERE"/*|"$PHYSICS"/*) refuse "evidence dir $EVID is inside a candidate tree" ;; esac # REFUSAL:evidence_inside -OMEGA_COMMIT=$(head_of "$HERE") || refuse "cannot read omega HEAD" +case "$EVID/" in "$HERE"/*) refuse "evidence dir $EVID is inside a candidate tree" ;; esac # REFUSAL:evidence_inside +case "$EVID/" in "$PHYSICS"/*) refuse "evidence dir $EVID is inside a candidate tree" ;; esac # REFUSAL:evidence_inside_physics +OMEGA_COMMIT=$(head_of "$HERE") || refuse "cannot read omega HEAD" # REFUSAL:omega_head [ "$REFUSE_DIRTY_OMEGA" != 1 ] || [ "$(clean "$HERE")" = true ] || refuse "omega tree $HERE is dirty" # REFUSAL:omega_dirty -PIN=$(tr -d '[:space:]' < "$HERE/physics.lock") || refuse "cannot read physics.lock" -PHYS_COMMIT=$(head_of "$PHYSICS") || refuse "cannot read physics HEAD at $PHYSICS" +PIN=$(tr -d '[:space:]' < "$HERE/physics.lock") || refuse "cannot read physics.lock" # REFUSAL:physics_lock +PHYS_COMMIT=$(head_of "$PHYSICS") || refuse "cannot read physics HEAD at $PHYSICS" # REFUSAL:physics_head [ "$PHYS_COMMIT" = "$PIN" ] || refuse "physics checkout is at $PHYS_COMMIT, physics.lock pins $PIN" # REFUSAL:physics_pin [ "$(clean "$PHYSICS")" = true ] || refuse "physics checkout $PHYSICS is dirty" # REFUSAL:physics_dirty OMEGA_CLEAN_BEFORE=$(clean "$HERE"); PHYS_CLEAN_BEFORE=true [ "$RAISE_QUIET" != 1 ] || [ ! -e "$QUIET_FLAG" ] || refuse "quiet flag is up: $(cat "$QUIET_FLAG")" # REFUSAL:quiet_flag [ -z "$(bash -c "$EST_LOAD_CMD" 2>/dev/null)" ] || refuse "an est_load process is running" # REFUSAL:est_load -RUN=$(mktemp -d "${TMPDIR:-/tmp}/chip-run.XXXXXX") || refuse "cannot create a run directory" +RUN=$(mktemp -d "${TMPDIR:-/tmp}/chip-run.XXXXXX") || refuse "cannot create a run directory" # REFUSAL:mktemp if [ -n "$HOST_TIER_CMD" ]; then (cd "$HERE" && CHIPRUN_RUN_DIR="$RUN" bash -c "$HOST_TIER_CMD") > "$RUN/host.log" 2>&1; HRC=$? tail -n 3 "$RUN/host.log" @@ -99,29 +146,31 @@ START=$(date -u +%Y-%m-%dT%H:%M:%SZ) if [ "$RAISE_QUIET" = 1 ]; then FLAG_TEXT="$OWNER start=$START expected_end=$(date -u -d '+2 hours' +%Y-%m-%dT%H:%M:%SZ) pid=$$" set -o noclobber - echo "$FLAG_TEXT" > "$QUIET_FLAG" 2>/dev/null || { set +o noclobber; refuse "could not create the quiet flag"; } + echo "$FLAG_TEXT" > "$QUIET_FLAG" 2>/dev/null || { set +o noclobber; refuse "could not create the quiet flag"; } # REFUSAL:flag_create set +o noclobber FLAG_MINE=1 fi if [ "$TAKE_GPU_LOCK" = 1 ]; then - exec 9> "$GPU_LOCK" || refuse "cannot open $GPU_LOCK" + { : >> "$GPU_LOCK"; } 2>/dev/null || refuse "cannot open $GPU_LOCK" # REFUSAL:gpu_open + exec 9>> "$GPU_LOCK" flock -n 9 || refuse "GPU lock $GPU_LOCK is held" # REFUSAL:gpu_lock fi if [ -n "${CHIPRUN_PREBUILT_BIN:-}" ]; then BIN=$CHIPRUN_PREBUILT_BIN - [ -x "$BIN" ] || refuse "CHIPRUN_PREBUILT_BIN $BIN is not executable" + [ -x "$BIN" ] || refuse "CHIPRUN_PREBUILT_BIN $BIN is not executable" # REFUSAL:prebuilt_not_exec else echo "== chip build" BIN=$RUN/$GATE.bin read -ra SRCS <<< "$TEST_SOURCE $SOURCES $EXTRA_BUILD_SOURCES" - for s in "${SRCS[@]}"; do case $s in /*) f=$s ;; *) f=$HERE/$s ;; esac; [ -f "$f" ] || refuse "missing source $s"; done + for s in "${SRCS[@]}"; do case $s in /*) f=$s ;; *) f=$HERE/$s ;; esac; [ -f "$f" ] || refuse "missing source $s"; done # REFUSAL:missing_source NV=$PHYSICS/$NVDIR (cd "$HERE" && gcc -std=gnu11 -O2 -Wall -Wextra -Werror -ffp-contract=off -fno-fast-math -pthread \ -Isrc -I"$PHYSICS/nvrm" -I"$PHYSICS/m16" \ -I"$NV/src/common/sdk/nvidia/inc" -I"$NV/kernel-open/common/inc" \ -I"$NV/kernel-open/nvidia-uvm" -I"$NV/src/nvidia/arch/nvalloc/unix/include" \ - -o "$BIN" "${SRCS[@]}") > "$RUN/chip-build.log" 2>&1 || { cat "$RUN/chip-build.log"; refuse "chip build failed"; } + -o "$BIN" "${SRCS[@]}") > "$RUN/chip-build.log" 2>&1; BRC=$? + [ "$BRC" = 0 ] || { cat "$RUN/chip-build.log"; refuse "chip build failed"; } # REFUSAL:build_failed fi SYMS=$(nm -u "$BIN" 2>&1) || refuse "nm cannot read $BIN" # REFUSAL:nm_unreadable if printf '%s\n' "$SYMS" | grep -Eq '\b(sqrtf?|expf?|exp2f?|logf?|log2f?|powf?|fmaf?|sinf?|cosf?|tanhf?|erff?|roundf?|fabsf?)\b'; then refuse "libm math symbols in $BIN"; fi # REFUSAL:libm @@ -141,6 +190,7 @@ PHYS_SAME=$([ "$(head_of "$PHYSICS")" = "$PHYS_COMMIT" ] && echo true || echo fa [ "$CHIP_RC" = 0 ] || fail "binary exit status $CHIP_RC" # REFUSAL:rc_nonzero [ "${#VLINES[@]}" -gt 0 ] || fail "no verdict line matching $VERDICT_RE" # REFUSAL:no_verdict [ "${#VLINES[@]}" -eq 0 ] || printf '%s\n' "${VLINES[$((${#VLINES[@]} - 1))]}" | grep -Eq -- "$PASS_LINE" || fail "last verdict line does not match PASS_LINE" # REFUSAL:fail_verdict +if [ "$REQUIRE_ALL_PASS" = 1 ] && [ "${#VLINES[@]}" -gt 0 ] && printf '%s\n' "${VLINES[@]}" | grep -Evq -- "$PASS_LINE"; then fail "a verdict line does not match PASS_LINE (REQUIRE_ALL_PASS=1)"; fi # REFUSAL:fail_any_verdict [ "$REFUSE_DIRTY_OMEGA" != 1 ] || [ "$OMEGA_CLEAN_AFTER" = true ] || fail "omega tree dirty after run" # REFUSAL:omega_dirty_after [ "$PHYS_CLEAN_AFTER" = true ] || fail "physics tree dirty after run" # REFUSAL:physics_dirty_after [ "$OMEGA_SAME" = true ] && [ "$PHYS_SAME" = true ] || fail "a HEAD moved during the run" # REFUSAL:head_moved From 9481fe6e3c8a71c6d57c720daeee99e5bf29c027 Mon Sep 17 00:00:00 2001 From: Drake Stapleton Date: Thu, 1 Oct 2026 23:16:58 -0500 Subject: [PATCH 3/5] chip_run: stop jq parsing run args as options; show receipt asserts [host NOT_RUN] Root cause 1: the receipt step built run_args and verdict_lines with `jq -n '$ARGS.positional' --args ...`. jq 1.7 still treats any value that starts with "-" after --args as an option, so run args such as --chip or --x (and any verdict line beginning with "-") made jq print "Unknown option" and the receipt step exit 1 with "receipt JSON could not be built". Every array element now gets an "x" prefix on the way in and jq strips it with map(.[1:]). Root cause 2: two asserts in the happy case ended in "> /dev/null" on the assert call itself, which hid both the ok and the FAIL lines (BAD still counted, so the log showed a failure count with no names). They now call a jqt helper that drops only jq's own stdout. New case dash_verdict: a fake chip prints "- VERDICT PASS" and the receipt must carry verdict_lines == ["- VERDICT PASS"]. Host: bash -n on both files only; the self-test and the module were NOT_RUN. Co-Authored-By: Claude Sonnet 5.5 Claude-Session: https://claude.ai/code/session_01DsjWa6csUe4NxndCTmugHu --- tests/test_chip_run.sh | 14 ++++++++++++-- tools/chip_run.sh | 5 +++-- 2 files changed, 15 insertions(+), 4 deletions(-) diff --git a/tests/test_chip_run.sh b/tests/test_chip_run.sh index e54f323fc..213af783d 100755 --- a/tests/test_chip_run.sh +++ b/tests/test_chip_run.sh @@ -46,6 +46,7 @@ int main(int argc, char **argv) { if (!strcmp(m, "fail")) { printf("RESULT chip x ok=false\nVERDICT FAIL\n"); return 0; } if (!strcmp(m, "failpass")) { printf("VERDICT FAIL\nVERDICT PASS\n"); return 0; } if (!strcmp(m, "passrc")) { printf("VERDICT PASS\n"); return 3; } + if (!strcmp(m, "dash")) { printf("- VERDICT PASS\n"); return 0; } printf("RESULT chip x ok=true\nVERDICT PASS\n"); return 0; } @@ -85,6 +86,7 @@ mkman "$T/m.sh"; mkman "$T/m-hostfail.sh" "HOST_TIER_CMD=false" mkman "$T/m-map.sh" "REFUSE_EXIT=1; REFUSE_VERDICT_LINE='VERDICT NOT_RUN'" mkman "$T/m-off.sh" "RAISE_QUIET=0; TAKE_GPU_LOCK=0" mkman "$T/m-all.sh" "REQUIRE_ALL_PASS=1; VERDICT_RE='^VERDICT'" +mkman "$T/m-dash.sh" "VERDICT_RE='^- VERDICT'; PASS_LINE='^- VERDICT PASS\$'" CRMAN=$T/m.sh; PD=(--physics-dir "$PHYS") reset_world() { @@ -111,6 +113,8 @@ assert() { local id=$1 d=$2; shift 2; if "$@"; then echo "ok $id: $d"; else ba no_flag() { [ ! -e "$FLAG" ]; } flag_is_other() { [ "$(cat "$FLAG" 2>/dev/null)" = other ]; } receipt_verdict() { [ "$(jq -r .verdict "$T"/ev-"$1"/*.json 2>/dev/null)" = "$2" ]; } +# jqt FILTER FILE: jq -e with its stdout dropped, so assert still prints its own ok or FAIL line +jqt() { jq -e "$@" > /dev/null; } reset_world; cr selftest_override CHIPRUN_SELFTEST=0 -- "${PD[@]}" expect selftest_override 2 '^REFUSED: .*self-test override' @@ -293,11 +297,17 @@ assert happy "receipt name is the sha256 of its content" test "$(sha256sum "$R" for f in gate owner omega_commit omega_tree_clean_before omega_tree_clean_after omega_commit_unchanged_after physics_commit physics_lock_pin \ physics_tree_clean_before physics_tree_clean_after physics_commit_unchanged_after binary_sha256 chip_log_sha256 run_args host_tier \ verdict_lines chip_exit_status started_utc finished_utc verdict reason extra_marker; do - assert happy "receipt has field $f" jq -e --arg f "$f" 'has($f)' "$R" > /dev/null + assert happy "receipt has field $f" jqt --arg f "$f" 'has($f)' "$R" done -assert happy "receipt verdict PASS, run_args from the command line" jq -e '.verdict == "PASS" and .run_args == ["--x","1"] and .host_tier == "host-tier-ok" and .omega_commit == "'"$OM_HEAD"'"' "$R" > /dev/null +assert happy "receipt verdict PASS, run_args from the command line" jqt '.verdict == "PASS" and .run_args == ["--x","1"] and .host_tier == "host-tier-ok" and .omega_commit == "'"$OM_HEAD"'"' "$R" LS=$(jq -r .chip_log_sha256 "$R" 2>/dev/null) assert happy "log blob exists, mode 0444, named by its sha256" test "$(stat -c %a "$T/ev-happy/blobs/$LS.log" 2>/dev/null)" = 444 -a "$(sha256sum "$T/ev-happy/blobs/$LS.log" 2>/dev/null | cut -d' ' -f1)" = "$LS" +# a verdict line that starts with "-" must reach the receipt intact (jq once read it as an option) +reset_world; CRMAN=$T/m-dash.sh cr dash_verdict FAKE_MODE=dash -- "${PD[@]}"; CRMAN=$T/m.sh +expect dash_verdict 0 '^CHIP_RUN: PASS' +RD=$(ls "$T"/ev-dash_verdict/*.json 2>/dev/null | head -1) +assert dash_verdict "receipt verdict_lines is the dash line, unchanged" jqt '.verdict_lines == ["- VERDICT PASS"]' "$RD" + if [ "$BAD" = 0 ]; then echo "CHIP_RUN_SELFTEST: PASS"; exit 0; fi echo "CHIP_RUN_SELFTEST: FAIL ($BAD)"; exit 1 diff --git a/tools/chip_run.sh b/tools/chip_run.sh index 73fc3eda3..a145232eb 100755 --- a/tools/chip_run.sh +++ b/tools/chip_run.sh @@ -203,13 +203,14 @@ if [ ! -e "$EVID/blobs/$LOG_SHA.log" ]; then rm -f "$TMPB" fi [ "$(sha "$EVID/blobs/$LOG_SHA.log")" = "$LOG_SHA" ] || fatal "log blob does not match its digest" +# The two arrays go to jq with an "x" prefix that jq strips: jq 1.7 still reads any --args value starting with "-" as an option. BODY=$(jq -n --arg gate "$GATE" --arg owner "$OWNER" --arg omega "$OMEGA_COMMIT" --arg phys "$PHYS_COMMIT" --arg pin "$PIN" \ --argjson oclean "$OMEGA_CLEAN_BEFORE" --argjson pclean "$PHYS_CLEAN_BEFORE" \ --argjson oafter "$OMEGA_CLEAN_AFTER" --argjson pafter "$PHYS_CLEAN_AFTER" --argjson osame "$OMEGA_SAME" --argjson psame "$PHYS_SAME" \ --arg bin "$BIN_SHA" --arg log "$LOG_SHA" --arg host "$HOST_TIER" --argjson rc "$CHIP_RC" \ --arg start "$START" --arg end "$END" --arg verdict "$VERDICT" --arg reason "$FAIL_REASON" \ - --argjson run_args "$(jq -n '$ARGS.positional' --args "${GATE_ARGS[@]}")" \ - --argjson vlines "$(jq -n '$ARGS.positional' --args "${VLINES[@]}")" '{ + --argjson run_args "$(jq -n '$ARGS.positional | map(.[1:])' --args "${GATE_ARGS[@]/#/x}")" \ + --argjson vlines "$(jq -n '$ARGS.positional | map(.[1:])' --args "${VLINES[@]/#/x}")" '{ gate: $gate, owner: $owner, omega_commit: $omega, omega_tree_clean_before: $oclean, omega_tree_clean_after: $oafter, omega_commit_unchanged_after: $osame, physics_commit: $phys, physics_lock_pin: $pin, physics_tree_clean_before: $pclean, physics_tree_clean_after: $pafter, physics_commit_unchanged_after: $psame, binary_sha256: $bin, chip_log_sha256: $log, From eb0d9277b2ab567238695d42649e20f127c751fa Mon Sep 17 00:00:00 2001 From: Drake Stapleton Date: Thu, 1 Oct 2026 23:22:37 -0500 Subject: [PATCH 4/5] test_chip_run: --mutants must refuse when the unmutated suite fails [host NOT_RUN] The --mutants branch counted a mutant as killed whenever "FAIL :" showed up in its run, and never checked that the unmutated suite passes. At the failing baseline 341cba7 (47 FAILs in forge log 041104) it still printed "CHIP_RUN_MUTANTS: PASS (47 killed)" (forge log 041107), a vacuous pass. The branch now runs the real module through the full suite once, before the mutant loop, and prints "CHIP_RUN_MUTANTS: FAIL baseline self-test does not pass" with the failing case names and exits 1 if that run does not exit 0. The nested run gets no arguments, so it does not recurse into --mutants. Host: bash -n and a stub-script probe of the guard only; the self-test, the mutants run and the module were NOT_RUN. Co-Authored-By: Claude Sonnet 5.5 Claude-Session: https://claude.ai/code/session_01DsjWa6csUe4NxndCTmugHu --- tests/test_chip_run.sh | 3 +++ 1 file changed, 3 insertions(+) diff --git a/tests/test_chip_run.sh b/tests/test_chip_run.sh index 213af783d..9468658d5 100755 --- a/tests/test_chip_run.sh +++ b/tests/test_chip_run.sh @@ -15,6 +15,9 @@ SRC_MODULE=${MODULE:-$TESTS_DIR/../tools/chip_run.sh} if [ "${1:-}" = --mutants ]; then M=$(mktemp -d) || exit 1; trap 'rm -rf "$M"' EXIT; bad=0; n=0 + # the unmutated suite must pass first: a failing baseline can print "FAIL :" for every mutant (no arguments, so no recursion) + MODULE="$SRC_MODULE" bash "${BASH_SOURCE[0]}" > "$M/base.out" 2>&1 \ + || { echo "CHIP_RUN_MUTANTS: FAIL baseline self-test does not pass"; grep -E '^(FAIL|CHIP_RUN_SELFTEST)' "$M/base.out" | head -20 | sed 's/^/ | /'; exit 1; } for id in $(grep -o '# REFUSAL:[a-z_]*$' "$SRC_MODULE" | sed 's/.*://' | sort -u); do n=$((n + 1)) sed "s/^.*# REFUSAL:$id\$/:/" "$SRC_MODULE" > "$M/chip_run.sh" From 6a6dc26324b554a8ba0547e9c0a627d2e324e1ee Mon Sep 17 00:00:00 2001 From: Drake Stapleton Date: Fri, 2 Oct 2026 01:21:18 -0500 Subject: [PATCH 5/5] chip_run: pin the jq fix with mutants, cover the var restore, fix header notes [host NOT_RUN] Inspector round 2 (return on eb0d927). R1: dash_verdict printed "- VERDICT PASS" (dash then space), which jq 1.7 does not treat as an option (isoptish in jqlang/jq tag jq-1.7 src/main.c lines 128-130: "-" followed by "-" or a letter), so the old idiom handled it. The fake chip and manifest now use "--- VERDICT PASS", which the old idiom rejects with "Unknown option". --mutants gains two explicit mutants that revert the "x" prefix for the verdict lines (needs dash_verdict to FAIL) and for the run args (needs happy to FAIL); each is a NOCHANGE if its sed did not produce the plain old idiom. The comments that said "any value starting with -" now say "--" or "-" plus a letter. R2: the restore of QUIET_FLAG, GPU_LOCK and EST_LOAD_CMD after the manifest is sourced now ends in "# REFUSAL:restore_vars" and has case restore_vars: a manifest with hostile values (flag already up, lock held, est_load answering) must still PASS, with the flag raised at the seam path (checked from inside the chip), the hostile flag untouched and the seam lock opened. R3: header notes for M1 to M9 from the inspector report (comments only). M10: case empty_args (RUN_ARGS empty, no gate args): PASS, run_args == [], the binary started with no arguments. Host: bash -n on both files and literal jq/sed probes only; the self-test and the mutants run are NOT_RUN. The old forge receipts do not count for this head. Co-Authored-By: Claude Sonnet 5.5 Claude-Session: https://claude.ai/code/session_01DsjWa6csUe4NxndCTmugHu --- tests/test_chip_run.sh | 39 +++++++++++++++++++++++++++++++++++---- tools/chip_run.sh | 32 +++++++++++++++++++++++--------- 2 files changed, 58 insertions(+), 13 deletions(-) diff --git a/tests/test_chip_run.sh b/tests/test_chip_run.sh index 9468658d5..3b7e3afc2 100755 --- a/tests/test_chip_run.sh +++ b/tests/test_chip_run.sh @@ -25,6 +25,20 @@ if [ "${1:-}" = --mutants ]; then MODULE="$M/chip_run.sh" bash "${BASH_SOURCE[0]}" > "$M/out" 2>&1 if grep -q "^FAIL $id:" "$M/out"; then echo "killed $id"; else echo "SURVIVED $id"; bad=1; fi done + # the jq array fix has no refusal line to delete: revert the "x" prefix idiom in a copy and need the named case to FAIL + # (the copy must contain the plain old idiom, else the sed missed and the "kill" would be for the wrong reason) + jqmut() { # NAME CASE SED-SCRIPT OLD-IDIOM-TEXT + n=$((n + 1)) + sed "$3" "$SRC_MODULE" > "$M/chip_run.sh" + cmp -s "$M/chip_run.sh" "$SRC_MODULE" && { echo "NOCHANGE $1"; bad=1; return; } + grep -qF -- "$4" "$M/chip_run.sh" || { echo "NOCHANGE $1 (old idiom not in the copy)"; bad=1; return; } + MODULE="$M/chip_run.sh" bash "${BASH_SOURCE[0]}" > "$M/out" 2>&1 + if grep -q "^FAIL $2:" "$M/out"; then echo "killed $1"; else echo "SURVIVED $1"; bad=1; fi + } + jqmut jq_vlines_prefix dash_verdict '/--argjson vlines/{s/ | map(\.\[1:\])//;s|\${VLINES\[@\]/#/x}|${VLINES[@]}|;}' \ + "'\$ARGS.positional' --args \"\${VLINES[@]}\"" + jqmut jq_gate_args_prefix happy '/--argjson run_args/{s/ | map(\.\[1:\])//;s|\${GATE_ARGS\[@\]/#/x}|${GATE_ARGS[@]}|;}' \ + "'\$ARGS.positional' --args \"\${GATE_ARGS[@]}\"" [ "$n" -gt 0 ] || bad=1 [ "$bad" = 0 ] && { echo "CHIP_RUN_MUTANTS: PASS ($n mutants killed)"; exit 0; } echo "CHIP_RUN_MUTANTS: FAIL"; exit 1 @@ -49,7 +63,7 @@ int main(int argc, char **argv) { if (!strcmp(m, "fail")) { printf("RESULT chip x ok=false\nVERDICT FAIL\n"); return 0; } if (!strcmp(m, "failpass")) { printf("VERDICT FAIL\nVERDICT PASS\n"); return 0; } if (!strcmp(m, "passrc")) { printf("VERDICT PASS\n"); return 3; } - if (!strcmp(m, "dash")) { printf("- VERDICT PASS\n"); return 0; } + if (!strcmp(m, "dash")) { printf("--- VERDICT PASS\n"); return 0; } printf("RESULT chip x ok=true\nVERDICT PASS\n"); return 0; } @@ -89,7 +103,7 @@ mkman "$T/m.sh"; mkman "$T/m-hostfail.sh" "HOST_TIER_CMD=false" mkman "$T/m-map.sh" "REFUSE_EXIT=1; REFUSE_VERDICT_LINE='VERDICT NOT_RUN'" mkman "$T/m-off.sh" "RAISE_QUIET=0; TAKE_GPU_LOCK=0" mkman "$T/m-all.sh" "REQUIRE_ALL_PASS=1; VERDICT_RE='^VERDICT'" -mkman "$T/m-dash.sh" "VERDICT_RE='^- VERDICT'; PASS_LINE='^- VERDICT PASS\$'" +mkman "$T/m-dash.sh" "VERDICT_RE='^--- VERDICT'; PASS_LINE='^--- VERDICT PASS\$'" CRMAN=$T/m.sh; PD=(--physics-dir "$PHYS") reset_world() { @@ -192,6 +206,15 @@ expect seam_changed 2 '^REFUSED: manifest changed CHIPRUN_PREBUILT_BIN' mkman "$T/m-selfset.sh" "RAISE_QUIET=0; TAKE_GPU_LOCK=0; CHIPRUN_SELFTEST=1" reset_world; raw -- "$T/m-selfset.sh" --evidence-dir "$T/ev-seam_selftest" "${PD[@]}" expect seam_selftest 2 '^REFUSED: manifest changed CHIPRUN_SELFTEST' +# a manifest that assigns QUIET_FLAG, GPU_LOCK and EST_LOAD_CMD is undone after it is sourced. Each hostile value +# would refuse the run if it leaked (flag already up, lock held, est_load answers); the chip checks the flag is at the seam path. +mkman "$T/m-restore.sh" "QUIET_FLAG=$T/hostile-flag; GPU_LOCK=$T/hostile.lock; EST_LOAD_CMD='echo 4242'" +reset_world; rm -f "$LOCK" "$T/hostile.lock"; echo hostile > "$T/hostile-flag"; exec 8> "$T/hostile.lock"; flock -x 8 +CRMAN=$T/m-restore.sh cr restore_vars FAKE_CMD="test -e $FLAG" -- "${PD[@]}"; exec 8>&-; CRMAN=$T/m.sh +expect restore_vars 0 '^CHIP_RUN: PASS' +assert restore_vars "the flag is dropped at the seam path after the run" no_flag +assert restore_vars "the manifest's flag path is left alone" test "$(cat "$T/hostile-flag" 2>/dev/null)" = hostile +assert restore_vars "the GPU lock was opened at the seam path" test -e "$LOCK" # usage, arguments, manifest reset_world; raw -- @@ -306,11 +329,19 @@ assert happy "receipt verdict PASS, run_args from the command line" jqt '.verdic LS=$(jq -r .chip_log_sha256 "$R" 2>/dev/null) assert happy "log blob exists, mode 0444, named by its sha256" test "$(stat -c %a "$T/ev-happy/blobs/$LS.log" 2>/dev/null)" = 444 -a "$(sha256sum "$T/ev-happy/blobs/$LS.log" 2>/dev/null | cut -d' ' -f1)" = "$LS" -# a verdict line that starts with "-" must reach the receipt intact (jq once read it as an option) +# a verdict line jq 1.7 would read as an option (it starts with "--") must reach the receipt intact; +# "- VERDICT PASS" (dash, space) would not be one, so it would not catch the bug reset_world; CRMAN=$T/m-dash.sh cr dash_verdict FAKE_MODE=dash -- "${PD[@]}"; CRMAN=$T/m.sh expect dash_verdict 0 '^CHIP_RUN: PASS' RD=$(ls "$T"/ev-dash_verdict/*.json 2>/dev/null | head -1) -assert dash_verdict "receipt verdict_lines is the dash line, unchanged" jqt '.verdict_lines == ["- VERDICT PASS"]' "$RD" +assert dash_verdict "receipt verdict_lines is the dash line, unchanged" jqt '.verdict_lines == ["--- VERDICT PASS"]' "$RD" +# no run args at all (RUN_ARGS empty, none on the command line): the binary gets none and run_args is [] +mkman "$T/m-noargs.sh" 'RUN_ARGS=""' +reset_world; CRMAN=$T/m-noargs.sh cr empty_args -- "${PD[@]}"; CRMAN=$T/m.sh +expect empty_args 0 '^CHIP_RUN: PASS' +RE=$(ls "$T"/ev-empty_args/*.json 2>/dev/null | head -1) +assert empty_args "receipt run_args is the empty list" jqt '.run_args == []' "$RE" +assert empty_args "the binary was started with no arguments" grep -q '^fake chip args=0$' "$T"/ev-empty_args/blobs/*.log if [ "$BAD" = 0 ]; then echo "CHIP_RUN_SELFTEST: PASS"; exit 0; fi echo "CHIP_RUN_SELFTEST: FAIL ($BAD)"; exit 1 diff --git a/tools/chip_run.sh b/tools/chip_run.sh index a145232eb..fae0b738f 100755 --- a/tools/chip_run.sh +++ b/tools/chip_run.sh @@ -2,6 +2,7 @@ # chip_run.sh MANIFEST [--physics-dir DIR] [--evidence-dir DIR] [-- gate args] # Run one chip binary under evidence. The one place that knows how (ground truth: # tools/run_numeric_transc_gate.sh, tools/run_unwritten_trap.sh, tests/run_reduce_chip.sh). +# The gcc line is the transc/unwritten-trap one; reduce differs (see NOT COVERED). # MANIFEST is shell syntax setting: GATE TEST_SOURCE SOURCES EXTRA_BUILD_SOURCES (relative # to the omega root, may use $PHYSICS and $HERE) RUN_ARGS VERDICT_RE PASS_LINE OWNER # EVIDENCE_DIR RAISE_QUIET TAKE_GPU_LOCK REFUSE_DIRTY_OMEGA (default 1) REFUSE_EXIT @@ -10,23 +11,32 @@ # VERDICT_RE must also match PASS_LINE, so set VERDICT_RE to verdict lines only), hooks # HOST_TIER_CMD (run first; nonzero refuses) and RECEIPT_EXTRA_JQ (jq filter on the receipt, # $log = chip log). The manifest cannot change the test seam variables below, QUIET_FLAG, -# GPU_LOCK or EST_LOAD_CMD (checked and restored after it is sourced). +# GPU_LOCK or EST_LOAD_CMD (checked and restored after it is sourced). That is an accident guard, +# not a boundary: the manifest is sourced into this shell and could still set any other variable. +# Gate args after "--" REPLACE the manifest RUN_ARGS (not appended); RUN_ARGS is split on whitespace. +# receipt host_tier = last line of the HOST_TIER_CMD log (empty if none); only its last 3 lines are +# printed. HOST_TIER_CMD runs in the omega root with CHIPRUN_RUN_DIR set, before the quiet flag and lock. # Physics dir, first match wins: --physics-dir, $PHYSICS_DIR, $PHYSICS, ~/workspace/physics. # Exit: 0 PASS; 1 FAIL (binary ran, verdict not PASS or tree changed); REFUSE_EXIT (default 2, # as run_unwritten_trap.sh) after printing "REFUSED: why" and REFUSE_VERDICT_LINE. A gate that # keeps transc semantics sets REFUSE_EXIT=1 REFUSE_VERDICT_LINE="VERDICT NOT_RUN". -# REFUSES (nothing is run): bad usage, argument or manifest; missing manifest variables or GATE -# characters; no evidence dir; test override env without CHIPRUN_SELFTEST=1 (checked before and +# Those two apply only to refusals after the manifest is sourced; usage, argument, seam-before and +# missing-manifest refusals always exit 2 with "CHIP_RUN: NOT_RUN". Exit 1 is also BAD_MANIFEST and +# the post-run "fatal" paths (log blob or receipt not written): "CHIP_RUN: FAIL ...", no receipt promised. +# REFUSES (the chip binary is not run; HOST_TIER_CMD, gcc and nm may already have run): bad usage, +# argument or manifest; missing manifest variables or GATE characters; no evidence dir; test override env without CHIPRUN_SELFTEST=1 (checked before and # after the manifest is sourced; a manifest that changes one is refused); no physics checkout; # unreadable omega or physics HEAD or physics.lock; physics not at the physics.lock pin; # physics dirty; omega dirty (if REFUSE_DIRTY_OMEGA=1); evidence dir inside omega or physics; # quiet flag already up or lost in a create race (if RAISE_QUIET=1); an est_load process; the # GPU lock unopenable or held (if TAKE_GPU_LOCK=1); no temp dir; HOST_TIER_CMD failing; a -# missing source; gcc failing; nm unreadable; libm math or CUDA symbols in the binary. +# missing source; gcc failing; nm unreadable; libm math or CUDA symbols in the binary. The libm check +# is a fixed list: sqrt exp exp2 log log2 pow fma sin cos tanh erf round fabs and their f variants; +# floor, ceil, fmod, tan, sinh, atan, log10 and the rest are not caught. # FAILS (ran to the end, receipt written): nonzero exit; no line matching VERDICT_RE; last such # line not matching PASS_LINE (any such line, if REQUIRE_ALL_PASS=1); omega (if # REFUSE_DIRTY_OMEGA=1) or physics dirty after the run; either HEAD moved. Never killed, never -# timed out. Quiet flag dropped only if still ours. +# timed out. Quiet flag dropped only if still ours. The receipt "reason" holds only the first failure. # RECEIPT /.json, mode 0444, noclobber, plus blobs/.log. # Fields: gate owner omega_commit omega_tree_clean_before omega_tree_clean_after # omega_commit_unchanged_after physics_commit physics_lock_pin physics_tree_clean_before @@ -44,11 +54,15 @@ # - REQUIRE_ALL_PASS checks lines that appear, not that a particular line appears: reduce's # SUM, MAX, MIN, MEAN, RED_GB10_PARITY and E1 lines are not each demanded. # - receipt reuse (an existing receipt with the same name is compared, not rewritten) has no case. +# - the build line: reduce (tests/run_reduce_chip.sh) adds -I"$PHYS/forge" (no variable here for it) +# and has neither -fno-fast-math nor -pthread; this module uses the transc/unwritten-trap flags. # Test seam (only with CHIPRUN_SELFTEST=1): CHIPRUN_PREBUILT_BIN CHIPRUN_QUIET_FLAG # CHIPRUN_GPU_LOCK CHIPRUN_EST_LOAD_CMD. Mutation check: each refusal line ends in # "# REFUSAL:"; tests/test_chip_run.sh --mutants deletes each one and needs case to FAIL. -# Not tagged: the "fatal" exits after the run (receipt and blob writing). -# Shell + coreutils + git + jq + gcc + nm + flock. No Python. +# The restore of QUIET_FLAG, GPU_LOCK and EST_LOAD_CMD after the manifest is tagged the same way +# (case restore_vars). --mutants also reverts the jq "x" prefix for the verdict lines and for the +# run args and needs case dash_verdict or happy to FAIL. Not tagged: the "fatal" exits after the run. +# Shell + GNU coreutils (date -d, realpath -m) + git + jq + gcc + nm + flock. No Python. set -u HERE=$(cd -P "$(dirname "${BASH_SOURCE[0]}")/.." && pwd) NVDIR=third_party/nvidia-open-580.173.02 # the one definition of the NVIDIA header tree @@ -112,7 +126,7 @@ case $REFUSE_EXIT in ''|*[!0-9]*) REX_BAD=1 ;; *) { [ "${#REFUSE_EXIT}" -le 3 ] case $REQUIRE_ALL_PASS in 0|1) ;; *) bad_manifest "REQUIRE_ALL_PASS=$REQUIRE_ALL_PASS is not 0 or 1" ;; esac # REFUSAL:require_all_value seam_check # REFUSAL:seam_after for v in "${SEAM_VARS[@]}"; do [ "${!v:-}" = "${SEAM0[$v]}" ] || refuse "manifest changed $v, a test seam variable"; done # REFUSAL:seam_changed -QUIET_FLAG=$QUIET0; GPU_LOCK=$GPU0; EST_LOAD_CMD=$EST0 +QUIET_FLAG=$QUIET0; GPU_LOCK=$GPU0; EST_LOAD_CMD=$EST0 # REFUSAL:restore_vars [ "$MRC" = 0 ] || refuse "manifest $MANIFEST failed to load" # REFUSAL:manifest_load for v in GATE TEST_SOURCE VERDICT_RE PASS_LINE OWNER; do [ -n "${!v}" ] || refuse "manifest does not set $v"; done # REFUSAL:manifest_vars case $GATE in *[!A-Za-z0-9_.-]*) refuse "GATE $GATE has characters outside A-Za-z0-9_.-" ;; esac # REFUSAL:gate_chars @@ -203,7 +217,7 @@ if [ ! -e "$EVID/blobs/$LOG_SHA.log" ]; then rm -f "$TMPB" fi [ "$(sha "$EVID/blobs/$LOG_SHA.log")" = "$LOG_SHA" ] || fatal "log blob does not match its digest" -# The two arrays go to jq with an "x" prefix that jq strips: jq 1.7 still reads any --args value starting with "-" as an option. +# The two arrays go to jq with an "x" prefix that jq strips: jq 1.7 reads an --args value that starts with "--" or with "-" and a letter as an option. BODY=$(jq -n --arg gate "$GATE" --arg owner "$OWNER" --arg omega "$OMEGA_COMMIT" --arg phys "$PHYS_COMMIT" --arg pin "$PIN" \ --argjson oclean "$OMEGA_CLEAN_BEFORE" --argjson pclean "$PHYS_CLEAN_BEFORE" \ --argjson oafter "$OMEGA_CLEAN_AFTER" --argjson pafter "$PHYS_CLEAN_AFTER" --argjson osame "$OMEGA_SAME" --argjson psame "$PHYS_SAME" \