interplane.Get Omega
Read in your language

omega-mv

Omega: a language for verified programs, semantic identity and machine realization. Seed-born work and existing implementations have distinct provenance.

Brought by drakestapleton

branch main Branches Tags History

omega-mv / tools / gen / abstract / test_gen_abstract.sh

261 lines · 26968 bytes Raw Blame History
1#!/usr/bin/env bash
2# tools/gen/abstract/test_gen_abstract.sh <build dir> -- tests of GEN-3 (aien-spark/omega#478):
3# 1 recheck: the schema v1 fixtures pass; every format mutant is refused with its reason
4# 2 corpus: files and prompt bytes, the C oracle reproduces every expected file, FAMSIG rule, the harness
5# (tests/one_layer/acceptance/ola.sh experiment) accepts every solution and every reference
6# 3 extract: two runs are byte-identical and equal the committed record set; the expected rejections
7# 4 verify: every committed record is VERIFIED
8# 5 transfer probes (tools/gen/abstract/probe): every positive and negative probe passes
9# 6 verify mutants: each must be BLOCKED with its reason
10# <build dir> holds gen_abstract/{recheck,gabs,oracle,famsig}, omegese, omega_emit, checker2, one_layer.
11# Every check has a negative control or a mutant that must fail it. CPU only; no model, no GPU.
12set -euo pipefail
13export LC_ALL=C
14B="${1:?usage: test_gen_abstract.sh <build dir>}"
15HERE="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
16ROOT="$(cd "$HERE/../../.." && pwd)"
17RC="$B/gen_abstract/recheck"
18FX="$HERE/fixtures"
19T="$(mktemp -d "${TMPDIR:-/tmp}/gen-abstract-test.XXXXXXXX")"
20trap 'rm -rf "$T"' EXIT
21fails=0 oks=0
22ok() { echo "ok $*"; oks=$((oks + 1)); }
23bad() { echo "FAIL $*"; fails=$((fails + 1)); }
24
25# ---- 1. recheck ------------------------------------------------------------------------------------------
26if "$RC" --root "$ROOT" --receipts "$FX/receipts" "$FX/abs-fixture.rec" "$FX/raw-fixture.rec" > "$T/ok.out"; then
27 ok "recheck: both schema v1 fixtures (abstraction, raw) accepted with --root and --receipts"
28else bad "recheck fixtures: $(cat "$T/ok.out")"; fi
29# mutant <name> <fixture> <expected reason substring> <recheck options...> -- reads the mutated record from $T/m.rec
30mut() {
31 local name="$1" want="$2"; shift 2
32 local out; out="$("$RC" "$@" "$T/m.rec" 2>&1 || true)"
33 case "$out" in REFUSED*"$want"*) ok " mutant refused: $name";; *) bad "mutant $name not refused as expected (want '$want'): $out";; esac
34}
35A="$FX/abs-fixture.rec" W="$FX/raw-fixture.rec"
36sed '1s/.*/gen-record 2/' "$A" > "$T/m.rec"; mut "wrong header" "line 1 must be"
37sed 's/^id abs-0123456789abcdef/id abs-0123456789abcdee/' "$A" > "$T/m.rec"; mut "id not from fingerprint" "first 16 hex of the fingerprint"
38sed 's/^kind abstraction/kind helper/' "$A" > "$T/m.rec"; mut "unknown kind" "kind raw"
39sed 's/^split corpus/split probe/' "$A" > "$T/m.rec"; mut "abstraction from a probe" "split corpus"
40sed 's/^family \(gs1-[0-9a-f]*\) \(gs1-[0-9a-f]*\)$/family \2 \1/' "$A" > "$T/m.rec"; mut "family not ascending" "family"
41sed 's/^params u32 u32 u32/params u32 u32 i32/' "$A" > "$T/m.rec"; mut "wrong param type" "params differ"
42sed 's/^ret u32/ret u64/' "$A" > "$T/m.rec"; mut "wrong return type" "ret differs"
43sed 's/^entry clampv/entry clamp/' "$A" > "$T/m.rec"; mut "entry not the signature name" "entry differs"
44sed 's/^signature fn clampv x uint lo uint hi uint to uint/signature fn clampv x uint lo uint hi int to uint/' "$A" > "$T/m.rec"; mut "signature types differ from body" "params differ"
45sed '0,/^fn clampv x uint lo uint hi uint to uint/{s/^fn clampv x uint lo uint hi uint to uint/fn clampv x uint lo uint hi uint to ulong/}' "$A" | sed 's/^signature .*/signature fn clampv x uint lo uint hi uint to uint/' > "$T/m.rec"
46 sed -i '/^body$/,$ s/^fn clampv x uint lo uint hi uint to uint$/fn clampv x uint lo uint hi uint to ulong/' "$T/m.rec"; mut "body fn line differs from signature" "signature differs from the body"
47sed 's/^pre STATED+TESTED/pre PROVED/' "$A" > "$T/m.rec"; mut "precondition claimed PROVED" "pre must be tagged STATED+TESTED"
48sed 's/^post STATED+TESTED .*/post STATED+TESTED/' "$A" > "$T/m.rec"; mut "empty postcondition" "post"
49sed 's/^example 12 3 9 -> 9/example 12 3 -> 9/' "$A" > "$T/m.rec"; mut "example arity" "wrong number of arguments"
50sed 's/^counter 5 9 3 -> 9/counter 5 9 3 -> TRAP 15/' "$A" > "$T/m.rec"; mut "counterexample trap code" "TRAP <1..14>"
51sed '/^limit /d' "$A" > "$T/m.rec"; mut "no limit" "at least one 'limit"
52sed '/^ancestry fx_b /d' "$A" > "$T/m.rec"; mut "single-source helper" ">= 2 distinct corpus solutions"
53sed "s/^ancestry fx_b .*/ancestry fx_b $(sed -n 's/^ancestry fx_a //p' "$A")/" "$A" > "$T/m.rec"; mut "two ancestors, one solution digest" ">= 2 distinct corpus solutions"
54fp="$(sed -n 's/^fingerprint //p' "$A")"
55sed "s/^differs fx_b .*/differs fx_b $fp/" "$A" > "$T/m.rec"; mut "helper identical to a whole corpus solution" "equals the whole corpus solution"
56sed '/^differs fx_b /d' "$A" > "$T/m.rec"; mut "one differs line" "differs"
57sed 's/^source \(.*\) [0-9a-f]*$/source \1 '"$(printf stale | sha256sum | cut -c1-64)"'/' "$A" > "$T/m.rec"; mut "stale source digest" "stale source digest" --root "$ROOT"
58sed 's|^source tools/gen/abstract/fixtures/source.txt|source ../x/source.txt|' "$A" > "$T/m.rec"; mut "source path with .." "relative path"
59fake="$(printf 'gen-receipt 1\nrecord abs-0123456789abcdef\nfixture forged\n' | sha256sum | cut -c1-64)"
60sed "s/^receipt .*/receipt $fake/" "$A" > "$T/m.rec"; mut "receipt id with no receipt file" "receipt file" --receipts "$FX/receipts"
61mkdir -p "$T/rc"; cp "$FX/receipts/"* "$T/rc/"; r="$(sed -n 's/^receipt //p' "$A")"; printf 'extra\n' >> "$T/rc/$r"; cp "$A" "$T/m.rec"; mut "edited receipt file" "does not hash to its id" --receipts "$T/rc"
62rw="$(sed -n 's/^receipt //p' "$W")"; sed "s/^receipt .*/receipt $rw/" "$A" > "$T/m.rec"; mut "another record's receipt" "not this record's" --receipts "$FX/receipts"
63sed 's/^validity unverified/validity trusted/' "$A" > "$T/m.rec"; mut "unknown validity" "validity"
64printf '\n' | cat "$A" - > "$T/m.rec"; mut "trailing empty line" "empty line"
65sed 's/^desc /desc /' "$A" > "$T/m.rec"; mut "two spaces" "two spaces"
66sed 's/^desc \(.*\)$/desc \1\r/' "$A" > "$T/m.rec"; mut "CR byte" "outside ASCII"
67sed '$d' "$A" > "$T/m.rec"; mut "body not closed by end" "must end with 'end'"
68sed '/^body$/,$ s/^ret x$/ret x\nend\nfn other a uint to uint\nret a/' "$A" > "$T/m.rec"; mut "two functions in an abstraction body" "exactly one function"
69sed 's/^fn clampv x uint lo uint hi uint to uint$/fn clampv res uint lo uint hi uint to uint/; s/^signature fn clampv x /signature fn clampv res /' "$A" > "$T/m.rec"; mut "parameter named res" "res is reserved"
70sed 's/^kind raw/kind abstraction/' "$W" > "$T/m.rec"; mut "raw record relabelled abstraction" "abstraction id"
71sed 's/^ancestry fx_clamp /ancestry fx_other /' "$W" > "$T/m.rec"; mut "raw ancestry not its own task" "its own task"
72sed 's/^signature fn fx_clamp a uint to uint/signature fn clampv x uint lo uint hi uint to uint/; s/^entry fx_clamp/entry clampv/; s/^params u32$/params u32 u32 u32/' "$W" > "$T/m.rec"; mut "raw signature not the entry (last fn)" "last fn line"
73grep -v '^ancestry ' "$A" | sed 's/^validity unverified/validity unverified\nancestry fx_a '"$(printf a | sha256sum | cut -c1-64)"'/' > "$T/m.rec"; mut "single ancestry line" ">= 2 distinct"
74"$RC" > /dev/null 2>&1 && bad "recheck with no record must be a usage error" || { [ $? = 2 ] && ok " usage error (exit 2) without a record" || bad "recheck usage exit code"; }
75
76
77# ---- 2. corpus ------------------------------------------------------------------------------------------
78CO="$ROOT/tests/one_layer/generalization/corpus"
79RS="$ROOT/tests/one_layer/generalization/records"
80recof() { local f; for f in "$RS"/abstraction/*.rec; do if grep -qx "entry $1" "$f"; then echo "$f"; fi; done; }
81ntask="$(ls "$CO/tasks" | wc -l)"
82[ "$ntask" -ge 48 ] && ok "corpus: $ntask tasks" || bad "corpus has $ntask tasks (want >= 48)"
83cbad=""
84for d in "$CO"/tasks/*/; do
85 t="$(basename "$d")"
86 for f in requirement prompt desc inputs expected solution.omegese reference.osc; do [ -s "$d/$f" ] || cbad+=" $t/$f"; done
87 LC_ALL=C grep -q '[^ -~]' "$d/prompt" && cbad+=" $t/prompt-bytes"
88 [ "$(wc -c < "$d/prompt")" -le 4096 ] || cbad+=" $t/prompt-size"
89 [ "$(wc -l < "$d/inputs")" -ge 8 ] || cbad+=" $t/inputs<8"
90 grep -q '^kind task$' "$d/requirement" && grep -q "^entry $t\$" "$d/requirement" || cbad+=" $t/requirement"
91 "$B/gen_abstract/oracle" "$t" < "$d/inputs" | cmp -s - "$d/expected" || cbad+=" $t/expected-not-oracle"
92done
93[ -z "$cbad" ] && ok "corpus: every task has its files, prompt bytes, >= 8 inputs, and expected == C oracle" || bad "corpus:$cbad"
94sed '1s/^\(.*\)$/9999999/' "$CO/tasks/clamp_sum/inputs" | "$B/gen_abstract/oracle" clamp_sum | cmp -s - "$CO/tasks/clamp_sum/expected" \
95 && bad "oracle negative control: a changed input still matched" || ok " negative control: one changed input changes the oracle output"
96for t in even_digsums sum_clamped sum_dists sum_sat; do
97 [ "$("$B/gen_abstract/oracle" --bound "$t")" = 0:4096 ] || cbad+=" $t/bound"
98done
99[ -z "$cbad" ] && [ -z "$("$B/gen_abstract/oracle" --bound clamp_sum)" ] && ! "$B/gen_abstract/oracle" --bound no_such_task > /dev/null 2>&1 \
100 && ok "oracle --bound: 0:4096 for the four loop-over-n tasks, empty for others, refused for an unknown task" || bad "oracle --bound:$cbad"
101"$B/gen_abstract/gabs" inputs 256 --max 0:4096 u32 u32 | awk '$1 > 4096 { f = 1 } END { exit f }' \
102 && "$B/gen_abstract/gabs" inputs 256 u32 u32 | awk '$1 > 4096 { f = 1 } END { exit !f }' \
103 && ok "gabs inputs --max 0:4096 bounds argument 0 (without --max some values exceed 4096)" || bad "gabs inputs --max does not bound argument 0"
104printf 'fn f a uint to uint\nbound a\nret a\nend\n' > "$T/kw.omegese"
105"$B/gen_abstract/gabs" split "$T/kw.omegese" "$T/kw" > /dev/null 2>&1 && bad "gabs split accepted a line opened by the keyword bound" \
106 || ok " negative control: gabs split refuses a line opened by an Omegese keyword it does not track (bound)"
107if [ -f "$ROOT/tests/one_layer/generalization/dev/META" ]; then cp "$ROOT/tests/one_layer/generalization/dev/META" "$T/devMETA"
108else git -C "$ROOT" show 7eb8534c42304505640013f64753d9c9db40dcf3:tests/one_layer/generalization/dev/META > "$T/devMETA"; fi
109FS="$B/gen_abstract/famsig"
110FC=7eb8534c42304505640013f64753d9c9db40dcf3
111if [ -f "$ROOT/tools/gen/protocol/famsig.c" ]; then
112 cmp -s "$B/gen_abstract/famsig-src/tools/gen/protocol/famsig.c" "$ROOT/tools/gen/protocol/famsig.c" \
113 && cmp -s "$B/gen_abstract/famsig-src/tools/gen/protocol/famsig_lib.h" "$ROOT/tools/gen/protocol/famsig_lib.h" \
114 && ok "famsig built from the in-tree tools/gen/protocol (GEN-1 merged)" || bad "famsig-src is not the in-tree tools/gen/protocol source (make gen-abstract)"
115else
116 [ "$(git -C "$ROOT" show "$FC:tests/one_layer/generalization/families/FAMSIG_V1.md" | sha256sum | cut -c1-64)" = dee5b30d9aebfc96b3b9e3418ca3089ab7be2f0f5e02cc4f6cbebe3601db1e76 ] \
117 && cmp -s "$B/gen_abstract/famsig-src/tools/gen/protocol/famsig.c" <(git -C "$ROOT" show "$FC:tools/gen/protocol/famsig.c") \
118 && ok "famsig consumed from gen/protocol 7eb8534c (FAMSIG_V1.md sha256 dee5b30d..., famsig.c as at that commit)" || bad "famsig pin: FAMSIG_V1.md or famsig.c is not the 7eb8534c one"
119fi
120"$FS" rule "$T/devMETA" "$CO/META" > "$T/rule.out" 2>&1 && tail -n 1 "$T/rule.out" | grep -qx 'RULE PASS' \
121 && ok "famsig rule dev/META corpus/META: RULE PASS, R1-R7 incl. coarse R6 ($(grep -c . "$CO/META") META lines, $(sed -n 's/^split corpus .*families=//p' "$T/rule.out") corpus families)" \
122 || bad "famsig rule: $(tail -n 2 "$T/rule.out")"
123prims=""; for p in arith branch loop array call nested; do grep -v '^#' "$CO/META" | grep -q "$p" || prims+=" $p"; done
124[ -z "$prims" ] && ok "corpus META covers all six primitives" || bad "corpus META misses:$prims"
125{ cat "$CO/META"; echo "zz_reserved corpus 1 1 2 0 0 0 loop(loop(branch(arith)))"; } > "$T/badMETA"
126"$FS" rule "$T/devMETA" "$T/badMETA" > "$T/rule5.out" 2>&1 || ! grep -q "^FAIL R3 .*zz_reserved" "$T/rule5.out" && bad "famsig rule did not refuse a reserved dev shape in the corpus with R3" || ok " negative control: a reserved dev shape in corpus META fails the rule"
127{ cat "$CO/META"; echo "zz_coarse corpus 1 0 1 0 1 1 seq(arith,loop(call(nested)))"; } > "$T/badMETA6"
128"$FS" rule "$T/devMETA" "$T/badMETA6" > "$T/rule6.out" 2>&1 || ! grep -q "^FAIL R6 .*zz_coarse" "$T/rule6.out" && bad "famsig rule did not refuse a corpus shape sharing a dev coarse signature with R6" || ok " negative control: a corpus shape whose coarse signature is a dev one (gc1:loop(call(arith))) fails R6"
129cmp -s <(grep -v '^#' "$CO/META" | tail -n +2 | cut -d' ' -f1) <(ls "$CO/tasks") && ok "corpus META has exactly one line per task" || bad "corpus META lines differ from the task list"
130# the harness, called (not copied): every solution IR as a candidate, plus a one-task mutant set
131H="$T/ola"; mkdir -p "$H/tasks/cases" "$H/cands/solutions" "$H/cands/mutant/wrap8" "$H/ev"
132for d in "$CO"/tasks/*/; do
133 t="$(basename "$d")"; mkdir -p "$H/tasks/cases/$t/hidden" "$H/cands/solutions/$t"
134 cp "$d/requirement" "$d/prompt" "$H/tasks/cases/$t/"; cp "$d/inputs" "$d/expected" "$d/reference.osc" "$H/tasks/cases/$t/hidden/"
135 "$B/omegese/omegese" emit "$d/solution.omegese" "$T/s.json" > /dev/null && "$B/omega_emit/omega_emit" emit "$T/s.json" "$H/cands/solutions/$t/candidate.oscir" > /dev/null
136done
137sed '1,/^body$/d' "$(recof sat8)" > "$T/m.omegese"
138cat "$CO/tasks/wrap8/misuse.sat8.omegese" >> "$T/m.omegese"
139"$B/omegese/omegese" emit "$T/m.omegese" "$T/m.json" > /dev/null && "$B/omega_emit/omega_emit" emit "$T/m.json" "$H/cands/mutant/wrap8/candidate.oscir" > /dev/null
140(cd "$H" && tar --format=ustar --sort=name --owner=0 --group=0 --numeric-owner --mtime=@0 -cf tasks.tar tasks && sha256sum tasks.tar > TASKS.sha256)
141OLA_ALLOW_DIRTY=1 OLA_EVIDENCE_ROOT="$H/ev" bash "$ROOT/tests/one_layer/acceptance/ola.sh" experiment "$H/tasks.tar" "$H/TASKS.sha256" "$H/cands" > "$H/out" 2> "$H/err" || true
142grep -q "^set=solutions accepted=$ntask/$ntask rejected=0 errors=0" "$H/out" && ok "harness: every Omegese solution accepted ($ntask/$ntask)" || bad "harness solutions: $(grep '^set=solutions' "$H/out")"
143grep -q "^references_accepted=$ntask/$ntask$" "$H/out" && ok "harness: every OSC reference accepted ($ntask/$ntask)" || bad "harness references: $(grep '^references' "$H/out")"
144mv="$(find "$H/ev" -path '*/sets/mutant/verdicts.txt' | head -n 1)"
145grep -q "^set=mutant accepted=0/$ntask " "$H/out" && grep -q '^wrap8 REJECT wrong_result' "$mv" && ok " negative control: the harness rejects the wrap8 candidate built from a misused record (wrong_result)" || bad "harness mutant: $(grep '^set=mutant' "$H/out") $(grep '^wrap8' "$mv")"
146
147# ---- 3. extract -----------------------------------------------------------------------------------------
148X="$HERE/extract"
149bash "$X" "$B" "$T/r1" > "$T/x1.out" 2>&1 && bash "$X" "$B" "$T/r2" > /dev/null 2>&1 || bad "extract failed: $(tail -n 2 "$T/x1.out")"
150diff -r "$T/r1" "$T/r2" > /dev/null && ok "extract: two runs are byte-identical ($(cat "$T/x1.out"))" || bad "extract is not deterministic"
151diff -r "$T/r1" "$RS" > /dev/null && ok "extract: output equals the committed record set (reconstructible from pinned sources)" || bad "committed records differ from a fresh extract: $(diff -rq "$T/r1" "$RS" | head -n 3)"
152for want in "^cube .* single-source: occurs in 1 extraction task$" "^dist .* single-source: occurs in 1 extraction task$" \
153 "^ds2 - .* calls digsum: v1 extracts leaf helpers only$" "^gcd .* identical to the whole corpus solution of gcd_only$"; do
154 grep -q "$want" "$RS/REJECTIONS" && ok " rejection logged: $(grep "$want" "$RS/REJECTIONS" | cut -d' ' -f1,4-)" || bad "REJECTIONS lacks /$want/"
155done
156for n in clamp absdiff sat8 digsum digcount popcnt sum4 max4 avg2; do
157 grep -qx "entry $n" "$RS"/abstraction/*.rec && ok " abstraction record: $n" || bad "no abstraction record for $n"
158done
159"$RC" --root "$ROOT" --receipts "$RS/receipts" "$RS"/raw/*.rec "$RS"/abstraction/*.rec > "$T/rc.out" 2>&1 && ok "recheck: all $(grep -c '^OK' "$T/rc.out") committed records" || bad "recheck committed: $(grep -v '^OK' "$T/rc.out" | head -n 2)"
160(cd "$RS" && sha256sum --quiet -c MANIFEST && sha256sum --quiet -c SET.sha256) && ok "MANIFEST and SET.sha256 match the record files" || bad "MANIFEST or SET.sha256 stale"
161# C/D candidate pools (GEN_PROTOCOL_V1.md section 3), recomputed here independently of extract
162grep -v '^#' "$CO/META" | tail -n +2 | while read -r t _ _ _ _ _ _ _ s; do echo "$("$FS" canon "$s") $t"; done | sort > "$T/fo"
163declare -A taken=(); pre=()
164for r in 0 1 2 3; do
165 for f in $(cut -d' ' -f1 "$T/fo" | uniq); do
166 [ "${#pre[@]}" -lt 14 ] || break
167 t="$(awk -v f="$f" '$1 == f { print $2 }' "$T/fo" | sed -n "$((r + 1))p")"
168 if [ -n "$t" ] && [ -z "${taken[$t]:-}" ]; then pre+=("$t"); taken[$t]=1; fi
169 done
170done
171[ "$(printf '%s\n' "${pre[@]}")" = "$(cat "$RS/PREFIX")" ] && ok "PREFIX: the 14 B-prefix ids by the protocol pick rule ($(paste -sd' ' "$RS/PREFIX"))" || bad "PREFIX differs from the recomputed pick"
172# dpool <prefix file>: abstraction MANIFEST lines with at least one ancestry task outside the prefix
173dpool() { grep ' abstraction/' "$RS/MANIFEST" | while read -r h f; do
174 if sed -n '/^body$/q; s/^ancestry \([^ ]*\) .*/\1/p' "$RS/$f" | grep -qvxF -f "$1"; then echo "$h $f"; fi; done; }
175probes="$(grep -v '^#' "$CO/PROBES" | cut -d' ' -f1 | sort -u | sed 's|.*|raw/raw-&.rec|')"
176cmp -s <(grep ' raw/' "$RS/MANIFEST" | grep -vF -f <(sed 's|.*|raw/raw-&.rec|' "$RS/PREFIX") | grep -vF -f <(printf '%s\n' "$probes")) "$RS/C.MANIFEST" \
177 && [ "$(wc -l < "$RS/C.MANIFEST")" = 23 ] \
178 && ok "C.MANIFEST: the 23 raw records of extraction tasks outside the prefix, MANIFEST lines (sha256 $(sha256sum < "$RS/C.MANIFEST" | cut -c1-16)...)" || bad "C.MANIFEST is not MANIFEST raw lines minus the prefix and the probe tasks"
179! awk '{ print $2 }' "$RS/C.MANIFEST" | (cd "$RS" && xargs grep -l '^split probe$') > /dev/null 2>&1 \
180 && ok " C.MANIFEST lists no split probe record (genret never indexes one)" || bad "C.MANIFEST lists a split probe record"
181cmp -s <(dpool "$RS/PREFIX") "$RS/D.MANIFEST" \
182 && ok "D.MANIFEST: the $(wc -l < "$RS/D.MANIFEST") abstraction records with ancestry outside the prefix (sha256 $(sha256sum < "$RS/D.MANIFEST" | cut -c1-16)...)" || bad "D.MANIFEST is not the abstraction lines minus prefix-only ancestry"
183{ cat "$RS/PREFIX"; echo avg_inc; } > "$T/pre+"
184dpool "$T/pre+" | grep -q "$(grep -l '^entry avg2$' "$RS"/abstraction/*.rec | xargs basename)" \
185 && bad "D rule kept avg2 although its whole ancestry (avg_double, avg_inc) is in the prefix" || ok " negative control: with avg_inc added to the prefix, avg2 (ancestry avg_double, avg_inc) leaves D"
186(cd "$RS" && sha256sum --quiet -c C.MANIFEST && sha256sum --quiet -c D.MANIFEST) && "$RC" --receipts "$RS/receipts" $(awk -v d="$RS" '{ print d "/" $2 }' "$RS/C.MANIFEST" "$RS/D.MANIFEST") > /dev/null 2>&1 \
187 && ok "C and D manifests: every listed record matches its digest and passes recheck --receipts (what genret runs)" || bad "C or D manifest lists a bad record"
188
189# ---- 4. verify ------------------------------------------------------------------------------------------
190V="$HERE/verify"
191bash "$V" "$B" "$RS"/raw/*.rec "$RS"/abstraction/*.rec > "$T/v.out" 2>&1 \
192 && ok "verify: $(grep -c '^VERIFIED' "$T/v.out") records VERIFIED" || bad "verify: $(grep -v '^VERIFIED' "$T/v.out" | head -n 3)"
193
194# ---- 5. probes ------------------------------------------------------------------------------------------
195bash "$HERE/probe" "$B" "$RS" > "$T/p.out" 2>&1 && ok "probes: $(tail -n 1 "$T/p.out") ($(grep -c ' positive .* PASS' "$T/p.out") positive, $(grep -c ' negative .* PASS' "$T/p.out") negative)" \
196 || bad "probes: $(grep -v ' PASS ' "$T/p.out" | head -n 3)"
197for n in clamp absdiff sat8 digsum digcount popcnt sum4 max4 avg2; do
198 grep -q " positive $n PASS" "$T/p.out" && grep -q " negative $n PASS" "$T/p.out" || bad "record $n lacks a passing positive and negative probe"
199done
200
201# ---- 6. verify mutants ----------------------------------------------------------------------------------
202CL="$(recof clamp)" RW="$RS/raw/raw-clamp_sum.rec"
203# vmut <name> <want> <record> [verify options] -- the record must be BLOCKED with <want> in the reason
204vmut() {
205 local name="$1" want="$2" rec="$3"; shift 3
206 local out; out="$(bash "$V" "$@" "$B" "$rec" 2>&1 || true)"
207 case "$out" in "BLOCKED "*"$want"*) ok " mutant blocked: $name";; *) bad "mutant $name not blocked as expected (want '$want'): $out";; esac
208}
209cp "$CL" "$T/v.rec"; out="$(bash "$V" --receipts "$RS/receipts" "$B" "$T/v.rec" || true)"; [ "$out" = "VERIFIED $(sed -n 's/^id //p' "$CL")" ] && ok " control: a copy of the clamp record verifies" || bad "control copy: $out"
210sed 's/^pre STATED+TESTED .*/pre STATED+TESTED true/' "$CL" > "$T/v.rec"; vmut "broken precondition (record only)" "pre differs from the spec file" "$T/v.rec" --receipts "$RS/receipts"
211sed 's/^ret x$/ret y/' "$CL" > "$T/v.rec"; vmut "invalid IR (unknown name in the body)" "invalid IR" "$T/v.rec" --receipts "$RS/receipts"
212sed 's/^params u32 u32 u32$/params u64 u64 u64/; s/^ret u32$/ret u64/; s/ uint/ ulong/g' "$CL" > "$T/v.rec"; vmut "wrong types (signature, params, ret and body all u64)" "fingerprint does not match the body" "$T/v.rec" --receipts "$RS/receipts"
213sed 's/^params u32 u32 u32$/params u32 u32 u64/' "$CL" > "$T/v.rec"; vmut "wrong type in params only" "params differ" "$T/v.rec" --receipts "$RS/receipts"
214sed '0,/^source /s/^source \(.*\) [0-9a-f]*$/source \1 '"$(printf stale | sha256sum | cut -c1-64)"'/' "$CL" > "$T/v.rec"; vmut "stale source digest" "stale source digest" "$T/v.rec" --receipts "$RS/receipts"
215sed 's/^receipt .*/receipt '"$(printf none | sha256sum | cut -c1-64)"'/' "$CL" > "$T/v.rec"; vmut "fake receipt id (no such receipt)" "receipt file" "$T/v.rec" --receipts "$RS/receipts"
216mkdir -p "$T/frc"; cp "$RS/receipts/"* "$T/frc/"
217{ sed -n '1,2p' "$RS/receipts/$(sed -n 's/^receipt //p' "$CL")"; echo "property inputs=forged expected=forged ACCEPT n=256"; } > "$T/forged"
218fid="$(sha256sum "$T/forged" | cut -c1-64)"; cp "$T/forged" "$T/frc/$fid"
219sed "s/^receipt .*/receipt $fid/" "$CL" > "$T/v.rec"; vmut "forged receipt (hashes to its name, not from the checks)" "receipt does not match the re-run checks" "$T/v.rec" --receipts "$T/frc"
220sed "s/^receipt .*/receipt $(sed -n 's/^receipt //p' "$RW")/" "$CL" > "$T/v.rec"; vmut "another record's receipt" "not this record's" "$T/v.rec" --receipts "$RS/receipts"
221sed "s/^ancestry clamp_triple .*/ancestry digsum_mod9 $(sha256sum "$CO/tasks/digsum_mod9/solution.omegese" | cut -c1-64)/" "$CL" > "$T/v.rec"
222vmut "single-source helper (forged second ancestor)" "does not contain this helper" "$T/v.rec" --receipts "$RS/receipts"
223sed "s/^ancestry clamp_triple .*/ancestry gap_half $(sha256sum "$CO/tasks/gap_half/solution.omegese" | cut -c1-64)/; /^ancestry sum_clamped /d" "$CL" > "$T/v.rec"
224vmut "single-source helper (one real ancestor)" "does not contain this helper" "$T/v.rec" --receipts "$RS/receipts"
225sed '/^family /s/ gs1-[0-9a-f]*$//' "$CL" > "$T/v.rec"; vmut "family list missing an ancestor family" "family" "$T/v.rec" --receipts "$RS/receipts"
226sed '/^body$/,$ s/^ret clamp add a b 10 100$/ret clamp add a b 10 101/' "$RW" > "$T/v.rec"
227vmut "raw record body edited" "body is not the task's solution" "$T/v.rec" --receipts "$RS/receipts"
228sed 's/^split corpus$/split probe/' "$RW" > "$T/v.rec"; vmut "raw record split relabelled" "split is not the task's" "$T/v.rec" --receipts "$RS/receipts"
229# consistent forgeries in a copy of the corpus: the spec file and the record agree, so only the checks can tell
230mkroot() { rm -rf "$T/root"; mkdir -p "$T/root/tests/one_layer/generalization"; cp -R "$CO" "$T/root/tests/one_layer/generalization/"; }
231respec() { # <spec name> <sed expr for spec and record> <record> -- edit both and re-pin the spec digest in the record
232 local sp="$T/root/tests/one_layer/generalization/corpus/specs/$1.spec"
233 sed -i "$2" "$sp"; sed "$2" "$3" | sed "s|^\(source tests/one_layer/generalization/corpus/specs/$1.spec\) .*|\1 $(sha256sum "$sp" | cut -c1-64)|" > "$T/v.rec"
234}
235mkroot; respec clamp 's/^\(pre\( STATED+TESTED\)\{0,1\}\) le lo hi$/\1 true/' "$CL"
236vmut "broken precondition (spec and record agree, pre true)" "property check failed" "$T/v.rec" --root "$T/root" --receipts "$RS/receipts"
237mkroot; respec clamp 's/^counter 5 9 3 -> 9$/counter 5 3 9 -> 5/' "$CL"
238vmut "counterexample that does not violate pre" "counter1-pre-false check failed" "$T/v.rec" --root "$T/root" --receipts "$RS/receipts"
239mkroot; respec clamp 's/^counter 5 9 3 -> 9$/counter 5 9 3 -> 7/' "$CL"
240vmut "counterexample with a wrong stated result" "counter1-result check failed" "$T/v.rec" --root "$T/root" --receipts "$RS/receipts"
241mkroot; respec clamp 's/^example 12 3 9 -> 9$/example 12 3 9 -> 12/' "$CL"
242vmut "wrong example" "example check failed" "$T/v.rec" --root "$T/root" --receipts "$RS/receipts"
243mkroot; mkdir -p "$T/root/tests/one_layer/generalization/corpus/tasks/clamp_only"
244sed '1,/^body$/d; s/^fn clamp /fn clamp_only /' "$CL" > "$T/root/tests/one_layer/generalization/corpus/tasks/clamp_only/solution.omegese"
245vmut "helper identical to a whole corpus solution" "identical to the whole corpus solution of clamp_only" "$CL" --root "$T/root" --receipts "$RS/receipts"
246mkroot; sed -i 's/^ret clamp add a b 10 100$/ret clamp add a b 10 99/' "$T/root/tests/one_layer/generalization/corpus/tasks/clamp_sum/solution.omegese"
247vmut "stale corpus (an ancestor solution changed)" "stale source digest" "$CL" --root "$T/root" --receipts "$RS/receipts"
248# a planted bug the public inputs cannot see (sat_sum saturating at 200, public inputs are <= 3 or >= 255):
249# the record agrees with its corpus copy, so only the oracle check on generated inputs can tell
250mkroot; SP="$T/root/tests/one_layer/generalization/corpus/tasks/sat_sum/solution.omegese"
251sed -i 's/^if gt x 255$/if gt x 200/' "$SP"; nsha="$(sha256sum < "$SP" | cut -c1-64)"
252sed "s|^\(source tests/one_layer/generalization/corpus/tasks/sat_sum/solution.omegese\) .*|\1 $nsha|; s/^ancestry sat_sum .*/ancestry sat_sum $nsha/; /^body$/,\$ s/^if gt x 255\$/if gt x 200/" "$RS/raw/raw-sat_sum.rec" > "$T/v.rec"
253cmp -s <(sed '1,/^body$/d' "$T/v.rec") "$SP" && ok " planted sat_sum bug: record body equals the planted solution" || bad "planted sat_sum record body is not the planted solution"
254vmut "planted bug invisible to the public tests (sat_sum saturates at 200)" "oracle check failed" "$T/v.rec" --root "$T/root" --receipts "$RS/receipts"
255bash "$X" --root "$T/root" "$B" "$T/rp" > "$T/rp.out" 2>&1 && bad "extract accepted the corpus with the planted sat_sum bug" \
256 || { grep -q "sat_sum fails its own checks: oracle check failed" "$T/rp.out" && ok " extract refuses the corpus with the planted sat_sum bug (oracle check)" || bad "extract planted bug: $(tail -n 1 "$T/rp.out")"; }
257sed 's/^validity verified$/validity unverified/' "$RW" > "$T/v.rec"; vmut "raw record marked unverified" "validity is not 'verified'" "$T/v.rec" --receipts "$RS/receipts"
258
259echo "test_gen_abstract: $oks ok, $fails failed"
260[ "$fails" = 0 ] || exit 1
261echo "test-gen-abstract: PASS"