benchmarks-mv
Measurement harnesses and evidence bundles for AIEN on the NVIDIA DGX Spark GB10. Speed is reported against the machine's physical limit and my own previous run. Attachment of AienOS.
Brought by drakestapleton
benchmarks-mv / tests / gates / pre-review.sh
| 1 | #!/usr/bin/env bash |
| 2 | # SPDX-License-Identifier: Apache-2.0 |
| 3 | # Explicit pre-review driver for DRA-948 input-provenance packets (L1328). |
| 4 | # |
| 5 | # Every accept or refuse decision about a document, a source row, a provider |
| 6 | # archive, a public route or a CI file is made by the native Omega checker |
| 7 | # tests/gates/provenance-check.om. This script only runs external tools (git, |
| 8 | # the cargo gates, curl, jq, sha256sum, cmp, dd and the documented bash block) |
| 9 | # and requires their exit codes. The host tool contract is in |
| 10 | # docs/reviews/REVIEW-LESSONS.md. |
| 11 | # |
| 12 | # tests/gates/pre-review.sh [--controls] COMMIT OMEGA_SOURCE PREFLIGHT.md |
| 13 | # |
| 14 | # --controls runs only the checker's own negative controls and the checker |
| 15 | # mutants (no gates, no public route, no packet replay) and never prints |
| 16 | # "PASS complete". |
| 17 | set -euo pipefail |
| 18 | export LC_ALL=C |
| 19 | |
| 20 | fail() { printf 'pre-review FAIL %s\n' "$*" >&2; exit 1; } |
| 21 | pass() { printf 'pre-review PASS %s\n' "$*"; } |
| 22 | |
| 23 | mode=full |
| 24 | if [[ ${1:-} = --controls ]]; then mode=controls; shift; fi |
| 25 | [[ $# = 3 ]] || fail 'usage: pre-review.sh [--controls] COMMIT OMEGA_SOURCE PREFLIGHT.md' |
| 26 | candidate=$1 |
| 27 | omega_source=$(realpath -- "$2") |
| 28 | relative_doc=$3 |
| 29 | root=$(git rev-parse --show-toplevel) |
| 30 | driver=$(realpath -- "${BASH_SOURCE[0]}") |
| 31 | [[ $candidate =~ ^[0-9a-f]{40}$ ]] || fail 'supply a full candidate commit' |
| 32 | [[ $(git -C "$root" cat-file -t "$candidate") = commit ]] || fail 'candidate is not a commit' |
| 33 | |
| 34 | scratch=$(mktemp -d) |
| 35 | trap 'rm -rf -- "$scratch"' EXIT |
| 36 | git clone --quiet --local --no-checkout -- "$root" "$scratch/checkout" |
| 37 | git -C "$scratch/checkout" checkout --quiet --detach "$candidate" |
| 38 | cd -P "$scratch/checkout" |
| 39 | printf 'pre-review head %s mode %s\n' "$(git rev-parse HEAD)" "$mode" |
| 40 | |
| 41 | if [[ $mode = full ]]; then |
| 42 | sh scripts/check-no-python.sh |
| 43 | pass 'no-python rc=0' |
| 44 | printf 'pre-review driver sha256 %s\n' "$(sha256sum < "$driver" | cut -d ' ' -f 1)" |
| 45 | [[ $(git hash-object --no-filters "$driver") = $(git rev-parse HEAD:tests/gates/pre-review.sh) ]] || |
| 46 | fail 'pre-review driver differs from candidate source' |
| 47 | fi |
| 48 | |
| 49 | # Build the checker with the newest public omega-mv main compiler, read from a |
| 50 | # Git object. Never use an installed, unversioned omc. |
| 51 | compiler_ref=$(GIT_CONFIG_NOSYSTEM=1 GIT_CONFIG_GLOBAL=/dev/null GIT_TERMINAL_PROMPT=0 \ |
| 52 | git ls-remote https://interplane.io/projects/omega-mv/repo.git refs/heads/main) |
| 53 | compiler_head=${compiler_ref%%$'\t'*} |
| 54 | [[ $compiler_head =~ ^[0-9a-f]{40}$ ]] || fail 'public omega-mv main has no exact head' |
| 55 | git -C "$omega_source" show "$compiler_head:seed/out/omc" > "$scratch/omc" |
| 56 | chmod +x "$scratch/omc" |
| 57 | printf 'pre-review omega-mv %s compiler %s\n' "$compiler_head" "$(sha256sum < "$scratch/omc" | cut -d ' ' -f 1)" |
| 58 | printf '%s\n' 'pre-review trust boundary: the driver and checker come from the candidate. Independent review must compare both with public main and audit reproduction commands and host inputs.' |
| 59 | checker_source=tests/gates/provenance-check.om |
| 60 | check="$scratch/provenance-check" |
| 61 | "$scratch/omc" < "$checker_source" > "$check" || fail 'checker did not compile' |
| 62 | chmod +x "$check" |
| 63 | printf 'pre-review checker source blob %s binary sha256 %s\n' "$(git hash-object --no-filters "$checker_source")" \ |
| 64 | "$(sha256sum < "$check" | cut -d ' ' -f 1)" |
| 65 | chk() { "$check" "$@"; } |
| 66 | |
| 67 | printf 'pre-review tools Bash %s; %s; %s; %s; %s\n' "$BASH_VERSION" "$(jq --version)" \ |
| 68 | "$(git --version)" "$(curl --version | sed -n '1p')" "$(sha256sum --version | sed -n '1p')" |
| 69 | |
| 70 | expect_refusal() { |
| 71 | local control=$1 diagnostic=$2 result |
| 72 | shift 2 |
| 73 | set +e |
| 74 | ( set -e; "$@" ) > "$scratch/refusal" 2>&1 |
| 75 | result=$? |
| 76 | set -e |
| 77 | [[ $result = 1 ]] && grep -Fq -- "$diagnostic" "$scratch/refusal" || |
| 78 | { cat "$scratch/refusal" >&2; fail "expected refusal for $control, got $result"; } |
| 79 | pass "control $control" |
| 80 | } |
| 81 | expect_status() { |
| 82 | local control=$1 want=$2 result |
| 83 | shift 2 |
| 84 | set +e |
| 85 | ( set -e; "$@" ) > /dev/null 2>&1 |
| 86 | result=$? |
| 87 | set -e |
| 88 | [[ $result = "$want" ]] || fail "expected exit $want for $control, got $result" |
| 89 | pass "control $control" |
| 90 | } |
| 91 | |
| 92 | tracked_file() { |
| 93 | [[ -f $1 && ! -L $1 ]] || fail "expected a regular file: $1" |
| 94 | git --literal-pathspecs ls-files --error-unmatch -- "$1" > /dev/null 2>&1 || fail "untracked evidence file: $1" |
| 95 | } |
| 96 | |
| 97 | # Projections: jq only turns JSON into tab-separated text. The checker judges it. |
| 98 | provider_filter='([.id,.sha]|@tsv), (.siblings|sort_by(.rfilename)[]|[.rfilename, |
| 99 | (.size|if type=="number" then tostring else "bad" end),.blobId,(.lfs.sha256//""), |
| 100 | (if .lfs then (.lfs.size|if type=="number" then tostring else "bad" end) else "" end)]|@tsv)' |
| 101 | blob_filter='[.schema,.repo.owner,.repo.name,.commit,.ref,.ref_kind,.path,.links.raw, |
| 102 | (.size|if type=="number" then tostring else "bad" end)]|@tsv' |
| 103 | |
| 104 | provider_check() { # archive file, capture URL |
| 105 | jq -r "$provider_filter" "$1" > "$scratch/projection" 2> /dev/null || |
| 106 | { echo 'provider archive is not valid JSON with a siblings list' >&2; return 1; } |
| 107 | chk provider "$2" < "$scratch/projection" |
| 108 | } |
| 109 | |
| 110 | # Compare the validated provider inventory with every local replay declaration. |
| 111 | # Duplicate replay rows fail even if multiple archives contain the same name. |
| 112 | check_inventory() { |
| 113 | LC_ALL=C sort -u "$1" > "$scratch/provider.names" |
| 114 | LC_ALL=C sort "$2" > "$scratch/replay.names" |
| 115 | cmp -s "$scratch/provider.names" "$scratch/replay.names" || |
| 116 | fail 'provider payload inventory and replay declarations differ' |
| 117 | } |
| 118 | verify_payload_bytes() { |
| 119 | local package=$1 file size blob lfs ignored actual |
| 120 | while IFS=$'\t' read -r file size blob lfs ignored; do |
| 121 | [[ -f $package/$file && ! -L $package/$file ]] || fail "missing regular provider payload: $file" |
| 122 | [[ $(stat -c %s -- "$package/$file") = "$size" ]] || fail "provider byte length mismatch: $file" |
| 123 | if [[ -n $lfs ]]; then |
| 124 | actual=$(sha256sum < "$package/$file") |
| 125 | [[ ${actual%% *} = "$lfs" ]] || fail "provider LFS digest mismatch: $file" |
| 126 | else |
| 127 | [[ $(git hash-object --no-filters -- "$package/$file") = "$blob" ]] || fail "provider blob digest mismatch: $file" |
| 128 | fi |
| 129 | done < "$2" |
| 130 | } |
| 131 | external_inventory() { |
| 132 | local file |
| 133 | while IFS= read -r file; do |
| 134 | if [[ -e $1/$file || -L $1/$file ]]; then |
| 135 | fail "external receipt covers a local provider payload: $file" |
| 136 | fi |
| 137 | done < "$2" |
| 138 | } |
| 139 | page_identity() { |
| 140 | chk contains "href=\"${1#https://interplane.io}\"" < "$2" || |
| 141 | fail "public file page does not identify this blob: $1" |
| 142 | } |
| 143 | |
| 144 | verify_row() { # raw file, sha256, quoted whole line, where |
| 145 | printf '%s %s\n' "$2" "$1" | sha256sum --check --status || fail "source SHA-256 mismatch: $4" |
| 146 | chk line "$3" < "$1" || fail "source text mismatch: $4 (expected whole line: $3)" |
| 147 | } |
| 148 | |
| 149 | fixture=tests/gates/provenance-fixture |
| 150 | sha_blob=98c86da8b401a0b26aafdb4dd03bf01f80980f4a027bad63bbc354164391fbeb |
| 151 | control_doc="$scratch/control.md" |
| 152 | doc_control() { chk doc < "$control_doc"; } |
| 153 | fresh_doc() { cp -- "$fixture/preflight.md" "$control_doc"; } |
| 154 | |
| 155 | # The checker's own negative controls, run on the fixture packet so that they do |
| 156 | # not depend on the packet under review. Mutants of the checker must fail them. |
| 157 | checker_controls() { |
| 158 | local diagnostic text i good saved fields url |
| 159 | fresh_doc |
| 160 | chk doc < "$control_doc" > /dev/null || fail 'fixture document refused' |
| 161 | pass 'control fixture document accepted' |
| 162 | fresh_doc |
| 163 | printf '%s\n' '# unsupported heading' >> "$control_doc" |
| 164 | sed -i '/^```bash pre-review$/a # unsupported comment' "$control_doc" |
| 165 | doc_control > "$scratch/accounting" || fail 'accounting fixture refused' |
| 166 | for text in '# unsupported heading' '# unsupported comment'; do |
| 167 | grep -Fxq -- "$(printf 'unchecked\t%s' "$text")" "$scratch/accounting" || fail "unaccounted text: $text" |
| 168 | done |
| 169 | for prefix in '# ' 'Unchecked: '; do |
| 170 | fresh_doc |
| 171 | { printf '%s' "$prefix"; head -c 700000 /dev/zero | tr '\0' x; printf 'TAILMARKER'; } > "$scratch/long-free" |
| 172 | cat "$scratch/long-free" >> "$control_doc" |
| 173 | doc_control > "$scratch/accounting" || fail 'long narrative refused' |
| 174 | tail -1 "$scratch/accounting" > "$scratch/emitted" |
| 175 | { printf 'unchecked\t'; if [[ $prefix = '# ' ]]; then cat "$scratch/long-free"; else tail -c +12 "$scratch/long-free"; fi; printf '\n'; } > "$scratch/expected" |
| 176 | cmp -s "$scratch/emitted" "$scratch/expected" || fail 'unchecked text was truncated or repeated' |
| 177 | done |
| 178 | printf '%s\n' blob.txt lfs.txt > "$scratch/local-names" |
| 179 | expect_refusal 'external receipt with packaged payload' 'external receipt covers a local provider payload' external_inventory "$fixture" "$scratch/local-names" |
| 180 | mkdir -p "$scratch/external-only" |
| 181 | external_inventory "$scratch/external-only" "$scratch/local-names" |
| 182 | fresh_doc; printf '%s\n' '#invalid' >> "$control_doc" |
| 183 | expect_refusal 'malformed heading' 'not in the evidence grammar' doc_control |
| 184 | sed '/^```bash pre-review$/,$d' "$fixture/preflight.md" > "$control_doc" |
| 185 | printf '%s\n' '```bash pre-review' ' # comment only' '```' >> "$control_doc" |
| 186 | expect_refusal 'comment-only block' 'block with a command' doc_control |
| 187 | sed '/^Replay /d' "$fixture/preflight.md" > "$control_doc" |
| 188 | printf 'External-control %s sha256 %s\n' a.txt "$sha_blob" b.txt "$sha_blob" >> "$control_doc" |
| 189 | expect_refusal 'duplicate external control' 'one external control' doc_control |
| 190 | fresh_doc; printf '%s\n' 'Input PREFLIGHT_INPUT_lower' >> "$control_doc" |
| 191 | expect_refusal 'lowercase input name' 'input row' doc_control |
| 192 | sed -E "/^Provider capture /s/ [0-9T:Z-]+ curl/ $(date -u -d tomorrow +%FT%TZ) curl/" "$fixture/preflight.md" > "$control_doc" |
| 193 | expect_refusal 'tomorrow capture' 'capture time' doc_control |
| 194 | sed -E "/^Provider capture /s/ [0-9T:Z-]+ curl/ $(date -u -d '+2 minutes' +%FT%TZ) curl/" "$fixture/preflight.md" > "$control_doc" |
| 195 | expect_refusal 'near-future capture' 'capture time' doc_control |
| 196 | sed '/^Provider capture /s/blobs=true/blobs= true/' "$fixture/preflight.md" > "$control_doc" |
| 197 | expect_refusal 'space in provider URL' 'provider capture row' doc_control |
| 198 | printf 'blob.txt\nlfs.txt\n' > "$scratch/all-names" |
| 199 | printf 'blob.txt\n' > "$scratch/declared" |
| 200 | expect_refusal 'omitted provider payload' 'inventory and replay' check_inventory "$scratch/all-names" "$scratch/declared" |
| 201 | printf 'blob.txt\nlfs.txt\nlfs.txt\n' > "$scratch/declared" |
| 202 | expect_refusal 'duplicate replay' 'inventory and replay' check_inventory "$scratch/all-names" "$scratch/declared" |
| 203 | printf '%s\n' '<main>missing link</main>' > "$scratch/no-link" |
| 204 | expect_refusal 'page missing exact blob href' 'does not identify this blob' page_identity 'https://interplane.io/test' "$scratch/no-link" |
| 205 | while IFS=$'\t' read -r diagnostic text; do |
| 206 | fresh_doc |
| 207 | printf '%s\n' "$text" >> "$control_doc" |
| 208 | expect_refusal "document line ${text:0:48}" "$diagnostic" doc_control |
| 209 | done < "$fixture/controls.tsv" |
| 210 | fresh_doc; printf 'Unchecked: a\tb\n' >> "$control_doc" |
| 211 | expect_refusal 'document tab' 'control character' doc_control |
| 212 | fresh_doc; printf 'Unchecked: a\r\n' >> "$control_doc" |
| 213 | expect_refusal 'document CRLF' 'control character' doc_control |
| 214 | fresh_doc; { printf 'Checked local blob.txt sha256 %s :: ' "$sha_blob"; head -c 700000 /dev/zero | tr '\0' x; printf '\n'; } >> "$control_doc" |
| 215 | expect_refusal 'document oversized row' 'row longer' doc_control |
| 216 | fresh_doc; { printf 'Unchecked: '; head -c 700000 /dev/zero | tr '\0' x; printf '\n'; } >> "$control_doc" |
| 217 | chk doc < "$control_doc" > /dev/null || fail 'oversized free line was refused' |
| 218 | pass 'control document oversized Unchecked line accepted' |
| 219 | sed '/^Scope: /d' "$fixture/preflight.md" > "$control_doc" |
| 220 | expect_refusal 'document without scope' 'exactly one input-provenance scope' doc_control |
| 221 | fresh_doc; printf 'Scope: input identities only. Evaluation status: NOT_RUN.\n' >> "$control_doc" |
| 222 | expect_refusal 'document with two scope lines' 'exactly one input-provenance scope' doc_control |
| 223 | sed '/^Provider capture /d' "$fixture/preflight.md" > "$control_doc" |
| 224 | expect_refusal 'document without provider capture' 'no provider capture row' doc_control |
| 225 | sed '/^Checked public /d' "$fixture/preflight.md" > "$control_doc" |
| 226 | expect_refusal 'document without public source row' 'no public source row' doc_control |
| 227 | for text in 2026-02-31T13:31:11Z 2023-02-29T00:00:00Z 2026-00-10T00:00:00Z 2026-11-00T00:00:00Z 2099-01-01T00:00:00Z 1969-12-31T23:59:59Z 2026-11-18T13:31:11 2026-13-01T00:00:00Z 2026-11-18T24:00:00Z; do |
| 228 | sed -E "/^Provider capture /s/ [0-9T:Z-]+ curl/ $text curl/" "$fixture/preflight.md" > "$control_doc" |
| 229 | expect_refusal "provider capture time $text" 'capture time' doc_control |
| 230 | done |
| 231 | sed -E "/^Provider capture /s/ [0-9T:Z-]+ curl/ 2024-02-29T12:00:00Z curl/" "$fixture/preflight.md" > "$control_doc" |
| 232 | chk doc < "$control_doc" > /dev/null || fail 'leap day capture time refused' |
| 233 | pass 'control leap day capture time accepted' |
| 234 | sed -E '/^Replay /d' "$fixture/preflight.md" > "$control_doc" |
| 235 | expect_refusal 'document without payload declaration' 'replay rows or one external control row' doc_control |
| 236 | fresh_doc; printf 'External-control receipt.txt sha256 %s\n' "$sha_blob" >> "$control_doc" |
| 237 | expect_refusal 'document with replay and external rows' 'replay rows or one external control row' doc_control |
| 238 | sed '/^```bash pre-review$/,$d' "$fixture/preflight.md" > "$control_doc" |
| 239 | expect_refusal 'document without block' 'exactly one complete bash pre-review block' doc_control |
| 240 | sed '$d' "$fixture/preflight.md" > "$control_doc" |
| 241 | expect_refusal 'document with unterminated block' 'unterminated' doc_control |
| 242 | fresh_doc; sed -n '/^```bash pre-review$/,$p' "$fixture/preflight.md" >> "$control_doc" |
| 243 | expect_refusal 'document with two blocks' 'exactly one complete bash pre-review block' doc_control |
| 244 | |
| 245 | url=$(jq -r '"https://huggingface.co/api/models/\(.id)/revision/\(.sha)?blobs=true"' "$fixture/provider.json") |
| 246 | provider_check "$fixture/provider.json" "$url" || fail 'fixture provider archive refused' |
| 247 | tail -n +2 "$scratch/projection" > "$scratch/fixture-provider-rows" |
| 248 | verify_payload_bytes "$fixture" "$scratch/fixture-provider-rows" |
| 249 | mkdir -p "$scratch/byte-probes" |
| 250 | for text in blob lfs; do |
| 251 | cp -- "$fixture/blob.txt" "$fixture/lfs.txt" "$scratch/byte-probes/" |
| 252 | printf 'X' | dd of="$scratch/byte-probes/$text.txt" bs=1 seek=2 count=1 conv=notrunc status=none |
| 253 | if [[ $text = blob ]]; then diagnostic='provider blob digest mismatch'; else diagnostic='provider LFS digest mismatch'; fi |
| 254 | expect_refusal "interior $text byte differs" "$diagnostic" verify_payload_bytes "$scratch/byte-probes" "$scratch/fixture-provider-rows" |
| 255 | done |
| 256 | pass 'control fixture provider archive accepted' |
| 257 | expect_refusal 'provider capture of another revision' 'differs from the archive identity' provider_check "$fixture/provider.json" "${url/0000/1111}" |
| 258 | expect_refusal 'provider capture with a longer URL' 'differs from the archive identity' provider_check "$fixture/provider.json" "${url}x" |
| 259 | printf '{"siblings":\n' > "$scratch/mutated.json" |
| 260 | expect_refusal 'provider archive malformed JSON' 'not valid JSON' provider_check "$scratch/mutated.json" "$url" |
| 261 | for text in '.siblings = []' '.siblings += [.siblings[0]]' '.siblings[0].rfilename = "../outside"' \ |
| 262 | '.siblings[0].blobId = "xyz"' '.sha = "abc"' '.siblings[1].lfs.size += 1' '.siblings[1].lfs.sha256 = "ab"' \ |
| 263 | '.siblings |= map(select(has("lfs")))' '.siblings |= map(select(has("lfs") | not))' \ |
| 264 | '.siblings[0].size = "13"' '.siblings[0].size = 1e30' '.id = "a/b/c"'; do |
| 265 | jq "$text" "$fixture/provider.json" > "$scratch/mutated.json" |
| 266 | expect_refusal "provider archive $text" provider provider_check "$scratch/mutated.json" "$url" |
| 267 | done |
| 268 | |
| 269 | good=$'forge/blob/1\to\tr\taaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\taaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\tcommit\tp.txt\t/o/r/raw/aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/p.txt\t12' |
| 270 | url=https://interplane.io/o/r/blob/aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/p.txt |
| 271 | printf '%s\n' "$good" | chk identity "$url" 12 || fail 'matching blob identity refused' |
| 272 | pass 'control matching blob identity accepted' |
| 273 | IFS=$'\t' read -r -a fields <<< "$good" |
| 274 | for i in 0 1 2 3 4 5 6 7 8; do |
| 275 | saved=${fields[i]} |
| 276 | fields[i]=zz |
| 277 | ( IFS=$'\t'; printf '%s\n' "${fields[*]}" ) > "$scratch/identity" |
| 278 | fields[i]=$saved |
| 279 | expect_refusal "blob identity field $i" 'identity mismatch' chk_identity "$url" 12 |
| 280 | done |
| 281 | printf '%s\n' "$good" > "$scratch/identity" |
| 282 | expect_refusal 'blob identity raw size' 'identity mismatch' chk_identity "$url" 13 |
| 283 | expect_refusal 'blob identity mutable route' 'canonical immutable' chk_identity "${url/aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/main}" 12 |
| 284 | expect_refusal 'raw route of a mutable ref' 'canonical immutable' chk raw "${url/aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/main}" |
| 285 | |
| 286 | printf 'first\nactual line\nlast' > "$scratch/lines" |
| 287 | chk line 'actual line' < "$scratch/lines" || fail 'whole line refused' |
| 288 | chk line 'last' < "$scratch/lines" || fail 'last line without newline refused' |
| 289 | pass 'control whole lines accepted' |
| 290 | for text in 'actual' 'ctual line' 'actual line ' 'la' ''; do |
| 291 | if [[ -n $text ]]; then |
| 292 | expect_status "line not whole: $text" 1 chk line "$text" < "$scratch/lines" |
| 293 | else |
| 294 | expect_status 'line empty needle' 2 chk line "$text" < "$scratch/lines" |
| 295 | fi |
| 296 | done |
| 297 | printf 'actual line\r\n' | { chk line 'actual line' && fail 'CRLF line accepted'; pass 'control CRLF line refused'; } |
| 298 | expect_status 'line empty input' 1 chk line x < /dev/null |
| 299 | { head -c 70000 /dev/zero | tr '\0' x; printf '\n'; } > "$scratch/wide" |
| 300 | chk line "$(head -c 70000 /dev/zero | tr '\0' x)" < "$scratch/wide" || fail 'line across the read size refused' |
| 301 | expect_status 'line across the read size, one byte short' 1 chk line "$(head -c 69999 /dev/zero | tr '\0' x)" < "$scratch/wide" |
| 302 | pass 'control line across the read size' |
| 303 | { head -c 65530 /dev/zero | tr '\0' x; printf 'needle'; head -c 100 /dev/zero | tr '\0' x; } > "$scratch/wide" |
| 304 | chk contains needle < "$scratch/wide" || fail 'substring across the read size refused' |
| 305 | printf 'aabaabaac' | chk contains aabaac || fail 'overlapping substring refused' |
| 306 | expect_status 'contains absent' 1 chk contains neddle < "$scratch/wide" |
| 307 | pass 'control substring' |
| 308 | |
| 309 | printf 'actual source line\n' > "$scratch/raw" |
| 310 | verify_row "$scratch/raw" "$(sha256sum < "$scratch/raw" | cut -d ' ' -f 1)" 'actual source line' control |
| 311 | pass 'control row accepted' |
| 312 | expect_refusal 'row quote is a prefix' 'source text mismatch' verify_row "$scratch/raw" "$(sha256sum < "$scratch/raw" | cut -d ' ' -f 1)" 'actual source' control |
| 313 | expect_refusal 'row quote asserts an unsupported setting' 'source text mismatch' verify_row "$scratch/raw" \ |
| 314 | "$(sha256sum < "$scratch/raw" | cut -d ' ' -f 1)" 'sets an input limit of fewer than 256 encoded tokens and greedy generation with a 160-token cap' control |
| 315 | expect_refusal 'row digest of other bytes' 'SHA-256 mismatch' verify_row "$scratch/raw" "$sha_blob" 'actual source line' control |
| 316 | |
| 317 | { cat .forgejo/workflows/ci.yml; printf ' - name: Publish\n run: cargo publish\n'; } > "$scratch/ci.yml" |
| 318 | expect_refusal 'CI with an unrecognised run step' 'unrecognised CI run step' chk_ci "$scratch/ci.yml" |
| 319 | { cat .forgejo/workflows/ci.yml; printf ' - name: Gate\n run: tests/gates/run.sh fmt; true\n'; } > "$scratch/ci.yml" |
| 320 | expect_refusal 'CI with a chained gate step' 'unrecognised CI run step' chk_ci "$scratch/ci.yml" |
| 321 | pass 'checker controls complete' |
| 322 | } |
| 323 | chk_identity() { chk identity "$@" < "$scratch/identity"; } |
| 324 | chk_ci() { chk ci < "$1"; } |
| 325 | |
| 326 | check_external() { # control receipt |
| 327 | local hash |
| 328 | hash=$(sha256sum < "$scratch/reproduce") |
| 329 | [[ -f $1 ]] && chk line "reproduction_sha256=${hash%% *}" < "$1" && |
| 330 | chk line payload_positive_exit=0 < "$1" && |
| 331 | chk line same_size_payload_corruption_exit=1 < "$1" || |
| 332 | fail 'external payload control receipt is absent or does not bind this reproduction' |
| 333 | } |
| 334 | |
| 335 | # Break the checker on purpose: each mutant must fail the checker's own controls. |
| 336 | mutants() { |
| 337 | local n=0 expr |
| 338 | while IFS= read -r expr; do |
| 339 | n=$((n + 1)) |
| 340 | sed -z "$expr" "$checker_source" > "$scratch/mutant.om" |
| 341 | cmp -s -- "$checker_source" "$scratch/mutant.om" && fail "mutant $n changed nothing: $expr" |
| 342 | "$scratch/omc" < "$scratch/mutant.om" > "$scratch/mutant" 2> /dev/null || fail "mutant $n did not compile" |
| 343 | chmod +x "$scratch/mutant" |
| 344 | if ( check="$scratch/mutant"; checker_controls ) > /dev/null 2>&1; then |
| 345 | fail "mutant $n survived the checker controls: $expr" |
| 346 | fi |
| 347 | pass "mutant $n killed" |
| 348 | done <<'MUTANTS' |
| 349 | s/if and same eq matched w\nret 0\nend\nret 1/if same\nret 0\nend\nret 1/ |
| 350 | s/ret refuse m_grammar\nend\nfn doc_end/ret 0\nend\nfn doc_end/ |
| 351 | s/ret le secs now/ret true/ |
| 352 | s/if ge q get st 12\nret refuse m_quote/if gt 0 q\nret refuse m_quote/ |
| 353 | s/if ne get exp i get argb i\nret refuse m_purl/if gt 0 i\nret refuse m_purl/ |
| 354 | s/if ne get exp i get aux i\nret refuse m_ident/if gt 0 i\nret refuse m_ident/ |
| 355 | s/if not hexrun p 40\nret false\nend\nput ur 4 p/if gt 0 p\nret false\nend\nput ur 4 p/ |
| 356 | s/if gt get st 13 n\nif not loose\nret refuse m_long/if gt 0 n\nif not loose\nret refuse m_long/ |
| 357 | s/ret eq get line p 32\nend/ret true\nend/ |
| 358 | s/ret ne c 35\nend/ret true\nend/ |
| 359 | s/if gt get st 9 1\nret refuse m_payload\nend/if gt get st 9 9\nret refuse m_payload\nend/ |
| 360 | s/if not or is_digit c or and ge c 65 le c 90 eq c 95/if not or is_digit c or and ge c 65 le c 122 eq c 95/ |
| 361 | s/ret le secs now/ret le secs add now 31536000/ |
| 362 | s/if or eq c 39 or eq c 32 lt c 33/if eq c 39/ |
| 363 | s/if heading\nret unchecked_from 0/if heading\nret 0/ |
| 364 | s/if gt n 0\nret unchecked_from 0/if gt 0 n\nret unchecked_from 0/ |
| 365 | s/stream_part begin i/stream_part i i/ |
| 366 | s/ret le secs now/ret le secs add now 3600/ |
| 367 | MUTANTS |
| 368 | } |
| 369 | |
| 370 | repository_controls() { |
| 371 | # The no-Python guard must still refuse a tracked Python file. Tracked history |
| 372 | # that held the original Python verifier is not in this repository's objects. |
| 373 | git clone --quiet --local -- . "$scratch/no-python" 2> /dev/null |
| 374 | printf 'print(1)\n' > "$scratch/no-python/evidence-probe.py" |
| 375 | git -C "$scratch/no-python" add evidence-probe.py |
| 376 | expect_refusal 'tracked Python file' 'no-python guard: FAIL' sh -c "cd '$scratch/no-python' && sh scripts/check-no-python.sh" |
| 377 | } |
| 378 | |
| 379 | checker_controls |
| 380 | repository_controls |
| 381 | mutants |
| 382 | ( |
| 383 | external_inventory() { return 0; } |
| 384 | if (checker_controls) > /dev/null 2>&1; then fail 'external inventory bypass survived'; fi |
| 385 | pass 'external inventory bypass killed' |
| 386 | ) |
| 387 | if [[ $mode = controls ]]; then |
| 388 | pass "controls-only head=$candidate (gates, public routes, packet replay NOT_RUN)" |
| 389 | exit 0 |
| 390 | fi |
| 391 | |
| 392 | # CI order and existing commands. The checker refuses a CI run step it does not cover. |
| 393 | gate_steps=$(chk ci < .forgejo/workflows/ci.yml) || fail 'CI contains a run step this driver does not cover' |
| 394 | manifest_steps=$(cat tests/gates/bench-*.gate | chk manifest) || fail 'gate manifests unreadable' |
| 395 | [[ $(sort <<< "$gate_steps") = "$(sort <<< "$manifest_steps")" ]] || fail 'CI gate steps and manifests disagree' |
| 396 | for step in $gate_steps; do |
| 397 | printf 'pre-review run tests/gates/run.sh %s\n' "$step" |
| 398 | CARGO_NET_OFFLINE=true tests/gates/run.sh "$step" |
| 399 | pass "gate $step rc=0" |
| 400 | done |
| 401 | [[ -z $(git status --porcelain) ]] || fail 'gates changed the fresh checkout' |
| 402 | [[ $(git rev-parse HEAD) = "$candidate" ]] || fail 'gates changed the candidate head' |
| 403 | |
| 404 | # The packet under review. |
| 405 | tracked_file "$relative_doc" |
| 406 | package=${relative_doc%/*} |
| 407 | [[ $package != "$relative_doc" ]] || fail 'preflight document needs a package directory' |
| 408 | chk doc < "$relative_doc" > "$scratch/rows" || fail 'evidence document refused' |
| 409 | chk block < "$relative_doc" > "$scratch/reproduce" || fail 'documented reproduction could not be extracted' |
| 410 | for kind in public copy local provider replay input external unchecked; do |
| 411 | sed -n "/^$kind\t/p" "$scratch/rows" > "$scratch/rows.$kind" |
| 412 | done |
| 413 | rows_of() { cat -- "$scratch/rows.$1"; } |
| 414 | printf 'pre-review rows %s\n' "$(cut -f1 "$scratch/rows" | sort | uniq -c | tr -s ' \n' ' ')" |
| 415 | rows_of unchecked | sed 's/^unchecked\t/pre-review unchecked (no evidential weight): /' |
| 416 | |
| 417 | get_public() { # URL, destination, Accept header |
| 418 | local status |
| 419 | status=$(curl -q --silent --show-error --proto '=https' --max-time 60 --header "Accept: $3" \ |
| 420 | --output "$2" --write-out '%{http_code}' -- "$1") || fail "public request failed: $1" |
| 421 | [[ $status = 200 ]] || fail "public HTTP $status: $1" |
| 422 | } |
| 423 | url_key() { printf '%s' "$1" | sha256sum | cut -c1-16; } |
| 424 | verify_public_url() { # fetch the three routes of one blob URL and check its identity |
| 425 | local url=$1 key |
| 426 | key=$(url_key "$url") |
| 427 | get_public "$url" "$scratch/html.$key" text/html |
| 428 | page_identity "$url" "$scratch/html.$key" |
| 429 | get_public "$url" "$scratch/json.$key" application/json |
| 430 | jq -r "$blob_filter" "$scratch/json.$key" > "$scratch/projection.$key" || fail "public blob JSON is malformed: $url" |
| 431 | get_public "$(chk raw "$url")" "$scratch/raw.$key" application/octet-stream |
| 432 | chk identity "$url" "$(wc -c < "$scratch/raw.$key")" < "$scratch/projection.$key" || |
| 433 | fail "public blob identity mismatch: $url" |
| 434 | } |
| 435 | public_failures=0 |
| 436 | while IFS= read -r url; do |
| 437 | set +e |
| 438 | ( set -e; verify_public_url "$url" ) |
| 439 | rc=$? |
| 440 | set -e |
| 441 | ((rc == 0)) || public_failures=1 |
| 442 | done < <({ rows_of public | cut -f2; rows_of copy | cut -f2; } | sort -u) |
| 443 | ((public_failures == 0)) || fail 'public source checks failed' |
| 444 | while IFS=$'\t' read -r _ url sha quote; do |
| 445 | verify_row "$scratch/raw.$(url_key "$url")" "$sha" "$quote" "$url" |
| 446 | printf 'pre-review evidence %s sha256=%s\n' "$url" "$sha" |
| 447 | done < "$scratch/rows.public" |
| 448 | while IFS=$'\t' read -r _ url sha file; do |
| 449 | tracked_file "$package/$file" |
| 450 | printf '%s %s\n' "$sha" "$scratch/raw.$(url_key "$url")" | sha256sum --check --status || fail "source SHA-256 mismatch: $url" |
| 451 | cmp -s -- "$scratch/raw.$(url_key "$url")" "$package/$file" || fail "source bytes mismatch: $url versus $file" |
| 452 | printf 'pre-review evidence %s equals %s\n' "$url" "$file" |
| 453 | done < "$scratch/rows.copy" |
| 454 | while IFS=$'\t' read -r _ file sha quote; do |
| 455 | tracked_file "$package/$file" |
| 456 | verify_row "$package/$file" "$sha" "$quote" "$file" |
| 457 | printf 'pre-review author-supplied local quote (independent support unchecked) %s sha256=%s\n' "$file" "$sha" |
| 458 | done < "$scratch/rows.local" |
| 459 | |
| 460 | # Live controls against the public forge: an unpublished commit, and the |
| 461 | # historical false claim backed only by a correct digest. |
| 462 | expect_refusal 'live unpublished commit' 'public HTTP 404' verify_public_url \ |
| 463 | https://interplane.io/drakestapleton/omega-tool-model/blob/0000000000000000000000000000000000000000/deployment/build-receipt.json |
| 464 | # Historical negative controls describe this immutable receipt, independent of the packet's sources. |
| 465 | url=https://interplane.io/drakestapleton/omega-tool-model/blob/b86d8082c7b90e39d67fa6be603afd287fe11553/deployment/build-receipt.json |
| 466 | sha=2b82d7cf149d84eacdaef43c90e9fd912ac1fe83186017aa57dacaebe14255d1 |
| 467 | if [[ ! -f $scratch/raw.$(url_key "$url") ]]; then verify_public_url "$url"; fi |
| 468 | expect_refusal 'live unsupported claim with the correct digest' 'source text mismatch' verify_row \ |
| 469 | "$scratch/raw.$(url_key "$url")" "$sha" 'sets an input limit of fewer than 256 encoded tokens and greedy generation with a 160-token cap' "$url" |
| 470 | expect_refusal 'live wrong digest' 'SHA-256 mismatch' verify_row "$scratch/raw.$(url_key "$url")" "$sha_blob" '{' "$url" |
| 471 | |
| 472 | : > "$scratch/all-provider-names" |
| 473 | : > "$scratch/all-provider-rows" |
| 474 | while IFS=$'\t' read -r _ file ts url; do |
| 475 | tracked_file "$package/$file" |
| 476 | provider_check "$package/$file" "$url" || fail "provider archive refused: $file" |
| 477 | tail -n +2 "$scratch/projection" >> "$scratch/all-provider-rows" |
| 478 | pass "provider $file declares capture time $ts" |
| 479 | done < "$scratch/rows.provider" |
| 480 | |
| 481 | cut -f1 "$scratch/all-provider-rows" > "$scratch/all-provider-names" |
| 482 | if [[ ! -s $scratch/rows.external ]]; then |
| 483 | cut -f2 "$scratch/rows.replay" > "$scratch/all-replay-names" |
| 484 | check_inventory "$scratch/all-provider-names" "$scratch/all-replay-names" |
| 485 | verify_payload_bytes "$package" "$scratch/all-provider-rows" |
| 486 | else |
| 487 | external_inventory "$package" "$scratch/all-provider-names" |
| 488 | fi |
| 489 | |
| 490 | # Replay the documented block in a cleared environment on a fresh copy of the packet. |
| 491 | replay_env=() |
| 492 | while IFS=$'\t' read -r _ name; do |
| 493 | [[ -v $name && -n ${!name} ]] || fail "missing declared input variable: $name" |
| 494 | replay_env+=("$name=${!name}") |
| 495 | done < "$scratch/rows.input" |
| 496 | run_repro() { |
| 497 | env -i PATH="$PATH" LC_ALL=C PREFLIGHT_EVIDENCE="$1" "${replay_env[@]}" \ |
| 498 | bash --noprofile --norc -euo pipefail "$scratch/reproduce" |
| 499 | } |
| 500 | fresh_package() { |
| 501 | local destination |
| 502 | destination=$(mktemp -d "$scratch/package.XXXXXXXX") |
| 503 | cp -a -- "$package/." "$destination/" |
| 504 | printf '%s\n' "$destination" |
| 505 | } |
| 506 | expect_replay_failure() { |
| 507 | local result=0 |
| 508 | run_repro "$1" > /dev/null 2>&1 || result=$? |
| 509 | [[ $result = 1 ]] || fail "expected documented check exit 1 for $2, got $result" |
| 510 | pass "control $2" |
| 511 | } |
| 512 | replay=$(fresh_package) |
| 513 | run_repro "$replay" || fail 'documented Bash reproduction failed' |
| 514 | pass 'documented Bash reproduction rc=0' |
| 515 | |
| 516 | hash=$(sha256sum < "$scratch/reproduce") |
| 517 | printf 'reproduction_sha256=wrong\npayload_positive_exit=0\nsame_size_payload_corruption_exit=1\n' > "$scratch/external-tamper" |
| 518 | printf 'reproduction_sha256=%s\npayload_positive_exit=0\nsame_size_payload_corruption_exit=1\n' "${hash%% *}" > "$scratch/external-example" |
| 519 | expect_refusal 'external receipt missing' 'external payload control receipt is absent' check_external "$scratch/missing" |
| 520 | expect_refusal 'external receipt for another reproduction' 'external payload control receipt is absent' check_external "$scratch/external-tamper" |
| 521 | check_external "$scratch/external-example" |
| 522 | artifact_bytes=PASS |
| 523 | if [[ -n $(rows_of external) ]]; then |
| 524 | artifact_bytes=AUTHOR_SUPPLIED_EXTERNAL_RECEIPT |
| 525 | IFS=$'\t' read -r _ file sha < <(rows_of external) |
| 526 | tracked_file "$package/$file" |
| 527 | printf '%s %s\n' "$sha" "$package/$file" | sha256sum --check --status || fail "external control receipt digest mismatch: $file" |
| 528 | check_external "$package/$file" |
| 529 | printf 'pre-review evidence external byte controls recorded in %s\n' "$file" |
| 530 | fi |
| 531 | while IFS=$'\t' read -r _ file; do |
| 532 | tracked_file "$package/$file" |
| 533 | [[ -s $package/$file ]] || fail "cannot damage an empty replay artifact: $file" |
| 534 | size=$(stat -c %s -- "$package/$file") |
| 535 | while read -r offset; do |
| 536 | replay=$(fresh_package) |
| 537 | octet=$(od -An -j "$offset" -N1 -tu1 -- "$replay/$file") |
| 538 | replacement='\000' |
| 539 | if ((octet == 0)); then replacement='\001'; fi |
| 540 | printf '%b' "$replacement" | dd of="$replay/$file" bs=1 seek="$offset" count=1 conv=notrunc status=none |
| 541 | expect_replay_failure "$replay" "$file damaged artifact bytes at offset $offset" |
| 542 | done < <(printf '%s\n' 0 "$((size/2))" "$((size-1))" | sort -nu) |
| 543 | done < "$scratch/rows.replay" |
| 544 | |
| 545 | while IFS=$'\t' read -r _ file ts url; do |
| 546 | for kind in wrong-blob wrong-lfs wrong-blob-size wrong-lfs-size; do |
| 547 | replay=$(fresh_package) |
| 548 | case $kind in |
| 549 | wrong-blob) |
| 550 | jq '(.siblings | map(select(has("lfs") | not))[0].rfilename) as $name | |
| 551 | (.siblings[] | select(.rfilename == $name) | .blobId) |= ((if .[0:1] == "0" then "1" else "0" end) + .[1:])' \ |
| 552 | "$package/$file" > "$replay/$file";; |
| 553 | wrong-lfs) |
| 554 | jq '(.siblings | map(select(has("lfs")))[0].rfilename) as $name | |
| 555 | (.siblings[] | select(.rfilename == $name) | .lfs.sha256) |= ((if .[0:1] == "0" then "1" else "0" end) + .[1:])' \ |
| 556 | "$package/$file" > "$replay/$file";; |
| 557 | *) |
| 558 | is_lfs=false |
| 559 | if [[ $kind = wrong-lfs-size ]]; then is_lfs=true; fi |
| 560 | jq --argjson lfs "$is_lfs" ' |
| 561 | (.siblings | map(select(has("lfs") == $lfs))[0].rfilename) as $name | |
| 562 | (.siblings[] | select(.rfilename == $name)) |= |
| 563 | (.size += 1 | if has("lfs") then .lfs.size = .size else . end)' \ |
| 564 | "$package/$file" > "$replay/$file";; |
| 565 | esac |
| 566 | provider_check "$replay/$file" "$(jq -r '"https://huggingface.co/api/models/\(.id)/revision/\(.sha)?blobs=true"' "$replay/$file")" || |
| 567 | fail "bad control setup: $file $kind" |
| 568 | expect_replay_failure "$replay" "$file $kind" |
| 569 | done |
| 570 | done < "$scratch/rows.provider" |
| 571 | |
| 572 | [[ -z $(git status --porcelain) ]] || fail 'provenance checks changed the fresh checkout' |
| 573 | pass "complete head=$candidate artifact-bytes=$artifact_bytes unchecked-lines=$(rows_of unchecked | wc -l)" |