@rightkit/release 0.6.57 → 0.6.61

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (71) hide show
  1. package/README.md +4 -0
  2. package/acceptance-admission.mjs +104 -0
  3. package/acceptance-launch.mjs +234 -0
  4. package/acceptance-lines.mjs +1254 -0
  5. package/acceptance-result.mjs +77 -0
  6. package/acceptance-rows.mjs +47 -0
  7. package/admission-files.mjs +2 -0
  8. package/affected-units.mjs +17 -0
  9. package/app-check.mjs +6 -2
  10. package/app-closure.mjs +3 -1
  11. package/bin/rightkit-gate.mjs +546 -121
  12. package/broker-admission.mjs +45 -2
  13. package/broker-pins.mjs +11 -1
  14. package/broker-toolchain.mjs +113 -0
  15. package/cargo-profile-contract.mjs +7 -2
  16. package/class-a-cache-history.mjs +135 -0
  17. package/cli/right-release.mjs +0 -0
  18. package/code-closure.mjs +24 -0
  19. package/config-inspect.mjs +6 -0
  20. package/consumer-contracts.mjs +3 -1
  21. package/contract-nn.json +166 -0
  22. package/deterministic-scans.mjs +835 -112
  23. package/feature-coverage.mjs +109 -82
  24. package/feature-partition.mjs +76 -0
  25. package/forbidden-literals.mjs +78 -0
  26. package/gate/calls.mjs +121 -0
  27. package/gate/compile.mjs +190 -0
  28. package/gate/crate-results.mjs +127 -0
  29. package/gate/run-calls.mjs +241 -0
  30. package/gate/tests.mjs +234 -0
  31. package/gate-coverage.mjs +12 -3
  32. package/gate-release-admission.mjs +200 -0
  33. package/gate-seam.mjs +100 -4
  34. package/gate-serve.mjs +178 -32
  35. package/gate-stages.mjs +59 -0
  36. package/legacy-contract-receipt.mjs +809 -0
  37. package/local-publish.mjs +2 -4
  38. package/local-runtime.mjs +2 -2
  39. package/nsis-payload.mjs +4 -3
  40. package/ownership-applicability.mjs +5 -0
  41. package/ownership-class-rules.mjs +19 -8
  42. package/ownership-mandatory-set.json +15 -21
  43. package/ownership-mandatory-set.mjs +19 -4
  44. package/package.json +14 -8
  45. package/probe-memo.mjs +252 -0
  46. package/publication-artifacts.mjs +56 -2
  47. package/publish-local-npm.mjs +3 -0
  48. package/publish-update.mjs +2 -2
  49. package/receipt-signature.mjs +40 -0
  50. package/release.mjs +47 -29
  51. package/resident-answers.mjs +66 -0
  52. package/rightkit-ownership.json +20 -11
  53. package/rightkit-versions.json +349 -183
  54. package/runtime-bundle-stage.mjs +146 -0
  55. package/scan-digest.mjs +28 -4
  56. package/seam-broker.mjs +8 -1
  57. package/shell-contract.mjs +23 -2
  58. package/snapshot-changes.mjs +106 -0
  59. package/snapshot-check.mjs +17 -13
  60. package/snapshot-dependency-reuse.mjs +186 -14
  61. package/snapshot-git.mjs +17 -1
  62. package/snapshot-metadata.mjs +155 -3
  63. package/snapshot.mjs +90 -12
  64. package/spawn-ledger.mjs +21 -2
  65. package/stage-sidecar.mjs +231 -19
  66. package/suite-trust-roots.mjs +2 -2
  67. package/test-env.mjs +26 -0
  68. package/tool-version-memo.mjs +46 -0
  69. package/win-package-recipe.mjs +11 -0
  70. package/bin/darwin/rightkit-swap +0 -0
  71. package/gate-acceptance.mjs +0 -3362
@@ -0,0 +1,1254 @@
1
+ // The gate's acceptance test: twelve lines that must be true of every run (GATE-CONTRACT GC-A27; Adrian, 2026-11-20: "An acceptance test
2
+ // should be a single list of things that has to pass any run").
3
+ //
4
+ // It judges ONE run, and takes nothing from the gate's own reporting (Adrian, 2026-11-21: "remove all dependency of gate reporting anything").
5
+ // Its evidence is what the gate does not write: git (the selected commit, its tree and files), the operating system's record of every program
6
+ // the run started and when it exited (Windows Security events 4688/4689, macOS eslogger), the broker's signed receipts (each job's command,
7
+ // folder, times, commit, tree and test programs), the gate's state on disk as the launcher copied it before the gate started (each row's
8
+ // last inputs and result) and as it stands after (the results the cache store took during the run), and the launcher's own record (commit,
9
+ // run id, the gate's pid, its clock, its exit, the lanes and time limit pinned at launch, the run lock). The test works out itself what the
10
+ // run owes, from the files each row last read and the selected tree. It stages nothing and knows no scenario. A line with no record to judge
11
+ // it from is "not measured", never a pass.
12
+ //
13
+ // Rules every check keeps (gatecodex reviews and Council CV-1 and CV-2, 2026-11-20):
14
+ // * Missing proof is not the absence of work. "Nothing was sent", "nothing repeated" and "no other compile" are shown only from a process
15
+ // record that covers the whole run; otherwise the line is not measured.
16
+ // * What the run owed (the test's own reckoning) and what it did (programs, signed jobs, stored results) are compared in both directions.
17
+ // * What a record cannot tell apart (a wrapped command with no child, a feature-set variant, a tie in time) is not measured, not guessed.
18
+ //
19
+ // The lines are not written here. They are read from the one table in docs/GATE-CONTRACT.md [GC-A27] between
20
+ // `<!-- acceptance-lines:begin -->` and `<!-- acceptance-lines:end -->`, and nothing is judged unless every line there has a check here and
21
+ // every check here has a line there.
22
+ //
23
+ // node acceptance-lines.mjs --run <run dir> --repo <dir> --receipts <dir> [--inventory <file>] [--broker-key <hex> --broker-key-id <hex>]
24
+ // [--successor <run dir>] [--live] [--contract <file>] [--json]
25
+ import fs from "node:fs";
26
+ import path from "node:path";
27
+ import { execFileSync } from "node:child_process";
28
+ import { createHash } from "node:crypto";
29
+ import { enumerateRows } from "./acceptance-rows.mjs";
30
+ import os from "node:os";
31
+ import { fileURLToPath } from "node:url";
32
+ import { kindOf } from "./acceptance-launch.mjs";
33
+
34
+ export const CONTRACT_FILE = path.resolve(path.dirname(fileURLToPath(import.meta.url)), "..", "..", "docs", "GATE-CONTRACT.md");
35
+ const BEGIN = "<!-- acceptance-lines:begin -->"; const END = "<!-- acceptance-lines:end -->";
36
+
37
+ /**
38
+ * The twelve lines as the contract states them: the rows `| \`NNxx\` | sentence |` between the two markers. Returns { lines: [{ id, text }],
39
+ * problems }. Anything that is not a clean table there (no markers, a row of another shape, a repeated id, an empty sentence) is a problem.
40
+ */
41
+ export function parseAcceptanceLines(text) {
42
+ const src = String(text ?? ""); const problems = [];
43
+ const b = src.indexOf(BEGIN); const e = src.indexOf(END);
44
+ if (b < 0 || e < 0 || e < b) return { lines: [], problems: [`the contract has no ${BEGIN} ... ${END} table`] };
45
+ if (src.indexOf(BEGIN, b + 1) >= 0 || src.indexOf(END, e + 1) >= 0) problems.push("the contract has more than one acceptance-lines table");
46
+ const lines = [];
47
+ for (const raw of src.slice(b + BEGIN.length, e).split(/\r?\n/)) {
48
+ const row = raw.trim();
49
+ if (!row || /^\|\s*Id\s*\|\s*Line\s*\|$/.test(row) || /^\|\s*-+\s*\|\s*-+\s*\|$/.test(row)) continue;
50
+ const m = /^\|\s*`(NN\d\d)`\s*\|\s*(.*?)\s*\|$/.exec(row);
51
+ if (!m) { problems.push(`a row of the acceptance-lines table is not \`| \\\`NNxx\\\` | sentence |\`: ${row.slice(0, 80)}`); continue; }
52
+ if (!m[2]) problems.push(`${m[1]} has no sentence`);
53
+ if (lines.some((l) => l.id === m[1])) problems.push(`${m[1]} appears more than once`);
54
+ lines.push(Object.freeze({ id: m[1], text: m[2] }));
55
+ }
56
+ if (!lines.length) problems.push("the acceptance-lines table has no lines");
57
+ return { lines: Object.freeze(lines), problems };
58
+ }
59
+
60
+ /** Both directions: a line the contract states with no check here, and a check here with no line in the contract. */
61
+ export function linkProblems(lines, checkIds = Object.keys(JUDGES)) {
62
+ const stated = new Set(lines.map((l) => l.id)); const checked = new Set(checkIds); const problems = [];
63
+ for (const id of stated) if (!checked.has(id)) problems.push(`${id} is a line in the contract and has no check`);
64
+ for (const id of checked) if (!stated.has(id)) problems.push(`${id} has a check and is not a line in the contract`);
65
+ return problems;
66
+ }
67
+
68
+ /** The contract's lines, linked to the checks; throws, naming every problem, when the table is malformed or the two do not match. */
69
+ export function readAcceptanceLines(text) {
70
+ const { lines, problems } = parseAcceptanceLines(text);
71
+ const all = [...problems, ...linkProblems(lines)];
72
+ if (all.length) throw Object.assign(new Error(`the contract and the acceptance test do not match: ${all.join("; ")}`), { problems: all });
73
+ return lines;
74
+ }
75
+
76
+ const PASS = "pass"; const FAIL = "fail"; const NOT_MEASURED = "not measured";
77
+ const result = (verdict, why) => ({ verdict, why });
78
+ /** Any failure fails the line; else any gap leaves it not measured; else it passes. Each list is reported in full, the first few shown. */
79
+ const decide = (fails, gaps, passWhy) => {
80
+ const uniq = (xs) => [...new Set(xs)];
81
+ const show = (xs) => `${uniq(xs).slice(0, 4).join("; ")}${uniq(xs).length > 4 ? `; and ${uniq(xs).length - 4} more` : ""}`;
82
+ if (fails.length) return result(FAIL, show(fails));
83
+ if (gaps.length) return result(NOT_MEASURED, show(gaps));
84
+ return result(PASS, passWhy);
85
+ };
86
+ const short = (s) => String(s).slice(0, 12);
87
+
88
+ // ---- reading the records ---------------------------------------------------------------------------------------------------------------------------
89
+ const ISO = /^\d{4}-\d\d-\d\dT\d\d:\d\d:\d\d(?:\.\d+)?Z$/;
90
+ const timeOf = (s) => (typeof s === "string" && ISO.test(s) ? Date.parse(s) : NaN);
91
+
92
+ /**
93
+ * A process start as the program it really ran (Council CV-1 F-4, F-22). A Windows `cmd /c <string>` start is decoded by cmd's own rules
94
+ * (https://learn.microsoft.com/windows-server/administration/windows-commands/cmd): with `/s`, the first and last quote of the string are
95
+ * removed and the rest is left as it is; without `/s`, a string that begins with a quote loses it and its closing partner. Then the program
96
+ * is the quoted head or the first word, the arguments are the words after it, and a caret outside quotes escapes the next character. A
97
+ * string this reader cannot resolve to one plain command (several commands, redirection, variables, quotes left in the arguments) is marked
98
+ * `ambiguous`, never guessed. A shell-string start (execSync: the whole line in cmd, no args) is read the same way.
99
+ * Returns { program, args, cwd, wrapped, ambiguous }.
100
+ */
101
+ export function decodeStart(entry) {
102
+ let program = String(entry.cmd ?? ""); let args = (entry.args ?? []).map(String);
103
+ let ambiguous = false; let intended = null;
104
+ const line = (() => {
105
+ if (/(^|[\\/])cmd(\.exe)?$/i.test(program)) {
106
+ const c = args.findIndex((a) => /^\/c$/i.test(a));
107
+ if (c < 0) return null;
108
+ let s = args.slice(c + 1).join(" ").trim();
109
+ const slashS = args.slice(0, c).some((a) => /^\/s$/i.test(a));
110
+ const a = s.indexOf('"'); const b = s.lastIndexOf('"');
111
+ // Without /s, exactly one pair of quotes and no special character keeps its quotes (cmd's first rule); otherwise the pair is removed.
112
+ const kept = !slashS && a === 0 && (s.match(/"/g) ?? []).length === 2 && !/[&<>()@^|]/.test(s);
113
+ // When a removed pair does not wrap the whole string, the quotes that held a spaced program path together are consumed and the path
114
+ // is split at its space: cmd's own reading of that is not one plain command.
115
+ if (!kept && (slashS || a === 0) && a >= 0 && b > a && !(a === 0 && b === s.length - 1)) {
116
+ ambiguous = true;
117
+ // The call the string was written as: its quoted head the program and its words, as written, the arguments. NN08 holds it against the
118
+ // run's other starts (frozen case gate 5): a call written twice is a repeat, however cmd then reads the second copy.
119
+ const w = /^"([^"]+)"(?:\s+(.*))?$/.exec(s);
120
+ if (w && !/["&|<>%]/.test(w[2] ?? "")) intended = { program: w[1], args: (w[2] ?? "").split(/\s+/).filter(Boolean) };
121
+ }
122
+ if (kept) return s;
123
+ if (slashS) { if (a >= 0 && b > a) s = s.slice(0, a) + s.slice(a + 1, b) + s.slice(b + 1); }
124
+ else if (s.startsWith('"')) { if (b > 0) s = s.slice(1, b) + s.slice(b + 1); }
125
+ return s;
126
+ }
127
+ if (!args.length && /\s/.test(program.trim())) return program.trim();
128
+ return null;
129
+ })();
130
+ if (line === null) return { program, args, cwd: String(entry.cwd ?? ""), wrapped: false, ambiguous: false };
131
+ const m = /^"([^"]+)"(?:\s+(.*))?$/.exec(line) ?? /^([^\s"]+)(?:\s+(.*))?$/.exec(line);
132
+ if (!m) return { program: line, args: [], cwd: String(entry.cwd ?? ""), wrapped: true, ambiguous: true };
133
+ program = m[1]; const rest = m[2] ?? "";
134
+ if (/["&|<>%]/.test(rest.replace(/\^./g, ""))) ambiguous = true;
135
+ args = rest.split(/\s+/).filter(Boolean).map((a) => a.replace(/\^(.)/g, "$1"));
136
+ return { program, args, cwd: String(entry.cwd ?? ""), wrapped: true, ambiguous, intended };
137
+ }
138
+ const baseOf = (p) => String(p).replaceAll("\\", "/").split("/").pop();
139
+ const programName = (p) => baseOf(p).replace(/\.(exe|cmd|bat|com)$/i, "").toLowerCase();
140
+
141
+ const COMPILING = new Set(["build", "check", "clippy", "doc", "test", "rustc", "rustdoc", "bench"]);
142
+ /** cargo's built-in short names (cargo b, c, t, d, r are build, check, test, doc, run); a verb is compared by what it means, never by its spelling. */
143
+ const VERB_ALIAS = { b: "build", c: "check", t: "test", d: "doc", r: "run" };
144
+ const canonVerb = (v) => (typeof v === "string" ? VERB_ALIAS[v] ?? v : v);
145
+ /** Verbs that compile and run test programs; any of them started outside the broker is the gate building tests itself. */
146
+ const TESTLIKE = new Set(["test", "bench", "nextest", "miri", "llvm-cov", "tarpaulin"]);
147
+ /** Verbs known not to build or run tests; any other cargo verb (a user alias in .cargo/config, a plugin) could be one and is not shown to be harmless. */
148
+ const NOT_TEST_VERBS = new Set(["build", "check", "clippy", "doc", "rustc", "rustdoc", "metadata", "fmt", "tree", "fetch", "vendor", "update", "generate-lockfile", "locate-project", "pkgid", "verify-project", "version", "help", "install", "publish", "package", "clean", "search", "login", "logout", "owner", "yank", "audit", "deny", "run"]);
149
+ /**
150
+ * Anything sent to the broker: a start of the rustright client, directly or through a decoded `cmd /c`, whatever it asks (a compile,
151
+ * `cargo metadata`, a version). Looking the program up (`where rustright`) starts something else and is not a send. A start that names
152
+ * rustright but cannot be decoded is returned with `ambiguous: true`. Returns { args, cwd, at, ms, ambiguous }, or null.
153
+ */
154
+ export function brokerStartOf(entry) {
155
+ const d = decodeStart(entry);
156
+ const at = typeof entry.at === "string" ? Date.parse(entry.at) : null; const ms = typeof entry.ms === "number" ? entry.ms : null;
157
+ if (programName(d.program) === "rustright") return { args: d.args, cwd: d.cwd, at, ms, ambiguous: d.ambiguous };
158
+ if (d.ambiguous && /rustright/i.test([entry.cmd, ...(entry.args ?? [])].join(" "))) return { args: [], cwd: d.cwd, at, ms, ambiguous: true };
159
+ return null;
160
+ }
161
+ /** A compile sent to the broker (`rustright cargo <sub> ...`), or null. Returns { sub, args (after the subcommand), cwd, at, ms }. */
162
+ export function brokerCompileOf(entry) {
163
+ const b = brokerStartOf(entry);
164
+ if (!b || b.ambiguous || b.args[0] !== "cargo" || !COMPILING.has(canonVerb(b.args[1]))) return null;
165
+ return { sub: canonVerb(b.args[1]), args: b.args.slice(2), cwd: b.cwd, at: b.at, ms: b.ms };
166
+ }
167
+ /** The values a cargo flag takes in an argument list: `--package x`, `--package=x`, `-p x`, `-px`. */
168
+ const valuesOf = (args, long, short = null) => {
169
+ const out = [];
170
+ for (let i = 0; i < args.length; i += 1) {
171
+ const a = args[i];
172
+ if (a === "--") break;
173
+ if (a === long || (short && a === short)) { if (i + 1 < args.length) out.push(args[(i += 1)]); }
174
+ else if (a.startsWith(`${long}=`)) out.push(a.slice(long.length + 1));
175
+ else if (short && a.startsWith(short) && a.length > short.length && !a.startsWith("--")) out.push(a.slice(short.length));
176
+ }
177
+ return out;
178
+ };
179
+ const cratesOf = (c) => valuesOf(c.args, "--package", "-p");
180
+ const targetsOf = (c) => valuesOf(c.args, "--target");
181
+
182
+ // ---- where a row's work happens -------------------------------------------------------------------------------------------------------------------
183
+ /**
184
+ * A Class B row id as its stage, workspace, crate, target and feature-set variant (Council CV-1 F-20): `clippy:rk:rk-leaf@x86_64-unknown-linux-gnu`
185
+ * is clippy of crate rk-leaf in workspace rk; `test:rust:rk:rk-leaf` a Rust test; `clippy:rightkit-a` a crate that is its own workspace;
186
+ * `clippy:rk:rk-slow:1` the second feature set. The workspace label is never a crate name.
187
+ */
188
+ export function rowOf(id) {
189
+ const [head, target = null] = String(id).split("@");
190
+ const [sub, ...rest] = head.split(":");
191
+ const variant = rest.find((s) => /^\d+$/.test(s)) ?? null;
192
+ const names = rest.filter((s) => s && s !== "rust" && !/^\d+$/.test(s));
193
+ return { sub, ws: names.length >= 2 ? names[0] : null, crate: names[names.length - 1] ?? null, target, variant };
194
+ }
195
+ /** A Class B row the broker compiles: a cargo stage, and for tests only the Rust ones (`test:npm:*` suites run in the gate, not the broker). */
196
+ const isBrokerRow = (id) => { const r = rowOf(id); return COMPILING.has(r.sub) && (r.sub !== "test" || String(id).startsWith("test:rust:")); };
197
+ /** Windows paths compare without case and without a trailing separator; other paths keep their case (Council CV-1 F-22, F-23). */
198
+ const isWin = (p) => /^[a-z]:[\\/]/i.test(p) || String(p).includes("\\");
199
+ const dirKey = (p) => { const s = String(p ?? ""); const n = s.replaceAll("\\", "/").replace(/\/+$/, ""); return isWin(s) ? n.toLowerCase() : n; };
200
+ /** A folder relative to the snapshot root ("" for the root), or null when it is outside the snapshot or the snapshot is unknown. */
201
+ const relToSnap = (dir, snapPath) => {
202
+ if (!snapPath) return null; const d = dirKey(dir); const s = dirKey(snapPath);
203
+ return d === s ? "" : d.startsWith(`${s}/`) ? d.slice(s.length + 1) : null;
204
+ };
205
+ /** Whether a compile runs in the row's workspace: the folder its label names, or, for a crate that is its own workspace, a folder of that name. */
206
+ const inWorkspace = (c, r, snapPath) => {
207
+ const rel = relToSnap(c.cwd, snapPath); if (rel === null) return false;
208
+ return r.ws !== null ? rel === dirKey(r.ws) : baseOf(rel) === r.crate;
209
+ };
210
+ /**
211
+ * Whether a broker compile does a Class B row's work: the same stage, the row's crate, in the row's workspace, and the row's target. A row
212
+ * with no target is the host build: the compile must name no target, or name a target that no targeted row of that crate and stage claims.
213
+ */
214
+ const covers = (c, id, snapPath, rowIds = []) => {
215
+ const r = rowOf(id);
216
+ if (!isBrokerRow(id) || c.sub !== r.sub || !cratesOf(c).includes(r.crate) || !inWorkspace(c, r, snapPath)) return false;
217
+ const ts = targetsOf(c);
218
+ if (r.target !== null) return ts.includes(r.target);
219
+ if (!ts.length) return true;
220
+ const claimed = new Set(rowIds.map(rowOf).filter((o) => o.sub === r.sub && o.crate === r.crate && o.ws === r.ws && o.target !== null).map((o) => o.target));
221
+ return ts.some((t) => !claimed.has(t));
222
+ };
223
+ /** The same row in another feature set (`clippy:rk:rk-slow:0` and `clippy:rk:rk-slow:1`): one compile command cannot tell them apart. */
224
+ const otherVariant = (a, b) => { const x = rowOf(a); const y = rowOf(b); return x.variant !== y.variant && x.sub === y.sub && x.target === y.target && x.ws === y.ws && x.crate === y.crate; };
225
+
226
+ /**
227
+ * The Class A tools whose starts are attributable to a row (Council CV-1 F-17): a row id's tool, and whether a start of that program does
228
+ * that row's work. A version or help query is a probe, not the row's work. A row with a workspace in its id (`cargo-deny:app/engine`) is done
229
+ * by a start in that workspace or naming its manifest; a row without one by any non-probe start of the tool.
230
+ */
231
+ const TOOLS = { rustfmt: "rustfmt", deny: "cargo-deny", "cargo-deny": "cargo-deny", "cargo-audit": "cargo-audit", shellcheck: "shellcheck", actionlint: "actionlint", oxlint: "oxlint", tsc: "tsc" };
232
+ const toolOf = (id) => TOOLS[String(id).split(":")[0]] ?? null;
233
+ const isProbe = (args) => args.length > 0 && args.every((a) => /^(--version|-version|-V|--help|-help|-h)$/.test(a));
234
+
235
+ const RUN_PARTS = [[/(rk-probe-|rk-gate-shim-|rk-cargo-shim-)[A-Za-z0-9_-]+/g, "$1*"], [/\/var\/folders\/[^/]+\/[^/]+\/T\//g, "$TMP/"], [/\b(pid|PID)([= :]?)\d+/g, "$1$2*"]];
236
+ const runPart = (s) => RUN_PARTS.reduce((v, [re, to]) => v.replace(re, to), String(s));
237
+ /** A decoded start as program, arguments and folder; Windows folders and programs compare without case or a trailing separator. */
238
+ function callOf(d, raw) {
239
+ const p = String(d.program); const bare = !/[\\/]/.test(p);
240
+ const prog = runPart(p.replace(/\.(exe|cmd|bat|com)$/i, ""));
241
+ return { name: programName(p), path: bare ? null : dirKey(prog), args: d.args.map(runPart), cwd: dirKey(runPart(d.cwd ?? "")), truncated: (raw.args ?? []).some((a) => /^\.\.\. \d+ args$/.test(String(a))), ambiguous: d.ambiguous };
242
+ }
243
+ /** The same program: one path, or a bare name (found on PATH) and a path ending in it. Two different paths are two programs. */
244
+ const sameProgram = (a, b) => a.name === b.name && (a.path === null || b.path === null || a.path === b.path);
245
+
246
+ /** The values a minimal TOML `[workspace] members = [...]` holds, or null when the manifest has no workspace table. */
247
+ const workspaceMembers = (toml) => {
248
+ const t = String(toml ?? ""); const ws = /^\[workspace\]\s*$([\s\S]*?)(?=^\[|(?![\s\S]))/m.exec(t); if (!ws) return null;
249
+ const m = /members\s*=\s*\[([\s\S]*?)\]/.exec(ws[1]); if (!m) return [];
250
+ return [...m[1].matchAll(/"([^"]+)"/g)].map((x) => x[1].replace(/\/+$/, ""));
251
+ };
252
+
253
+ // ---- the evidence (none of it written by the gate) ----------------------------------------------------------------------------------------------
254
+ /**
255
+ * A Windows command line as its program would read it (CommandLineToArgvW / the MSVC runtime rules): whitespace separates arguments outside
256
+ * quotes; `2n` backslashes before a quote are `n` backslashes and the quote toggles quoting; `2n+1` are `n` and a literal quote; `""` inside
257
+ * quotes is a literal quote.
258
+ */
259
+ export function parseCommandLine(line) {
260
+ const s = String(line ?? ""); const out = []; let cur = ""; let quoted = false; let any = false;
261
+ for (let i = 0; i < s.length; i += 1) {
262
+ const c = s[i];
263
+ if (c === "\\") { let n = 0; while (s[i] === "\\") { n += 1; i += 1; } if (s[i] === '"') { cur += "\\".repeat(Math.floor(n / 2)); if (n % 2) { cur += '"'; any = true; } else { i -= 1; } } else { cur += "\\".repeat(n); i -= 1; } any = true; continue; }
264
+ if (c === '"') { if (quoted && s[i + 1] === '"') { cur += '"'; i += 1; } else quoted = !quoted; any = true; continue; }
265
+ if (!quoted && /\s/.test(c)) { if (any) { out.push(cur); cur = ""; any = false; } continue; }
266
+ cur += c; any = true;
267
+ }
268
+ if (any) out.push(cur);
269
+ return out;
270
+ }
271
+
272
+ /**
273
+ * Programs as the operating system recorded them, from Windows Security events 4688 (a process created: new pid, creator pid, image path,
274
+ * command line, time) and 4689 (a process exited: pid, image path, exit status, time). Event ids are reused by Windows, so an exit is joined
275
+ * to the latest start of that pid before it. 4688 records no working folder, so `cwd` is null. Returns [{ pid, ppid, exe, args, cwd, start,
276
+ * end, exit }], times in ms.
277
+ */
278
+ export function processesFromWindowsEvents(events) {
279
+ const procs = [];
280
+ const sorted = [...(events ?? [])].map((e) => ({ ...e, t: timeOf(e.time) })).filter((e) => Number.isFinite(e.t)).sort((a, b) => a.t - b.t);
281
+ for (const e of sorted) {
282
+ if (e.id === 4688) { const known = typeof e.commandLine === "string" && e.commandLine.trim() !== ""; const argv = known ? parseCommandLine(e.commandLine) : []; procs.push({ pid: e.pid, ppid: e.ppid, exe: String(e.exe ?? ""), args: argv.slice(1), argsKnown: known, cwd: null, start: e.t, end: null, exit: null }); }
283
+ else if (e.id === 4689) { const p = [...procs].reverse().find((x) => x.pid === e.pid && x.end === null && x.start <= e.t); if (p) { p.end = e.t; p.exit = Number.isInteger(e.exit) ? e.exit : null; } }
284
+ }
285
+ return procs;
286
+ }
287
+ /** Programs from macOS `eslogger exec exit` lines, as normalized by the collector ({ event, pid, ppid, path, args, cwd, time, status }). */
288
+ export function processesFromEslogger(lines) {
289
+ return processesFromWindowsEvents((lines ?? []).map((l) => (l.event === "exec" ? { id: 4688, pid: l.pid, ppid: l.ppid, exe: l.path, commandLine: null, time: l.time } : { id: 4689, pid: l.pid, exit: l.status, time: l.time }))).map((p, i, all) => {
290
+ const exec = (lines ?? []).filter((l) => l.event === "exec" && l.pid === p.pid)[all.slice(0, i).filter((q) => q.pid === p.pid).length];
291
+ return exec ? { ...p, args: Array.isArray(exec.args) ? exec.args.slice(1) : p.args, argsKnown: Array.isArray(exec.args), cwd: typeof exec.cwd === "string" ? exec.cwd : null } : p;
292
+ });
293
+ }
294
+
295
+ /**
296
+ * The run's own programs: the gate process the launcher started (its pid, a child of the launcher, started inside the launcher's span) and
297
+ * every program descended from it, each joined to the parent that was running when it started. Returns { root, procs, gaps }.
298
+ */
299
+ function runTree(launch, processes, witness) {
300
+ const gaps = []; const all = processes ?? [];
301
+ if (!witness) return { root: null, procs: [], gaps: ["there is no operating-system record of the programs this run started"] };
302
+ gaps.push(...(witness.problems ?? []).map((p) => `the operating-system process record is incomplete: ${p}`));
303
+ const start = timeOf(launch?.startedAt); const end = timeOf(launch?.endedAt);
304
+ if (!(timeOf(witness.from) <= start)) gaps.push("the operating-system process record does not start before the run did");
305
+ if (!Number.isFinite(end)) gaps.push("the launcher never saw the run end, so the process record cannot be shown to cover it");
306
+ else if (!(timeOf(witness.to) >= end)) gaps.push("the operating-system process record ends before the run did");
307
+ // The log itself must have advanced past the run's end when it was read (its newest event), so events cannot be missing from the tail.
308
+ if (witness.continuous !== true) gaps.push("the process record does not show the Security log's records ran without a break across the run, so a lost start or exit is not ruled out");
309
+ if (!Number.isFinite(timeOf(witness.newest))) gaps.push("the process record does not say how far the Security log had advanced when it was read");
310
+ else if (Number.isFinite(end) && timeOf(witness.newest) < end) gaps.push("the Security log's newest event is older than the run's end, so events may not have been written yet");
311
+ if (all.some((p) => !Number.isInteger(p.pid) || !Number.isInteger(p.ppid) || !Number.isFinite(p.start))) gaps.push("the process record holds a start with no usable process id, parent or time");
312
+ const root = all.find((p) => p.pid === launch?.gatePid && p.ppid === launch?.launcherPid && p.start >= start - 1000 && (!Number.isFinite(end) || p.start <= end)) ?? null;
313
+ if (!root) { gaps.push(`the process record has no start of the gate process ${launch?.gatePid ?? "(unknown)"} by its launcher`); return { root: null, procs: [], gaps }; }
314
+ const inTree = new Set([root]); let grew = true;
315
+ while (grew) {
316
+ grew = false;
317
+ for (const p of all) {
318
+ if (inTree.has(p)) continue;
319
+ const parent = [...inTree].filter((q) => q.pid === p.ppid && q.start <= p.start && (q.end === null || q.end >= p.start)).sort((a, b) => b.start - a.start)[0];
320
+ if (parent) { inTree.add(p); grew = true; }
321
+ }
322
+ }
323
+ if (root.end === null) gaps.push("the gate process the launcher started has no recorded exit, so that nothing else ran after it cannot be shown");
324
+ // The Windows console host: the system conhost.exe Windows starts for each console program, with a handle argument and -ForceV1. It exits after the program it serves,
325
+ // and there is one per console child, so it is the operating system's own start, not a program the run chose: it is neither outlived-by nor a repeat.
326
+ const consoleHost = (p) => /\/windows\/system32\/conhost\.exe$/.test(dirKey(p.exe)) && Array.isArray(p.args) && p.args.length > 0 && p.argsKnown !== false && p.args.every((a) => /^(0x[0-9a-f]+|-ForceV[12])$/i.test(String(a)));
327
+ const procs = [...inTree].filter((p) => p !== root && !consoleHost(p)).sort((a, b) => a.start - b.start);
328
+ const open = procs.filter((p) => p.end === null);
329
+ if (open.length) gaps.push(`${open.length} program(s) of the run have no recorded exit (first: ${programName(open[0].exe)})`);
330
+ // A start whose command line the record does not hold is an unknown call, not an empty one: for a tool the lines read arguments of, what it did is not shown.
331
+ const tracked = new Set(["cargo", "rustc", "rustright", ...Object.values(TOOLS)]);
332
+ const blind = procs.filter((p) => p.argsKnown === false && tracked.has(programName(p.exe)));
333
+ if (blind.length) gaps.push(`${blind.length} program(s) of the run that the lines read arguments of have no command line in the process record (first: ${programName(blind[0].exe)}), so what they did is not shown`);
334
+ return { root, procs, gaps };
335
+ }
336
+
337
+ /** A broker job from its signed receipt: only the signed payload is read. Submission time is the signed start less the signed waits. */
338
+ function jobOf(r) {
339
+ const p = r?.doc?.provenance?.payload ?? null; const req = p?.request ?? null;
340
+ const argv = Array.isArray(req?.requestedArgv) ? req.requestedArgv.map(String) : null;
341
+ const started = timeOf(p?.startedAt); const t = p?.timingsMs ?? {};
342
+ const waits = ["admission", "queue", "bind"].map((k) => (Number.isFinite(t[k]) ? t[k] : 0)).reduce((a, b) => a + b, 0);
343
+ return {
344
+ file: r.file, verified: r.verified?.ok === true, problems: r.verified?.problems ?? [], jobId: p?.jobId ?? null, argv, cwd: typeof req?.workspace === "string" ? req.workspace : null,
345
+ sub: argv ? cargoVerb(argv) : null, args: argv ? argv.slice(1) : [], gate: p?.gate ?? null, started, ended: timeOf(p?.terminalAt), submitted: Number.isFinite(started) ? started - waits : NaN, queueMs: Number.isFinite(t.queue) ? t.queue : null,
346
+ testExecutables: p?.testExecutables, testExecutablesReason: p?.testExecutablesReason,
347
+ };
348
+ }
349
+
350
+ /**
351
+ * What the run owes, worked out from git and an independent row inventory (rightkit#1514 step 3; chat gate 2026-11-21: no gate history). `inventory`:
352
+ * Map row id -> { stage, files: [paths the row reads] }, from a source that is not the gate's reporting (the planner's entry point once it takes plain
353
+ * data; null until then). The prior state is the tree of the launcher's baseline commit (the previous launched run's selected commit), never a gate
354
+ * file. A row none of whose files changed between the two trees is owed reuse; a row with a changed, added or removed file is owed a rerun of exactly
355
+ * those files' work. Returns Map id -> { id, stage, expect: "reuse"|"run", changed: [paths], priorFailed, isNew }.
356
+ */
357
+ function expectedRows(inventory, git, prior, priorInventory = null) {
358
+ const out = new Map();
359
+ if (!inventory || typeof git?.priorBlobOf !== "function") return out;
360
+ for (const [id, row] of inventory) {
361
+ // A file a row read at the baseline and no longer exists is a change to it too: the files are those of both trees.
362
+ const files = [...new Set([...(Array.isArray(row?.files) ? row.files : []), ...(Array.isArray(priorInventory?.get(id)?.files) ? priorInventory.get(id).files : [])].map((p) => String(p).replaceAll("\\", "/")))];
363
+ const changed = files.filter((p) => (git.blobOf(p) ?? null) !== (git.priorBlobOf(p) ?? null));
364
+ const isNew = files.length > 0 && files.every((p) => (git.priorBlobOf(p) ?? null) === null);
365
+ out.set(id, { id, stage: row?.stage === "B" ? "B" : "A", expect: changed.length || !files.length ? "run" : "reuse", changed: changed.length ? changed : (files.length ? [] : ["(no input files)"]), priorFailed: prior?.failedRows?.has(id) === true, priorUnknown: prior?.unknownRows?.has(id) === true, isNew });
366
+ }
367
+ return out;
368
+ }
369
+
370
+ /**
371
+ * The work each row actually did, from evidence the gate does not write: a result the cache store took during the run (its entry's own time),
372
+ * a program of the row's tool the operating system saw start, or a broker job the broker signed that covers the row.
373
+ */
374
+ function workOf(ctx, id) {
375
+ const tool = toolOf(id);
376
+ let progs = tool ? ctx.starts.filter((d) => programName(d.program) === tool && !isProbe(d.args)) : [];
377
+ if (tool === "rustfmt") { const ed = String(id).split(":")[1]; progs = progs.filter((d) => valuesOf(d.args, "--edition").includes(ed)); }
378
+ const jobs = isBrokerRow(id) ? ctx.vjobs.filter((j) => j.sub && covers(j, id, ctx.snap.path, [...ctx.expected.keys()])) : [];
379
+ // A job that covers two feature-set variants of one row cannot say which it built (feature-set variants are told apart by their id only).
380
+ const sharers = tool && tool !== "rustfmt" ? [...ctx.expected.keys()].filter((o) => o !== id && toolOf(o) === tool).length : 0;
381
+ // A start of a tool that serves several rows is one row's work only when the row names a workspace and the start's folder is known and inside it; otherwise which
382
+ // row it served is not shown, and it is never credited to every row of the tool.
383
+ const rowWs = tool && tool !== "rustfmt" ? String(id).split(":").slice(1).join(":").replaceAll("\\", "/").replace(/^\/+|\/+$/g, "") : "";
384
+ let looseOnly = false;
385
+ if (sharers > 0 && rowWs && ctx.snap.path) {
386
+ const place = (d) => { if (!d.cwd) return "unknown"; const rel = relToSnap(d.cwd, ctx.snap.path); if (rel === null) return "other"; if (rel === rowWs || rel.startsWith(`${rowWs}/`)) return "mine"; if (rel === "" || rowWs.startsWith(`${rel}/`)) return "above"; return "other"; };
387
+ const mine = progs.filter((d) => place(d) === "mine"); const loose = progs.filter((d) => place(d) === "above" || place(d) === "unknown");
388
+ progs = mine.length ? mine : loose; looseOnly = mine.length === 0 && loose.length > 0;
389
+ }
390
+ const shared = sharers > 0 && progs.length > 0 && (!rowWs || looseOnly);
391
+ const ambiguous = shared || jobs.some((j) => [...ctx.expected.keys()].some((o) => o !== id && otherVariant(o, id) && covers(j, o, ctx.snap.path, [...ctx.expected.keys()])));
392
+ return { progs, jobs, ambiguous, did: jobs.length > 0 || progs.length > 0 };
393
+ }
394
+ const classOf = (ctx, id) => ctx.expected.get(id)?.stage ?? (isBrokerRow(id) ? "B" : "A");
395
+ /** Every row that did work in this run: rows with a cache write, plus rows a broker job covers. */
396
+ const rowsThatWorked = (ctx) => new Set([...ctx.expected.keys()].filter((id) => workOf(ctx, id).did));
397
+ /** What the line cannot show without a validated baseline and an independent inventory (EGM design, rightkit#1514). */
398
+ const baselineGaps = (ctx) => [...(ctx.baselineGap ? [ctx.baselineGap] : []), ...(ctx.inventory && ctx.inventoryUncovered?.length ? [`the test's own enumeration covers the Rust formatting and compile rows only; ${ctx.inventoryUncovered.length} kinds of row are decided by rules that exist only in gate code (row-rules-only-in-gate-code.md), so the rows they decide are not measured`] : []), ...(ctx.inventory ? [] : ["no independent row inventory is available (a planner entry point that takes plain data is separate work), so which rows exist and what files each reads is not shown"])];
399
+
400
+ // ---- the twelve lines -------------------------------------------------------------------------------------------------------------------------------
401
+ /** The cargo subcommand of an argument list, reading past global options (+toolchain, -C dir, -Z flag, --config k=v, --manifest-path p, --color when, ...). */
402
+ const cargoVerb = (args) => {
403
+ const withValue = new Set(["-C", "-Z", "--config", "--manifest-path", "--color", "--target-dir", "-j", "--jobs", "--message-format", "--profile"]);
404
+ for (let i = 0; i < args.length; i += 1) { const a = String(args[i]); if (a.startsWith("+")) continue; if (withValue.has(a)) { i += 1; continue; } if (a.startsWith("-")) continue; return canonVerb(a); }
405
+ return null;
406
+ };
407
+ /** The path operands of a Class A program (the arguments that are not options), as written. */
408
+ const operandsOf = (d) => (programName(d.program) === "rustfmt" ? rustfmtFiles(d) : d.args.filter((a, i, all) => !String(a).startsWith("-") && !(i > 0 && ["--config", "--edition", "--config-path"].includes(all[i - 1]))).map((a) => String(a).replaceAll("\\", "/")));
409
+ const classAStarts = (ctx) => ctx.starts.filter((d) => Object.values(TOOLS).includes(programName(d.program)) && !isProbe(d.args));
410
+ function nn01(ctx) {
411
+ const fails = []; const gaps = [...ctx.processGaps, ...ctx.sendGaps, ...ctx.jobGaps];
412
+ if (!/^[0-9a-f]{40}$/.test(String(ctx.commit ?? ""))) return result(NOT_MEASURED, "the launcher's record names no selected commit");
413
+ if (!ctx.tree) return result(NOT_MEASURED, `git cannot say which tree commit ${short(ctx.commit)} is`);
414
+ // Every broker job is signed as this commit's tree, built from a snapshot the broker confirmed unchanged.
415
+ for (const j of ctx.jobs) {
416
+ if (!j.verified) { (ctx.verifierPinned ? fails : gaps).push(`broker job ${j.jobId ?? path.basename(j.file)}: its receipt ${ctx.verifierPinned ? `does not verify (${j.problems.join("; ") || "no reason given"})` : "cannot be verified: no broker key is pinned"}`); continue; }
417
+ if (j.gate?.commit !== ctx.commit) fails.push(`broker job ${j.jobId} built commit ${short(j.gate?.commit)}, not the selected ${short(ctx.commit)}`);
418
+ if (j.gate?.tree !== ctx.tree) fails.push(`broker job ${j.jobId} built tree ${short(j.gate?.tree)}, not the selected commit's ${short(ctx.tree)}`);
419
+ if (j.gate?.snapshotUnchanged === false) fails.push(`broker job ${j.jobId}: the broker found the snapshot changed`);
420
+ else if (j.gate?.snapshotUnchanged !== true) gaps.push(`broker job ${j.jobId}: the broker's receipt does not say whether the snapshot stayed unchanged`);
421
+ if (j.cwd && ctx.snap.path && relToSnap(j.cwd, ctx.snap.path) === null) fails.push(`broker job ${j.jobId} built in ${j.cwd}, outside the snapshot ${ctx.snap.path}`);
422
+ }
423
+ const clients = ctx.sends.filter((d) => COMPILING.has(canonVerb(d.args[1])));
424
+ const compileJobs = ctx.jobs.filter((j) => COMPILING.has(j.sub));
425
+ if (clients.length > compileJobs.length) gaps.push(`${clients.length} broker client compile start(s) and ${compileJobs.length} signed compile job(s): what the others built is not shown`);
426
+ // Class A work is bound to the selected tree by the folder it ran in: a program that ran in another folder read another tree, and one whose folder
427
+ // the record does not keep (Windows event 4688 has none) cannot be placed.
428
+ const aStarts = classAStarts(ctx);
429
+ if (aStarts.length && ctx.snap.path) {
430
+ const unplaced = aStarts.filter((d) => !d.cwd);
431
+ const elsewhere = aStarts.filter((d) => d.cwd && relToSnap(d.cwd, ctx.snap.path) === null);
432
+ if (elsewhere.length) fails.push(`${elsewhere.length} Class A program(s) ran outside the selected snapshot (first: ${programName(elsewhere[0].program)} in ${elsewhere[0].cwd})`);
433
+ if (unplaced.length) gaps.push(`${unplaced.length} Class A program(s) ran in a folder the process record does not keep, so that they read the selected tree is not shown`);
434
+ // A program that ran inside the snapshot read the selected commit's bytes when the files its arguments name, read on disk after the run, are those of the
435
+ // selected tree. A program with no such file in its arguments (cargo-deny reads the lock and manifests, shellcheck follows source) leaves what it read unshown.
436
+ for (const d of aStarts.filter((x) => x.cwd && relToSnap(x.cwd, ctx.snap.path) !== null)) {
437
+ const base = relToSnap(d.cwd, ctx.snap.path); const named = [];
438
+ for (const o of operandsOf(d)) {
439
+ const abs = /^([a-z]:[\\/]|[\\/])/i.test(o);
440
+ const joined = abs ? relToSnap(o, ctx.snap.path) : [base, o.replace(/^\.\//, "")].filter(Boolean).join("/");
441
+ const rel = joined === null ? null : path.posix.normalize(joined);
442
+ if (rel === null || rel === ".." || rel.startsWith("../")) { fails.push(`${programName(d.program)} names ${o}, outside the selected snapshot`); continue; }
443
+ if (typeof ctx.blobOf === "function" && ctx.blobOf(rel) !== null && ctx.blobOf(rel) !== undefined) named.push(rel);
444
+ else gaps.push(`${programName(d.program)} names ${o}, which is not a file of the selected tree (a generated or untracked file, or not a file at all), so what it read there is not shown`);
445
+ }
446
+ if (!named.length) { gaps.push(`${programName(d.program)} names no file of the selected tree in its arguments, so what it read is not shown`); continue; }
447
+ for (const rel of named) {
448
+ // The launcher's stat record of the snapshot at the gate's exit: a file written after its program started is not what the program was handed.
449
+ const folder = path.basename(String(ctx.snap.path)); const dirStat = ctx.snapshotStat && Object.hasOwn(ctx.snapshotStat.dirs ?? {}, folder) ? ctx.snapshotStat.dirs[folder] : null; const raw = dirStat && Object.hasOwn(dirStat, rel) ? dirStat[rel] : null; const entry = Array.isArray(raw) && raw.length >= 2 && Number.isFinite(raw[0]) && Number.isFinite(raw[1]) ? raw : null;
450
+ if (!ctx.snapshotStat) gaps.push(`${programName(d.program)} was handed ${rel} and the launcher recorded no stat record of the snapshot, so when it was last written is not shown`);
451
+ else if (!entry) gaps.push(`${programName(d.program)} was handed ${rel} and the launcher's stat record of the snapshot has no stat record of ${rel}, so when it was last written is not shown`);
452
+ else if (d.at - entry[1] >= 0 && d.at - entry[1] <= 50) gaps.push(`${programName(d.program)} was handed ${rel}, last written within 50 ms of ${programName(d.program)} starting (the file system's own clock tick), so which came first is not shown`);
453
+ else if (entry[1] > d.at) fails.push(`${programName(d.program)} was handed ${rel}, which was written after ${programName(d.program)} started (${rel} was written after ${programName(d.program)} started: ${new Date(entry[1]).toISOString()} against ${new Date(d.at).toISOString()})`);
454
+ const disk = typeof ctx.diskBlobs === "function" ? ctx.diskBlobs(`${ctx.snap.path}${isWin(ctx.snap.path) ? "\\" : "/"}${rel.replaceAll("/", isWin(ctx.snap.path) ? "\\" : "/")}`, rel) : null;
455
+ if (disk === null || disk === undefined) gaps.push(`${programName(d.program)} was handed ${rel} and its bytes on disk after the run were not read, so that it read the selected commit's file is not shown`);
456
+ else if (disk !== ctx.blobOf(rel)) fails.push(`${programName(d.program)} was handed ${rel}, whose bytes on disk are not the selected commit's`);
457
+ }
458
+ }
459
+ } else if (aStarts.length) gaps.push("Class A work ran and no broker job names the snapshot folder, so that it read the selected tree is not shown");
460
+ // A compile the gate ran itself, outside the broker, has no signed commit or tree.
461
+ // rustc asked only for its version or for information (--print, with the crate name and types cargo gives its target-info probe, and a `-` for the empty crate) is a
462
+ // discovery probe, not a compile (NN03 counts it as one); any other rustc start, with a source, an --emit or any other option, compiles.
463
+ const rustcProbe = (args) => { if (!args.length) return false; let info = false; for (let i = 0; i < args.length; i += 1) { const x = String(args[i]); if (/^(-vV|--version|-V|-v)$/.test(x) || x === "--print" || /^--print=./.test(x)) { info = true; if (x === "--print") i += 1; continue; } if (x === "-" || /^-[WADF][a-z][a-z_-]*$/.test(x)) continue; if (x === "--crate-name" || x === "--crate-type" || x === "--target") { i += 1; continue; } return false; } return info; };
464
+ const own = ctx.starts.filter((d) => (programName(d.program) === "cargo" && COMPILING.has(cargoVerb(d.args))) || (programName(d.program) === "rustc" && !rustcProbe(d.args)));
465
+ if (own.length) fails.push(`${own.length} compile(s) ran outside the broker (first: ${programName(own[0].program)} ${own[0].args.slice(0, 3).join(" ")}), so what they built is not shown`);
466
+ return decide(fails, gaps, `selected commit ${short(ctx.commit)} is tree ${short(ctx.tree)}; ${ctx.jobs.length} broker job(s) signed for that tree on an unchanged snapshot; nothing compiled outside the broker`);
467
+ }
468
+
469
+ function nn02(ctx) {
470
+ const fails = []; const gaps = [...ctx.sendGaps, ...ctx.processGaps];
471
+ const mine = (d) => !d.cwd || !ctx.snap.path || relToSnap(d.cwd, ctx.snap.path) !== null;
472
+ const a = classAStarts(ctx).filter(mine);
473
+ // Class A failed: a Class A result the cache store took as a failure, or a Class A tool that exited non-zero.
474
+ // A Class A tool that exited non-zero, or an unchanged Class A row whose earlier result was a failure and is reused (F-9): Class A failed.
475
+ const failedRows = [...ctx.expected.values()].filter((e) => e.stage === "A" && e.expect === "reuse" && e.priorFailed).map((e) => e.id);
476
+ const failedProgs = a.filter((d) => d.exit !== null && d.exit !== 0);
477
+ if (a.some((d) => d.end !== null && !Number.isInteger(d.exit))) gaps.push("a Class A program ended with no recorded exit status, so that it succeeded is not shown");
478
+ const failed = failedRows.length > 0 || failedProgs.length > 0;
479
+ const rust = ctx.rustStarts;
480
+ const clients = rust.filter((d) => d.args[0] === "cargo");
481
+ const probes = rust.filter((d) => !clients.includes(d));
482
+ const unknownClient = probes.filter((d) => !(isProbe(d.args) || /^(quiet|verify-receipt|request-digest|status|trampoline-capability)$/.test(d.args[0] ?? "")));
483
+ if (unknownClient.length) gaps.push(`${unknownClient.length} broker client start(s) that are not a send or a known probe (first: rustright ${unknownClient[0].args.slice(0, 2).join(" ")}), so whether they sent work is not shown`);
484
+ gaps.push(...ctx.jobGaps);
485
+ if (!ctx.inventory || ctx.inventoryUncovered?.length) gaps.push("Class A rows that run in the gate's own process leave no program, so that none of them failed is not shown");
486
+ // A Class A program of the run's tree that failed, or ended with no status, in a folder outside the snapshot cannot be placed as this run's unit or another's.
487
+ const elsewhere = classAStarts(ctx).filter((d) => !mine(d) && d.exit !== 0);
488
+ if (elsewhere.length) gaps.push(`${programName(elsewhere[0].program)} exited ${elsewhere[0].exit === null ? "with no recorded status" : "non-zero"} in ${elsewhere[0].cwd}, outside the snapshot, so whether that was this run's Class A unit is not shown`);
489
+ // A reused Class A row is reused with whatever its earlier outcome was; with that outcome unknown (or no predecessor evidence at all), that Class A did not fail is not shown.
490
+ const reusedUnknown = [...ctx.expected.values()].filter((e) => e.stage === "A" && e.expect === "reuse" && (e.priorUnknown || !ctx.prior)).map((e) => e.id);
491
+ if (reusedUnknown.length) gaps.push(`${reusedUnknown[0]} is reused and what happened to it in the previous launched run is not known, so that Class A did not fail is not shown`);
492
+ if (failed) {
493
+ if (ctx.jobs.length || clients.length) fails.push(`Class A failed (${failedRows[0] ?? programName(failedProgs[0].program)}) and ${ctx.jobs.length} broker job(s) / ${clients.length} broker client start(s) still followed`);
494
+ return decide(fails, gaps, `Class A failed (${failedRows.slice(0, 2).join(", ") || programName(failedProgs[0].program)}) and nothing went to the broker`);
495
+ }
496
+ if (!a.length && !ctx.expected.size) gaps.push("no Class A program started and no Class A row is known, so that Class A finished is not shown");
497
+ for (const e of ctx.expected.values()) if (e.stage === "A" && e.expect === "run" && !workOf(ctx, e.id).did && toolOf(e.id)) gaps.push(`${e.id} is owed a Class A run and no program of it was seen, so when Class A finished is not shown`);
498
+ const aEnd = Math.max(-Infinity, ...a.map((d) => d.end ?? Infinity));
499
+ if (a.some((d) => d.end === null)) gaps.push("a Class A program has no recorded exit, so when Class A finished is not shown");
500
+ for (const j of ctx.jobs) {
501
+ if (!Number.isFinite(j.submitted)) { gaps.push(`broker job ${j.jobId}: its receipt gives no time`); continue; }
502
+ if (j.submitted < aEnd) fails.push(`broker job ${j.jobId} was submitted before Class A finished`);
503
+ else if (j.submitted === aEnd) gaps.push(`broker job ${j.jobId} was submitted at the same moment Class A ended, so which came first is not shown`);
504
+ }
505
+ for (const c of clients) { if (c.at < aEnd) fails.push(`a broker client started (rustright ${c.args.slice(0, 2).join(" ")}) before Class A finished`); else if (c.at === aEnd) gaps.push("a broker client started at the same moment Class A ended, so which came first is not shown"); }
506
+ if (clients.length > ctx.jobs.length) gaps.push(`${clients.length} broker client send(s) and ${ctx.jobs.length} signed job(s): a send with no receipt cannot be placed after Class A`);
507
+ return decide(fails, gaps, `Class A passed (${a.length} tool program(s)), then ${ctx.jobs.length} broker job(s) were submitted after it ended`);
508
+ }
509
+
510
+ function nn03(ctx) {
511
+ const gaps = [...ctx.sendGaps, ...ctx.processGaps, ...ctx.jobGaps]; const fails = [];
512
+ const owedA = [...ctx.expected.values()].filter((e) => e.stage === "A" && e.expect === "run");
513
+ const all = classAStarts(ctx);
514
+ if (all.some((d) => d.end !== null && d.end < d.at)) return result(NOT_MEASURED, "the process record has a Class A program ending before it started");
515
+ const a = all.filter((d) => Number.isFinite(d.at) && d.end !== null);
516
+ gaps.push(...baselineGaps(ctx));
517
+ if (!a.length) {
518
+ // Positive proof of complete reuse is the one pass that needs no readiness: every Class A row is owed reuse, none ran, and the record is whole.
519
+ const rows = [...ctx.expected.values()].filter((e) => e.stage === "A");
520
+ if (!rows.length) gaps.push("no Class A row is known, so that none was owed work is not shown");
521
+ // No program of an owed row is no evidence that it waited (the record may be unreadable, or the row ran in the gate's own process): not shown, never a fail.
522
+ if (owedA.length) gaps.push(`${owedA.length} Class A row(s) were owed a run (first: ${owedA[0].id}) and no Class A program started, so that none waited with a lane free is not shown`);
523
+ return decide(fails, gaps, `Class A was wholly reused (${rows.length} row(s) owed reuse, no program started), so no row waited`);
524
+ }
525
+ const lanes = Number(ctx.launch?.lanes);
526
+ if (!Number.isInteger(lanes) || lanes <= 0) return result(NOT_MEASURED, "the launcher's record gives no lane count for Class A on this host");
527
+ // When each row became ready is an input from outside the gate (none exists on a real run yet); a row's start is held to it. Without it the first start
528
+ // is the row's own evidence that it was ready, which can show a lane left idle but never a row that waited before any start.
529
+ // Discovery probes, from the process record alone: the commands the gate runs to find out what the tree is and what changed (git rev-parse, diff, ls-files and the like,
530
+ // cargo metadata, rustc -vV) that started and ended before the first Class A program started. The last of them to exit is when independent work was known to be ready.
531
+ const GIT_PROBES = new Set(["rev-parse", "diff", "diff-tree", "ls-files", "ls-tree", "cat-file", "status", "log", "show", "merge-base", "rev-list", "describe", "name-rev", "symbolic-ref"]);
532
+ const gitVerb = (args) => { for (let i = 0; i < args.length; i += 1) { const x = String(args[i]); if (x === "-c" || x === "-C") { i += 1; continue; } if (x.startsWith("-")) continue; return x; } return null; };
533
+ const firstStart = Math.min(...a.map((d) => d.at));
534
+ let probeReady = null; let probeProblem = null;
535
+ { const probes = ctx.procs.map((p, i) => ({ p, d: ctx.starts[i] })).filter(({ p, d }) => p.start < firstStart && !d.ambiguous && ((programName(p.exe) === "git" && GIT_PROBES.has(gitVerb(p.args))) || (programName(p.exe) === "cargo" && cargoVerb(p.args) === "metadata") || (programName(p.exe) === "rustc" && p.args.length > 0 && p.args.every((x) => /^(-vV|--version|-V|-v)$/.test(x)))));
536
+ if (probes.some(({ p }) => p.argsKnown === false)) probeProblem = "a discovery probe has no command line in the process record";
537
+ else if (probes.some(({ p }) => p.end === null)) probeProblem = "a discovery probe has no recorded exit";
538
+ else if (probes.some(({ p }) => p.end > firstStart)) probeProblem = "a discovery probe was still running when Class A started";
539
+ else if (probes.length) probeReady = Math.max(...probes.map(({ p }) => p.end)); }
540
+ // A readiness handed in is keyed by program name, so it can belong to one row only when exactly one Class A start of that program exists; with two or more
541
+ // starts of it nothing says which start it is for, and taking it for all of them hides the wait before an earlier one (CV-6 F-6): it is not used and is a gap.
542
+ const startsOf = (name) => a.filter((o) => programName(o.program) === name).length;
543
+ const sharedName = [...new Set(a.map((d) => programName(d.program)))].filter((n) => startsOf(n) > 1 && Number.isFinite(ctx.readiness?.get(n)));
544
+ const given = (d) => { const n = programName(d.program); if (startsOf(n) > 1) return null; const r = ctx.readiness?.get(n); return Number.isFinite(r) ? r : null; };
545
+ if (sharedName.length) gaps.push(`a readiness is keyed by program name and ${sharedName.join(", ")} started more than once, so which start it belongs to is not shown and it is not used`);
546
+ const ready = (d) => given(d) ?? probeReady;
547
+ // Between two moments, the time a lane stood free: every interval between consecutive start and end events is looked at, and the lanes busy over the whole
548
+ // interval (programs other than the one waiting) are counted, so a lane idle for part of a wait is found however many programs overlapped some of it.
549
+ const idleIn = (from, to, self) => {
550
+ const pts = [...new Set([from, to, ...a.flatMap((o) => [o.at, o.end]).filter((t) => t > from && t < to)])].sort((x, y) => x - y);
551
+ let idle = 0;
552
+ for (let i = 0; i + 1 < pts.length; i += 1) { const busy = a.filter((o) => o !== self && o.at <= pts[i] && o.end >= pts[i + 1]).length; if (busy < lanes) idle += pts[i + 1] - pts[i]; }
553
+ return idle;
554
+ };
555
+ const firstReady = Math.min(...a.map((d) => ready(d) ?? d.at));
556
+ for (const d of a) {
557
+ const r = ready(d) ?? firstReady;
558
+ if (!(d.at > r)) continue;
559
+ // A readiness taken from the probes is when discovery ended: the gate's own work after it, before its first Class A start, leaves no process record and is a gap, not a wait;
560
+ // a wait after the first start is counted from the first start.
561
+ // That readiness is the gate's discovery ending, not evidence that this row was ready (a row can wait on its own dependency): a wait counted from it is not shown, never a fail.
562
+ if (given(d) === null && probeReady !== null) { const from = Math.max(r, firstStart); if (!(d.at > from)) continue; const idleLate = idleIn(from, d.at, d); if (idleLate > 0) gaps.push(`${programName(d.program)} was ready at ${new Date(r).toISOString()} (the last discovery probe's exit) and started ${Math.round(d.at - r)} ms later, ${Math.round(idleLate)} ms of it after Class A had started with a lane free of ${lanes}; a row's readiness taken from the probe's exit is not evidence that it was ready, so that it waited with capacity free is not shown`); continue; }
563
+ const idle = idleIn(r, d.at, d);
564
+ if (idle > 0) fails.push(`${programName(d.program)} was ready at ${new Date(r).toISOString()} and started ${Math.round(d.at - r)} ms later, ${Math.round(idle)} ms of it with a lane free of ${lanes}`);
565
+ }
566
+ if (probeReady !== null && a.some((d) => given(d) === null)) { const planning = firstStart - probeReady; gaps.push(`the gate's own work between the last discovery probe's exit (${new Date(probeReady).toISOString()}) and the first Class A start (${Math.round(planning)} ms) leaves no process record, so that no Class A row was held back in it is not shown (a first start at the very moment of the last probe's exit is a tie, not a measurement)`); }
567
+ else if (!a.every((d) => ready(d) !== null)) gaps.push(`when each Class A row became ready is not shown by any evidence outside the gate for every program that started, so a row that waited before it started is not ruled out${probeProblem ? ` (${probeProblem})` : ""}`);
568
+ for (const e of owedA) if (toolOf(e.id) && !workOf(ctx, e.id).did) gaps.push(`${e.id} is owed a Class A run and no program of it started, so how long it waited is not shown`);
569
+ gaps.push(...(ctx.launch?.lanesSource ? [] : ["the launcher's record does not say where its lane count came from"]));
570
+ return decide(fails, gaps, `${a.length} Class A program(s); none waited while a lane of ${lanes} was free`);
571
+ }
572
+
573
+ function nn04() {
574
+ // The contract sentence is about the order of two events inside the gate: its forecast written, then its first cache lookup. Evidence the gate does
575
+ // not write shows neither. Chat gate, 2026-11-21: not measured until Adrian rewords the sentence; the contract is unchanged.
576
+ return result(NOT_MEASURED, "the line is about the order of the gate's own forecast and first lookup, which evidence the gate does not write cannot show; it stays not measured until Adrian rewords it");
577
+ }
578
+
579
+ /** The packages a signed job builds that no owed row (an id of `owed`) needs, in the job's workspace, stage and target. */
580
+ function extraCrates(ctx, j, owed) {
581
+ return cratesOf(j).filter((c) => ![...owed].some((id) => covers({ ...j, args: ["-p", c, ...targetsOf(j).flatMap((t) => ["--target", t])] }, id, ctx.snap.path, [...ctx.expected.keys()])));
582
+ }
583
+
584
+ function nn05(ctx) {
585
+ const fails = []; const gaps = [...ctx.sendGaps, ...ctx.processGaps, ...ctx.jobGaps, ...baselineGaps(ctx)];
586
+ // What the file system shows of the gate's scan-result store, listed by the launcher before and after: entries are named by keys only the gate's code computes, so the
587
+ // entries a run wrote cannot be mapped to the rows from outside it, and a lookup (a read) leaves no trace in a listing.
588
+ if (!ctx.cacheStore) gaps.push("the launcher recorded no listing of the cache store before and after the run, so that the lookup and the store agree with the work is not shown");
589
+ else gaps.push(`${ctx.cacheStore.written.length} cache entr${ctx.cacheStore.written.length === 1 ? "y" : "ies"} written during the run (${ctx.cacheStore.removed.length} removed) in the launcher's listing; entries are keyed by values only the gate's code computes, so which row each belongs to is not shown, and a lookup leaves no trace in a listing`);
590
+ // The test cannot see a lookup or what the gate said about it; it can see the work. A mismatch between the work owed and the work done is the
591
+ // disagreement the line is about, and that the gate stopped and named the row is not shown by evidence the gate does not write.
592
+ const owed = new Set([...ctx.expected.values()].filter((e) => e.expect === "run").map((e) => e.id));
593
+ for (const id of owed) { const w = workOf(ctx, id); if (!w.did) (ctx.processGaps.length || ctx.jobGaps.length || (!toolOf(id) && !isBrokerRow(id)) ? gaps : fails).push(`${id} was owed a rerun and ${toolOf(id) || isBrokerRow(id) ? "no program or signed job shows it" : "has no program or signed job that could show it (an in-process row)"}`); if (w.ambiguous) gaps.push(`${id}: a broker job covers it and another variant of it, so which it built is not shown`); }
594
+ // A Class A program no known row plans: with the inventory complete it is work nothing owed; with it incomplete, a row the test cannot see may plan it.
595
+ { const known = new Set([...ctx.expected.keys()].map(toolOf).filter(Boolean)); const mineA = classAStarts(ctx).filter((d) => !d.cwd || !ctx.snap.path || relToSnap(d.cwd, ctx.snap.path) !== null); const strayTool = mineA.filter((d) => !known.has(programName(d.program)));
596
+ if (strayTool.length) (ctx.inventory && !ctx.inventoryUncovered?.length ? fails : gaps).push(`${programName(strayTool[0].program)} ran and no known row plans it${ctx.inventory && !ctx.inventoryUncovered?.length ? "" : " (the inventory does not cover every kind of row)"}`); }
597
+ for (const id of rowsThatWorked(ctx)) {
598
+ const e = ctx.expected.get(id);
599
+ if (e?.expect === "reuse") (ctx.launch?.baseline?.stable === true ? fails : gaps).push(`${id} did work although no file it reads changed${ctx.launch?.baseline?.stable === true ? "" : " (and the launcher does not show the gate code, tools and environment are the baseline's)"}`);
600
+ }
601
+ const jobList = ctx.vjobs;
602
+ const strays = jobList.filter((j) => j.sub && ![...ctx.expected.keys()].some((id) => covers(j, id, ctx.snap.path, [...ctx.expected.keys()])));
603
+ const haveB = [...ctx.expected.values()].some((e) => e.stage === "B");
604
+ // A job no known row explains is work nothing owed only when the inventory covers every kind of row; with kinds decided only in gate code (test, doc, ...), a row the test cannot see may own it.
605
+ const complete = ctx.inventory && !ctx.inventoryUncovered?.length;
606
+ if (strays.length) ((haveB && complete) ? fails : gaps).push(`${strays.length} broker job(s) do no ${haveB ? "known" : "known (no Class B row is known at all)"} row's work${complete ? "" : " (the inventory does not cover every kind of row, so a row the test cannot see may own them)"} (first: cargo ${strays[0].sub} ${strays[0].args.slice(0, 4).join(" ")})`);
607
+ for (const e of [...ctx.expected.values()].filter((x) => x.expect === "run" && toolOf(x.id) === "rustfmt")) {
608
+ const ed = e.id.split(":")[1]; const handed = rustfmtStarts(ctx).filter((d) => valuesOf(d.args, "--edition").includes(ed)).flatMap(rustfmtFiles);
609
+ const extra = handed.filter((p) => !e.changed.includes(p));
610
+ if (extra.length) fails.push(`${e.id}: rustfmt was handed ${extra.slice(0, 3).join(", ")}, which no owed change needs`);
611
+ }
612
+ for (const j of jobList.filter((x) => x.sub && !strays.includes(x))) {
613
+ const extra = extraCrates(ctx, j, owed);
614
+ if (extra.length) fails.push(`broker job ${j.jobId} also builds ${extra.join(", ")}, which no owed row needs`);
615
+ }
616
+ // A mismatch is a fail above; that the gate stopped and named the row and its cause is not shown by evidence the gate does not write, and matters only then.
617
+ // The work can match the record whether or not the lookup agreed with it (a gate that went on despite a disagreement can do exactly the owed work): a pass
618
+ // needs evidence of the lookup, and none exists outside the gate, so the line can fail here and cannot pass.
619
+ if (!fails.length) gaps.push("that the lookup agreed with the record, rather than disagreed and the gate went on, is not shown by evidence the gate does not write");
620
+ return decide(fails, gaps, "");
621
+ }
622
+
623
+ function nn06(ctx) {
624
+ const fails = []; const gaps = [...ctx.sendGaps, ...ctx.processGaps, ...ctx.jobGaps, ...baselineGaps(ctx)];
625
+ const reuse = [...ctx.expected.values()].filter((e) => e.expect === "reuse");
626
+ // Git shows file changes only. A tool, environment or gate-code change also reruns a row; the launcher records these before the run and the run
627
+ // counts as unchanged only when they equal the baseline's, so an unchanged-looking row that legitimately reruns is not a false pass.
628
+ const stable = ctx.launch?.baseline?.stable === true;
629
+ if (reuse.length && !stable) gaps.push("the launcher does not show that the gate code, tools and keyed environment are the baseline's, so an unchanged-looking row may still be owed a rerun");
630
+ for (const e of reuse) {
631
+ const w = workOf(ctx, e.id);
632
+ if (w.ambiguous) gaps.push(`${e.id}: a start or job that could be this row's or another row's cannot be assigned to one`);
633
+ if (e.priorUnknown) gaps.push(`${e.id} is unchanged and whether it failed in the previous launched run is not shown (the previous run's failing program serves several rows)`);
634
+ if (w.jobs.length) (stable ? fails : gaps).push(`${e.id} is unchanged and broker job ${w.jobs[0].jobId} did its work`);
635
+ if (w.progs.length) (stable ? fails : gaps).push(`${e.id} is unchanged and ${toolOf(e.id)} started${toolOf(e.id) === "rustfmt" ? " (rustfmt was handed files for an edition nothing changed in)" : ""}`);
636
+ }
637
+ // A reused failure stays a failure: the previous launched run's own evidence says the row failed, and this run cannot end green over it.
638
+ if (reuse.length && !ctx.prior) gaps.push("the previous launched run's evidence is not available, so whether an unchanged row failed before is not shown");
639
+ const failures = reuse.filter((e) => e.priorFailed);
640
+ const otherRed = classAStarts(ctx).some((d) => d.exit !== null && d.exit !== 0);
641
+ if (failures.length && Number.isInteger(ctx.exit) && ctx.exit !== 0 && otherRed) gaps.push(`${failures[0].id} failed in the previous launched run and is unchanged, and the run ended red, but a Class A program of another row also failed, so that the reused failure kept it red is not shown`);
642
+ if (failures.length) { if (!Number.isInteger(ctx.exit)) gaps.push("the run's exit is not known"); else if (ctx.exit === 0) fails.push(`${failures[0].id} failed in the previous launched run and is unchanged, and the run exited 0`); }
643
+ const inProcess = reuse.filter((e) => !toolOf(e.id) && !isBrokerRow(e.id));
644
+ if (inProcess.length) gaps.push(`${inProcess.length} unchanged row(s) run in the gate's own process (first: ${inProcess[0].id}), so that none reran is not shown by any program or signed job`);
645
+ return decide(fails, gaps, `${reuse.length} unchanged row(s) did no work${failures.length ? `, ${failures.length} of them an earlier failure that kept the run red` : ""}`);
646
+ }
647
+
648
+ const rustfmtStarts = (ctx) => ctx.starts.filter((d) => programName(d.program) === "rustfmt" && !isProbe(d.args));
649
+ /** The file operands of a rustfmt start, as given (rustfmt is run from the snapshot root). */
650
+ const rustfmtFiles = (d) => { const out = []; for (let i = 0; i < d.args.length; i += 1) { const a = String(d.args[i]); if (["--edition", "--config", "--config-path", "--emit", "--color"].includes(a)) { i += 1; continue; } if (!a.startsWith("-")) out.push(a.replaceAll("\\", "/")); } return out; };
651
+ function nn07(ctx) {
652
+ const fails = []; const gaps = [...ctx.sendGaps, ...ctx.processGaps, ...ctx.jobGaps, ...baselineGaps(ctx)];
653
+ const run = [...ctx.expected.values()].filter((e) => e.expect === "run"); const seenJobs = new Set();
654
+ for (const e of run) {
655
+ if (e.isNew && !toolOf(e.id) && !isBrokerRow(e.id)) { gaps.push(`${e.id} is a new row with no program or signed job that could show it ran`); continue; }
656
+ if (toolOf(e.id) === "rustfmt") {
657
+ const ed = e.id.split(":")[1]; const handed = rustfmtStarts(ctx).filter((d) => valuesOf(d.args, "--edition").includes(ed)).flatMap(rustfmtFiles);
658
+ const owed = e.changed.filter((p) => /\.rs$/.test(p));
659
+ for (const p of owed) if (!handed.includes(p)) (ctx.processGaps.length ? gaps : fails).push(`${e.id}: ${p} changed and was never handed to rustfmt`);
660
+ const extra = handed.filter((p) => !owed.includes(p) && !run.some((o) => o !== e && toolOf(o.id) === "rustfmt" && o.changed.includes(p)));
661
+ if (extra.length) fails.push(`${e.id}: rustfmt was handed ${extra.slice(0, 3).join(", ")}, which did not change`);
662
+ for (const p of new Set(handed)) if (handed.filter((x) => x === p).length > 1) fails.push(`${e.id}: rustfmt was handed ${p} more than once`);
663
+ continue;
664
+ }
665
+ const w = workOf(ctx, e.id);
666
+ if (w.ambiguous) { gaps.push(`${e.id}: its tool serves other rows too and the start(s) or broker job(s) seen cannot be told apart by row, so that this row ran is not shown`); continue; }
667
+ if (isBrokerRow(e.id) ? !w.jobs.length : !w.did) (ctx.processGaps.length || ctx.jobGaps.length ? gaps : fails).push(`${e.id} changed (${e.changed.slice(0, 2).join(", ")}) and ${isBrokerRow(e.id) ? "no signed broker job built it" : "did no work"}`);
668
+ // The job that built a changed row builds only what is owed in that workspace and stage: an extra package is work no change needs.
669
+ if (isBrokerRow(e.id)) for (const j of w.jobs) { if (seenJobs.has(j.jobId)) continue; seenJobs.add(j.jobId); const extra = extraCrates(ctx, j, run.map((o) => o.id)); if (extra.length) fails.push(`broker job ${j.jobId} also builds ${extra.join(", ")}, which no owed row needs`); }
670
+ }
671
+ return decide(fails, gaps, `${run.length} changed row(s) ran again, each with only the work its change needs`);
672
+ }
673
+
674
+ function nn08(ctx) {
675
+ const gaps = [...ctx.processGaps];
676
+ // A shell wrapper whose program the record shows start as its child is that child's call: the child is compared, not the wrapper.
677
+ const resolved = new Set(ctx.procs.filter((p) => /(^|[\\/])cmd\.exe$/i.test(p.exe) && ctx.procs.some((c) => c.ppid === p.pid && c.start >= p.start && (p.end === null || c.start <= p.end))));
678
+ const calls = []; const wrapped = []; let unclear = 0;
679
+ ctx.procs.forEach((p, i) => {
680
+ if (resolved.has(p)) return;
681
+ if (p.argsKnown === false) { unclear += 1; return; }
682
+ const d = ctx.starts[i];
683
+ if (d.ambiguous) { if (d.intended) wrapped.push({ ...callOf({ ...d, ...d.intended }, { args: d.intended.args }), parent: ctx.parentKey(p), cwdKnown: p.cwd !== null }); else unclear += 1; return; }
684
+ calls.push({ ...callOf(d, { args: p.args }), parent: ctx.parentKey(p), cwdKnown: p.cwd !== null });
685
+ });
686
+ const groups = new Map();
687
+ for (const c of calls) { const k = JSON.stringify([c.name, c.args]); (groups.get(k) ?? groups.set(k, []).get(k)).push(c); }
688
+ // A repeat is proven only when program, arguments and a known, equal folder all match. An unknown folder on either side leaves two such calls possibly the
689
+ // same call, which is not shown to be a repeat (and not shown to be distinct): it is a gap, never a fail.
690
+ const known = (a, b) => a.cwdKnown && b.cwdKnown;
691
+ const proven = (a, b) => sameProgram(a, b) && known(a, b) && a.cwd === b.cwd;
692
+ const possible = (a, b) => sameProgram(a, b) && !known(a, b);
693
+ const repeats = []; let possibly = 0;
694
+ for (const g of groups.values()) {
695
+ const dup = g.filter((c, i) => g.some((o, j) => j !== i && proven(o, c))); if (dup.length > 1) repeats.push(dup);
696
+ if (g.some((c, i) => g.some((o, j) => j !== i && possible(o, c)))) possibly += 1;
697
+ }
698
+ if (possibly) gaps.push(`${possibly} program and argument list(s) started more than once with a folder the record does not keep: possibly the same call, so a repeat is not shown`);
699
+ if (ctx.procs.some((p) => p.args.some((a) => /^\.\.\. \d+ args$/.test(String(a))))) unclear += 1;
700
+ // A wrapper with no child shows only what it was written as, not that the shell started anything: it is never counted as a start and never makes a repeat.
701
+ unclear += wrapped.length;
702
+ if (unclear) gaps.push(`${unclear} start(s) are command lines with no child to show what they ran, so they cannot be compared`);
703
+ // Without a folder (Windows event 4688 records none) calls compare by program and arguments: that finds more repeats, never fewer.
704
+ const how = ctx.procs.some((p) => p.cwd === null) ? " (compared by program and arguments: the record keeps no folder)" : "";
705
+ const fails = repeats.map((g) => `${g.length}x ${g[0].name} ${g[0].args.join(" ").slice(0, 70)}`);
706
+ return decide(fails.length ? [`${repeats.reduce((n, g) => n + g.length - 1, 0)} repeat start(s): ${fails.join("; ")}`] : [], fails.length ? [] : gaps, `${calls.length} program start(s), no two alike${how}`);
707
+ }
708
+
709
+ function nn10(ctx) {
710
+ const fails = []; const gaps = [...ctx.sendGaps, ...ctx.processGaps, ...ctx.jobGaps];
711
+ const cargoStarts = ctx.starts.filter((d) => programName(d.program) === "cargo");
712
+ const direct = cargoStarts.filter((d) => TESTLIKE.has(cargoVerb(d.args)));
713
+ if (direct.length) fails.push(`${direct.length} cargo test start(s) ran outside the broker, so the gate built tests itself`);
714
+ // A cargo verb that is not known to build no tests (a user alias in .cargo/config, a plugin) may be one.
715
+ const unknownVerb = cargoStarts.filter((d) => { const v = cargoVerb(d.args); return v !== null && !TESTLIKE.has(v) && !COMPILING.has(v) && !NOT_TEST_VERBS.has(v); });
716
+ if (unknownVerb.length) gaps.push(`cargo ${cargoVerb(unknownVerb[0].args)} ran outside the broker and is not a verb known to build no tests (it may be an alias for one), so that the gate built no tests itself is not shown`);
717
+ if (ctx.jobs.some((j) => !j.argv)) gaps.push("a broker job's signed receipt names no command, so whether it was a test build is not shown");
718
+ // A signed job whose verb is not known to build no tests is not shown to have built none either (an alias or plugin).
719
+ const unknownJob = ctx.jobs.filter((j) => j.sub && !TESTLIKE.has(j.sub) && !COMPILING.has(j.sub) && !NOT_TEST_VERBS.has(j.sub));
720
+ if (unknownJob.length) gaps.push(`a signed job runs cargo ${unknownJob[0].sub}, which is not a verb known to build no tests (it may be an alias for one), so that the broker only compiled is not shown`);
721
+ // Every verb that builds test programs (test, bench, nextest, miri, ...) is a test build, signed or requested.
722
+ const tests = ctx.jobs.filter((j) => TESTLIKE.has(j.sub));
723
+ // Every test request the process record saw go to the broker needs its own signed job.
724
+ const requested = ctx.sends.filter((d) => TESTLIKE.has(canonVerb(d.args[1])));
725
+ if (requested.length > tests.length) gaps.push(`${requested.length} test request(s) went to the broker and ${tests.length} signed test job(s) exist: a request with no receipt is not shown to be compile only`);
726
+ if (!tests.length) return decide(fails, gaps, "the broker built no test and no cargo test ran outside it");
727
+ let programs = 0; const claims = new Map();
728
+ for (const j of tests) {
729
+ const what = `broker job ${j.jobId ?? path.basename(j.file)}`;
730
+ if (!j.verified) { (ctx.verifierPinned ? fails : gaps).push(`${what}: its receipt ${ctx.verifierPinned ? "does not verify" : "cannot be verified: no broker key is pinned"}`); continue; }
731
+ if (!Array.isArray(j.testExecutables) && typeof j.testExecutablesReason === "string") { gaps.push(`${what}: the receipt gives a reason string and no program list, which is not proof the broker only compiled and produced nothing`); continue; }
732
+ if (!Array.isArray(j.testExecutables) && typeof j.testExecutablesReason !== "string") { gaps.push(`${what}: the signed receipt carries no manifest of test programs (no testExecutables), so that the broker only compiled is not shown`); continue; }
733
+ if (Array.isArray(j.testExecutables) && !j.testExecutables.length) gaps.push(`${what}: the receipt lists no test program, which by itself does not show the build produced none (a complete signed outcome is needed), so that the gate had nothing to run is not shown`);
734
+ for (const exe of Array.isArray(j.testExecutables) ? j.testExecutables : []) {
735
+ programs += 1;
736
+ const file = typeof exe === "string" ? exe : exe?.path; const digest = typeof exe === "object" ? exe?.sha256 : null;
737
+ if (typeof file !== "string") { fails.push(`${what}: the receipt lists a test program with no path`); continue; }
738
+ const ran = ctx.procs.filter((p) => dirKey(p.exe) === dirKey(file));
739
+ if (!ran.length) { (ctx.processGaps.length ? gaps : fails).push(`${what}: the broker built ${path.basename(file)} and the gate never ran it`); continue; }
740
+ if (ran.length > 1) fails.push(`${what}: the gate ran ${path.basename(file)} ${ran.length} times`);
741
+ // One launch is credited to one receipt only: a program two receipts both list cannot have run for both.
742
+ const claimed = claims.get(dirKey(file));
743
+ if (claimed && claimed !== j.jobId) { fails.push(`${what}: ${path.basename(file)} is also listed by broker job ${claimed}, and its launch is credited to that receipt only`); continue; }
744
+ claims.set(dirKey(file), j.jobId);
745
+ // Execution after production: a launch before the broker finished the build ran something else.
746
+ if (!Number.isFinite(j.ended)) gaps.push(`${what}: the receipt gives no end time, so that ${path.basename(file)} ran after it was built is not shown`);
747
+ else if (ran.some((p) => p.start === j.ended)) gaps.push(`${what}: ${path.basename(file)} started at the very moment the build ended, so which came first is not shown`);
748
+ if (Number.isFinite(j.ended) && ran.some((p) => p.start < j.ended)) fails.push(`${what}: ${path.basename(file)} was started before the broker finished building it (job ended ${new Date(j.ended).toISOString()})`);
749
+ // The image at execution: the file's digest now equals the signed digest, and the file was last written before the launch and not since, so what ran is what the broker built.
750
+ const img = typeof ctx.digestOf === "function" ? ctx.digestOf(file) : null;
751
+ const now = img && typeof img === "object" ? img.sha256 : img; const written = img && typeof img === "object" ? img.mtimeMs : null;
752
+ if (typeof digest !== "string") gaps.push(`${what}: the receipt gives no digest for ${path.basename(file)}`);
753
+ else if (now === null || now === undefined) gaps.push(`${what}: ${path.basename(file)} cannot be read now to compare with the digest the broker signed`);
754
+ else if (now !== digest) fails.push(`${what}: ${path.basename(file)} is not the program the broker built (digest ${short(now)}, signed ${short(digest)})`);
755
+ else if (!Number.isFinite(written)) gaps.push(`${what}: when ${path.basename(file)} was last written is not shown, so that the image that ran is the one the broker built is not shown`);
756
+ else if (written > Math.min(...ran.map((p) => p.start))) fails.push(`${what}: ${path.basename(file)} was written after the gate started it, so the image that ran is not the image now`);
757
+ // No digest of the bytes that ran, taken when they ran, exists outside the gate: a digest read afterwards and a write time do not identify them.
758
+ gaps.push(`${what}: the image of ${path.basename(file)} at the moment it ran is not shown by any record outside the gate (a digest taken after the run and a write time do not identify the bytes that ran)`);
759
+ }
760
+ }
761
+ return decide(fails, gaps, `${tests.length} test build(s) by the broker, compile only and signed; the gate ran the ${programs} program(s) they list, each the one the broker built`);
762
+ }
763
+
764
+ function nn11(ctx) {
765
+ const { launch } = ctx;
766
+ const startMono = /^\d+$/.test(String(launch?.startMono ?? "")) ? BigInt(launch.startMono) : null; const endMono = /^\d+$/.test(String(launch?.endMono ?? "")) ? BigInt(launch.endMono) : null;
767
+ const limitMs = Number(launch?.limitMs);
768
+ // The budget is selected by what was run, not by a label: the kind must be the stage the launched gate was asked for.
769
+ const asked = Array.isArray(launch?.gate?.args) ? kindOf(launch.gate.args) : null;
770
+ if (launch?.kind !== undefined && asked !== null && launch.kind !== asked) return result(NOT_MEASURED, `the run kind ${JSON.stringify(launch.kind)} does not match the stage the gate was asked for (--to ${asked}), so the pinned limit is not this run's`);
771
+ if (startMono === null) return result(NOT_MEASURED, "the launcher's record has no start on its monotonic clock");
772
+ if (!Number.isFinite(limitMs) || limitMs <= 0) return result(NOT_MEASURED, `no time limit was pinned at launch for ${launch?.host ?? "this host"} and run kind ${launch?.kind ?? "(none)"}`);
773
+ // Programs the run owns that outlive the gate count too (Council CV-1 F-29), on the wall clock of the process record.
774
+ const lastProg = Math.max(-Infinity, ...[ctx.root, ...ctx.procs].filter(Boolean).map((p) => p.end ?? -Infinity));
775
+ const earlyBy = ctx.root && Number.isFinite(ctx.root.start) ? Math.max(0, timeOf(launch.startedAt) - ctx.root.start) : 0;
776
+ // An owned program still open is counted up to the end of the process record: the run lasted at least that long.
777
+ const openLower = Math.max(-Infinity, ...ctx.procs.filter((p) => p.end === null).map((p) => timeOf(ctx.witnessTo) - timeOf(launch.startedAt)));
778
+ if (endMono === null) { if (Number.isFinite(openLower) && openLower > limitMs) return result(FAIL, `at least ${(openLower / 1000).toFixed(1)} s, limit ${(limitMs / 1000).toFixed(1)} s`); return result(NOT_MEASURED, `limit ${(limitMs / 1000).toFixed(1)} s, but the launcher never saw the run end`); }
779
+ if (endMono < startMono) return result(NOT_MEASURED, "the launcher's monotonic clock runs backwards between its start and end");
780
+ let took = Number(endMono - startMono) / 1e6 + earlyBy;
781
+ const wallEnd = timeOf(launch.endedAt); if (Number.isFinite(lastProg) && Number.isFinite(wallEnd) && lastProg > wallEnd) took += lastProg - wallEnd;
782
+ if (Number.isFinite(openLower)) took = Math.max(took, openLower);
783
+ if (took > limitMs) return result(FAIL, `${(took / 1000).toFixed(1)}${Number.isFinite(openLower) ? " (at least)" : ""} s, limit ${(limitMs / 1000).toFixed(1)} s (pinned at launch${launch.limitsSha256 ? `, limits ${short(launch.limitsSha256)}` : ""})`);
784
+ if (ctx.processGaps.length) return result(NOT_MEASURED, `${(took / 1000).toFixed(1)} s on the launcher's clock, inside the limit, but the run's own programs are not all accounted for: ${ctx.processGaps[0]}`);
785
+ return result(PASS, `${(took / 1000).toFixed(1)} s on the launcher's clock, limit ${(limitMs / 1000).toFixed(1)} s pinned at launch`);
786
+ }
787
+
788
+ const after2 = (next, ctx) => timeOf(next?.launch?.startedAt) >= timeOf(ctx.launch?.endedAt ?? ctx.launch?.startedAt);
789
+ function nn12(ctx) {
790
+ const { live } = ctx;
791
+ if (!live) return result(NOT_MEASURED, "what was left behind is judged right after the run ends (--live)");
792
+ // What the launcher saw the moment the gate exited (before anything could clear it): no lock and no gate process left.
793
+ const after = ctx.launch?.afterRun;
794
+ if (!after || !Array.isArray(after.locks) || !Number.isFinite(timeOf(after.observedAt))) return result(NOT_MEASURED, "the launcher recorded no observation of locks and the gate process at the moment the run ended, so what was left behind is not shown");
795
+ if (after.locksKnown !== true) return result(NOT_MEASURED, "the launcher could not read the snapshot root's locks at the moment the run ended, so that none was left is not shown");
796
+ if (after.locks.length) return result(FAIL, `the lock ${after.locks[0]} was still there when the run ended`);
797
+ if (after.rootAlive === true) return result(FAIL, "the gate process was still alive when the launcher saw the run end");
798
+ // The snapshot lock is looked for in the snapshot root the launcher recorded, not inferred from broker work (a run with no broker job has one too).
799
+ const locks = typeof live.locksIn === "function" && ctx.launch?.snapshotsRoot ? live.locksIn(ctx.launch.snapshotsRoot) : null;
800
+ if (locks === null && !ctx.snap.path) return result(NOT_MEASURED, "neither the launcher's snapshot root nor a broker job names where the snapshot lock lives, so it cannot be looked for");
801
+ if (locks && locks.length) return result(FAIL, `the lock ${locks[0]} is still there after the run`);
802
+ if (ctx.snap.path && live.exists(`${ctx.snap.path}.lock`)) return result(FAIL, `the lock ${ctx.snap.path}.lock is still there after the run`);
803
+ // The operating system's own process listing, read after the run, must agree with the liveness probe: a machine's listing is never empty, and a program the
804
+ // probe finds alive (the gate process above all) must be in it. Otherwise neither is believed and nothing is shown.
805
+ if (typeof live.inventory === "function") {
806
+ const listing = live.inventory();
807
+ if (!Array.isArray(listing)) return result(NOT_MEASURED, "the operating system's process listing could not be read after the run, so that no program of the run is left is not shown");
808
+ if (listing.length === 0) return result(NOT_MEASURED, "the operating system's process listing is empty, so what is still alive is not shown");
809
+ const mine = [...(ctx.root ? [ctx.root] : []), ...ctx.procs];
810
+ const unlisted = mine.filter((p) => live.alive(p.pid, p.start) === true && !listing.some((q) => q.pid === p.pid));
811
+ if (unlisted.length) return result(NOT_MEASURED, `the process listing omits ${programName(unlisted[0].exe)} ${unlisted[0].pid}, which the liveness probe finds alive, so the listing is not trusted`);
812
+ }
813
+ // A program of the run that was still going when the gate exited outlived it, whether or not it has since ended.
814
+ // The snapshot lock's job holder is a PowerShell the gate starts to hold the Windows job its tree runs in; it polls and exits when the job is empty, so it always ends just
815
+ // after the gate. A holder (this exact file form, in the launcher's snapshot root) that ended within 2 s of the gate's exit, or whose exit is not recorded (a gap, below), is not
816
+ // left behind; one still there later is.
817
+ const holderOf = (p) => /^(powershell|pwsh)$/.test(programName(p.exe)) && (() => { const i = (p.args ?? []).findIndex((a) => String(a).toLowerCase() === "-file"); const f = i < 0 ? null : String(p.args[i + 1] ?? ""); const root = dirKey(ctx.launch?.snapshotsRoot ?? ""); return f !== null && root !== "" && /[\\/][0-9a-f]{16}\.lock\.children[\\/]job-holder-[0-9a-f]{16}\.json\.ps1$/i.test(f) && dirKey(f).startsWith(`${root}/`); })();
818
+ if (ctx.root && ctx.root.end !== null) { const late = ctx.procs.filter((p) => (p.end === null || p.end > ctx.root.end) && !(holderOf(p) && (p.end === null || p.end - ctx.root.end <= 2000))); if (late.length) return result(FAIL, `${late.length} program(s) of the run outlived the gate's exit (first: ${programName(late[0].exe)} ${late[0].pid})`); }
819
+ const rootProc = ctx.root ? [ctx.root] : [];
820
+ const alive = [...rootProc, ...ctx.procs].filter((p) => live.alive(p.pid, p.start) === true);
821
+ if (alive.length) return result(FAIL, `${alive.length} program(s) the run started are still alive: ${alive.slice(0, 5).map((p) => `${programName(p.exe)} ${p.pid}`).join(", ")}`);
822
+ // A process found at a recorded id whose start time cannot be read may be the run's program or another that took the id: not shown either way.
823
+ const unknownLive = [...rootProc, ...ctx.procs].filter((p) => live.alive(p.pid, p.start) === null);
824
+ if (unknownLive.length) return result(NOT_MEASURED, `${unknownLive.length} process(es) are found at an id the run used (first: ${programName(unknownLive[0].exe)} ${unknownLive[0].pid}) and their start time cannot be read, so whether they are the run's programs is not shown`);
825
+ if (ctx.processGaps.length) return result(NOT_MEASURED, `the run's programs cannot all be shown gone: ${ctx.processGaps[0]}`);
826
+ if (!Number.isInteger(ctx.exit) || ctx.exit !== 0) {
827
+ // A run that did not end normally passes only on the next ordinary run: its launcher took this run's lock over and named it, and it ended 0.
828
+ const next = ctx.successor; const prev = next?.launch?.previous;
829
+ // The same gate executable, and only the ordinary arguments: --to <stage> and --commit <sha>, each with a value.
830
+ const ordinary = (args) => { if (!Array.isArray(args) || args.length < 1) return false; for (let i = 1; i < args.length; i += 2) { const flag = args[i]; const val = args[i + 1]; if (!["--to", "--commit"].includes(flag) || val === undefined || String(val).startsWith("-")) return false; if (flag === "--commit" && !/^[0-9a-f]{40}$/.test(val)) return false; } return true; };
831
+ // The same gate executable by its path and by the code behind it: the tree of the gate's own folder at the commit each run was launched from, recorded by the launcher.
832
+ const codeOf = (l) => (typeof l?.fingerprint?.gateCodeTree === "string" && l.fingerprint.gateCodeTree !== "" ? l.fingerprint.gateCodeTree : null);
833
+ const sameGate = typeof next?.launch?.gate?.path === "string" && next.launch.gate.path === ctx.launch?.gate?.path && codeOf(next.launch) !== null && codeOf(next.launch) === codeOf(ctx.launch);
834
+ const sameStore = next?.launch?.snapshotsRoot && next.launch.snapshotsRoot === ctx.launch?.snapshotsRoot;
835
+ if (next && prev?.runId === ctx.launch?.runId && (prev.reclaimed === true || prev.fromLastRun === true) && after2(next, ctx) && next.launch?.exit === 0 && next.launch?.host === ctx.launch?.host && sameStore && sameGate && ordinary(next.launch?.gate?.args)) return result(PASS, `the run ended with ${ctx.exit ?? ctx.launch?.signal ?? "no exit"}; the next ordinary run took it over and ended 0, and nothing was left behind`);
836
+ return result(NOT_MEASURED, `the run ended with ${ctx.exit ?? ctx.launch?.signal ?? "no exit"}; that the next ordinary run starts safely by itself needs that run's record (--successor)`);
837
+ }
838
+ return result(PASS, "no lock and no program of the run left behind");
839
+ }
840
+
841
+
842
+ /** Text with its comments removed (block, line and hash comments), so a declaration that is commented out is not read as active. */
843
+ const withoutComments = (t, hash = true) => { const s = String(t).replace(/\/\*[\s\S]*?\*\//g, "").replace(/(^|[^:"'\w])\/\/.*$/gm, "$1"); return hash ? s.replace(/(^|\s)#.*$/gm, "$1") : s; };
844
+ /** The text between the braces that follow the first `bundle` key (JSON5), or null. Only that object's own keys are searched. */
845
+ const skipQuoted = (t, i) => { const q = t[i]; let j = i + 1; while (j < t.length && t[j] !== q) { if (t[j] === "\\") j += 1; j += 1; } return j + 1; };
846
+ /** The end (exclusive) of the value that starts at i inside an object: up to the next comma or closing brace at its own depth, strings skipped. */
847
+ const valueEnd = (t, i) => { let d = 0; let j = i; while (j < t.length) { const c = t[j]; if (c === '"' || c === "'") { j = skipQuoted(t, j); continue; } if (c === "{" || c === "[") d += 1; else if (c === "}" || c === "]") { if (d === 0) return j; d -= 1; } else if (c === "," && d === 0) return j; j += 1; } return j; };
848
+ /** The raw text of the value of the direct key `key` of the object text `obj` (which starts with its brace), reading JSON5 (bare or quoted keys, strings skipped), or null. */
849
+ function childValue(obj, key) {
850
+ let i = 1;
851
+ while (i < obj.length) {
852
+ while (i < obj.length && /[\s,]/.test(obj[i])) i += 1;
853
+ if (i >= obj.length || obj[i] === "}") return null;
854
+ let k;
855
+ if (obj[i] === '"' || obj[i] === "'") { const e = skipQuoted(obj, i); k = obj.slice(i + 1, e - 1); i = e; }
856
+ else { const m = /^[A-Za-z_$][\w$-]*/.exec(obj.slice(i)); if (!m) return null; k = m[0]; i += k.length; }
857
+ while (i < obj.length && /\s/.test(obj[i])) i += 1;
858
+ if (obj[i] !== ":") return null;
859
+ i += 1; while (i < obj.length && /\s/.test(obj[i])) i += 1;
860
+ const end = valueEnd(obj, i);
861
+ if (k === key) return obj.slice(i, end).trim();
862
+ i = end;
863
+ }
864
+ return null;
865
+ }
866
+ /** The object at a path of keys from the root object of a JSON5 text, or null. */
867
+ const objectAt = (text, keys) => { let cur = text.slice(Math.max(0, text.indexOf("{"))).trim(); if (!cur.startsWith("{")) return null; for (const k of keys) { const v = childValue(cur, k); if (v === null || !v.startsWith("{")) return null; cur = v; } return cur; };
868
+ /** Whether a crate folder of the selected tree declares a sidecar: an active externalBin in the bundle declaration of its Tauri configuration, read structurally for each format. Returns { bound, file }. */
869
+ function sidecarBound(read, dir) {
870
+ for (const base of [dir, `${dir}/src-tauri`]) {
871
+ for (const name of ["tauri.conf.json", "tauri.conf.json5", "Tauri.toml"]) {
872
+ const file = `${base}/${name}`; let body;
873
+ try { body = read(file); } catch { continue; }
874
+ try { const conf = JSON.parse(body); const list = conf?.bundle?.externalBin ?? conf?.tauri?.bundle?.externalBin; if (Array.isArray(list) && list.length) return { bound: true, file }; continue; } catch { /* not strict JSON: read the text */ }
875
+ const text = withoutComments(body, name === "Tauri.toml");
876
+ if (name === "Tauri.toml") {
877
+ // the externalBin key of the [bundle] (or [tauri.bundle]) table only, never of another table
878
+ const sec = /^\s*\[(?:tauri\.)?bundle\]\s*$([\s\S]*?)(?=^\s*\[|(?![\s\S]))/m.exec(text);
879
+ if (sec && /^\s*externalBin\s*=\s*\[\s*["']/m.test(sec[1])) return { bound: true, file };
880
+ } else {
881
+ // the bundle object of the root (Tauri 2) or of its tauri object (Tauri 1), and only that object's own externalBin key
882
+ const block = objectAt(text, ["bundle"]) ?? objectAt(text, ["tauri", "bundle"]);
883
+ const list = block === null ? null : childValue(block, "externalBin");
884
+ if (list !== null && /^\[\s*["']/.test(list)) return { bound: true, file };
885
+ }
886
+ }
887
+ }
888
+ return { bound: false };
889
+ }
890
+ function nn09(ctx) {
891
+ // The compiles are the broker's signed jobs (argv, workspace, times); a broker client start with no signed job is a compile not shown.
892
+ const fails = []; const gaps = [...ctx.sendGaps];
893
+ const unverified = ctx.jobs.filter((j) => !j.verified); if (unverified.length) (ctx.verifierPinned ? fails : gaps).push(`${unverified.length} broker job(s) whose receipt ${ctx.verifierPinned ? "does not verify" : "cannot be verified: no broker key is pinned"}`);
894
+ const compiles = ctx.jobs.filter((j) => j.verified && j.sub && COMPILING.has(j.sub)).map((j) => ({ ...j, at: j.submitted }));
895
+ const clients = ctx.sends.filter((d) => COMPILING.has(canonVerb(d.args[1])));
896
+ if (clients.length > compiles.length) gaps.push(`${clients.length} broker client compile start(s) and only ${compiles.length} signed compile job(s), so a compile may be missing`);
897
+ gaps.push(...ctx.foreignGaps);
898
+ gaps.push(...ctx.processGaps.map((g) => `that every compile has its signed job cannot be shown: ${g}`));
899
+ if (ctx.jobs.some((j) => !j.argv)) gaps.push("a broker job's signed receipt names no command, so what it built is not shown");
900
+ if (!compiles.length) return decide(fails, gaps, "nothing was compiled by the broker");
901
+ // One group is one workspace and stage (subcommand and its settings): crate and target selectors are what one command gathers. Settings
902
+ // compare by meaning: the same flags in another order, `--release` and `--profile release`, and a feature list in another order are the same
903
+ // settings (Council CV-1 F-24). What follows `--` goes to the compiler in order and is kept in order.
904
+ const VALUE_FLAGS = new Set(["--profile", "--features", "-F", "--message-format", "--manifest-path", "--config", "-Z", "--color", "-j", "--jobs", "--target-dir", "--bin", "--test", "--example", "--bench"]);
905
+ const manifestKey = (v) => String(v).replaceAll("\\", "/").replace(/^\.\//, "");
906
+ const featureSet = (v) => v.split(/[\s,]+/).filter(Boolean).sort().join(",");
907
+ const unitsOf = (args) => {
908
+ const cut = args.indexOf("--"); const head = cut < 0 ? args : args.slice(0, cut); const tail = cut < 0 ? [] : args.slice(cut);
909
+ const units = [];
910
+ for (let i = 0; i < head.length; i += 1) {
911
+ const a = head[i];
912
+ if (["-p", "--package", "--target"].includes(a)) { i += 1; continue; }
913
+ // Output formatting changes how diagnostics are printed, not what is built: two compiles that differ only in it are compatible.
914
+ if (a === "--message-format" || a === "--color") { i += 1; continue; }
915
+ if (/^--(message-format|color)=/.test(a) || a === "-q" || a === "--quiet" || a === "-v" || a === "--verbose") continue;
916
+ if (/^(--package=|--target=)/.test(a) || /^-p./.test(a)) continue;
917
+ if (a === "--release") { units.push("--profile release"); continue; }
918
+ if (a === "--frozen") { units.push("--locked", "--offline"); continue; }
919
+ if (/^-F./.test(a)) { units.push(`--features ${featureSet(a.slice(2))}`); continue; }
920
+ if (/^-Z./.test(a)) { units.push(`-Z ${a.slice(2)}`); continue; }
921
+ if (/^--profile=/.test(a)) { units.push(`--profile ${a.slice(10)}`); continue; }
922
+ if (/^--features=/.test(a)) { units.push(`--features ${featureSet(a.slice(11))}`); continue; }
923
+ { const eq = /^(--[a-z][\w-]*)=(.*)$/.exec(a); if (eq && VALUE_FLAGS.has(eq[1])) { const n = eq[1] === "-j" ? "--jobs" : eq[1]; units.push(`${n} ${n === "--features" ? featureSet(eq[2]) : n === "--manifest-path" ? manifestKey(eq[2]) : eq[2]}`); continue; } }
924
+ if (/^-j\d+$/.test(a)) { units.push(`--jobs ${a.slice(2)}`); continue; }
925
+ if (VALUE_FLAGS.has(a) && i + 1 < head.length) { const v = head[(i += 1)]; units.push(`${a === "-F" ? "--features" : a === "-j" ? "--jobs" : a} ${a === "--features" || a === "-F" ? featureSet(v) : a === "--manifest-path" ? manifestKey(v) : v}`); continue; }
926
+ units.push(a);
927
+ }
928
+ return { units: [...new Set(units)].sort(), tail };
929
+ };
930
+ const settings = (args) => { const u = unitsOf(args); return [...u.units, ...u.tail].join(" "); };
931
+ // The workspace a compile runs in. Two folders that nest are one workspace when the outer one's manifest, at the run's Git tree, lists the
932
+ // inner one as a member; when that manifest cannot be read, which workspace it is stays disputed (Council CV-1 F-24).
933
+ const rels = compiles.map((c) => relToSnap(c.cwd, ctx.snap.path));
934
+ if (rels.some((r) => r === null)) gaps.push("a broker compile ran outside the snapshot or the snapshot folder is unknown, so its workspace cannot be placed");
935
+ // The workspace of an invocation is read from the selected tree: the nearest ancestor folder (or its own) whose Cargo.toml declares [workspace];
936
+ // a folder with a package and no workspace above it is its own. When a manifest on the way cannot be read the workspace is disputed.
937
+ const wsOf = new Map();
938
+ for (const r of new Set(rels.filter((x) => x !== null))) {
939
+ let d = r; let found = null; let unread = null;
940
+ for (;;) {
941
+ try { if (workspaceMembers(ctx.readTree(`${d ? `${d}/` : ""}Cargo.toml`)) !== null) { found = d; break; } }
942
+ catch (e) { if (e?.code !== "ENOENT") unread = e.message; }
943
+ if (d === "") break; d = d.includes("/") ? d.slice(0, d.lastIndexOf("/")) : "";
944
+ }
945
+ if (found === null && unread !== null) gaps.push(`the workspace of a compile in ${r || "."} cannot be read from the selected tree (${unread}), so whether it shares a workspace with another is disputed`);
946
+ wsOf.set(r, found ?? r);
947
+ }
948
+ const groups = new Map();
949
+ compiles.forEach((c, i) => { const ws = rels[i] === null ? `?${c.cwd}` : wsOf.get(rels[i]); const k = `${ws}\u0000${c.sub}\u0000${settings(c.args)}`; (groups.get(k) ?? groups.set(k, []).get(k)).push(c); });
950
+ // Two commands of one workspace and stage whose settings differ are separate groups only when every differing option is one whose meaning the check knows; an option it does
951
+ // does not know could be another spelling of the same setting, and the split between them is then not shown to be justified.
952
+ { const MEANING = /^(--profile|--features|--jobs|--manifest-path|--config|-Z|--target-dir|--locked|--offline|--all-features|--no-default-features|--bin|--test|--example|--bench|--lib|--bins|--tests|--examples|--benches|--all-targets|--workspace|--all|--exclude|--ignore-rust-version|--keep-going|--future-incompat-report|--timings|--unit-graph|--build-plan|--no-deps|--document-private-items|--open)(?=\s|$)/;
953
+ const byStage = new Map(); for (const [k, cs] of groups) { const [w, sub] = k.split("\u0000"); const key = w + "\u0000" + sub; (byStage.get(key) ?? byStage.set(key, []).get(key)).push(unitsOf(cs[0].args).units); }
954
+ for (const [key, list] of byStage) { if (list.length < 2) continue; const all = list.flat(); const odd = all.filter((u) => list.some((l) => !l.includes(u)) && !MEANING.test(u)); if (odd.length) gaps.push(`compiles in ${key.split("\u0000")[0] || "."} differ in option(s) the check does not know the meaning of (${[...new Set(odd)].slice(0, 3).join(", ")}), so that the split between them is justified, and not a different spelling of one setting, is not shown`); } }
955
+ // A split is justified, by the check itself, only by the policy of the run's own Git tree (Council CV-1 F-25, F-26): ci/shards.json `solo`
956
+ // names crates that always get a job of their own. Every crate and target is built once; a solo crate is alone in its command, with its
957
+ // targets combined in one command; every other crate of the group shares one command.
958
+ let solo; let soloProblem = null;
959
+ const soloSet = () => { if (solo || soloProblem) return solo; try { const d = ctx.readTree("ci/shards.json"); const doc = typeof d === "string" ? JSON.parse(d) : d; solo = new Set(Array.isArray(doc?.solo) ? doc.solo.map(String) : []); } catch (e) { soloProblem = `ci/shards.json at the run's tree cannot be read (${e.message})`; } return solo; };
960
+ // Frozen case GCX-09-7: a crate the producer's own rule (sidecarBoundCrate: an externalBin in its Tauri config) finds sidecar-bound at the
961
+ // run's tree also keeps its own command. The crate's folder is a member of the group's workspace whose manifest names it, read at that tree.
962
+ const treeText = (p) => { const v = ctx.readTree(p.replaceAll("\\", "/")); return typeof v === "string" ? v : JSON.stringify(v); };
963
+ const packageName = (toml) => /^\[package\][^[]*?^name\s*=\s*"([^"]+)"/m.exec(String(toml))?.[1] ?? null;
964
+ const boundMemo = new Map();
965
+ const sidecarOf = (ws, crate) => {
966
+ const key = `${ws}\u0000${crate}`; if (boundMemo.has(key)) return boundMemo.get(key);
967
+ let out;
968
+ try {
969
+ const members = workspaceMembers(treeText(`${ws ? `${ws}/` : ""}Cargo.toml`)) ?? [""];
970
+ const dirs = members.map((m) => (m.endsWith("/*") ? `${m.slice(0, -1)}${crate}` : m));
971
+ let dir = null;
972
+ for (const d of dirs) { const rel = [ws, d].filter(Boolean).join("/"); try { if (packageName(treeText(`${rel ? `${rel}/` : ""}Cargo.toml`)) === crate) { dir = rel; break; } } catch { /* not this member */ } }
973
+ if (dir === null) out = { unknown: `no member of ${ws || "."}/Cargo.toml at the run's tree is package ${crate}` };
974
+ else { const b = sidecarBound(treeText, dir); out = b.bound ? { bound: true, file: String(b.file).replaceAll("\\", "/") } : { bound: false }; }
975
+ } catch (e) { out = { unknown: `${ws || "."}/Cargo.toml at the run's tree cannot be read (${e.message})` }; }
976
+ boundMemo.set(key, out); return out;
977
+ };
978
+ const justified = [];
979
+ for (const [k, cs] of groups) {
980
+ const where = `${cs.length}x cargo ${k.split("\u0000")[1]} in ${k.split("\u0000")[0] || "."}`;
981
+ const seen = new Map();
982
+ for (const c of cs) for (const crate of cratesOf(c)) for (const t of targetsOf(c).length ? targetsOf(c) : [null]) { const u = `${crate}@${t}`; seen.set(u, (seen.get(u) ?? 0) + 1); }
983
+ const dup = [...seen].filter(([, n]) => n > 1).map(([u]) => u.replace(/@null$/, ""));
984
+ if (dup.length) fails.push(`${where}: ${dup.join(", ")} built more than once in one workspace and stage`);
985
+ // Commands that each name exactly one --target are one command per target: the split Cargo's feature unification requires (several targets in one call give each the union of both
986
+ // targets' features: HeardRight on the Dell, 2026-11-10; gate/calls.mjs), which is checkable from the commands alone. Each target's commands are judged by the usual rules; a command
987
+ // naming two or more targets, or none, gets no such reason and the group is judged whole. (EGM ruling, 2026-11-21.)
988
+ const partition = cs.length > 1 && cs.every((c) => targetsOf(c).length === 1);
989
+ const byTarget = new Map(); if (partition) for (const c of cs) { const t = targetsOf(c)[0]; (byTarget.get(t) ?? byTarget.set(t, []).get(t)).push(c); }
990
+ if (!partition && cs.length < 2) continue;
991
+ const policy = soloSet();
992
+ if (!policy) { gaps.push(`${where} were sent as separate commands; ${soloProblem}, so the split cannot be checked`); continue; }
993
+ const failsBefore = fails.length;
994
+ for (const slice of partition ? [...byTarget.values()] : [cs]) {
995
+ const where = `${slice.length}x cargo ${k.split("\u0000")[1]} in ${k.split("\u0000")[0] || "."}${partition && byTarget.size > 1 ? ` for target ${targetsOf(slice[0])[0]}` : ""}`;
996
+ const ws = k.split("\u0000")[0]; const set = new Set(policy); const reasons = new Map(); const unknown = [];
997
+ for (const n of new Set(slice.flatMap(cratesOf))) {
998
+ if (policy.has(n)) { reasons.set(n, "solo per the run's ci/shards.json"); continue; }
999
+ const b = ws.startsWith("?") ? { unknown: "its workspace is not placed" } : sidecarOf(ws, n);
1000
+ if (b.bound) { set.add(n); reasons.set(n, `sidecar-bound per ${b.file} at the run's tree`); } else if (b.unknown) unknown.push(`${n}: ${b.unknown}`);
1001
+ }
1002
+ const soloCmds = slice.filter((c) => cratesOf(c).some((n) => set.has(n)));
1003
+ const mixed = soloCmds.filter((c) => cratesOf(c).length > 1);
1004
+ const ordinary = slice.filter((c) => !cratesOf(c).some((n) => set.has(n)));
1005
+ const perSolo = new Map(); for (const c of soloCmds.filter((x) => cratesOf(x).length === 1)) perSolo.set(cratesOf(c)[0], (perSolo.get(cratesOf(c)[0]) ?? 0) + 1);
1006
+ if (mixed.length) fails.push(`${where}: crate(s) that must build alone (${[...new Set(mixed.flatMap(cratesOf).filter((n) => set.has(n)))].join(", ")}) were built together with other crates`);
1007
+ if ([...perSolo.values()].some((n) => n > 1)) fails.push(`${where}: a solo crate was sent as several commands for one target instead of one`);
1008
+ // NN09: "every split has a reason the check can verify"; a crate whose manifest cannot be found at the run's tree has no such reason.
1009
+ if (ordinary.length > 1) fails.push(`${where} were sent as separate commands, and only ${slice.length - ordinary.length} of them are for a crate the run's tree keeps alone (ci/shards.json solo, or sidecar-bound)${unknown.length ? `; no reason found for ${unknown.slice(0, 2).join("; ")}` : ""}`);
1010
+ if (!mixed.length && ![...perSolo.values()].some((n) => n > 1) && ordinary.length <= 1) justified.push([...perSolo.keys()].map((n) => `${n} ${reasons.get(n)}`).join(", "));
1011
+ }
1012
+ if (partition && byTarget.size > 1 && fails.length === failsBefore) justified.push(`split by target (${[...byTarget.keys()].join(", ")}): one target per command, because Cargo unifies features across the targets of one command`);
1013
+ }
1014
+ // Council CV-1 F-27: actual command intervals, not group envelopes. Commands that did not all start together cannot pass without a record of
1015
+ // when each became ready and how much capacity was free, which no record of the run carries yet.
1016
+ // Independent groups run at the same time: the gate submits each without waiting for another to end. A job the broker queued for want of
1017
+ // capacity (its signed queue wait) is the broker's, not the gate's.
1018
+ if (compiles.some((c) => !Number.isFinite(c.submitted) || !Number.isFinite(c.ended))) gaps.push("a broker job's receipt gives no submission or end time");
1019
+ else for (const c of compiles) {
1020
+ const first = compiles.reduce((a, b) => (b.submitted < a.submitted ? b : a)); const late = c.submitted - first.submitted;
1021
+ if (c !== first && late > 250 && !compiles.some((o) => o !== c && o.ended <= c.submitted)) gaps.push(`broker job ${c.jobId} was submitted ${Math.round(late)} ms after the first while it ran; whether it waited for capacity or was held back is not shown`);
1022
+ const behind = compiles.find((o) => o !== c && Number.isFinite(c.started) && c.started >= o.ended && o.started < c.started);
1023
+ if (behind && c.queueMs !== null && c.queueMs <= 0) gaps.push(`broker job ${c.jobId} started only after job ${behind.jobId} ended with no queue wait signed, so whether the gate held it back or the broker had no capacity is not shown`);
1024
+ // A job submitted only after another ended may have waited for a free lane or for its own readiness: neither is recorded, so that independent groups could have run together is not shown.
1025
+ const before = compiles.find((o) => o !== c && o.ended <= c.submitted); if (before) gaps.push(`broker job ${c.jobId} (cargo ${c.sub} ${cratesOf(c).join(" ")}) was submitted only after job ${before.jobId} ended, and no record shows it was ready or that a lane was free before then, so that independent groups could have run together is not shown`); }
1026
+ return decide(fails, gaps, `${compiles.length} compile command(s) in ${groups.size} group(s), one per workspace and stage${justified.filter(Boolean).length ? ` (split: ${justified.filter(Boolean).join("; ")})` : ""}, all submitted together`);
1027
+ }
1028
+
1029
+
1030
+ const JUDGES = Object.freeze({ NN01: nn01, NN02: nn02, NN03: nn03, NN04: nn04, NN05: nn05, NN06: nn06, NN07: nn07, NN08: nn08, NN09: nn09, NN10: nn10, NN11: nn11, NN12: nn12 });
1031
+ export const CHECK_IDS = Object.freeze(Object.keys(JUDGES));
1032
+
1033
+ /**
1034
+ * Whether a recorded process is still running: the process at its id must have started when the record says it did (within `tolMs`). `readStart(pid)` gives the start
1035
+ * time of the process now at that id in ms, `undefined` when none exists and `null` when it exists and its start time cannot be read. Returns true (the same process),
1036
+ * false (no process, or another that took the id), or null (not shown: an unreadable start time, or a record with no start).
1037
+ */
1038
+ export function liveCheck({ pid, start, readStart, tolMs = 2000 }) {
1039
+ const s = readStart(pid);
1040
+ if (s === undefined) return false;
1041
+ if (s === null || !Number.isFinite(s) || !Number.isFinite(start)) return null;
1042
+ return Math.abs(s - start) <= tolMs;
1043
+ }
1044
+
1045
+ /**
1046
+ * The arguments of `rustright verify-receipt` for one receipt: the caller pins the key, key id, host and broker digest (written at the broker's enrollment, not by the gate);
1047
+ * the job id, nonce and request digest are the receipt's own signed payload, so the signature, the pinned key and the pinned host and broker digest are what is checked.
1048
+ * Null when the payload names no job id, nonce or request digest, or a pin is missing.
1049
+ */
1050
+ export function verifierArgv({ file, body, key, keyId, host, brokerDigest }) {
1051
+ let payload = null; try { payload = JSON.parse(body)?.provenance?.payload ?? null; } catch { payload = null; }
1052
+ const need = { nonce: payload?.nonce, requestDigest: payload?.requestDigest, jobId: payload?.jobId };
1053
+ if (!key || !keyId || !host || !brokerDigest || Object.values(need).some((v) => typeof v !== "string" || v === "")) return null;
1054
+ return ["verify-receipt", "--receipt", file, "--public-key", key, "--key-id", keyId, "--host", host, "--broker-digest", brokerDigest, "--nonce", need.nonce, "--request-digest", need.requestDigest, "--job-id", need.jobId];
1055
+ }
1056
+
1057
+ /**
1058
+ * The snapshot folder, from the broker's signed job folders and the selected tree alone: the folder each job ran in, less the part that is a
1059
+ * Cargo workspace of the tree (`ws` when `ws/Cargo.toml` is in the tree). Null when the jobs do not agree on one, or there are none.
1060
+ */
1061
+ function snapshotOf(jobs, readTree) {
1062
+ const roots = new Set();
1063
+ for (const j of jobs) {
1064
+ if (!j.cwd) continue; const segs = dirKey(j.cwd).split("/"); let found = null;
1065
+ for (let k = 1; k <= segs.length; k += 1) { const rel = segs.slice(k).join("/"); try { readTree(`${rel ? `${rel}/` : ""}Cargo.toml`); found = segs.slice(0, k).join("/"); break; } catch { /* not this split */ } }
1066
+ if (found === null) return null; roots.add(found);
1067
+ }
1068
+ return roots.size === 1 ? [...roots][0] : null;
1069
+ }
1070
+
1071
+ /**
1072
+ * Judges one run against `lines` (readAcceptanceLines of the contract; required, and checked again here) from evidence the gate does not write:
1073
+ * `launch`: the launcher's record (acceptance-launch.mjs). `processes` + `witness`: the operating system's record of every program start and
1074
+ * exit in the run's window (processesFromWindowsEvents / processesFromEslogger) and what it covers. `receipts`: the broker's receipts that
1075
+ * appeared during the run, each { file, sha256, doc, verified: { ok, problems } } (verified against the pinned broker key). `inventory`: Map row id ->
1076
+ * { stage, files } from a source that is not the gate (null until the planner takes plain data). `prior`: { failedRows } from the previous launched
1077
+ * run's own evidence. `git`: { tree, blobOf(path), priorBlobOf(path), readTree(path) } at the selected and the baseline commit. `live` / `successor`
1078
+ * (NN12),
1079
+ * `digestOf(file)` (NN10). Returns { lines: [{ id, text, verdict, why }], pass, failed, notMeasured }.
1080
+ */
1081
+ export function judgeRun({ lines, launch = null, processes = null, witness = null, receipts = [], inventory = null, priorInventory = null, inventoryUncovered = [], prior = null, readiness = null, diskBlobs = null, cacheStore = null, snapshotStat = null, git = null, live = null, successor = null, verifierPinned = false, digestOf = null } = {}) {
1082
+ const unlinked = Array.isArray(lines) ? linkProblems(lines) : ["no lines were given: read them from the contract with readAcceptanceLines"];
1083
+ if (unlinked.length) throw Object.assign(new Error(`the contract and the acceptance test do not match: ${unlinked.join("; ")}`), { problems: unlinked });
1084
+ const g = git ?? { tree: null, blobOf: () => null, readTree: () => { throw new Error("no git reader was given (--repo)"); } };
1085
+ const tree = runTree(launch, processes, witness);
1086
+ const start = timeOf(launch?.startedAt); const end = timeOf(launch?.endedAt);
1087
+ const jobsAll = (receipts ?? []).map(jobOf);
1088
+ const inWindow = jobsAll.filter((j) => !Number.isFinite(j.submitted) || ((!Number.isFinite(start) || j.submitted >= start) && (!Number.isFinite(end) || j.submitted <= end)));
1089
+ const startsAll = tree.procs.map((p) => ({ ...decodeStart({ cmd: p.exe, args: p.args, cwd: p.cwd ?? "" }), at: p.start, end: p.end, exit: p.exit }));
1090
+ const hasChild = (p) => /(^|[\\/])cmd\.exe$/i.test(p.exe) && tree.procs.some((c) => c !== p && c.ppid === p.pid && c.start >= p.start && (p.end === null || c.start <= p.end));
1091
+ const rustStarts = startsAll.filter((d, i) => programName(d.program) === "rustright" && !hasChild(tree.procs[i]));
1092
+ const sends = rustStarts.filter((d) => d.args[0] === "cargo");
1093
+ // One job to one send: the same command, and the same folder where both are known. A job no send of this run's tree matches is not shown to be this run's.
1094
+ const claimed = new Set(); const jobs = []; const foreign = [];
1095
+ // A job is credited only when exactly one send matches it and that send matches no other job: two sends that both fit one job, or two jobs that both fit one send, are
1096
+ // neither credited (which is which is not shown) and are carried as gaps.
1097
+ const sortedJobs = [...inWindow].sort((a, b) => (a.submitted || 0) - (b.submitted || 0));
1098
+ const candidatesOf = (j) => {
1099
+ const key = j.argv ? j.argv.join("\u0000") : null;
1100
+ // The send is alive while its job runs: it started no later than the job's submission and is not recorded as ended before the job's end (a second of slack
1101
+ // for the clocks); a job with no usable times is matched to nothing.
1102
+ const alive = (d) => Number.isFinite(j.submitted) && Number.isFinite(j.ended) && d.at - 1000 <= j.submitted && (d.end === null || j.ended <= d.end + 1000);
1103
+ return key === null ? [] : sends.filter((d) => d.args.slice(1).join("\u0000") === key && (!d.cwd || !j.cwd || dirKey(d.cwd) === dirKey(j.cwd)) && alive(d));
1104
+ };
1105
+ const cands = new Map(sortedJobs.map((j) => [j, candidatesOf(j)]));
1106
+ for (const j of sortedJobs) {
1107
+ const c = cands.get(j);
1108
+ // Credited when the jobs that fit these sends are exactly as many as the sends and all fit the very same sends (one to one, or k identical jobs for k identical sends,
1109
+ // where which is which cannot change what is judged); a job and a send that fit more or fewer than that are not paired.
1110
+ const sig = (x) => x.map((d) => sends.indexOf(d)).join(",");
1111
+ const related = sortedJobs.filter((o) => cands.get(o).some((d) => c.includes(d)));
1112
+ const ok = c.length > 0 && related.length === c.length && related.every((o) => sig(cands.get(o)) === sig(c));
1113
+ if (ok) { c.forEach((d) => claimed.add(d)); jobs.push(j); } else foreign.push(j);
1114
+ }
1115
+ const ctx = {
1116
+ launch, witnessTo: witness?.to ?? null, commit: launch?.commit ?? null, tree: g.tree, blobOf: g.blobOf, diskBlobs, cacheStore, snapshotStat,
1117
+ sendGaps: sends.filter((d) => !claimed.has(d)).map((d) => `a broker send (cargo ${d.args.slice(1, 4).join(" ")}) has no signed job that matches its command, folder and lifetime, so what it built is not shown`), rustStarts, sends, vjobs: jobs.filter((j) => j.verified), foreignGaps: foreign.map((j) => `broker job ${j.jobId ?? path.basename(j.file)} is not shown to be this run's: no send of the run's own process tree has its command and folder`), jobGaps: [...foreign.map((j) => `broker job ${j.jobId ?? path.basename(j.file)} is not shown to be this run's: no send of the run's own process tree has its command and folder`), ...jobs.filter((j) => j.verified && !j.cwd).map((j) => `broker job ${j.jobId ?? path.basename(j.file)} is signed with no workspace, so which workspace and crate it built is not shown`), ...jobs.filter((j) => !j.verified).map((j) => `broker job ${j.jobId ?? path.basename(j.file)} is not credited: its receipt ${verifierPinned ? `does not verify (${j.problems.join("; ") || "no reason given"})` : "cannot be verified, no broker key is pinned"}`)],
1118
+ inventory: inventory ? new Map(inventory) : null, inventoryUncovered, readiness, prior,
1119
+ baselineGap: !launch?.baseline?.commit ? "the launcher has no earlier launched run to take a baseline commit from, so what changed since cannot be shown" : launch.baseline.exit !== 0 ? "the previous launched run did not end cleanly, so its state is not a baseline" : typeof g.priorBlobOf !== "function" ? "git cannot show the baseline commit's tree" : null, exit: Number.isFinite(end) && Number.isInteger(launch?.exit) ? launch.exit : null,
1120
+ root: tree.root, procs: tree.procs, processGaps: tree.gaps, starts: startsAll,
1121
+ parentKey: (p) => { const parent = [tree.root, ...tree.procs].find((q) => q && q.pid === p.ppid && q.start <= p.start); return parent ? `${programName(parent.exe)}#${parent.start}` : "?"; },
1122
+ jobs, verifierPinned, snap: { path: snapshotOf(jobs, g.readTree) }, readTree: g.readTree,
1123
+ expected: expectedRows(inventory ? new Map(inventory) : null, g, prior, priorInventory ? new Map(priorInventory) : null),
1124
+ live, successor, digestOf,
1125
+ };
1126
+ const judged = lines.map(({ id, text: sentence }) => { let r; try { r = JUDGES[id](ctx); } catch (e) { r = result(FAIL, `the check itself failed: ${e.message}`); } return { id, text: sentence, verdict: r.verdict, why: r.why }; });
1127
+ const failed = judged.filter((l) => l.verdict === FAIL).map((l) => l.id); const notMeasured = judged.filter((l) => l.verdict === NOT_MEASURED).map((l) => l.id);
1128
+ return { lines: judged, pass: failed.length === 0 && notMeasured.length === 0, failed, notMeasured };
1129
+ }
1130
+
1131
+ /**
1132
+ * A run folder's evidence as judgeRun reads it, gathered from outside the gate: the launcher's record, the process record the launcher exported,
1133
+ * the broker receipts that appeared during the run (read once; the verifier is handed those bytes), git at the selected and the baseline commit, the
1134
+ * previous launched run's own evidence for what failed, and an independent row inventory when one is given. No gate file is read: no history, no
1135
+ * cache entry, no gate output.
1136
+ */
1137
+ export function readRunDir(dir, { repo = null, receiptsDir = null, verify = null, inventoryFile = null } = {}) {
1138
+ const text = (p) => { try { return fs.readFileSync(p, "utf8"); } catch { return null; } };
1139
+ const json = (p) => { try { return JSON.parse(text(p) ?? "null"); } catch { return null; } };
1140
+ const launch = json(path.join(dir, "launch.json"));
1141
+ const procsOf = (d) => { const proc = json(path.join(d, "processes.json")); return proc?.kind === "windows-security" ? processesFromWindowsEvents(proc.events) : proc?.kind === "eslogger" ? processesFromEslogger(proc.events) : null; };
1142
+ const processes = procsOf(dir); const proc = json(path.join(dir, "processes.json"));
1143
+ const receiptsBefore = new Set((text(path.join(dir, "before", "receipts.txt")) ?? "").split(/\r?\n/).filter(Boolean));
1144
+ const receiptsOf = (rdir, skip) => {
1145
+ const out = []; if (!rdir) return out;
1146
+ for (const f of fs.readdirSync(rdir).filter((n) => n.endsWith(".json") && !skip.has(n))) {
1147
+ const file = path.join(rdir, f); const body = fs.readFileSync(file);
1148
+ let doc = null; try { doc = JSON.parse(body.toString("utf8")); } catch { doc = null; }
1149
+ // The verifier is handed these very bytes (a private copy), never the path again: nothing can change between what is verified and what is read.
1150
+ out.push({ file, sha256: createHash("sha256").update(body).digest("hex"), doc, verified: verify ? verify(body) : { ok: false, problems: ["no broker key is pinned"] } });
1151
+ }
1152
+ return out;
1153
+ };
1154
+ const receipts = receiptsOf(receiptsDir, receiptsBefore);
1155
+ // An inventory handed in is an unauthenticated input: the test's own enumeration of the selected tree (acceptance-rows.mjs) always stands, and the file can only add rows or
1156
+ // widen a row's files, never remove a row, narrow one, or claim a kind covered. With no repository there is nothing to check it against, and that is said.
1157
+ const givenDoc = inventoryFile ? json(inventoryFile) : null;
1158
+ const given = givenDoc ? new Map(Object.entries(givenDoc.rows ?? givenDoc)) : null;
1159
+ let inventory = given; let inventoryUncovered = given ? [...(Array.isArray(givenDoc.uncovered) ? givenDoc.uncovered : []), "a handed-in inventory file is not authenticated and there is no repository to check it against"] : null; let priorInventory = null;
1160
+ let git = null; let prior = null;
1161
+ if (repo && launch?.commit) {
1162
+ const run = (...a) => execFileSync("git", ["-C", repo, ...a], { encoding: "utf8", stdio: ["ignore", "pipe", "pipe"], windowsHide: true, maxBuffer: 256 * 1024 * 1024 });
1163
+ const blobsOf = (commit) => { try { const tree = run("rev-parse", `${commit}^{tree}`).trim(); const m = new Map(); for (const l of run("ls-tree", "-r", "-z", tree).split("\0")) { const x = /^\d+ blob ([0-9a-f]+)\t(.+)$/.exec(l); if (x) m.set(x[2], x[1]); } return { tree, m }; } catch { return null; } };
1164
+ const sel = blobsOf(launch.commit); const base = launch.baseline?.commit ? blobsOf(launch.baseline.commit) : null;
1165
+ // The test's own enumeration of the selected tree (acceptance-rows.mjs): the rows a tree states, and the kinds only gate code decides.
1166
+ if (base) priorInventory = enumerateRows({ files: base.m, read: (p) => run("cat-file", "-p", `${base.tree}:${p}`) }).rows;
1167
+ if (sel) {
1168
+ const e = enumerateRows({ files: sel.m, read: (p) => run("cat-file", "-p", `${sel.tree}:${p}`) }); inventory = new Map(e.rows); inventoryUncovered = [...e.uncovered];
1169
+ if (given) {
1170
+ for (const [id, row] of given) { const own = inventory.get(id); if (own) inventory.set(id, { ...own, files: [...new Set([...(own.files ?? []), ...(Array.isArray(row?.files) ? row.files : [])])] }); else inventory.set(id, row); }
1171
+ inventoryUncovered.push("a handed-in inventory file added or widened rows; it cannot remove or narrow any and does not change which kinds are covered");
1172
+ }
1173
+ }
1174
+ if (sel) git = { tree: sel.tree, blobOf: (p) => sel.m.get(String(p).replaceAll("\\", "/")) ?? null, priorBlobOf: base ? (p) => base.m.get(String(p).replaceAll("\\", "/")) ?? null : undefined, readTree: (p) => { const t = run("cat-file", "-p", `${sel.tree}:${p}`); try { return JSON.parse(t); } catch { return t; } } };
1175
+ }
1176
+ // What failed in the previous launched run, from that run's own evidence: a program of a row's tool that exited non-zero, or a verified broker job
1177
+ // that did not succeed. Rows are the inventory's; a row with no such evidence is not marked failed.
1178
+ if (launch?.baseline?.out && inventory) {
1179
+ // The predecessor's process record counts only when it has events and its own export reported no problem and a continuous log; an empty or failed export is not "nothing failed".
1180
+ const pdir = launch.baseline.out; const prevLaunch = json(path.join(pdir, "launch.json")); const pproc = json(path.join(pdir, "processes.json"));
1181
+ const pp = pproc && Array.isArray(pproc.events) && pproc.events.length > 0 && (pproc.problems ?? []).length === 0 && pproc.continuous === true ? procsOf(pdir) : null;
1182
+ // The predecessor's evidence counts only when its own record is there, names the run the launcher says came before, and ended: otherwise nothing is known of
1183
+ // what failed (an empty set would read as "nothing failed").
1184
+ if (pp && prevLaunch?.runId && prevLaunch.runId === launch.baseline.runId && Number.isFinite(timeOf(prevLaunch.endedAt))) {
1185
+ const failed = new Set(); const unknown = new Set();
1186
+ for (const p of pp) {
1187
+ const tool = TOOLS[programName(p.exe)] ?? null; if (!tool || isProbe(p.args)) continue;
1188
+ const red = p.end !== null && p.exit !== null && p.exit !== 0; const unsure = p.end === null || p.exit === null;
1189
+ if (!red && !unsure) continue;
1190
+ const ed = valuesOf(p.args, "--edition")[0] ?? null;
1191
+ const rows = [...inventory.keys()].filter((id) => toolOf(id) === tool && (tool !== "rustfmt" || ed === null || id.split(":")[1] === ed));
1192
+ // One row names its tool's failure; a tool that serves several rows leaves each of them unknown.
1193
+ for (const id of rows) (rows.length === 1 && red ? failed : unknown).add(id);
1194
+ }
1195
+ // The predecessor's signed broker outcomes are not part of the evidence read here, so what happened to any Class B row in it is not known.
1196
+ for (const [id, row] of inventory) if (row?.stage === "B") unknown.add(id);
1197
+ prior = { failedRows: failed, unknownRows: unknown, runId: prevLaunch.runId };
1198
+ }
1199
+ }
1200
+ // The launcher's own listings: the gate's scan-result store before and after the run, and the stat record of the snapshots at the gate's exit. Nothing in them is a record the gate writes.
1201
+ const listing = (p) => { const d = json(p); return d && d.files && typeof d.files === "object" ? d.files : null; };
1202
+ const storeBefore = listing(path.join(dir, "before", "cache-store.json")); const storeAfter = listing(path.join(dir, "cache-store-after.json"));
1203
+ const cacheStore = storeBefore && storeAfter ? { dir: json(path.join(dir, "cache-store-after.json"))?.dir ?? null, written: Object.keys(storeAfter).filter((k) => !storeBefore[k] || storeBefore[k][0] !== storeAfter[k][0] || storeBefore[k][1] !== storeAfter[k][1]).sort(), removed: Object.keys(storeBefore).filter((k) => !storeAfter[k]).sort() } : null;
1204
+ const statDoc = json(path.join(dir, "snapshot-stat.json")); const snapshotStat = statDoc && statDoc.dirs && typeof statDoc.dirs === "object" && statDoc.known === true ? { root: statDoc.root ?? null, dirs: statDoc.dirs } : null;
1205
+ return { cacheStore, snapshotStat, launch, processes, witness: proc ? { kind: proc.kind, from: proc.from, to: proc.to, newest: proc.newest, continuous: proc.continuous === true, problems: proc.problems ?? [] } : null, receipts, inventory, priorInventory, inventoryUncovered, prior, git };
1206
+ }
1207
+
1208
+ // ---- command line -----------------------------------------------------------------------------------------------------------------------------------
1209
+ if (process.argv[1] && path.resolve(process.argv[1]) === fileURLToPath(import.meta.url)) {
1210
+ const opt = (name) => { const i = process.argv.indexOf(name); return i < 0 ? null : process.argv[i + 1]; };
1211
+ const usage = "usage: acceptance-lines.mjs --run <run dir> --repo <dir> --receipts <dir> [--inventory <file>] [--broker-key <hex> --broker-key-id <hex> [--rustright <client>]] [--successor <run dir>] [--live] [--contract <file>] [--json]";
1212
+ const runDir = opt("--run"); if (!runDir) { console.error(usage); process.exit(2); }
1213
+ const contractFile = opt("--contract") ?? CONTRACT_FILE; let lines;
1214
+ try { lines = readAcceptanceLines(fs.readFileSync(contractFile, "utf8")); } catch (e) { console.error(`NOT JUDGED: ${e.code === "ENOENT" ? `the contract ${contractFile} cannot be read` : e.message}`); process.exit(2); }
1215
+ const key = opt("--broker-key"); const keyId = opt("--broker-key-id"); const client = opt("--rustright") ?? "rustright";
1216
+ let host = null; try { host = JSON.parse(fs.readFileSync(path.join(runDir, "launch.json"), "utf8")).host; } catch { host = null; }
1217
+ // The broker's own verifier (rustright verify-receipt) with the key pinned by the caller.
1218
+ const brokerDigest = opt("--broker-digest"); const brokerHost = opt("--broker-host") ?? host;
1219
+ const verify = key && keyId && brokerHost ? (body) => { const dir = fs.mkdtempSync(path.join(os.tmpdir(), "rk-verify-")); const file = path.join(dir, "receipt.json"); fs.writeFileSync(file, body); const argv = verifierArgv({ file, body, key, keyId, host: brokerHost, brokerDigest }); if (!argv) return { ok: false, problems: ["the receipt names no job id, nonce or request digest, or no broker digest is pinned (--broker-digest), so it cannot be verified"] }; try { execFileSync(client, argv, { stdio: ["ignore", "pipe", "pipe"], windowsHide: true }); return { ok: true, problems: [] }; } catch (e) { return { ok: false, problems: [String(e.stderr ?? e.message).trim().split(/\r?\n/).pop()] }; } } : null;
1220
+ const evidence = readRunDir(runDir, { repo: opt("--repo"), receiptsDir: opt("--receipts"), verify, inventoryFile: opt("--inventory") });
1221
+ // The start time of the process now at an id (ms), undefined when there is none, null when it cannot be read: a recorded id is the run's program only if it started when the record says.
1222
+ const startCache = new Map();
1223
+ const readStart = (pid) => {
1224
+ if (startCache.has(pid)) return startCache.get(pid);
1225
+ let out;
1226
+ try { process.kill(pid, 0); } catch (e) { if (e.code !== "EPERM") out = undefined; }
1227
+ if (out === undefined && !(startCache.has(pid))) { startCache.set(pid, undefined); return undefined; }
1228
+ try {
1229
+ const text = process.platform === "win32"
1230
+ ? execFileSync("powershell", ["-NoProfile", "-NonInteractive", "-Command", `$p = Get-CimInstance Win32_Process -Filter 'ProcessId=${Number(pid)}'; if ($p) { $p.CreationDate.ToUniversalTime().ToString('o') }`], { encoding: "utf8", windowsHide: true }).trim()
1231
+ : execFileSync("ps", ["-o", "lstart=", "-p", String(Number(pid))], { encoding: "utf8" }).trim();
1232
+ const t = Date.parse(text); out = text === "" ? undefined : Number.isFinite(t) ? t : null;
1233
+ } catch { out = null; }
1234
+ startCache.set(pid, out); return out;
1235
+ };
1236
+ const alive = (pid, start) => liveCheck({ pid, start, readStart });
1237
+ const locksIn = (d) => { try { return fs.readdirSync(d).filter((n) => n.endsWith(".lock")).map((n) => path.join(d, n)); } catch { return null; } };
1238
+ // The operating system's own listing of running programs (tasklist or ps), read when --live is judged.
1239
+ const inventory = () => {
1240
+ try {
1241
+ if (process.platform === "win32") return execFileSync("tasklist", ["/FO", "CSV", "/NH"], { encoding: "utf8", windowsHide: true }).split(/\r?\n/).filter(Boolean).map((l) => ({ pid: Number(l.split('","')[1]) })).filter((p) => Number.isInteger(p.pid));
1242
+ return execFileSync("ps", ["-A", "-o", "pid="], { encoding: "utf8" }).split(/\r?\n/).map((l) => ({ pid: Number(l.trim()) })).filter((p) => Number.isInteger(p.pid) && p.pid > 0);
1243
+ } catch { return null; }
1244
+ };
1245
+ const live = process.argv.includes("--live") ? { exists: (p) => fs.existsSync(p), alive, locksIn, inventory } : null;
1246
+ const successor = opt("--successor") ? { launch: (() => { try { return JSON.parse(fs.readFileSync(path.join(opt("--successor"), "launch.json"), "utf8")); } catch { return null; } })() } : null;
1247
+ const digestOf = (file) => { try { const body = fs.readFileSync(file); return { sha256: createHash("sha256").update(body).digest("hex"), mtimeMs: fs.statSync(file).mtimeMs }; } catch { return null; } };
1248
+ // The bytes of a file on disk as git would id them (sha1 of `blob <size>\u0000<bytes>`), read after the run: independent of the gate.
1249
+ const diskBlobs = (abs) => { try { const b = fs.readFileSync(abs); return createHash("sha1").update(Buffer.concat([Buffer.from(`blob ${b.length}\u0000`), b])).digest("hex"); } catch { return null; } };
1250
+ const verdict = judgeRun({ lines, ...evidence, live, successor, verifierPinned: Boolean(verify), digestOf, diskBlobs });
1251
+ if (process.argv.includes("--json")) console.log(JSON.stringify(verdict, null, 2));
1252
+ else { for (const l of verdict.lines) console.log(`${l.id} ${l.verdict.toUpperCase().padEnd(12)} ${l.text}\n ${l.why}`); console.log(verdict.pass ? "PASS: all twelve lines" : `NOT PASSED: ${verdict.failed.length} failed, ${verdict.notMeasured.length} not measured`); }
1253
+ process.exit(verdict.pass ? 0 : 1);
1254
+ }