interplane.Get Omega
Read in your language

omega-mv

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

Brought by drakestapleton

branch main Branches Tags History

omega-mv / research / atemporal / at1 / evaluator / src / mutants.rs

438 lines · 23053 bytes Raw Blame History
1// SPDX-License-Identifier: Apache-2.0
2// Copyright 2026 Drake Stapleton (AIEN / aien-dev)
3//
4// Licensed under the Apache License, Version 2.0 (the "License");
5// you may not use this file except in compliance with the License.
6// You may obtain a copy of the License at
7//
8// http://www.apache.org/licenses/LICENSE-2.0
9//
10// Unless required by applicable law or agreed to in writing, software
11// distributed under the License is distributed on an "AS IS" BASIS,
12// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13// See the License for the specific language governing permissions and
14// limitations under the License.
15
16//! Mutant kill receipt. Every mutant is a deliberately broken engine, oracle or
17//! result file. A cell is KILLED when the verifier raises the mutant's intended
18//! finding and every other FAIL finding lies inside the mutant's explained set;
19//! ACCIDENT when it is caught only by something else; SURVIVED when nothing
20//! fires; BLIND when the mutant's written values equal the honest ones (then
21//! the receipt states whether AT1_SPEC section 9.2 predicts that blindness).
22
23use crate::case::{validate_bytes, Case};
24use crate::corpus::valid_specs;
25use crate::model::{shadow, Mods, Status};
26use crate::rat::Q;
27use crate::result::{Ck, Kind, RVal, ResultFile};
28use crate::synth::{engine_result, oracle_record, splice, EngineMut, OracleMut};
29use crate::verify::{verify, Role, Sev};
30
31pub fn engine_mut(name: &str) -> Option<EngineMut> {
32 let mut e = EngineMut::default();
33 match name {
34 "honest" => {}
35 "M1-drop-v" => e.physics.drop_v = true,
36 "M2-flip-v" => e.physics.flip_v = true,
37 "M3-wrong-level" => e.physics.shift_level = true,
38 "M4-phase-sign" => e.physics.phase_minus = true,
39 "M5-y-sign" => e.y_sign = true,
40 "M6-axis-swap" => e.axis_swap = true,
41 "M8-ideal-marginal" => e.ideal_marginal = true,
42 "M9-stale-label" => e.stale_label = true,
43 "M10-bound-none-nonzero" => e.bound_kind_none_nonzero = true,
44 _ => return None,
45 }
46 Some(e)
47}
48
49pub fn oracle_mut(name: &str) -> Option<OracleMut> {
50 let mut o = OracleMut::default();
51 match name {
52 "honest" => {}
53 "O1-ideal-without-h" => o.ideal_drop_h = true,
54 "O2-oracle-drop-v" => o.physics = Mods { drop_v: true, ..Mods::default() },
55 "O3-oracle-phase-sign" => o.physics = Mods { phase_minus: true, ..Mods::default() },
56 _ => return None,
57 }
58 Some(o)
59}
60
61const PHYSICS: [&str; 7] = ["M1-drop-v", "M2-flip-v", "M3-wrong-level", "M4-phase-sign", "M5-y-sign", "M6-axis-swap", "M8-ideal-marginal"];
62const ORACLE: [&str; 3] = ["O1-ideal-without-h", "O2-oracle-drop-v", "O3-oracle-phase-sign"];
63
64/// AT1_SPEC 9.2 blindness for M1 to M4 on the section 13 positive cases (P-class
65/// of the path). M5, M6 and M8 blindness follows from the honest values
66/// (no label with P(Y+) != 1/2; P(X+) = P(Y+) on every label; p(k) = w/N).
67fn spec_blind(m: &str, path: &str) -> Option<bool> {
68 let cls = if path.contains("P1a") || path.contains("P1b") {
69 "P1"
70 } else if path.contains("P1c") {
71 "P1c"
72 } else if path.contains("P6") || path.contains("N1f") {
73 "P6"
74 } else {
75 "other"
76 };
77 match m {
78 "M1-drop-v" | "M2-flip-v" => Some(cls == "P1" || cls == "P1c"),
79 "M3-wrong-level" => Some(cls == "P1"),
80 "M4-phase-sign" => Some(cls == "P6"),
81 _ => None,
82 }
83}
84
85
86/// Flipping the sign of every clock phase (the M4 / O3 defect, which acts on the interacting
87/// conditional states only; the ideal reference is a separate formula) is complex conjugation
88/// of the conditional state when the case data are real (psi_0 real and no Y component in h or any v_j, so every
89/// level vector is real). Conjugation keeps p(k), P(X) and P(Z) and maps P(Y+) to 1 - P(Y+),
90/// so such a case is blind to a phase-sign mutant exactly when P(Y+) = 1/2 on every DEFINED
91/// label (the AT1_SPEC 9.2 M4 reasoning: only a complex relative
92/// phase is visible). N3 is such a case: chi_k = (1 + i^k)(1, 0) (AT1_SPEC 13.2).
93fn conjugation_blind(c: &Case) -> bool {
94 let real = c.psi[0].im.is_zero() && c.psi[1].im.is_zero() && c.h[1].is_zero() && c.v.iter().all(|v| v[1].is_zero());
95 if !real {
96 return false;
97 }
98 let sh = shadow(c, &Mods::default(), false);
99 let half = Q::frac(1, 2);
100 let y_half = |s: &[[crate::model::Val; 2]; 3]| s[1][0].q == half;
101 (0..c.m).all(|k| sh.pauli[k].as_ref().map_or(true, |p| y_half(p)))
102}
103
104/// Predicted blindness of the oracle mutants, from AT1_SPEC 9.2 (no derivation from the
105/// mutant's own output): O2 drops V, so it is blind exactly where M1 is (P1, P1c); O3 flips
106/// the phase sign, so it is blind where M4 is (P6 and its IDEAL-target twin N1f) and on every
107/// trivial kernel, where the trivial-kernel rule leaves all reference values undefined.
108/// O1 (IDEAL reference without h) is predicted never blind; the receipt shows whether that holds.
109fn oracle_predicted_blind(m: &str, path: &str, c: &Case) -> bool {
110 match m {
111 "O2-oracle-drop-v" => spec_blind("M1-drop-v", path) == Some(true),
112 "O3-oracle-phase-sign" => spec_blind("M4-phase-sign", path) == Some(true) || shadow(c, &Mods::default(), false).trivial || conjugation_blind(c),
113 _ => false,
114 }
115}
116fn honest_engine_derived_blind(m: &str, c: &Case) -> bool {
117 let sh = shadow(c, &Mods::default(), false);
118 if sh.trivial {
119 return true;
120 }
121 let half = Q::frac(1, 2);
122 let wn = c.w.div(&Q::int(c.n as i64));
123 match m {
124 "M5-y-sign" => (0..c.m).all(|k| sh.pauli[k].as_ref().map_or(true, |p| p[1][0].q == half)),
125 "M6-axis-swap" => (0..c.m).all(|k| sh.pauli[k].as_ref().map_or(true, |p| p[0][0].q == p[1][0].q)),
126 "M8-ideal-marginal" => (0..c.m).all(|k| sh.p[k].q == wn),
127 _ => false,
128 }
129}
130
131fn engine_values_equal(a: &ResultFile, b: &ResultFile) -> bool {
132 a.kernel_dim == b.kernel_dim && a.constraint == b.constraint && a.povm == b.povm && a.label == b.label && a.clock == b.clock && a.pauli == b.pauli && a.bound_kind == b.bound_kind
133}
134fn oracle_values_equal(a: &ResultFile, b: &ResultFile) -> bool {
135 a.ref_label == b.ref_label && a.ref_clock == b.ref_clock && a.ref_ideal == b.ref_ideal && a.ref_inter == b.ref_inter
136}
137
138struct Cell {
139 mutant: String,
140 case: String,
141 runner_codes: String,
142 findings: Vec<String>,
143 intended: String,
144 verdict: String,
145}
146
147fn judge_cell(fails: &[String], flagged: &[String], intended: &[&str], allowed: &[&str]) -> &'static str {
148 let ok = |f: &String| intended.iter().any(|i| f == i) || allowed.iter().any(|a| if a.ends_with('*') { f.starts_with(&a[..a.len() - 1]) } else { f == a });
149 let hit = fails.iter().chain(flagged.iter()).any(|f| intended.iter().any(|i| f == i));
150 if fails.is_empty() && flagged.is_empty() {
151 "SURVIVED"
152 } else if hit && fails.iter().all(ok) && flagged.iter().all(ok) {
153 if fails.iter().any(|f| intended.iter().any(|i| f == i)) { "KILLED" } else { "FLAGGED" }
154 } else {
155 "ACCIDENT"
156 }
157}
158
159fn codes_of(r: &ResultFile) -> String {
160 if r.verdict.failure_codes.is_empty() { "none".into() } else { r.verdict.failure_codes.join(",") }
161}
162
163pub fn receipt(out: &str) -> i32 {
164 let mut cells: Vec<Cell> = Vec::new();
165 let specs = valid_specs();
166 let cases: Vec<(String, Case, Vec<u8>)> = specs
167 .iter()
168 .map(|(p, _, s)| {
169 let b = s.bytes();
170 (p.clone(), validate_bytes(&b).expect("public case valid"), b)
171 })
172 .collect();
173 let honest_o = |c: &Case| oracle_record(c, &OracleMut::default(), "at1-eval synth-oracle honest");
174 let honest_e = |c: &Case| engine_result(c, &EngineMut::default(), "at1-eval synth-engine honest");
175 // ---- physics mutants of the engine, on every positive case and the N1 family ----
176 for (path, c, cb) in cases.iter().filter(|(p, _, _)| p.starts_with("positive/") || p.contains("/N1")) {
177 let o = honest_o(c);
178 let he = honest_e(c);
179 for m in PHYSICS {
180 let em = engine_mut(m).unwrap();
181 let e = engine_result(c, &em, &format!("at1-eval synth-engine {}", m));
182 let r = splice(&e, &o).expect("splice");
183 let rep = verify(&r.bytes(), Some(cb), Role::Candidate);
184 let fails: Vec<String> = rep.findings.iter().filter(|f| f.sev == Sev::Fail).map(|f| f.code.clone()).collect();
185 let flagged: Vec<String> = rep.findings.iter().filter(|f| f.sev != Sev::Fail).map(|f| f.code.clone()).collect();
186 let code_ok = if c.target_ideal {
187 r.verdict.failure_codes.iter().any(|x| x == "ORACLE_DISAGREEMENT" || x == "TRIVIAL_PHYSICAL_STATE")
188 } else {
189 r.verdict.failure_codes.iter().any(|x| x == "INTERACTING_DEVIATION_EXCEEDED" || x == "TRIVIAL_PHYSICAL_STATE")
190 };
191 let intended = if c.target_ideal { "EXPECTATION-NOT-MET via check 11 ORACLE_DISAGREEMENT (or check 3)" } else { "EXPECTATION-NOT-MET via check 10 INTERACTING_DEVIATION_EXCEEDED (or check 3)" };
192 let trivial_claim = rep.codes().iter().any(|x| x == "E4-SHADOW-TRIVIAL");
193 let mut allowed: Vec<&str> = vec!["E4-SHADOW-*"];
194 if trivial_claim {
195 allowed.extend(["E4-CHECK-MISMATCH", "E4-OUTCOME-MISMATCH", "E4-CODES-MISMATCH", "E4-EXPECTATION-MISMATCH", "E4-UNDEFINED-DISCIPLINE"]);
196 }
197 let blind = engine_values_equal(&e, &he);
198 let expected_blind = spec_blind(m, path).unwrap_or_else(|| honest_engine_derived_blind(m, c));
199 let verdict = if blind {
200 if expected_blind { "BLIND (predicted)".to_string() } else { "BLIND (NOT predicted)".to_string() }
201 } else {
202 let v = judge_cell(&fails, &flagged, &["E4-EXPECTATION-NOT-MET"], &allowed);
203 let v = if v == "KILLED" && !code_ok { "ACCIDENT" } else { v };
204 // a kill where blindness was predicted means the mutant is not the one the spec describes
205 if expected_blind { format!("UNEXPECTED ({} although predicted blind)", v) } else { v.to_string() }
206 };
207 cells.push(Cell { mutant: m.into(), case: path.clone(), runner_codes: codes_of(&r), findings: rep.codes(), intended: intended.into(), verdict });
208 }
209 }
210 // ---- engine mutants with a single target case ----
211 let find = |p: &str| cases.iter().find(|(x, _, _)| x.contains(p)).expect("case present");
212 for (m, cpath, intended, allowed) in [
213 ("M9-stale-label", "N3-zero-label", "E4-LABEL-RULE", vec!["E4-EXPECTATION-NOT-MET", "E4-SHADOW-*"]),
214 ("M10-bound-none-nonzero", "P2-kat", "E4-BOUND-NONE-NONZERO", vec!["E4-EXPECTATION-NOT-MET"]),
215 ] {
216 let (path, c, cb) = find(cpath);
217 let e = engine_result(c, &engine_mut(m).unwrap(), &format!("at1-eval synth-engine {}", m));
218 let r = splice(&e, &honest_o(c)).unwrap();
219 let rep = verify(&r.bytes(), Some(cb), Role::Candidate);
220 let fails: Vec<String> = rep.findings.iter().filter(|f| f.sev == Sev::Fail).map(|f| f.code.clone()).collect();
221 let flagged: Vec<String> = rep.findings.iter().filter(|f| f.sev != Sev::Fail).map(|f| f.code.clone()).collect();
222 let v = judge_cell(&fails, &flagged, &[intended], &allowed);
223 cells.push(Cell { mutant: m.into(), case: path.clone(), runner_codes: codes_of(&r), findings: rep.codes(), intended: intended.into(), verdict: v.into() });
224 }
225 // ---- oracle mutants: the oracle record itself (gate G3 role) ----
226 for (path, c, cb) in cases.iter() {
227 let ho = honest_o(c);
228 for m in ORACLE {
229 let o = oracle_record(c, &oracle_mut(m).unwrap(), &format!("at1-eval synth-oracle {}", m));
230 let rep = verify(&o.bytes(), Some(cb), Role::Oracle);
231 let fails: Vec<String> = rep.findings.iter().filter(|f| f.sev == Sev::Fail).map(|f| f.code.clone()).collect();
232 let flagged: Vec<String> = rep.findings.iter().filter(|f| f.sev != Sev::Fail).map(|f| f.code.clone()).collect();
233 let (intended, allowed): (&[&str], Vec<&str>) = match m {
234 "O1-ideal-without-h" => (&["E4-ORACLE-IDEAL"], vec![]),
235 _ => (&["E4-ORACLE-INTERACTING", "E4-ORACLE-CLOCK", "E4-ORACLE-LABEL", "E4-ORACLE-TRIVIAL"], vec!["E4-SHADOW-*", "E4-ORACLE-*", "E4-CHECK-MISMATCH", "E4-OUTCOME-MISMATCH", "E4-CODES-MISMATCH", "E4-EXPECTATION-MISMATCH", "E4-UNDEFINED-DISCIPLINE", "E4-TRIVIAL-SHAPE"]),
236 };
237 let blind = oracle_values_equal(&o, &ho);
238 let predicted = oracle_predicted_blind(m, path, c);
239 let verdict = match (blind, predicted) {
240 (true, true) => "BLIND (predicted)".to_string(),
241 (true, false) => "BLIND (NOT predicted)".to_string(),
242 (false, true) => format!("UNEXPECTED ({} although predicted blind)", judge_cell(&fails, &flagged, intended, &allowed)),
243 (false, false) => judge_cell(&fails, &flagged, intended, &allowed).to_string(),
244 };
245 cells.push(Cell { mutant: m.into(), case: path.clone(), runner_codes: codes_of(&o), findings: rep.codes(), intended: intended.join("|"), verdict });
246 }
247 }
248 // ---- result-file mutants on honest spliced results ----
249 let honest_spliced = |p: &str| {
250 let (path, c, cb) = find(p);
251 (path.clone(), splice(&honest_e(c), &honest_o(c)).unwrap(), cb.clone())
252 };
253 let mut file_cells: Vec<(&str, &str, &str, Box<dyn Fn(&mut ResultFile) -> Option<Vec<u8>>>)> = Vec::new();
254 file_cells.push(("F1-wrong-evidence-digest", "P2-kat", "E4-EVIDENCE-DIGEST", Box::new(|r: &mut ResultFile| {
255 let mut b = r.evidence_digest.clone().into_bytes();
256 b[0] = if b[0] == b'0' { b'1' } else { b'0' };
257 r.evidence_digest = String::from_utf8(b).unwrap();
258 Some(r.bytes())
259 })));
260 file_cells.push(("F2-wrong-verdict-id", "P2-kat", "E4-VERDICT-ID", Box::new(|r: &mut ResultFile| {
261 let mut b = r.verdict_id.clone().into_bytes();
262 b[5] = if b[5] == b'0' { b'1' } else { b'0' };
263 r.verdict_id = String::from_utf8(b).unwrap();
264 r.evidence_digest = r.compute_evidence();
265 Some(r.bytes())
266 })));
267 file_cells.push(("F3-dropped-line", "P2-kat", "E4-PARSE", Box::new(|r: &mut ResultFile| {
268 let mut l = r.lines();
269 let i = l.iter().position(|x| x.starts_with("pauli 1 Y PLUS ")).unwrap();
270 l.remove(i);
271 Some(crate::text::join_lf(&l))
272 })));
273 file_cells.push(("F4-outcome-lie", "N1-p2", "E4-OUTCOME-MISMATCH", Box::new(|r: &mut ResultFile| {
274 r.verdict.outcome = "PASS".into();
275 r.seal();
276 Some(r.bytes())
277 })));
278 file_cells.push(("F5-codes-lie", "N4a", "E4-CODES-MISMATCH", Box::new(|r: &mut ResultFile| {
279 r.verdict.failure_codes.retain(|x| x != "PROBABILITY_SUM_EXCEEDED");
280 r.seal();
281 Some(r.bytes())
282 })));
283 file_cells.push(("F6-check-lie", "N1-p2", "E4-CHECK-MISMATCH", Box::new(|r: &mut ResultFile| {
284 r.verdict.checks[9] = Ck::Pass;
285 r.seal();
286 Some(r.bytes())
287 })));
288 file_cells.push(("F7-expectation-lie", "P2-kat", "E4-EXPECTATION-MISMATCH", Box::new(|r: &mut ResultFile| {
289 r.verdict.expectation = "NO".into();
290 r.seal();
291 Some(r.bytes())
292 })));
293 file_cells.push(("F8-oracle-is-engine", "P2-kat", "E4-PROV-ORACLE-IS-ENGINE", Box::new(|r: &mut ResultFile| {
294 r.prov.oracle_sha256 = r.prov.engine_sha256.clone();
295 r.seal();
296 Some(r.bytes())
297 })));
298 file_cells.push(("F10-time-order", "P2-kat", "E4-PROV-TIME-ORDER", Box::new(|r: &mut ResultFile| {
299 r.prov.run_started = "2026-10-09T00:00:01Z".into();
300 r.seal();
301 Some(r.bytes())
302 })));
303 file_cells.push(("F11-case-sha", "P2-kat", "E4-CASE-SHA", Box::new(|r: &mut ResultFile| {
304 r.case_file_sha256 = crate::sha256::sha256_hex(b"not the case");
305 r.seal();
306 Some(r.bytes())
307 })));
308 file_cells.push(("F12-undefined-on-defined", "P2-kat", "E4-UNDEFINED-DISCIPLINE", Box::new(|r: &mut ResultFile| {
309 r.pauli[1][2][0] = RVal::undefined();
310 let nt = !crate::verify::claims_trivial(r);
311 r.verdict = crate::judge::rederive(r, nt);
312 r.seal();
313 Some(r.bytes())
314 })));
315 file_cells.push(("F13-trivial-shape", "N2-every", "E4-TRIVIAL-SHAPE", Box::new(|r: &mut ResultFile| {
316 r.povm = RVal::undefined();
317 let nt = !crate::verify::claims_trivial(r);
318 r.verdict = crate::judge::rederive(r, nt);
319 r.seal();
320 Some(r.bytes())
321 })));
322 file_cells.push(("F14-nonfinite-value", "P2-kat", "E4-EXPECTATION-NOT-MET", Box::new(|r: &mut ResultFile| {
323 r.pauli[0][0][0] = RVal { kind: Kind::Nonfinite, bound: r.pauli[0][0][0].bound.clone() };
324 let nt = !crate::verify::claims_trivial(r);
325 r.verdict = crate::judge::rederive(r, nt);
326 r.seal();
327 Some(r.bytes())
328 })));
329 file_cells.push(("F15-dirty-tree", "P2-kat", "E4-PROV-DIRTY-TREE", Box::new(|r: &mut ResultFile| {
330 r.prov.source_tree_clean = "NO".into();
331 r.seal();
332 Some(r.bytes())
333 })));
334 file_cells.push(("F16-unknown-contract", "P2-kat", "E4-PROV-CONTRACT-UNKNOWN", Box::new(|r: &mut ResultFile| {
335 r.prov.contract_commit = "1111111111111111111111111111111111111111".into();
336 r.seal();
337 Some(r.bytes())
338 })));
339 file_cells.push(("F17-wrong-kernel-dim", "P2-kat", "E4-SHADOW-KERNEL-DIM", Box::new(|r: &mut ResultFile| {
340 r.kernel_dim = 3;
341 r.seal();
342 Some(r.bytes())
343 })));
344 file_cells.push(("F18-label-status-lie", "N3-zero", "E4-LABEL-RULE", Box::new(|r: &mut ResultFile| {
345 // label 2 (p = 0) claimed DEFINED with label 1's Pauli values
346 r.label[2] = Status::Defined;
347 r.pauli[2] = r.pauli[1].clone();
348 let nt = !crate::verify::claims_trivial(r);
349 r.verdict = crate::judge::rederive(r, nt);
350 r.seal();
351 Some(r.bytes())
352 })));
353 // F19/F20 (review finding 1): every reference_ideal value forged to 1/2 behind a bound of 1,
354 // on a case where no check reads reference_ideal (INTERACTING target) and on a trivial kernel
355 for (name, cp) in [("F19-wide-bound-reference-ideal", "P2-kat"), ("F20-wide-bound-reference-ideal-trivial", "N2-every")] {
356 file_cells.push((name, cp, "E4-ORACLE-IDEAL", Box::new(|r: &mut ResultFile| {
357 let wide = crate::rat::parse_scaled("1@0").expect("bound literal").0;
358 for k in 0..r.ref_ideal.len() {
359 for a in 0..3 {
360 for g in 0..2 {
361 r.ref_ideal[k][a][g] = crate::result::RVal::of(0.5, &wide);
362 }
363 }
364 }
365 r.seal();
366 Some(r.bytes())
367 })));
368 }
369 for (m, cp, intended, f) in file_cells.iter() {
370 let (path, mut r, cb) = honest_spliced(cp);
371 let b = f(&mut r).unwrap();
372 let rep = verify(&b, Some(&cb), Role::Candidate);
373 let fails: Vec<String> = rep.findings.iter().filter(|f| f.sev == Sev::Fail).map(|f| f.code.clone()).collect();
374 let flagged: Vec<String> = rep.findings.iter().filter(|f| f.sev != Sev::Fail).map(|f| f.code.clone()).collect();
375 let allowed: Vec<&str> = match *m {
376 "F12-undefined-on-defined" | "F18-label-status-lie" => vec!["E4-EXPECTATION-NOT-MET", "E4-SHADOW-LABEL"],
377 _ => vec![],
378 };
379 let v = judge_cell(&fails, &flagged, &[intended], &allowed);
380 let rc = crate::result::parse(&b).map(|x| codes_of(&x)).unwrap_or_else(|_| "unparsed".into());
381 cells.push(Cell { mutant: m.to_string(), case: path, runner_codes: rc, findings: rep.codes(), intended: intended.to_string(), verdict: v.into() });
382 }
383 // F9: an oracle record handed in as a candidate result
384 {
385 let (path, c, cb) = find("P2-kat");
386 let o = honest_o(c);
387 let rep = verify(&o.bytes(), Some(cb), Role::Candidate);
388 let fails: Vec<String> = rep.findings.iter().filter(|f| f.sev == Sev::Fail).map(|f| f.code.clone()).collect();
389 let flagged: Vec<String> = rep.findings.iter().filter(|f| f.sev != Sev::Fail).map(|f| f.code.clone()).collect();
390 let v = judge_cell(&fails, &flagged, &["E4-PROV-ORACLE-RECORD"], &[]);
391 cells.push(Cell { mutant: "F9-oracle-record-as-candidate".into(), case: path.clone(), runner_codes: codes_of(&o), findings: rep.codes(), intended: "E4-PROV-ORACLE-RECORD".into(), verdict: v.into() });
392 }
393 // ---- honest controls: every valid public case must verify PASS with no finding ----
394 let mut honest_bad = 0;
395 for (path, c, cb) in cases.iter() {
396 let r = splice(&honest_e(c), &honest_o(c)).unwrap();
397 let rep = verify(&r.bytes(), Some(cb), Role::Candidate);
398 let ro = verify(&honest_o(c).bytes(), Some(cb), Role::Oracle);
399 let v = if rep.status() == "PASS" && ro.status() == "PASS" { "PASS" } else { honest_bad += 1; "FAIL" };
400 let mut f = rep.codes();
401 f.extend(ro.codes().into_iter().map(|x| format!("oracle:{}", x)));
402 cells.push(Cell { mutant: "honest".into(), case: path.clone(), runner_codes: codes_of(&r), findings: f, intended: "no finding".into(), verdict: v.into() });
403 }
404 // ---- write ----
405 let mut s = String::from("# AT-1 Agent 4 mutant kill receipt (generated by `at1-eval mutants`; deterministic)\n# mutant\tcase\trunner_failure_codes\tverifier_findings\tintended\tverdict\n");
406 let mut bad = honest_bad;
407 let mut tally: std::collections::BTreeMap<String, (usize, usize, usize, usize)> = Default::default();
408 for c in &cells {
409 s.push_str(&format!("{}\t{}\t{}\t{}\t{}\t{}\n", c.mutant, c.case, c.runner_codes, if c.findings.is_empty() { "none".into() } else { c.findings.join(",") }, c.intended, c.verdict));
410 let t = tally.entry(c.mutant.clone()).or_default();
411 if c.mutant == "honest" {
412 continue;
413 }
414 if c.verdict.starts_with("KILLED") || c.verdict.starts_with("FLAGGED") {
415 t.0 += 1;
416 } else if c.verdict == "BLIND (predicted)" {
417 t.1 += 1;
418 } else {
419 t.2 += 1;
420 bad += 1;
421 }
422 t.3 += 1;
423 }
424 s.push_str("# summary: mutant\tkilled_or_flagged\tblind_explained\tunexpected\tcells\n");
425 for (m, t) in &tally {
426 if m == "honest" {
427 continue;
428 }
429 s.push_str(&format!("# {}\t{}\t{}\t{}\t{}\n", m, t.0, t.1, t.2, t.3));
430 }
431 s.push_str(&format!("# honest controls failing: {}\n# MUTANT_RECEIPT: {}\n", honest_bad, if bad == 0 { "PASS" } else { "FAIL" }));
432 if let Some(parent) = std::path::Path::new(out).parent() {
433 let _ = std::fs::create_dir_all(parent);
434 }
435 std::fs::write(out, s.as_bytes()).expect("write receipt");
436 println!("MUTANT_RECEIPT: {} ({} cells, {} unexpected) -> {}", if bad == 0 { "PASS" } else { "FAIL" }, cells.len(), bad, out);
437 if bad == 0 { 0 } else { 1 }
438}