From 30daff8822d77a87061b7f8b6c11f9adf653f321 Mon Sep 17 00:00:00 2001 From: Meta Vens Date: Wed, 16 Sep 2026 18:06:51 +0200 Subject: [PATCH] Pin the nineteen rules Cut 8 held but nothing tested Soul's pass found the suite claimed more than it proved: H1-H20 killed twenty mutations, and nineteen further permissivenesses could be restored with every test still green. A rule no test reaches is a rule the next pass may delete by accident. Two of them were about the receipt's atomicity and its reach, and needed new machinery. A store in `receipt.rs`'s tests records the replacement set of every swap it is asked for, which lets one test say what no assertion over the resulting image could: a commit is one compare-and-swap, and the documents and their receipt go in it together. Splitting the receipt into a second swap now fails. Separately, a batch citing three image documents is pinned against all three, so truncating the strong reads to the first of them fails. The rest are one fixture apiece, each closing a row the per-kind rules already held: stewardship looked up in image as well as batch; the cut report's repo as well as its branch; a promise measured by the claim that names that label; the invariant vocabulary taken from the in-force target and not a superseded one; a question that is answered or withdrawn but never superseded, and a target never answered; the derived stewardship dated by the hand-off; derived writes passing A3-A7, so a derived identity the batch already holds is A4's refusal and not a store error; A4 and A2 themselves; a question's two distinct options and its recommendation among them; unique labels on a question's options and a target's invariants; a finding's locations; and an `Answered` naming the ruling that actually answers its subject. `tools/eureka-cut8-mutations.psd1` grows to H1-H39. H21 and H22 pin the opener's epoch key and count, H23 `EmptyRepos`; the rest are Soul's own survivors, adopted as entries so the thing that found them is the thing that guards them. Harness: M0 green at 31 tests, H1-H39 all killed by their own test. Co-Authored-By: Claude Fable 5.1 --- crates/huginn-mind/src/admission.rs | 148 ++++++++++++++++++- crates/huginn-mind/src/receipt.rs | 78 +++++++++- tools/eureka-cut8-mutations.psd1 | 218 +++++++++++++++++++++++++++- 3 files changed, 438 insertions(+), 6 deletions(-) diff --git a/crates/huginn-mind/src/admission.rs b/crates/huginn-mind/src/admission.rs index 121721c..f89d9d1 100644 --- a/crates/huginn-mind/src/admission.rs +++ b/crates/huginn-mind/src/admission.rs @@ -1043,9 +1043,23 @@ mod tests { committed(admit(&mut mind, vec![resolution(nested.clone(), withdrawn())])); // Refused, one per kind, and every non-resolvable kind. - assert_eq!(refusal(admit(&mut world(), vec![resolution(target_ref, withdrawn())])), incompatible(K::Target, "Withdrawn")); - assert_eq!(refusal(admit(&mut world(), vec![resolution(question_ref, fixed())])), incompatible(K::Question, "Fixed")); - assert_eq!(refusal(admit(&mut world(), vec![resolution(ruling_ref, withdrawn())])), incompatible(K::Ruling, "Withdrawn")); + assert_eq!(refusal(admit(&mut world(), vec![resolution(target_ref.clone(), withdrawn())])), incompatible(K::Target, "Withdrawn")); + assert_eq!(refusal(admit(&mut world(), vec![resolution(question_ref.clone(), fixed())])), incompatible(K::Question, "Fixed")); + assert_eq!(refusal(admit(&mut world(), vec![resolution(ruling_ref.clone(), withdrawn())])), incompatible(K::Ruling, "Withdrawn")); + // A kind admits the outcomes of its own row and no others: a question + // is answered or withdrawn, never superseded; a target is superseded, + // never answered. + assert_eq!( + refusal(admit(&mut world(), vec![ + question("Q2", &["A", "B"], "A"), + resolution(question_ref, superseded(&[r(K::Question, &id("question", "Q2"))])), + ])), + incompatible(K::Question, "Superseded") + ); + assert_eq!( + refusal(admit(&mut world(), vec![resolution(target_ref, ResolutionOutcome::Answered { by: ruling_ref })])), + incompatible(K::Target, "Answered") + ); assert_eq!( refusal(admit(&mut world(), vec![resolution(spec_ref.clone(), ResolutionOutcome::Answered { by: r(K::Ruling, &id("ruling", "R1")) })])), incompatible(K::CutSpec, "Answered") @@ -1124,6 +1138,84 @@ mod tests { again.answers = Some(s(&id("question", "Q1"))); again.choice = Some(l("B")); assert_eq!(refusal(admit(&mut mind, vec![D::Ruling(again)])), MindRefusal::AlreadyResolved { subject: id("question", "Q1") }); + + // An explicit `Answered` must name the ruling that actually answers + // its subject: a ruling answering Q1 does not resolve Q2. + let mut mind = seeded(); + committed(admit(&mut mind, vec![question("Q1", &["A", "B"], "A"), question("Q2", &["A", "B"], "A")])); + let mut answering = ruling("R1"); + answering.answers = Some(s(&id("question", "Q1"))); + answering.choice = Some(l("A")); + let wrong = resolution(r(K::Question, &id("question", "Q2")), ResolutionOutcome::Answered { by: r(K::Ruling, &id("ruling", "R1")) }); + assert_eq!( + refusal(admit(&mut mind, vec![D::Ruling(answering), wrong])), + MindRefusal::IncompatibleResolution { subject_kind: K::Question, outcome: "Answered".into() } + ); + } + + #[test] + fn a_batch_is_one_to_sixty_four_documents_each_with_its_own_identity() { + let mut mind = seeded(); + // A2 at both ends, and at the boundary the batch is admitted whole. + assert_eq!(refusal(admit(&mut mind, vec![])), MindRefusal::BatchSize { actual: 0 }); + let over = (0..65).map(|index| question(&format!("Q{index}"), &["A", "B"], "A")).collect::>(); + assert_eq!(refusal(admit(&mut mind, over)), MindRefusal::BatchSize { actual: 65 }); + let full = (0..BATCH_MAX).map(|index| question(&format!("Q{index}"), &["A", "B"], "A")).collect::>(); + let (_, writes) = committed(admit(&mut mind, full)); + assert_eq!(writes.len(), BATCH_MAX); + // A4: one identity, once, whatever the two documents say. + assert_eq!( + refusal(admit(&mut mind, vec![question("Z", &["A", "B"], "A"), question("Z", &["A", "B"], "B")])), + MindRefusal::IdentityCollision { kind: K::Question, id: id("question", "Z") } + ); + } + + #[test] + fn a_question_offers_at_least_two_options_and_recommends_one_of_them() { + let mut mind = seeded(); + assert_eq!( + refusal(admit(&mut mind, vec![question("Q7", &["A"], "A")])), + MindRefusal::InvalidOptions { question: id("question", "Q7") } + ); + assert_eq!( + refusal(admit(&mut mind, vec![question("Q8", &["A", "B"], "C")])), + MindRefusal::InvalidOptions { question: id("question", "Q8") } + ); + committed(admit(&mut mind, vec![question("Q9", &["A", "B"], "B")])); + } + + #[test] + fn a_label_names_one_option_and_one_invariant() { + let mut mind = seeded(); + assert_eq!( + refusal(admit(&mut mind, vec![question("Q1", &["A", "A"], "A")])), + MindRefusal::DuplicateLabel { field: "question.options".into(), label: "A".into() } + ); + assert_eq!( + refusal(admit(&mut mind, vec![ + target(2, &["x", "x"]), + resolution(r(K::Target, &id("target", "r1")), superseded(&[r(K::Target, &id("target", "r2"))])), + ])), + MindRefusal::DuplicateLabel { field: "target.invariants".into(), label: "x".into() } + ); + } + + /// Every A7 reference the image resolved is pinned, not the first of + /// them, so a batch citing three documents cannot commit over a change to + /// the other two. + #[test] + fn every_cited_image_document_is_a_strong_read() { + let mut mind = seeded(); + committed(admit(&mut mind, vec![D::Ruling(ruling("R1")), D::Ruling(ruling("R2")), D::Ruling(ruling("R3"))])); + let cited = ["R1", "R2", "R3"].map(|label| mind.envelope(K::Ruling, &id("ruling", label)).unwrap().clone()); + let mut spec = cut_spec("1", 1); + spec.rulings = cited.iter().map(|envelope| s(&envelope.key)).collect(); + let (receipt_id, _) = committed(admit(&mut mind, vec![D::CutSpec(spec)])); + let receipt = mind.receipts().unwrap().into_iter().find(|receipt| receipt.receipt_id == receipt_id).unwrap(); + assert_eq!(receipt.strong_reads.len(), 3); + for envelope in &cited { + assert!(receipt.strong_reads.contains(&DocumentVersion::from_envelope(envelope)), "{}", envelope.key); + } } #[test] @@ -1170,6 +1262,9 @@ mod tests { report.branch = s("another-branch"); assert_eq!(refusal(admit(&mut mind, vec![D::CutReport(report)])), MindRefusal::SpecMismatch { field: "branch".into() }); let mut report = cut_report("1", 1); + report.repo = repo(OTHER_REPO); + assert_eq!(refusal(admit(&mut mind, vec![D::CutReport(report)])), MindRefusal::SpecMismatch { field: "repo".into() }); + let mut report = cut_report("1", 1); report.range.head = epiphany_pipeline::Sha("abcdef0".into()); assert_eq!(refusal(admit(&mut mind, vec![D::CutReport(report)])), MindRefusal::RangeOutsideCommits { head: "abcdef0".into() }); committed(admit(&mut mind, vec![resolution(r(K::CutSpec, &id("cut_spec", "cut-1.r1")), withdrawn())])); @@ -1207,6 +1302,12 @@ mod tests { ])])), MindRefusal::PromiseWithoutVerdict { promise: "P1".into() } ); + // A promise is measured by the claim that names it, not by any claim + // that names a promise: the report promises P1 and nothing else. + assert_eq!( + refusal(admit(&mut mind, vec![verdict("1", 1, vec![claim(ClaimOutcome::Holds, &[], Some("P2"), &[])])])), + MindRefusal::PromiseWithoutVerdict { promise: "P1".into() } + ); assert_eq!( refusal(admit(&mut mind, vec![verdict("1", 1, vec![claim(ClaimOutcome::Holds, &[], Some("P1"), &["M9"])])])), MindRefusal::UnknownMutationLabel { label: "M9".into() } @@ -1228,6 +1329,11 @@ mod tests { let mut bare = finding("1", 1, "F1", FindingConfidence::Plausible); bare.evidence = vec![]; assert_eq!(refusal(admit(&mut mind, vec![D::Finding(bare)])), MindRefusal::FindingWithoutEvidence); + // Locations are evidence's other half: a finding that names no place + // in the code is refused the same way. + let mut placeless = finding("1", 1, "F1", FindingConfidence::Plausible); + placeless.locations = vec![]; + assert_eq!(refusal(admit(&mut mind, vec![D::Finding(placeless)])), MindRefusal::FindingWithoutEvidence); let mut unknown = finding("1", 1, "F1", FindingConfidence::Plausible); unknown.invariants = vec![l("nope")]; assert_eq!(refusal(admit(&mut mind, vec![D::Finding(unknown)])), MindRefusal::UnknownInvariant { label: "nope".into() }); @@ -1270,6 +1376,21 @@ mod tests { assert!( matches!(refusal(outcome), MindRefusal::Document(PipelineRefusal::InvalidFormat { field, .. }) if field == "payload") ); + + // The in-force target owns the invariant vocabulary. Supersede r1 with + // an r2 that drops its label, and the label is unknown again; r2's own + // label is what a finding may cite. + committed(admit(&mut mind, vec![ + target(2, &["other"]), + resolution(r(K::Target, &id("target", "r1")), superseded(&[r(K::Target, &id("target", "r2"))])), + ])); + assert_eq!( + refusal(admit(&mut mind, vec![D::Finding(finding("1", 1, "F2", FindingConfidence::Plausible))])), + MindRefusal::UnknownInvariant { label: INVARIANT.into() } + ); + let mut current = finding("1", 1, "F3", FindingConfidence::Plausible); + current.invariants = vec![l("other")]; + committed(admit(&mut mind, vec![D::Finding(current)])); } #[test] @@ -1289,6 +1410,11 @@ mod tests { refusal(admit(&mut mind, vec![D::Campaign(empty)])), MindRefusal::EmptyRepos { campaign: "other:campaign:self".into() } ); + // The stewardship may be held in the image: a later campaign over the + // same repo carries no stewardship of its own. + let D::Campaign(mut second) = campaign(&[REPO]) else { panic!() }; + second.slug = slug("second"); + committed(admit(&mut mind, vec![D::Campaign(second)])); let mut spec = cut_spec("1", 1); spec.repo = repo(OTHER_REPO); assert_eq!(refusal(admit(&mut mind, vec![D::CutSpec(spec)])), MindRefusal::RepoNotInCampaign { repo: OTHER_REPO.into() }); @@ -1324,7 +1450,23 @@ mod tests { let Some(D::Stewardship(derived)) = receiving.get(K::Stewardship, &assigned).unwrap() else { panic!() }; assert_eq!(derived.note, Line(key.clone())); assert_eq!(derived.instance, slug(OTHER_INSTANCE)); + // The stewardship starts the day the repo was handed over, not on some + // clock of admission's own. + assert_eq!(derived.assigned_on, date()); assert_eq!(source.envelope(K::HandOff, &key).map(|e| &e.payload), receiving.envelope(K::HandOff, &key).map(|e| &e.payload)); + + // A derived write passes A3-A7 like any other. A batch carrying its own + // stewardship of the repo collides with the derived one at A4, as a + // typed refusal, not as a duplicate identity the store complains about. + let mut colliding = opened(MemoryStore::new(), OTHER_INSTANCE); + committed(admit(&mut colliding, vec![instance(OTHER_INSTANCE)])); + assert_eq!( + refusal(admit(&mut colliding, vec![ + hand_off(INSTANCE, OTHER_INSTANCE, REPO, &[]), + stewardship(OTHER_INSTANCE, REPO), + ])), + MindRefusal::IdentityCollision { kind: K::Stewardship, id: assigned } + ); } /// The key of the resolution of a stewardship: the subject's root, then diff --git a/crates/huginn-mind/src/receipt.rs b/crates/huginn-mind/src/receipt.rs index 31d69f9..a2e8066 100644 --- a/crates/huginn-mind/src/receipt.rs +++ b/crates/huginn-mind/src/receipt.rs @@ -259,9 +259,83 @@ pub(crate) fn sha256_hex(bytes: &[u8]) -> String { #[cfg(test)] mod tests { + use std::sync::{Arc, Mutex}; + use super::*; - use crate::fixtures::{INSTANCE, instance, prepare}; - use epiphany_pipeline::{PipelineDocument, PipelineRefusal}; + use crate::fixtures::{INSTANCE, admit, committed, id, instance, opened, prepare, question, seed}; + use crate::store::test_stores::MemoryStore; + use cultcache_rs::{CacheBackingStore, PushAllOptions}; + use epiphany_pipeline::{PipelineDocument, PipelineKind, PipelineRefusal}; + + /// A memory store that keeps the replacement set of every swap it was + /// asked for, so a test can count the commit's calls as well as read + /// their contents. + #[derive(Clone)] + struct RecordingStore { + inner: MemoryStore, + calls: Arc>>>, + } + + impl RecordingStore { + fn new() -> Self { + Self { inner: MemoryStore::new(), calls: Arc::new(Mutex::new(Vec::new())) } + } + + fn forget(&self) { + self.calls.lock().unwrap().clear(); + } + + fn calls(&self) -> Vec> { + self.calls.lock().unwrap().clone() + } + } + + impl CacheBackingStore for RecordingStore { + fn pull_all(&self) -> anyhow::Result> { + self.inner.pull_all() + } + + fn push(&mut self, entry: &CultCacheEnvelope) -> anyhow::Result<()> { + self.inner.push(entry) + } + + fn delete(&mut self, entry: &CultCacheEnvelope) -> anyhow::Result<()> { + self.inner.delete(entry) + } + + fn push_all(&mut self, entries: &[CultCacheEnvelope], options: PushAllOptions) -> anyhow::Result<()> { + self.inner.push_all(entries, options) + } + } + + impl MindStore for RecordingStore { + fn compare_and_swap_batch( + &self, + expected: &[CultCacheEnvelope], + replacements: Vec, + ) -> anyhow::Result { + self.calls.lock().unwrap().push(replacements.clone()); + self.inner.compare_and_swap_batch(expected, replacements) + } + } + + /// The receipt is part of the batch's own swap, never a second one after + /// it: a receipt written separately could land while the documents did + /// not, or the reverse. + #[test] + fn a_commit_is_one_swap_carrying_the_documents_and_the_receipt_together() { + let store = RecordingStore::new(); + let mut mind = opened(store.clone(), INSTANCE); + seed(&mut mind); + store.forget(); + let (receipt_id, _) = committed(admit(&mut mind, vec![question("Q1", &["A", "B"], "A")])); + let calls = store.calls(); + assert_eq!(calls.len(), 1, "one commit, one swap"); + let landed = calls[0].iter().map(|entry| (entry.r#type.clone(), entry.key.clone())).collect::>(); + assert_eq!(landed.len(), 2, "{landed:?}"); + assert!(landed.contains(&(PipelineKind::Question.type_id().to_string(), id("question", "Q1"))), "{landed:?}"); + assert!(landed.contains(&(HuginnCommitReceipt::TYPE.to_string(), receipt_id)), "{landed:?}"); + } /// S5 closed against the real type: the organ's own receipt in a mind's /// store is never decoded as a pipeline document. diff --git a/tools/eureka-cut8-mutations.psd1 b/tools/eureka-cut8-mutations.psd1 index 653f5e9..9086272 100644 --- a/tools/eureka-cut8-mutations.psd1 +++ b/tools/eureka-cut8-mutations.psd1 @@ -1,4 +1,4 @@ -# Cut 8 mutations, H1-H20: each entry restores one permissiveness the cut +# Cut 8 mutations, H1-H39: each entry restores one permissiveness the cut # closed and names the test that must fail while it is applied. Run through # Epiphany's harness from this repo: # @@ -270,5 +270,221 @@ impl MindStore for OwnedRedbMessagePackBackingStore { '@ New = '' } + @{ + Id = 'H21' + Rule = 'Opener step 3: the epoch record is the record under the epoch''s own key; any other key is not it.' + Test = 'mind::tests::the_opener_refuses_foreign_epoch_missing_identity_and_foreign_type_before_attaching' + File = 'crates/huginn-mind/src/mind.rs' + Old = @' + if record.key != PIPELINE_SCHEMA_EPOCH { + return Err(foreign(record.key.clone())); + } +'@ + New = '' + } + @{ + Id = 'H22' + Rule = 'Opener step 3: exactly one epoch record, counted before any value is read, so the store''s order cannot decide the outcome.' + Test = 'mind::tests::the_opener_refuses_foreign_epoch_missing_identity_and_foreign_type_before_attaching' + File = 'crates/huginn-mind/src/mind.rs' + Old = @' + let extra = records.count(); + if extra > 0 { + return Err(foreign(format!("{} records", extra + 1))); + } +'@ + New = '' + } + @{ + Id = 'H23' + Rule = 'campaign: a campaign of no repos is refused, and by the organ''s own refusal (EmptyRepos), not a minted leaf bound.' + Test = 'admission::tests::a_campaign_names_only_repos_this_mind_stewards' + File = 'crates/huginn-mind/src/admission.rs' + Old = @' + if campaign.repos.is_empty() { + return Err(MindRefusal::EmptyRepos { campaign: key.into() }); + } +'@ + New = '' + } + @{ + Id = 'H24' + Rule = 'A11: the receipt lands inside the batch''s own compare-and-swap, never in a second one after it.' + Test = 'receipt::tests::a_commit_is_one_swap_carrying_the_documents_and_the_receipt_together' + File = 'crates/huginn-mind/src/receipt.rs' + Old = @' + replacements.push(receipt_envelope); + let expected: &[CultCacheEnvelope] = &strong_reads; + let landed = MindStore::compare_and_swap_batch(mind.store(), expected, replacements).map_err(unavailable)?; +'@ + New = @' + let expected: &[CultCacheEnvelope] = &strong_reads; + let landed = MindStore::compare_and_swap_batch(mind.store(), expected, replacements).map_err(unavailable)?; + let landed = landed && MindStore::compare_and_swap_batch(mind.store(), &[], vec![receipt_envelope]).map_err(unavailable)?; +'@ + } + @{ + Id = 'H25' + Rule = 'A7: every reference the image resolved is pinned as a strong read, not the first of them.' + Test = 'admission::tests::every_cited_image_document_is_a_strong_read' + File = 'crates/huginn-mind/src/admission.rs' + Old = @' + .filter_map(|(type_id, key)| self.raw_envelope(type_id, key).cloned()) + .collect::>(); +'@ + New = @' + .filter_map(|(type_id, key)| self.raw_envelope(type_id, key).cloned()) + .take(1) + .collect::>(); +'@ + } + @{ + Id = 'H26' + Rule = 'campaign: stewardship is looked for in image and batch, not in the batch alone.' + Test = 'admission::tests::a_campaign_names_only_repos_this_mind_stewards' + File = 'crates/huginn-mind/src/admission.rs' + Old = ' if docs.stewardship_of(mind, repo, None).is_none() {' + New = ' if !docs.batch.iter().any(|staged| matches!(&staged.document, D::Stewardship(stewardship) if stewardship.repo == *repo)) {' + } + @{ + Id = 'H27' + Rule = 'cut_report: the report''s repo must equal its spec''s, not only its branch.' + Test = 'admission::tests::a_cut_report_cites_an_in_force_spec_and_agrees_with_it' + File = 'crates/huginn-mind/src/admission.rs' + Old = @' + if report.repo != spec.repo { + return Err(MindRefusal::SpecMismatch { field: "repo".into() }); + } +'@ + New = '' + } + @{ + Id = 'H28' + Rule = 'Ruling A: a promise is measured by the claim naming that label, not by any claim naming any promise.' + Test = 'admission::tests::verdict_vocabulary_binds_claims_to_findings_promises_and_mutations' + File = 'crates/huginn-mind/src/admission.rs' + Old = ' let count = verdict.claims.iter().filter(|claim| claim.promise.as_ref() == Some(&promise.label)).count();' + New = ' let count = verdict.claims.iter().filter(|claim| claim.promise.is_some()).count();' + } + @{ + Id = 'H29' + Rule = 'finding: the invariant vocabulary is the in-force target''s, not any target the campaign ever had.' + Test = 'admission::tests::a_finding_names_evidence_locations_and_known_invariants' + File = 'crates/huginn-mind/src/admission.rs' + Old = ' D::Target(target) if target.campaign == finding.campaign && docs.in_force(K::Target, target_key) => Some(target),' + New = ' D::Target(target) if target.campaign == finding.campaign && (docs.in_force(K::Target, target_key) || true) => Some(target),' + } + @{ + Id = 'H30' + Rule = 'The matrix is one row per kind: a question is answered or withdrawn, never superseded.' + Test = 'admission::tests::the_resolution_matrix_is_admissions' + File = 'crates/huginn-mind/src/admission.rs' + Old = @' + (K::Question, O::Withdrawn { .. }) => true, +'@ + New = @' + (K::Question, O::Withdrawn { .. }) => true, + (K::Question, O::Superseded { by }) => all(by, K::Question), +'@ + } + @{ + Id = 'H31' + Rule = 'hand_off: the derived stewardship starts on the day the repo was handed over.' + Test = 'admission::tests::a_hand_off_derives_this_minds_side_only' + File = 'crates/huginn-mind/src/admission.rs' + Old = ' assigned_on: hand_off.handed_on.clone(),' + New = ' assigned_on: epiphany_pipeline::Date("2026-01-01".into()),' + } + @{ + Id = 'H32' + Rule = 'Derived writes pass A3-A7 like any other; a derived identity the batch already holds is A4''s refusal, not a store error.' + Test = 'admission::tests::a_hand_off_derives_this_minds_side_only' + File = 'crates/huginn-mind/src/admission.rs' + Old = @' + for document in derive(&docs, &mind) { + document.validate()?; + let envelope = document.prepare(self.cache()).map_err(unavailable)?; + docs.push(stage(envelope, &mind)?)?; + } + for staged in &docs.batch[originals..] { + resolve(&docs, staged, &mind, &mut strong)?; + } +'@ + New = @' + for document in derive(&docs, &mind) { + let envelope = document.prepare(self.cache()).map_err(unavailable)?; + docs.batch.push(Staged { kind: document.kind(), key: envelope.key.clone(), document, envelope }); + } + let _ = originals; +'@ + } + @{ + Id = 'H33' + Rule = 'A4: one identity, once, within a batch.' + Test = 'admission::tests::a_batch_is_one_to_sixty_four_documents_each_with_its_own_identity' + File = 'crates/huginn-mind/src/admission.rs' + Old = @' + if self.batch.iter().any(|other| other.kind == staged.kind && other.key == staged.key) { + return Err(MindRefusal::IdentityCollision { kind: staged.kind, id: staged.key }); + } +'@ + New = '' + } + @{ + Id = 'H34' + Rule = 'A2: one to sixty-four envelopes, both ends checked.' + Test = 'admission::tests::a_batch_is_one_to_sixty_four_documents_each_with_its_own_identity' + File = 'crates/huginn-mind/src/admission.rs' + Old = ' if envelopes.is_empty() || envelopes.len() > BATCH_MAX {' + New = ' if false {' + } + @{ + Id = 'H35' + Rule = 'question: a question offers a real choice, at least two options, one of them the recommendation.' + Test = 'admission::tests::a_question_offers_at_least_two_options_and_recommends_one_of_them' + File = 'crates/huginn-mind/src/admission.rs' + Old = @' + if question.options.len() < 2 || !question.options.iter().any(|option| option.label == question.recommended) { + return Err(MindRefusal::InvalidOptions { question: key.into() }); + } +'@ + New = '' + } + @{ + Id = 'H36' + Rule = 'question: an option label names one option.' + Test = 'admission::tests::a_label_names_one_option_and_one_invariant' + File = 'crates/huginn-mind/src/admission.rs' + Old = ' unique_labels("question.options", question.options.iter().map(|option| option.label.0.as_str()))' + New = ' Ok(())' + } + @{ + Id = 'H37' + Rule = 'target: an invariant label names one invariant.' + Test = 'admission::tests::a_label_names_one_option_and_one_invariant' + File = 'crates/huginn-mind/src/admission.rs' + Old = ' unique_labels("target.invariants", target.invariants.iter().map(|invariant| invariant.label.0.as_str()))' + New = ' Ok(())' + } + @{ + Id = 'H38' + Rule = 'finding: a finding names where in the code it lives, not only that evidence exists.' + Test = 'admission::tests::a_finding_names_evidence_locations_and_known_invariants' + File = 'crates/huginn-mind/src/admission.rs' + Old = ' if finding.evidence.is_empty() || finding.locations.is_empty() {' + New = ' if finding.evidence.is_empty() {' + } + @{ + Id = 'H39' + Rule = 'resolution: an Answered names the ruling that answers this subject, not some other question''s ruling.' + Test = 'admission::tests::a_ruling_answering_a_question_derives_the_answered_resolution_atomically' + File = 'crates/huginn-mind/src/admission.rs' + Old = @' + if ruling.answers.as_ref().map(|answers| answers.0.as_str()) != Some(subject_id) { + return Err(incompatible()); + } +'@ + New = ' let _ = (ruling, subject_id);' + } ) }