interplane.Get Omega
Read in your language

aien-sovereign-core-mv

AienOS host runtime: inference scheduling, paged KV state, the aien CLI and Spark verification tooling. Its inference engine is in alpha testing (DGX Spark GB10); Omega is the implementation destination.

Brought by drakestapleton

branch main Branches Tags History

aien-sovereign-core-mv / docs / campaigns / next-phase-1 / test-rows-v8.sh

317 lines · 30128 bytes Raw Blame History
1#!/usr/bin/env bash
2# SPDX-License-Identifier: Apache-2.0
3# Copyright 2026 Drake Stapleton (AIEN / aien-dev)
4#
5# Licensed under the Apache License, Version 2.0 (the "License");
6# you may not use this file except in compliance with the License.
7# You may obtain a copy of the License at
8#
9# http://www.apache.org/licenses/LICENSE-2.0
10#
11# Unless required by applicable law or agreed to in writing, software
12# distributed under the License is distributed on an "AS IS" BASIS,
13# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14# See the License for the specific language governing permissions and
15# limitations under the License.
16
17# NEXT-PHASE-1 v8: red/green tests for rows-v8.jq (row <id>-A, <id>-CM, T6/T7 row names), its wiring
18# in make-receipt.sh, v8-results.sh, run-v8.sh, tasks-v8.json and np1-v8.decl.json.
19# Shell + jq only. Usage:
20# NP1_EDIT_MERGE=/path/to/np1_edit_merge test-rows-v8.sh
21# Build the binary with: cargo build -q -p aien-runtime --example np1_edit_merge
22# (it lands in target/debug/examples/np1_edit_merge). Exit 0 only if every case holds.
23set -u
24HERE=$(cd "$(dirname "$0")" && pwd)
25T=$HERE/tests-v6
26MB=${NP1_EDIT_MERGE:-}
27[ -n "$MB" ] && [ -x "$MB" ] || { echo "test-rows-v8: set NP1_EDIT_MERGE to the built np1_edit_merge example (cargo build -q -p aien-runtime --example np1_edit_merge)" >&2; exit 2; }
28pass=0 fail=0
29check() { # check NAME EXPECTED ACTUAL
30 if [ "$2" = "$3" ]; then pass=$((pass + 1)); echo "ok $1 (got: ${3:-none})"
31 else fail=$((fail + 1)); echo "FAIL $1: expected [${2}] got [${3}]"; fi
32}
33R8=$(cat "$HERE/rows-v8.jq")
34fails_of() { jq -r "$R8"'
35v6_rows | [.[] | select(.result != "PASS") | "\(.row)\(if .result == "NOT_RUN" then ":NOT_RUN" else "" end)"] | join(",")'; }
36names_of() { jq -r "$R8"'v6_rows | map(.row) | join(",")'; }
37
38# ---- fixtures: the frozen good evidence plus the v8 fields ---------------------
39# Non-edit: the grant's proposal_sha256 is the accepted attempt text_sha256 (t1 / r1).
40# Edit: the grant's proposal_sha256 is p1 and the re-derivation agrees with it.
41fx() { # fx KIND -> evidence JSON
42 case $1 in
43 T4) jq -c '.a2_v5_value = {s3_content_sha256: "c1"} | .authorizations[0].proposal_sha256 = "t1" | .s3.proposal_sha256 = "t1"' "$T/good-T4.evidence.json" ;;
44 R1) jq -c '.a2_v5_value = {s3_content_sha256: "c1"} | .authorizations[0].proposal_sha256 = "r1" | .s3.proposal_sha256 = "r1"' "$T/good-R1.evidence.json" ;;
45 T5) jq -c '.a2_v5_value = {s3_content_sha256: "c1"} | .authorizations[0].proposal_sha256 = "p1" | .s3.proposal_sha256 = "p1"
46 | .v8_merge = {ok: true, path: "CHANGELOG.md", prior_sha256: .seed.sha256, reply_sha256: "t1", proposal_sha256: "p1", content_sha256: "c1"}' "$T/good-T5.evidence.json" ;;
47 esac
48}
49mut() { fx "$1" | jq -c "$2" | fails_of; }
50redof() { local k=$1; mut "$@" | tr ',' '\n' | grep -cx -e "$k-A" -e "$k-CM" | sed 's/^2$/A and CM red/'; }
51
52# ---- 1. every <id>-A clause ----------------------------------------------------
53for k in T4 R1 T5; do check "good $k evidence (v8 rows)" "" "$(fx $k | fails_of)"; done
54for k in T4 R1 T5; do
55 A="$k-A"; CM="$k-CM"
56 check "$k: two authorizations" "A and CM red" "$(redof $k '.authorizations += [.authorizations[0] | .id = 10]')"
57 check "$k: no authorization" "A and CM red" "$(redof $k '.authorizations = []')"
58 check "$k: auth content differs from S5 content" "A and CM red" "$(redof $k '.authorizations[0].content_sha256 = "x"')"
59 check "$k: S5 content differs" "A and CM red" "$(redof $k '.s5.content_sha256 = "x"')"
60 check "$k: S5 disk differs" "A and CM red" "$(redof $k '.s5.disk_sha256 = "x"')"
61 check "$k: S3 proposal content differs" "A and CM red" "$(redof $k '.a2_v5_value.s3_content_sha256 = "x"')"
62 check "$k: S3 proposal content absent" "A and CM red" "$(redof $k '.a2_v5_value = null')"
63 check "$k: auth path differs from S5 path" "A and CM red" "$(redof $k '.authorizations[0].path = "OTHER.md"')"
64 check "$k: proposal_path differs" "A and CM red" "$(redof $k '.s3.proposal_path = "OTHER.md"')"
65 check "$k: grant has no proposal_sha256" "A and CM red" "$(redof $k '.authorizations[0].proposal_sha256 = null')"
66 check "$k: no accepted attempt" "A and CM red" "$(redof $k '.s3.attempts = []')"
67done
68# non-edit proposal clause (as v5 A2)
69check "T4: proposal_sha256 differs from attempt text_sha256" "A and CM red" "$(redof T4 '.authorizations[0].proposal_sha256 = "other"')"
70check "R1: attempt text_sha256 differs from proposal_sha256" "A and CM red" "$(redof R1 '.s3.attempts[0].text_sha256 = "other"')"
71check "T4: a merge value is ignored for a non-edit launch" "" "$(mut T4 '.v8_merge = null')"
72# edit proposal clause: re-derivation
73check "T5: no re-derivation (null) is FAIL" "T5-A,T5-CM" "$(mut T5 '.v8_merge = null')"
74check "T5: re-derivation field absent is FAIL" "T5-A,T5-CM" "$(mut T5 'del(.v8_merge)')"
75check "T5: re-derivation ok false" "T5-A,T5-CM" "$(mut T5 '.v8_merge.ok = false')"
76check "T5: reply_sha256 mismatch" "T5-A,T5-CM" "$(mut T5 '.v8_merge.reply_sha256 = "x"')"
77check "T5: prior_sha256 mismatch" "T5-A,T5-CM" "$(mut T5 '.v8_merge.prior_sha256 = "x"')"
78check "T5: proposal_sha256 mismatch" "T5-A,T5-CM" "$(mut T5 '.v8_merge.proposal_sha256 = "x"')"
79check "T5: content_sha256 mismatch" "T5-A,T5-CM" "$(mut T5 '.v8_merge.content_sha256 = "x"')"
80check "T5: no seed recorded" "T5-K,T5-B,T5-A,T5-CM" "$(mut T5 '.seed = null')"
81check "T5: raw reply equal to proposal is not enough without re-derivation" "T5-A,T5-CM" "$(mut T5 '.authorizations[0].proposal_sha256 = "t1" | .v8_merge = null')"
82# <id>-CM depends on <id>-A, not on the v5 row A2
83check "T5: v5 A2 FAIL no longer fails CM" "" "$(mut T5 '.a2_v5 = "FAIL"')"
84check "T5: v5 A2 null no longer fails CM" "" "$(mut T5 '.a2_v5 = null')"
85check "T4: <id>-A FAIL fails CM (and nothing else)" "T4-A,T4-CM" "$(mut T4 '.authorizations[0].proposal_sha256 = "other"')"
86check "T5: CM value records the A result" "FAIL" "$(fx T5 | jq '.v8_merge = null' | jq -r "$R8"'v6_rows | .[] | select(.row == "T5-CM") | .value.a_row')"
87
88
89# ---- 1b. named negative tests (ACCEPTANCE-v8 Addendum A5): each turns <id>-A red ------
90isred() { mut "$@" | tr ',' '\n' | grep -cx -e "$1-A" | sed 's/^1$/red/'; }
91check "A5 altered content (edit): S5 disk != auth content" "red" "$(isred T5 '.s5.disk_sha256 = "x"')"
92check "A5 altered content (non-edit): S5 disk != auth content" "red" "$(isred T4 '.s5.disk_sha256 = "x"')"
93check "A5 changed target: auth path != S5 path and != destination" "red" "$(isred T5 '.authorizations[0].path = "OTHER.md"')"
94check "A5 changed target: auth, S5 and proposal_path agree but not the destination" "red" \
95 "$(isred T5 '.authorizations[0].path = "OTHER.md" | .s5.path_rel = "OTHER.md" | .s3.proposal_path = "OTHER.md"')"
96check "A5 changed target (non-edit): same, R1" "red" "$(isred R1 '.authorizations[0].path = "OTHER.md" | .s5.path_rel = "OTHER.md" | .s3.proposal_path = "OTHER.md"')"
97check "A5 stale seed: re-derivation prior_sha256 != declared pre-seed sha256" "red" "$(isred T5 '.v8_merge.prior_sha256 = "stale"')"
98check "A5 stale seed: declared pre-seed differs from the re-derivation and the grant" "red" "$(isred T5 '.seed.sha256 = "stale"')"
99check "A5 replay: two authorization records" "red" "$(isred T5 '.authorizations += [.authorizations[0] | .id = 10]')"
100check "A5 replay: authorization prior_sha256 is not the pre-seed" "red" "$(isred T5 '.authorizations[0].prior_sha256 = "other"')"
101check "A5 replay (non-edit): two authorization records" "red" "$(isred T4 '.authorizations += [.authorizations[0] | .id = 10]')"
102check "A5 transformation after approval: precondition, auth content == proposal content" "c1 c1 c1" \
103 "$(fx T5 | jq -r '[.authorizations[0].content_sha256, .a2_v5_value.s3_content_sha256, .s5.content_sha256] | join(" ")')"
104check "A5 transformation after approval: S5 disk differs" "red" "$(isred T5 '.s5.disk_sha256 = "changed"')"
105check "A5 transformation after approval: committed proposal differs from S3's" "red" "$(isred T5 '.s3.proposal_sha256 = "changed"')"
106check "A5 missing re-derivation on an edit launch" "red" "$(isred T5 '.v8_merge = null')"
107# A1: every stage present and non-empty
108for s in raw_reply final_proposed_content approved_content committed_proposal executed_bytes; do :; done
109check "A1 stages listed with their hashes (edit)" "raw_reply transform_inputs final_proposed_content approved_content committed_proposal executed_bytes" \
110 "$(fx T5 | jq -r "$R8"'v6_rows | .[] | select(.row == "T5-A") | .value.stages | keys_unsorted | join(" ")' | sed 's/^/ /;s/^ //')"
111check "A1 stage values (edit)" "t1 29e905c61fee80afd95f0a2b7a1ab35347f9fa0cb5871560085163662a1b072b c1 c1 p1 c1" \
112 "$(fx T5 | jq -r "$R8"'v6_rows | .[] | select(.row == "T5-A") | .value.stages | [.raw_reply, .transform_inputs, .final_proposed_content, .approved_content, .committed_proposal, .executed_bytes] | join(" ")')"
113check "A1 target listed (edit)" "CHANGELOG.md CHANGELOG.md CHANGELOG.md CHANGELOG.md" \
114 "$(fx T5 | jq -r "$R8"'v6_rows | .[] | select(.row == "T5-A") | .value.target | [.target_auth, .target_s5, .target_proposal, .target_destination] | join(" ")')"
115check "A1 non-edit: transform_inputs is none" "null" "$(fx T4 | jq -c "$R8"'v6_rows | .[] | select(.row == "T4-A") | .value.stages.transform_inputs')"
116check "A1 empty reply hash (edit)" "red" "$(isred T5 '.s3.attempts[0].text_sha256 = "" | .v8_merge.reply_sha256 = ""')"
117check "A1 empty approved content" "red" "$(isred T4 '.authorizations[0].content_sha256 = "" | .s5.content_sha256 = "" | .s5.disk_sha256 = "" | .a2_v5_value.s3_content_sha256 = ""')"
118check "A1 empty executed bytes" "red" "$(isred T4 '.s5.disk_sha256 = null')"
119check "A1 empty committed proposal" "red" "$(isred T4 '.authorizations[0].proposal_sha256 = "" | .s3.attempts[0].text_sha256 = "" | .s3.proposal_sha256 = ""')"
120# ---- 2. row names carry the launch id (T6, T7), T4/T5 unchanged ----------------
121check "T4 row names" "T4-L,T4-M,T4-A,T4-CM" "$(fx T4 | names_of)"
122check "T5 row names" "T5-P,T5-K,T5-N,T5-B,T5-A,T5-CM" "$(fx T5 | names_of)"
123check "R1 row names" "R1-X,R1-P,R1-T,R1-A,R1-CM" "$(fx R1 | names_of)"
124T6=$(jq -c '.tasks[] | select(.id == "T6")' "$HERE/tasks-v8.json")
125T7=$(jq -c '.tasks[] | select(.id == "T7")' "$HERE/tasks-v8.json")
126fx6() { fx T4 | jq -c --argjson t "$T6" '.task = $t | .s3.proposal_path = $t.destination | .s5.path_rel = $t.destination | .authorizations[0].path = $t.destination | .containment.workspace_changed = [$t.destination]'; }
127check "T6 row names" "T6-L,T6-M,T6-A,T6-CM" "$(fx6 | names_of)"
128check "T6 good evidence" "" "$(fx6 | fails_of)"
129check "T6: 11 non-empty lines" "T6-L" "$(fx6 | jq -c '.committed.text = ([range(11)] | map("line \(.)") | join("\n"))' | fails_of)"
130check "T6: another max_tokens" "T6-M" "$(fx6 | jq -c '.max_tokens.used = 96' | fails_of)"
131SEED7=$HERE/seed-v8/T7/TODO.md
132T7TXT=$'# Todo\n\n## Next\n- write tests\n- fix login bug\n\n## Later\n- tidy docs\n'
133fx7() { fx T5 | jq -c --argjson t "$T7" --rawfile s "$SEED7" --arg sh "$(sha256sum "$SEED7" | cut -d' ' -f1)" --arg c "$T7TXT" \
134 '.task = $t | .seed = {path: "TODO.md", text: $s, sha256: $sh} | .committed.text = $c
135 | .s3.proposal_path = "TODO.md" | .s5.path_rel = "TODO.md" | .authorizations[0].path = "TODO.md" | .authorizations[0].prior_sha256 = $sh
136 | .v8_merge.prior_sha256 = $sh | .containment.workspace_changed = ["TODO.md"]'; }
137check "T7 row names" "T7-P,T7-K,T7-N,T7-B,T7-A,T7-CM" "$(fx7 | names_of)"
138check "T7 good evidence" "" "$(fx7 | fails_of)"
139check "T7: new line after the next heading" "T7-N" "$(fx7 | jq -c '.committed.text = "# Todo\n\n## Next\n- write tests\n\n## Later\n- tidy docs\n- fix login bug\n"' | fails_of)"
140check "T7: a seed line dropped" "T7-K" "$(fx7 | jq -c '.committed.text = "# Todo\n\n## Next\n- write tests\n- fix login bug\n\n## Later\n"' | fails_of)"
141check "T7: second heading dropped" "T7-K" "$(fx7 | jq -c '.committed.text = "# Todo\n\n## Next\n- write tests\n- tidy docs\n- fix login bug\n"' | fails_of)"
142check "T7: re-derivation absent" "T7-A,T7-CM" "$(fx7 | jq -c '.v8_merge = null' | fails_of)"
143check "A5 missing re-derivation on an edit launch (T7 shape)" "red" "$(fx7 | jq -c '.v8_merge = null' | fails_of | tr ',' '\n' | grep -cx 'T7-A' | sed 's/^1$/red/')"
144check "T7 seed bytes and sha256 as frozen" "52 0f55ac918c057213c0df504fb82ae62a5447c315ac10709953c9a55a6bffcc82" \
145 "$(wc -c <"$SEED7" | tr -d ' ') $(sha256sum "$SEED7" | cut -d' ' -f1)"
146check "T7 seed bytes" "$(printf '# Todo\n\n## Next\n- write tests\n\n## Later\n- tidy docs\n' | sha256sum | cut -d' ' -f1)" "$(sha256sum "$SEED7" | cut -d' ' -f1)"
147
148# ---- 3. the real v7 T5 receipt: v7 A2 FAIL as recorded, v8 T5-A PASS -------------
149REC=$HERE/d8cc248acede0b7029fa54ce6b2598b573aa63acc38ca2f65b9ccefe1e6d6b7b.json
150REPLY=$HERE/replies/cd8e3b30c007e2f0bfe66277688dbec833d55a7bbefc47103203f2615125d094.txt
151SEED5=$HERE/seed-v6/T5/CHANGELOG.md
152MERGE=$("$MB" CHANGELOG.md "$SEED5" "$REPLY")
153check "real merge: ok" "true" "$(jq -r .ok <<<"$MERGE")"
154check "real merge: recorded A2 FAIL in the v7 receipt" "FAIL" "$(jq -r '.acceptance_v5.authority[] | select(.row == "A2") | .result' "$REC")"
155check "real merge: recorded T5-CM FAIL in the v7 receipt" "FAIL" "$(jq -r '.acceptance_v6[] | select(.row == "T5-CM") | .result' "$REC")"
156# evidence rebuilt from the receipt's own recorded values
157EV=$(jq -c --argjson m "$MERGE" --rawfile seed "$SEED5" --arg ss "$(sha256sum "$SEED5" | cut -d' ' -f1)" '
158 (.acceptance_v5.authority[] | select(.row == "A2") | .value) as $a2
159 | (.acceptance_v6[] | select(.row == "T5-B") | .value) as $b
160 | {task: {id: "T5", kind: "edit", destination: "CHANGELOG.md"},
161 authorizations: [{path: $a2.auth_path, content_sha256: $a2.auth_content_sha256, proposal_sha256: $a2.auth_proposal_sha256, prior_sha256: $b.auth_prior_sha256}],
162 s5: {content_sha256: $a2.s5_content_sha256, disk_sha256: $a2.s5_disk_sha256, path_rel: $a2.s5_path},
163 s3: {proposal_path: (.runs[0].proposal_path), proposal_sha256: .runs[0].proposal_sha256, attempts: (.runs[0].proposal_attempts | map({attempt, outcome, text_sha256}))},
164 seed: {sha256: $ss, text: $seed}, a2_v5: "FAIL", a2_v5_value: $a2, v8_merge: $m}' "$REC")
165arow() { jq -r "$R8"'. as $e | v6_a_row("T5") | .result' ; }
166check "real v7 T5 evidence: T5-A PASS" "PASS" "$(arow <<<"$EV")"
167check "real v7 T5 evidence: seed sha256 is the recorded one" "$(jq -r '.acceptance_v6[] | select(.row == "T5-B") | .value.seed_sha256' "$REC")" "$(jq -r .seed.sha256 <<<"$EV")"
168check "real v7 T5 evidence: re-derived proposal equals the grant's" "$(jq -r .proposal_sha256 <<<"$MERGE")" "$(jq -r '.authorizations[0].proposal_sha256' <<<"$EV")"
169check "real v7 T5 evidence: re-derived reply is the accepted attempt" "$(jq -r .reply_sha256 <<<"$MERGE")" "$(jq -r '.s3.attempts | map(select(.outcome == "parsed")) | last | .text_sha256' <<<"$EV")"
170check "real v7 T5 evidence: null re-derivation FAILs" "FAIL" "$(jq '.v8_merge = null' <<<"$EV" | arow)"
171check "real v7 T5 evidence: wrong seed FAILs (re-derivation from a seed with an extra line)" "FAIL" \
172 "$(tmpd=$(mktemp -d); printf '# Changelog\n\n## 0.1.0\n- initial release\n- x\n' >"$tmpd/s"; m=$("$MB" CHANGELOG.md "$tmpd/s" "$REPLY"); rm -rf "$tmpd"; jq --argjson m "$m" '.v8_merge = $m' <<<"$EV" | arow)"
173
174# ---- 4. machine copies and declaration -------------------------------------------
175check "tasks-v8.json order" "T4 T5 T6 T7 N1 N2 R1" "$(jq -r '[.tasks[].id] | join(" ")' "$HERE/tasks-v8.json")"
176check "tasks-v8.json T4 and T5 copied from tasks-v6.json" "true" \
177 "$(jq -n --slurpfile a "$HERE/tasks-v6.json" --slurpfile b "$HERE/tasks-v8.json" '[$a[0].tasks[] | select(.id == "T4" or .id == "T5")] == [$b[0].tasks[] | select(.id == "T4" or .id == "T5")]')"
178check "tasks-v8.json N1, N2, R1 copied from tasks-v6.json" "true" \
179 "$(jq -n --slurpfile a "$HERE/tasks-v6.json" --slurpfile b "$HERE/tasks-v8.json" '[$a[0].tasks[] | select(.id | IN("N1","N2","R1"))] == [$b[0].tasks[] | select(.id | IN("N1","N2","R1"))]')"
180check "tasks-v8.json T7 seed" "seed-v8/T7" "$(jq -r '.tasks[] | select(.id == "T7") | .seed' "$HERE/tasks-v8.json")"
181check "tasks-v8.json same field names as tasks-v6.json" "true" \
182 "$(jq -n --slurpfile a "$HERE/tasks-v6.json" --slurpfile b "$HERE/tasks-v8.json" '([$a[0].tasks[] | keys] | unique) == ([$b[0].tasks[] | keys] | unique)')"
183for id in T4 T5 T6 T7 R1; do
184 row=$(jq -r --arg id "$id" '.tasks[] | select(.id == $id) | "| \(.id) | `\(.goal)` | `\(.destination)` | \(.phrases | map("`" + . + "`") | join(", ")) |"' "$HERE/tasks-v8.json")
185 check "tasks-v8.json $id row is in ACCEPTANCE-v8.md" "yes" "$(grep -Fqx -- "$row" "$HERE/ACCEPTANCE-v8.md" && echo yes || echo no)"
186done
187check "ACCEPTANCE-v8.md records the T7 seed sha256" "1" "$(grep -c 0f55ac918c057213c0df504fb82ae62a5447c315ac10709953c9a55a6bffcc82 "$HERE/ACCEPTANCE-v8.md" | sed 's/^[2-9]/1/')"
188check "ACCEPTANCE-v8.md has no em or en dash" "0" "$(grep -cP '\x{2014}|\x{2013}' "$HERE/ACCEPTANCE-v8.md")"
189D=$HERE/../scoring/declarations
190check "np1-v8.decl.json: 115 rows, all reps 1, no duplicates" "115 1 115" \
191 "$(jq -r '"\(.rows | length) \([.rows[].reps] | unique | join(",")) \([.rows[].row] | unique | length)"' "$D/np1-v8.decl.json")"
192check "np1-v8.decl.json: per launch counts" "N1 5, N2 5, R1 21, T4 20, T5 22, T6 20, T7 22" \
193 "$(jq -r '[.rows[].row | split("/")[0]] | group_by(.) | map("\(.[0]) \(length)") | join(", ")' "$D/np1-v8.decl.json")"
194check "np1-v8.decl.json: v7 rows with A2 replaced for T4 T5 R1" "true" \
195 "$(jq -n --slurpfile a "$D/np1-v7.decl.json" --slurpfile b "$D/np1-v8.decl.json" '
196 ([$a[0].rows[] | .row | select(startswith("T4/") or startswith("T5/") or startswith("R1/") | not)] | sort) as $same
197 | ([$b[0].rows[] | .row | select(startswith("T6/") or startswith("T7/") | not)] | map(select(test("^(T4|T5|R1)/") | not)) | sort) == $same
198 and ([$a[0].rows[] | .row | select(IN("T4/A2", "T5/A2", "R1/A2"))] | length) == 3
199 and ([$b[0].rows[] | .row | select(IN("T4/A2", "T5/A2", "R1/A2"))] | length) == 0
200 and ([$b[0].rows[] | .row | select(IN("T4/T4-A", "T5/T5-A", "R1/R1-A", "T6/T6-A", "T7/T7-A"))] | length) == 5')"
201check "np1-v8.decl.json: T6 is T4 renamed, T7 is T5 renamed" "true" \
202 "$(jq -n --slurpfile b "$D/np1-v8.decl.json" '
203 ([$b[0].rows[] | .row | select(startswith("T4/")) | sub("^T4/T4-"; "T6/T6-") | sub("^T4/"; "T6/")]) == ([$b[0].rows[] | .row | select(startswith("T6/"))])
204 and ([$b[0].rows[] | .row | select(startswith("T5/")) | sub("^T5/T5-"; "T7/T7-") | sub("^T5/"; "T7/")]) == ([$b[0].rows[] | .row | select(startswith("T7/"))])')"
205
206# ---- 5. make-receipt.sh, v8-results.sh, scoring ----------------------------------
207tmp=$(mktemp -d); trap 'rm -rf "$tmp"' EXIT
208tmp=$(cd "$tmp" && pwd -P)
209cp -R "$HERE/tests-v5/v4-run" "$tmp/run"
210for f in "$tmp"/run/run.json "$tmp"/run/steps/*.json; do sed -i "s#@RUN@#$tmp/run#g" "$f"; done
211rec() { # rec LAUNCH [env...] -> receipt path
212 local id=$1 o; shift
213 o=$(mktemp -d "$tmp/out.XXXX")
214 env "$@" V6_TASK="$id" V6_MAX_TOKENS=48 bash "$HERE/make-receipt.sh" "$tmp/run" "$o" t t t 0 >"$o.sum" 2>"$o.err" \
215 || { echo "make-receipt.sh failed:"; cat "$o.err"; exit 1; }
216 ls "$o"/*.json
217}
218v5e=(TASK_ID=R1 TASK_SPEC="$HERE/tasks-v8.json" TASK_ACCEPTANCE="$HERE/ACCEPTANCE-v8.md")
219r7=$(rec R1 V6_ROWS=rows-v7.jq "${v5e[@]}")
220r7m=$(rec R1 V6_ROWS=rows-v7.jq V8_MERGE='{"ok":true}' "${v5e[@]}")
221check "rows-v7.jq: V8_MERGE changes nothing (receipt byte-identical)" "$(sha256sum <"$r7")" "$(sha256sum <"$r7m")"
222r8=$(rec R1 V6_ROWS=rows-v8.jq "${v5e[@]}")
223check "rows-v8.jq: receipt records the module" "rows-v8.jq $(sha256sum "$HERE/rows-v8.jq" | cut -d' ' -f1)" "$(jq -r '"\(.v6_rows_module.file) \(.v6_rows_module.sha256)"' "$r8")"
224check "rows-v8.jq: R1 rows are named R1-A and R1-CM (no A2 in the v6 rows)" "R1-X,R1-P,R1-T,R1-A,R1-CM" "$(jq -r '[.acceptance_v6[].row] | join(",")' "$r8")"
225check "rows-v8.jq: the v5 row A2 is still computed in the receipt" "1" "$(jq '[.acceptance_v5.authority[] | select(.row == "A2")] | length' "$r8")"
226check "rows-v8.jq: R1-A sees the v5 A2 value (S3 content sha256)" "true" "$(jq -r '[.acceptance_v6[] | select(.row == "R1-A")][0].value.s3_content_sha256 != null' "$r8")"
227check "rows-v8.jq: Q2 task_spec_matches_acceptance holds for R1 against ACCEPTANCE-v8.md" "true" "$(jq -r '.acceptance_v5.task_quality[] | select(.row == "Q2") | .value.task_spec_matches_acceptance' "$r8")"
228check "rows-v8.jq: no V8_MERGE gives merge null" "null" "$(jq -c '[.acceptance_v6[] | select(.row == "R1-A")][0].value.merge' "$r8")"
229rm8=$(rec T5 V6_ROWS=rows-v8.jq V8_MERGE='{"ok":true,"reply_sha256":"zz"}')
230check "rows-v8.jq: V8_MERGE reaches the T5-A row" '{"ok":true,"reply_sha256":"zz"}' "$(jq -c '[.acceptance_v6[] | select(.row == "T5-A")][0].value.merge' "$rm8")"
231check "make-receipt: V8_MERGE must be JSON" "refused" "$(V8_MERGE=notjson V6_ROWS=rows-v8.jq V6_TASK=T5 bash "$HERE/make-receipt.sh" "$tmp/run" "$tmp/out-bad" t t t 0 >/dev/null 2>&1 && echo accepted || echo refused)"
232for id in T6 T7; do
233 e=(TASK_ID=$id TASK_SPEC="$HERE/tasks-v8.json" TASK_ACCEPTANCE="$HERE/ACCEPTANCE-v8.md")
234 rm -rf "$tmp/run-$id"; cp -R "$tmp/run" "$tmp/run-$id" # the driver's goal is the task goal, as in a real launch
235 jq --arg g "$(jq -r --arg id "$id" '.tasks[] | select(.id == $id) | .goal' "$HERE/tasks-v8.json")" '.goal = $g' "$tmp/run/run.json" >"$tmp/run-$id/run.json"
236 o=$(mktemp -d "$tmp/out.XXXX")
237 env V6_ROWS=rows-v8.jq "${e[@]}" V6_TASK=$id V6_MAX_TOKENS=48 bash "$HERE/make-receipt.sh" "$tmp/run-$id" "$o" t t t 0 >/dev/null 2>&1; r=$(ls "$o"/*.json)
238 check "make-receipt: $id Q2 task row matches ACCEPTANCE-v8.md" "true" "$(jq -r '.acceptance_v5.task_quality[] | select(.row == "Q2") | .value.task_spec_matches_acceptance' "$r")"
239 check "make-receipt: $id receipt rows are named for the launch" "true" "$(jq -r --arg id "$id" '[.acceptance_v6[].row | startswith($id + "-")] | all' "$r")"
240done
241# v8-results.sh: A2 dropped, <id>-A kept, A1 and the legacy containment row dropped
242r=$(rec R1 V6_ROWS=rows-v8.jq "${v5e[@]}")
243check "v8-results: R1 has no A2, no A1, has R1-A" "0 0 1 21" "$(bash "$HERE/v8-results.sh" R1 "$r" | jq -s -r '"\(map(select(.row == "R1/A2")) | length) \(map(select(.row == "R1/A1")) | length) \(map(select(.row == "R1/R1-A")) | length) \(length)"')"
244check "v8-results: N1 gives only its 5 rows" "N1/N1-B N1/N1-C N1/N1-E N1/N1-H N1/N1-Z" "$(bash "$HERE/v8-results.sh" N1 "$(rec N1 V6_ROWS=rows-v8.jq)" | jq -r .row | sort | paste -sd' ')"
245DECL=$D/np1-v8.decl.json; SCORER=$HERE/../scoring/score-rows.sh
246jq -c '.rows[] | {row, rep: 1, verdict: "PASS"}' "$DECL" >"$tmp/all.jsonl"
247check "score: every declared row PASS" "PASS" "$(bash "$SCORER" "$DECL" "$tmp/all.jsonl" | jq -r .verdict)"
248grep -v '"T7/T7-A"' "$tmp/all.jsonl" >"$tmp/missing.jsonl"
249check "score: T7/T7-A missing is not PASS" "NOT_RUN" "$(bash "$SCORER" "$DECL" "$tmp/missing.jsonl" | jq -r .verdict)"
250sed 's/{"row":"T5\/T5-A","rep":1,"verdict":"PASS"}/{"row":"T5\/T5-A","rep":1,"verdict":"FAIL"}/' "$tmp/all.jsonl" >"$tmp/onefail.jsonl"
251check "score: T5/T5-A FAIL" "FAIL" "$(bash "$SCORER" "$DECL" "$tmp/onefail.jsonl" | jq -r .verdict)"
252{ grep -v '"T6/' "$tmp/all.jsonl"; bash "$HERE/v8-results.sh" T6 - "$DECL" "launch failed: no run.json"; } >"$tmp/nolaunch.jsonl"
253check "score: failed launch T6 is FAIL on its 20 rows" "FAIL 20" "$(bash "$SCORER" "$DECL" "$tmp/nolaunch.jsonl" | jq -r '"\(.verdict) \([.rows[] | select(.verdict == "FAIL")] | length)"')"
254{ cat "$tmp/all.jsonl"; echo '{"row":"T4/A2","rep":1,"verdict":"FAIL"}'; } >"$tmp/a2.jsonl"
255check "score: an A2 line is not a declared row (extra, verdict stays PASS)" "PASS 1" "$(bash "$SCORER" "$DECL" "$tmp/a2.jsonl" | jq -r '"\(.verdict) \(.extras | length)"')"
256
257# ---- 6. run-v8.sh is run-v7.sh plus the v8 wiring (pinned) ------------------------
258d=$(diff "$HERE/run-v7.sh" "$HERE/run-v8.sh")
259check "run-v8.sh vs run-v7.sh: hunk headers" "2,4c2,4 6c6 8c8 11c11,13 13c15 16,18c18,25 20c27 23c30 39a47,58 41,44c60,63 46,47c65,66 50c69 55,56c74,75" "$(grep -E '^[0-9]' <<<"$d" | paste -sd' ')"
260check "run-v8.sh vs run-v7.sh: sha256 of the whole diff" "3baf95b5631a7629941e234992201acebbb13a82583bc38e0f4ca1cfb2150354" "$(sha256sum <<<"$d" | cut -d' ' -f1)"
261check "run-v8.sh: declared wiring" "1 1 1 1 1 1" \
262 "$(for p in 'TASKS=$HERE/tasks-v8.json' 'declarations/np1-v8.decl.json' 'V6_ROWS=rows-v8.jq V8_MERGE=' 'TASK_ACCEPTANCE="$HERE/ACCEPTANCE-v8.md"' 'SPEC="ACCEPTANCE-v8.md spec_version 8"' 'MERGEBIN=${7:?MERGE_BIN}'; do grep -cF -- "$p" "$HERE/run-v8.sh"; done | paste -sd' ')"
263check "run-v8.sh: passes V8_MERGE and calls the merge binary for edits" "1 1" \
264 "$(for p in 'V8_MERGE="$v8merge"' '"$MERGEBIN" "$(jq -r .destination <<<"$t")"'; do grep -cF -- "$p" "$HERE/run-v8.sh"; done | paste -sd' ')"
265check "v8-results.sh vs v6-results.sh: only the A2 filter line differs in code" "26c27" "$(diff "$HERE/v6-results.sh" "$HERE/v8-results.sh" | grep -E '^[0-9]+(,[0-9]+)?[acd][0-9]' | grep -v '^[0-9,]*c1[0-9]*$' | grep -E '^26' | paste -sd' ')"
266
267check "run-v8.sh: RUN_BASE pinned (guard lines present)" "1 1 1" \
268 "$(for p in 'PINNED_BASE=/home/drakestapleton/workspace/np1-v8-runs' '[ "$BASE" = "$PINNED_BASE" ] || {' '[ ! -e "$BASE" ] || {'; do grep -cF -- "$p" "$HERE/run-v8.sh"; done | paste -sd' ')"
269msg=$(bash "$HERE/run-v8.sh" "$tmp/other-base" "$tmp/o" a b c /bin/true /bin/true 2>&1); rc=$?
270check "run-v8.sh: a different RUN_BASE is refused before anything runs" "2 yes no" \
271 "$rc $(grep -q 'RUN_BASE must be /home/drakestapleton/workspace/np1-v8-runs' <<<"$msg" && echo yes || echo no) $([ -e "$tmp/other-base" ] && echo yes || echo no)"
272
273# ---- harness approval-desk key (sc#342): rows-v9.jq and make-receipt.sh allow exactly ./approval-desk.key --------
274# run-campaign.sh creates the key in the compose dir since sc#342. rows-v8.jq is pinned by completed runs' receipts and
275# stays byte-identical (it still calls the key stray); rows-v9.jq is rows-v8.jq with only the v6_stray line changed.
276R9=$(cat "$HERE/rows-v9.jq")
277fails9() { jq -r "$R9"'
278v6_rows | [.[] | select(.result != "PASS") | "\(.row)\(if .result == "NOT_RUN" then ":NOT_RUN" else "" end)"] | join(",")'; }
279mut9() { fx "$1" | jq -c "$2" | fails9; }
280for k in T4 R1 T5; do
281 check "rows-v9 $k: good evidence" "" "$(fx $k | fails9)"
282 check "rows-v9 $k: harness approval-desk key in the compose dir is allowed" "" "$(mut9 $k '.containment.compose_dir_files += ["./approval-desk.key"]')"
283 for f in ./other.key ./approval-desk.key.bak ./approval-desk.keys ./sub/approval-desk.key ./branch-1.stage; do
284 check "rows-v9 $k: $f beside the key is stray" "$k-CM" "$(mut9 $k ".containment.compose_dir_files += [\"./approval-desk.key\", \"$f\"]")"
285 done
286done
287check "rows-v8 (pinned by completed runs, unchanged): the key is still stray there" "T4-CM" "$(mut T4 '.containment.compose_dir_files += ["./approval-desk.key"]')"
288check "rows-v9.jq vs rows-v8.jq: outside comments, only the v6_stray line differs (exact harness names)" \
289 '< def v6_stray: .containment.compose_dir_files | map(select(test("^\\./(machine\\.id|cortex\\.cx|jspace)") | not));|> def v6_stray: .containment.compose_dir_files | map(select(IN("./machine.id", "./cortex.cx", "./jspace", "./jspace/jspace.data", "./jspace/jspace.meta", "./approval-desk.key") | not));' \
290 "$(diff <(grep -v '^#' "$HERE/rows-v8.jq") <(grep -v '^#' "$HERE/rows-v9.jq") | grep -E '^[<>]' | paste -sd'|')"
291mrf=$(grep -F ') as $stray' "$HERE/make-receipt.sh" | sed -E 's/^ *\| *//; s/ as \$stray$//')
292strayof() { jq -nc --argjson c "$1" "\$c as \$cfiles | $mrf"; }
293check "make-receipt.sh: one compose-dir allowlist line" "1" "$(grep -cF ') as $stray' "$HERE/make-receipt.sh")"
294check "make-receipt.sh: the harness files and the approval-desk key are not stray" "[]" \
295 "$(strayof '["./approval-desk.key","./cortex.cx","./jspace","./jspace/jspace.data","./jspace/jspace.meta","./machine.id"]')"
296for f in ./other.key ./approval-desk.key.bak ./approval-desk.keys ./sub/approval-desk.key ./branch-1.stage; do
297 check "make-receipt.sh: $f beside the key is stray" "[\"$f\"]" "$(strayof "[\"./approval-desk.key\",\"./machine.id\",\"$f\"]")"
298done
299check "make-receipt.sh: V6_ROWS accepts rows-v9.jq; it reads tasks-v8.json and gets the A2 value and V8_MERGE as rows-v8.jq" "1 1 1" \
300 "$(for p in 'rows-v6.jq|rows-v7.jq|rows-v8.jq|rows-v9.jq)' 'case $V6_ROWS in rows-v8.jq|rows-v9.jq) V6TF=$HERE/tasks-v8.json ;; esac' 'if ($rows6 == "rows-v8.jq" or $rows6 == "rows-v9.jq") then {a2_v5_value:'; do grep -cF -- "$p" "$HERE/make-receipt.sh"; done | paste -sd' ')"
301
302# ---- exact names only (G6 follow-up): rows-v9.jq and make-receipt.sh ---------------------------------------------
303# The real v5 dry compose-dir layout (G6, D2 run.json) passes; a name that only starts like a harness file is stray.
304# rows-v8.jq (pinned) keeps its prefix match: ./machine.idX still passes there.
305for k in T4 R1 T5; do
306 check "rows-v9 $k: real v5 dry compose-dir layout is allowed" "" "$(mut9 $k '.containment.compose_dir_files = ["./approval-desk.key","./cortex.cx","./jspace","./jspace/jspace.data","./jspace/jspace.meta","./machine.id"]')"
307 for f in ./machine.idX ./machine.id.bak ./cortex.cxY ./jspaceX ./jspace.data ./jspace/other ./jspace/jspace.meta.tmp ./jspace/jspace.dataX ./jspace/sub/jspace.data; do
308 check "rows-v9 $k: $f (only a prefix of a harness name) is stray" "$k-CM" "$(mut9 $k ".containment.compose_dir_files += [\"$f\"]")"
309 done
310done
311check "rows-v8 (pinned, unchanged): prefix match still admits ./machine.idX there" "" "$(mut T4 '.containment.compose_dir_files += ["./machine.idX"]' | tr ',' '\n' | grep -x T4-CM || true)"
312check "make-receipt.sh: real v5 dry compose-dir layout is not stray" "[]" "$(strayof '["./approval-desk.key","./cortex.cx","./jspace","./jspace/jspace.data","./jspace/jspace.meta","./machine.id"]')"
313for f in ./machine.idX ./machine.id.bak ./cortex.cxY ./jspaceX ./jspace.data ./jspace/other ./jspace/jspace.meta.tmp ./jspace/jspace.dataX ./jspace/sub/jspace.data; do
314 check "make-receipt.sh: $f (only a prefix of a harness name) is stray" "[\"$f\"]" "$(strayof "[\"./machine.id\",\"$f\"]")"
315done
316echo "test-rows-v8: $pass passed, $fail failed"
317[ "$fail" -eq 0 ]