Move every derivation out of admission into docs.rs

`Docs`, `Staged`, `Held`, `kind_of_type` and `later_than` leave
`admission.rs` whole and land in `src/docs.rs`, so the read side of Cut 9
can reach the derivations without admission exporting its internals. One
owner for in force: the views will call the same `Docs` the rules do,
never a second copy.

Three edits ride along, each an extraction the views need and admission
now runs through:

- `closing_resolution_unless` is `in_force_unless`'s body, returning the
  resolution that closes a document rather than a bool; `in_force_unless`
  is `.is_none()` over it.
- `resolutions_of` and `assignments_of` are the scope selectors
  `latest_resolution`, `latest_stewardship` and `stewardships_of` already
  spelled out one at a time.

Nothing else changes: same bodies, same call sites, `admission.rs` keeps
every rule and every `docs.` call reads as before. Its module doc says
where in force lives now.

Nine cut-8 entries re-anchor because their code moved: H33, H41, H62,
H63, H65, H66 and H67 by file, H47 and H60 on the scope selectors the
extraction introduced. Their rules are unchanged, and H49's mutant still
compiles because `Docs`'s fields are `pub(crate)`.

`cargo test -p huginn-mind --lib`: 46 passed, 0 failed, 0 warnings.
`eureka-cut8-mutations.psd1` through Epiphany's harness: M0 green,
H1-H67 all killed.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
This commit is contained in:
Meta Vens 2026-09-16 21:13:03 +02:00
commit 5ae34f8147
4 changed files with 291 additions and 233 deletions

View file

@ -22,22 +22,22 @@
//!
//! Every cross-field and cross-document rule lives here and nowhere else:
//! the leaf never gains one, the daemon and the client never re-derive one.
//! "In force" is recursive: a document is in force when no resolution that is
//! itself in force names it, so a withdrawn resolution stops closing its
//! subject. It is computed at rule time over image and batch, never stored.
//! In force, the sequences and the scopes are `docs.rs`'s, shared with the
//! views (Cut 9).
use std::collections::BTreeSet;
use chrono::{DateTime, Utc};
use cultcache_rs::CultCacheEnvelope;
use epiphany_pipeline::{
ClaimOutcome, FindingConfidence, Line, OrgRepo, PipelineDocument, PipelineKind, PipelineRef, PipelineRefusal,
ClaimOutcome, FindingConfidence, Line, PipelineDocument, PipelineKind, PipelineRef, PipelineRefusal,
PipelineResolution, PipelineStewardship, ResolutionOutcome, RulingAuthority, Short, Slug, pipeline_key,
validate_pipeline_write_envelope,
};
use schemars::JsonSchema;
use serde::{Deserialize, Serialize};
use crate::docs::{Docs, Staged};
use crate::mind::{HuginnMindEpoch, Mind, unavailable};
use crate::receipt::{self, CommitOutcome, PipelineProvenance};
use crate::refusal::MindRefusal;
@ -174,31 +174,6 @@ impl<S: MindStore> Mind<S> {
}
}
/// A batch document after A3 and A5: decoded, keyed, and its envelope.
struct Staged {
kind: PipelineKind,
key: String,
document: PipelineDocument,
envelope: CultCacheEnvelope,
}
/// An image document, decoded.
struct Held {
kind: PipelineKind,
key: String,
document: PipelineDocument,
}
/// The image and the batch, the two places a rule may look.
struct Docs {
image: Vec<Held>,
batch: Vec<Staged>,
}
fn kind_of_type(type_id: &str) -> Option<PipelineKind> {
PipelineKind::ALL.iter().copied().find(|kind| kind.type_id() == type_id)
}
/// The kind segment of a full id, for the one field typed `Short` whose
/// referent may be of any kind.
fn kind_of_id(id: &str) -> Option<PipelineKind> {
@ -206,169 +181,6 @@ fn kind_of_id(id: &str) -> Option<PipelineKind> {
PipelineKind::ALL.iter().copied().find(|kind| kind.name() == name)
}
impl Docs {
fn from_image(envelopes: &[CultCacheEnvelope]) -> Result<Self, MindRefusal> {
let mut image = Vec::new();
for envelope in envelopes {
let Some(kind) = kind_of_type(&envelope.r#type) else { continue };
let document = PipelineDocument::decode(envelope).map_err(|refusal| MindRefusal::Unavailable {
detail: format!("stored document {} does not decode: {refusal}", envelope.key),
})?;
image.push(Held { kind, key: envelope.key.clone(), document });
}
Ok(Self { image, batch: Vec::new() })
}
/// A4: one identity, once.
fn push(&mut self, staged: Staged) -> Result<(), MindRefusal> {
if self.batch.iter().any(|other| other.kind == staged.kind && other.key == staged.key) {
return Err(MindRefusal::IdentityCollision { kind: staged.kind, id: staged.key });
}
self.batch.push(staged);
Ok(())
}
fn in_batch(&self, kind: PipelineKind, id: &str) -> Option<&PipelineDocument> {
self.batch.iter().find(|staged| staged.kind == kind && staged.key == id).map(|staged| &staged.document)
}
fn in_image(&self, kind: PipelineKind, id: &str) -> Option<&PipelineDocument> {
self.image.iter().find(|held| held.kind == kind && held.key == id).map(|held| &held.document)
}
fn find(&self, kind: PipelineKind, id: &str) -> Option<&PipelineDocument> {
self.in_batch(kind, id).or_else(|| self.in_image(kind, id))
}
fn of_kind(&self, kind: PipelineKind) -> impl Iterator<Item = (&str, &PipelineDocument)> {
let batch = self.batch.iter().filter(move |staged| staged.kind == kind).map(|staged| (staged.key.as_str(), &staged.document));
let image = self.image.iter().filter(move |held| held.kind == kind).map(|held| (held.key.as_str(), &held.document));
batch.chain(image)
}
fn resolutions(&self) -> impl Iterator<Item = (&str, &PipelineResolution)> {
self.of_kind(PipelineKind::Resolution).filter_map(|(key, document)| match document {
PipelineDocument::Resolution(resolution) => Some((key, resolution)),
_ => None,
})
}
fn stewardships(&self) -> impl Iterator<Item = (&str, &PipelineStewardship)> {
self.of_kind(PipelineKind::Stewardship).filter_map(|(key, document)| match document {
PipelineDocument::Stewardship(stewardship) => Some((key, stewardship)),
_ => None,
})
}
/// The greatest sequence among a subject's resolutions in image or batch,
/// `0` when it has none, so the next is `latest + 1`. `own` is the
/// document being checked, excluded by content identity so that an exact
/// replay measures the same `latest` the first admission did.
fn latest_resolution(&self, subject: &PipelineRef, own: Option<&PipelineResolution>) -> u32 {
self.resolutions()
.filter(|(_, resolution)| resolution.subject == *subject && own != Some(*resolution))
.map(|(_, resolution)| resolution.sequence)
.max()
.unwrap_or(0)
}
/// The sequence a derivation takes: the one the record it already derived
/// carries, when image or batch holds that record, so an exact replay
/// re-derives the same document and A9 answers with the stored receipt;
/// otherwise the next. A derivation is recognised by what it writes into
/// its record: a resolution by its outcome, an assignment by its note.
fn derived_resolution_sequence(&self, subject: &PipelineRef, derived: impl Fn(&ResolutionOutcome) -> bool) -> u32 {
self.resolutions()
.find(|(_, resolution)| resolution.subject == *subject && derived(&resolution.outcome))
.map_or_else(|| self.latest_resolution(subject, None) + 1, |(_, resolution)| resolution.sequence)
}
/// The same for the assignment a hand-off derives, which notes its key.
fn derived_stewardship_sequence(&self, mind: &Slug, repo: &OrgRepo, note: &str) -> u32 {
self.stewardships()
.find(|(_, stewardship)| stewardship.instance == *mind && stewardship.repo == *repo && stewardship.note.0 == note)
.map_or_else(|| self.latest_stewardship(mind, repo, None) + 1, |(_, stewardship)| stewardship.sequence)
}
/// The same for a repo's assignments to one mind.
fn latest_stewardship(&self, mind: &Slug, repo: &OrgRepo, own: Option<&PipelineStewardship>) -> u32 {
self.stewardships()
.filter(|(_, stewardship)| stewardship.instance == *mind && stewardship.repo == *repo && own != Some(*stewardship))
.map(|(_, stewardship)| stewardship.sequence)
.max()
.unwrap_or(0)
}
/// No resolution that is itself in force names the document. The
/// recursion is the whole rule: a withdrawn resolution stops counting, so
/// its subject is open again. `key(R)` is strictly longer than the id it
/// resolves, so the chain is bounded and this terminates.
fn in_force(&self, kind: PipelineKind, id: &str) -> bool {
self.in_force_unless(kind, id, |_| false)
}
/// In force, ignoring a resolution the caller's own document is or
/// derives: the ruling that answers a question is what resolves it, the
/// hand-off that withdraws a stewardship is what resolves that, and a
/// resolution does not resolve its own subject out from under itself.
fn in_force_unless(&self, kind: PipelineKind, id: &str, own: impl Fn(&PipelineResolution) -> bool) -> bool {
!self.resolutions().any(|(key, resolution)| {
resolution.subject.kind == kind
&& resolution.subject.id.0 == id
&& !own(resolution)
&& self.in_force(PipelineKind::Resolution, key)
})
}
/// Every in-force stewardship of `(mind, repo)`, ignoring the withdrawal
/// `hand_off_key` derives. The stewardship row holds one in force at a
/// time, but that exclusion can put a second back in the list: the one a
/// replayed hand-off withdrew, beside whatever stewards the repo now.
fn stewardships_of(&self, mind: &Slug, repo: &OrgRepo, hand_off_key: Option<&str>) -> Vec<(&str, &PipelineStewardship)> {
self.stewardships()
.filter(|(key, stewardship)| {
stewardship.instance == *mind
&& stewardship.repo == *repo
&& self.in_force_unless(PipelineKind::Stewardship, key, |resolution| {
matches!(&resolution.outcome, ResolutionOutcome::Withdrawn { reason } if Some(reason.0.as_str()) == hand_off_key)
})
})
.collect()
}
/// The in-force record that stands later than `base` in the scope `base`
/// is sequenced in, if any: what a withdrawal that put `base` back in
/// force would leave standing beside it.
fn later_in_force(&self, base: &PipelineDocument) -> Option<&str> {
let kind = base.kind();
self.of_kind(kind).find(|(key, other)| later_than(base, other) && self.in_force(kind, key)).map(|(key, _)| key)
}
/// The stewardship of `(mind, repo)` a hand-off acts on: the one whose
/// withdrawal already carries `hand_off_key`, when image or batch holds
/// that withdrawal, so a replay derives the same withdrawal again and A9
/// answers with the stored receipt; otherwise the one in force. Key order
/// cannot pick between the two the exclusion leaves standing -- once a
/// repo has changed hands ten times, `n11` sorts before `n2` -- so the
/// content match picks, as it does for the sequence the other derivations
/// take.
fn stewardship_of(&self, mind: &Slug, repo: &OrgRepo, hand_off_key: Option<&str>) -> Option<(&str, &PipelineStewardship)> {
let candidates = self.stewardships_of(mind, repo, hand_off_key);
hand_off_key
.and_then(|hand_off| {
candidates.iter().find(|(key, _)| {
self.resolutions().any(|(_, resolution)| {
resolution.subject.kind == PipelineKind::Stewardship
&& resolution.subject.id.0 == *key
&& matches!(&resolution.outcome, ResolutionOutcome::Withdrawn { reason } if reason.0 == hand_off)
})
})
})
.or_else(|| candidates.first())
.copied()
}
}
/// A3 through the leaf, then A5.
fn stage(envelope: CultCacheEnvelope, mind: &Slug) -> Result<Staged, MindRefusal> {
validate_pipeline_write_envelope(&envelope)?;
@ -787,26 +599,6 @@ fn matrix(subject: PipelineKind, outcome: &ResolutionOutcome) -> bool {
fits
}
/// Whether `other` is a later record than `base` in the scope `base` is
/// sequenced in: `(instance, repo)` for a stewardship, the campaign for a
/// target and the cut for a cut spec. Kinds that carry no sequence have no
/// scope and no order, and a resolution is never a base here: the cap above
/// refuses the withdrawal that would reinstate one before the question of a
/// later record arises.
fn later_than(base: &PipelineDocument, other: &PipelineDocument) -> bool {
use PipelineDocument as D;
match (base, other) {
(D::Stewardship(base), D::Stewardship(other)) => {
other.instance == base.instance && other.repo == base.repo && other.sequence > base.sequence
}
(D::Target(base), D::Target(other)) => other.campaign == base.campaign && other.revision > base.revision,
(D::CutSpec(base), D::CutSpec(other)) => {
other.campaign == base.campaign && other.cut == base.cut && other.revision > base.revision
}
_ => false,
}
}
/// The resolution row: the sequence, the in-force subject, the matrix, the
/// Q19 cap and the reinstatement rule it rests on, a non-empty supersession,
/// every referent in force, and the two

View file

@ -0,0 +1,259 @@
//! The image and the batch, the two places a rule or a view may look, and
//! every derivation over them. "In force" is recursive: a document is in force
//! when no resolution that is itself in force names it, so a withdrawn
//! resolution stops closing its subject. Computed over image and batch at rule
//! time, over the image at read time, never stored, and never from
//! `stored_at`.
use cultcache_rs::CultCacheEnvelope;
use epiphany_pipeline::{
OrgRepo, PipelineDocument, PipelineKind, PipelineRef, PipelineResolution, PipelineStewardship, ResolutionOutcome,
Slug,
};
use crate::refusal::MindRefusal;
/// A batch document after A3 and A5: decoded, keyed, and its envelope.
pub(crate) struct Staged {
pub(crate) kind: PipelineKind,
pub(crate) key: String,
pub(crate) document: PipelineDocument,
pub(crate) envelope: CultCacheEnvelope,
}
/// An image document, decoded.
pub(crate) struct Held {
pub(crate) kind: PipelineKind,
pub(crate) key: String,
pub(crate) document: PipelineDocument,
}
/// The image and the batch, the two places a rule may look.
pub(crate) struct Docs {
pub(crate) image: Vec<Held>,
pub(crate) batch: Vec<Staged>,
}
fn kind_of_type(type_id: &str) -> Option<PipelineKind> {
PipelineKind::ALL.iter().copied().find(|kind| kind.type_id() == type_id)
}
impl Docs {
pub(crate) fn from_image(envelopes: &[CultCacheEnvelope]) -> Result<Self, MindRefusal> {
let mut image = Vec::new();
for envelope in envelopes {
let Some(kind) = kind_of_type(&envelope.r#type) else { continue };
let document = PipelineDocument::decode(envelope).map_err(|refusal| MindRefusal::Unavailable {
detail: format!("stored document {} does not decode: {refusal}", envelope.key),
})?;
image.push(Held { kind, key: envelope.key.clone(), document });
}
Ok(Self { image, batch: Vec::new() })
}
/// A4: one identity, once.
pub(crate) fn push(&mut self, staged: Staged) -> Result<(), MindRefusal> {
if self.batch.iter().any(|other| other.kind == staged.kind && other.key == staged.key) {
return Err(MindRefusal::IdentityCollision { kind: staged.kind, id: staged.key });
}
self.batch.push(staged);
Ok(())
}
pub(crate) fn in_batch(&self, kind: PipelineKind, id: &str) -> Option<&PipelineDocument> {
self.batch.iter().find(|staged| staged.kind == kind && staged.key == id).map(|staged| &staged.document)
}
pub(crate) fn in_image(&self, kind: PipelineKind, id: &str) -> Option<&PipelineDocument> {
self.image.iter().find(|held| held.kind == kind && held.key == id).map(|held| &held.document)
}
pub(crate) fn find(&self, kind: PipelineKind, id: &str) -> Option<&PipelineDocument> {
self.in_batch(kind, id).or_else(|| self.in_image(kind, id))
}
pub(crate) fn of_kind(&self, kind: PipelineKind) -> impl Iterator<Item = (&str, &PipelineDocument)> {
let batch = self.batch.iter().filter(move |staged| staged.kind == kind).map(|staged| (staged.key.as_str(), &staged.document));
let image = self.image.iter().filter(move |held| held.kind == kind).map(|held| (held.key.as_str(), &held.document));
batch.chain(image)
}
pub(crate) fn resolutions(&self) -> impl Iterator<Item = (&str, &PipelineResolution)> {
self.of_kind(PipelineKind::Resolution).filter_map(|(key, document)| match document {
PipelineDocument::Resolution(resolution) => Some((key, resolution)),
_ => None,
})
}
pub(crate) fn stewardships(&self) -> impl Iterator<Item = (&str, &PipelineStewardship)> {
self.of_kind(PipelineKind::Stewardship).filter_map(|(key, document)| match document {
PipelineDocument::Stewardship(stewardship) => Some((key, stewardship)),
_ => None,
})
}
/// Every resolution of one subject, in image and batch: the scope a
/// subject's sequence counts in and the scope its history is read from.
pub(crate) fn resolutions_of(&self, subject: &PipelineRef) -> impl Iterator<Item = (&str, &PipelineResolution)> {
self.resolutions().filter(move |(_, resolution)| resolution.subject == *subject)
}
/// Every assignment of one repo to one mind, in image and batch, in force
/// or not: the scope a stewardship's sequence counts in and the scope its
/// history is read from.
pub(crate) fn assignments_of(&self, mind: &Slug, repo: &OrgRepo) -> impl Iterator<Item = (&str, &PipelineStewardship)> {
self.stewardships().filter(move |(_, stewardship)| stewardship.instance == *mind && stewardship.repo == *repo)
}
/// The greatest sequence among a subject's resolutions in image or batch,
/// `0` when it has none, so the next is `latest + 1`. `own` is the
/// document being checked, excluded by content identity so that an exact
/// replay measures the same `latest` the first admission did.
pub(crate) fn latest_resolution(&self, subject: &PipelineRef, own: Option<&PipelineResolution>) -> u32 {
self.resolutions_of(subject)
.filter(|(_, resolution)| own != Some(*resolution))
.map(|(_, resolution)| resolution.sequence)
.max()
.unwrap_or(0)
}
/// The sequence a derivation takes: the one the record it already derived
/// carries, when image or batch holds that record, so an exact replay
/// re-derives the same document and A9 answers with the stored receipt;
/// otherwise the next. A derivation is recognised by what it writes into
/// its record: a resolution by its outcome, an assignment by its note.
pub(crate) fn derived_resolution_sequence(
&self,
subject: &PipelineRef,
derived: impl Fn(&ResolutionOutcome) -> bool,
) -> u32 {
self.resolutions()
.find(|(_, resolution)| resolution.subject == *subject && derived(&resolution.outcome))
.map_or_else(|| self.latest_resolution(subject, None) + 1, |(_, resolution)| resolution.sequence)
}
/// The same for the assignment a hand-off derives, which notes its key.
pub(crate) fn derived_stewardship_sequence(&self, mind: &Slug, repo: &OrgRepo, note: &str) -> u32 {
self.stewardships()
.find(|(_, stewardship)| stewardship.instance == *mind && stewardship.repo == *repo && stewardship.note.0 == note)
.map_or_else(|| self.latest_stewardship(mind, repo, None) + 1, |(_, stewardship)| stewardship.sequence)
}
/// The same for a repo's assignments to one mind.
pub(crate) fn latest_stewardship(&self, mind: &Slug, repo: &OrgRepo, own: Option<&PipelineStewardship>) -> u32 {
self.assignments_of(mind, repo)
.filter(|(_, stewardship)| own != Some(*stewardship))
.map(|(_, stewardship)| stewardship.sequence)
.max()
.unwrap_or(0)
}
/// No resolution that is itself in force names the document. The
/// recursion is the whole rule: a withdrawn resolution stops counting, so
/// its subject is open again. `key(R)` is strictly longer than the id it
/// resolves, so the chain is bounded and this terminates.
pub(crate) fn in_force(&self, kind: PipelineKind, id: &str) -> bool {
self.in_force_unless(kind, id, |_| false)
}
/// In force, ignoring a resolution the caller's own document is or
/// derives: the ruling that answers a question is what resolves it, the
/// hand-off that withdraws a stewardship is what resolves that, and a
/// resolution does not resolve its own subject out from under itself.
pub(crate) fn in_force_unless(&self, kind: PipelineKind, id: &str, own: impl Fn(&PipelineResolution) -> bool) -> bool {
self.closing_resolution_unless(kind, id, own).is_none()
}
/// The in-force resolution naming the document, other than `own`, if any;
/// exact rather than a tie-break because A8 and the Q19 cap admit at most
/// one.
pub(crate) fn closing_resolution_unless(
&self,
kind: PipelineKind,
id: &str,
own: impl Fn(&PipelineResolution) -> bool,
) -> Option<(&str, &PipelineResolution)> {
self.resolutions().find(|&(key, resolution)| {
resolution.subject.kind == kind
&& resolution.subject.id.0 == id
&& !own(resolution)
&& self.in_force(PipelineKind::Resolution, key)
})
}
/// Every in-force stewardship of `(mind, repo)`, ignoring the withdrawal
/// `hand_off_key` derives. The stewardship row holds one in force at a
/// time, but that exclusion can put a second back in the list: the one a
/// replayed hand-off withdrew, beside whatever stewards the repo now.
pub(crate) fn stewardships_of(
&self,
mind: &Slug,
repo: &OrgRepo,
hand_off_key: Option<&str>,
) -> Vec<(&str, &PipelineStewardship)> {
self.assignments_of(mind, repo)
.filter(|(key, _)| {
self.in_force_unless(PipelineKind::Stewardship, key, |resolution| {
matches!(&resolution.outcome, ResolutionOutcome::Withdrawn { reason } if Some(reason.0.as_str()) == hand_off_key)
})
})
.collect()
}
/// The in-force record that stands later than `base` in the scope `base`
/// is sequenced in, if any: what a withdrawal that put `base` back in
/// force would leave standing beside it.
pub(crate) fn later_in_force(&self, base: &PipelineDocument) -> Option<&str> {
let kind = base.kind();
self.of_kind(kind).find(|(key, other)| later_than(base, other) && self.in_force(kind, key)).map(|(key, _)| key)
}
/// The stewardship of `(mind, repo)` a hand-off acts on: the one whose
/// withdrawal already carries `hand_off_key`, when image or batch holds
/// that withdrawal, so a replay derives the same withdrawal again and A9
/// answers with the stored receipt; otherwise the one in force. Key order
/// cannot pick between the two the exclusion leaves standing -- once a
/// repo has changed hands ten times, `n11` sorts before `n2` -- so the
/// content match picks, as it does for the sequence the other derivations
/// take.
pub(crate) fn stewardship_of(
&self,
mind: &Slug,
repo: &OrgRepo,
hand_off_key: Option<&str>,
) -> Option<(&str, &PipelineStewardship)> {
let candidates = self.stewardships_of(mind, repo, hand_off_key);
hand_off_key
.and_then(|hand_off| {
candidates.iter().find(|(key, _)| {
self.resolutions().any(|(_, resolution)| {
resolution.subject.kind == PipelineKind::Stewardship
&& resolution.subject.id.0 == *key
&& matches!(&resolution.outcome, ResolutionOutcome::Withdrawn { reason } if reason.0 == hand_off)
})
})
})
.or_else(|| candidates.first())
.copied()
}
}
/// Whether `other` is a later record than `base` in the scope `base` is
/// sequenced in: `(instance, repo)` for a stewardship, the campaign for a
/// target and the cut for a cut spec. Kinds that carry no sequence have no
/// scope and no order, and a resolution is never a base here: the cap above
/// refuses the withdrawal that would reinstate one before the question of a
/// later record arises.
fn later_than(base: &PipelineDocument, other: &PipelineDocument) -> bool {
use PipelineDocument as D;
match (base, other) {
(D::Stewardship(base), D::Stewardship(other)) => {
other.instance == base.instance && other.repo == base.repo && other.sequence > base.sequence
}
(D::Target(base), D::Target(other)) => other.campaign == base.campaign && other.revision > base.revision,
(D::CutSpec(base), D::CutSpec(other)) => {
other.campaign == base.campaign && other.cut == base.cut && other.revision > base.revision
}
_ => false,
}
}

View file

@ -18,6 +18,7 @@
//! `now` is passed in.
pub mod admission;
mod docs;
pub mod mind;
pub mod receipt;
pub mod refusal;

View file

@ -25,11 +25,17 @@
# $env:CARGO_TARGET_DIR = 'C:\Users\Meta\.cargo-target-codex'
# powershell -File F:\Projects\Epiphany\tools\eureka-mutations.ps1 -Repo F:\Projects\Huginn `
# -Entries tools/eureka-cut8-mutations.psd1 `
# -Target crates/huginn-mind/src/mind.rs,crates/huginn-mind/src/receipt.rs,crates/huginn-mind/src/admission.rs,crates/huginn-mind/src/store.rs `
# -Target crates/huginn-mind/src/mind.rs,crates/huginn-mind/src/receipt.rs,crates/huginn-mind/src/admission.rs,crates/huginn-mind/src/docs.rs,crates/huginn-mind/src/store.rs `
# -Test 'cargo test -p huginn-mind --lib'
#
# `store.rs` is a target only for H5, whose mutant needs a `MindStore` impl
# for the transient redb store that the live crate deliberately lacks.
#
# Cut 9 moved `Docs`, its derivations and `later_than` into `docs.rs`, so the
# nine entries that anchor them name that file: H33, H41, H62, H63, H65, H66
# and H67 by file alone, and H47 and H60 re-anchored on the scope selectors
# `assignments_of` and `resolutions_of` the move extracted. Their rules are
# unchanged.
@{
Mutations = @(
@{
@ -442,7 +448,7 @@ impl MindStore for OwnedRedbMessagePackBackingStore {
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'
File = 'crates/huginn-mind/src/docs.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 });
@ -518,7 +524,7 @@ impl MindStore for OwnedRedbMessagePackBackingStore {
Id = 'H41'
Rule = 'In force is recursive: a withdrawn resolution no longer closes its subject.'
Test = 'admission::tests::a_withdrawn_resolution_reopens_its_subject_and_stays_readable'
File = 'crates/huginn-mind/src/admission.rs'
File = 'crates/huginn-mind/src/docs.rs'
Old = @'
&& !own(resolution)
&& self.in_force(PipelineKind::Resolution, key)
@ -587,22 +593,22 @@ impl MindStore for OwnedRedbMessagePackBackingStore {
}
@{
Id = 'H47'
Rule = 'stewardship_of: only an in-force assignment counts, so a handed-away repo is not stewarded.'
Rule = 'stewardships_of: only an in-force assignment counts, so a handed-away repo is not stewarded.'
Test = 'admission::tests::a_repo_is_stewarded_once_at_a_time_and_again_after_a_transfer'
File = 'crates/huginn-mind/src/admission.rs'
File = 'crates/huginn-mind/src/docs.rs'
Old = @'
.filter(|(key, stewardship)| {
stewardship.instance == *mind
&& stewardship.repo == *repo
&& self.in_force_unless(PipelineKind::Stewardship, key, |resolution| {
matches!(&resolution.outcome, ResolutionOutcome::Withdrawn { reason } if Some(reason.0.as_str()) == hand_off_key)
})
self.assignments_of(mind, repo)
.filter(|(key, _)| {
self.in_force_unless(PipelineKind::Stewardship, key, |resolution| {
matches!(&resolution.outcome, ResolutionOutcome::Withdrawn { reason } if Some(reason.0.as_str()) == hand_off_key)
})
})
'@
New = @'
.filter(|(_key, stewardship)| {
self.assignments_of(mind, repo)
.filter(|_| {
let _ = hand_off_key;
stewardship.instance == *mind && stewardship.repo == *repo
true
})
'@
}
@ -723,10 +729,10 @@ impl MindStore for OwnedRedbMessagePackBackingStore {
Id = 'H60'
Rule = 'latest_resolution reads the image only, not the batch.'
Test = 'admission::tests::the_latest_resolution_counts_the_batch'
File = 'crates/huginn-mind/src/admission.rs'
File = 'crates/huginn-mind/src/docs.rs'
Old = @'
self.resolutions()
.filter(|(_, resolution)| resolution.subject == *subject && own != Some(*resolution))
self.resolutions_of(subject)
.filter(|(_, resolution)| own != Some(*resolution))
'@
New = @'
self.image.iter().filter(|held| held.kind == PipelineKind::Resolution).filter_map(|held| match &held.document { PipelineDocument::Resolution(resolution) => Some((held.key.as_str(), resolution)), _ => None })
@ -751,7 +757,7 @@ impl MindStore for OwnedRedbMessagePackBackingStore {
Id = 'H62'
Rule = 'stewardship_of: the assignment a hand-off withdraws is picked by key order, so a replay after ten transfers withdraws whichever sorts first.'
Test = 'admission::tests::a_source_side_replay_withdraws_the_assignment_it_withdrew'
File = 'crates/huginn-mind/src/admission.rs'
File = 'crates/huginn-mind/src/docs.rs'
Old = @'
let candidates = self.stewardships_of(mind, repo, hand_off_key);
hand_off_key
@ -775,7 +781,7 @@ impl MindStore for OwnedRedbMessagePackBackingStore {
Id = 'H63'
Rule = 'stewardship_of: H62''s weaker half, any withdrawal of a candidate identifies it, whatever hand-off gave the reason.'
Test = 'admission::tests::a_source_side_replay_withdraws_the_assignment_it_withdrew'
File = 'crates/huginn-mind/src/admission.rs'
File = 'crates/huginn-mind/src/docs.rs'
Old = ' && matches!(&resolution.outcome, ResolutionOutcome::Withdrawn { reason } if reason.0 == hand_off)'
New = ' && { let _ = hand_off; matches!(&resolution.outcome, ResolutionOutcome::Withdrawn { .. }) }'
}
@ -791,7 +797,7 @@ impl MindStore for OwnedRedbMessagePackBackingStore {
Id = 'H65'
Rule = 'later_than: a cut spec is sequenced within its campaign, not within its cut.'
Test = 'admission::tests::a_reinstatement_reads_the_revisions_of_its_own_cut'
File = 'crates/huginn-mind/src/admission.rs'
File = 'crates/huginn-mind/src/docs.rs'
Old = ' other.campaign == base.campaign && other.cut == base.cut && other.revision > base.revision'
New = ' other.campaign == base.campaign && other.revision > base.revision'
}
@ -799,7 +805,7 @@ impl MindStore for OwnedRedbMessagePackBackingStore {
Id = 'H66'
Rule = 'later_in_force: a later record blocks a reinstatement whether or not it still stands.'
Test = 'admission::tests::a_withdrawn_later_assignment_does_not_block_a_reinstatement'
File = 'crates/huginn-mind/src/admission.rs'
File = 'crates/huginn-mind/src/docs.rs'
Old = ' self.of_kind(kind).find(|(key, other)| later_than(base, other) && self.in_force(kind, key)).map(|(key, _)| key)'
New = ' self.of_kind(kind).find(|(key, other)| later_than(base, other)).map(|(key, _)| key)'
}
@ -807,7 +813,7 @@ impl MindStore for OwnedRedbMessagePackBackingStore {
Id = 'H67'
Rule = 'later_in_force: the image only, so a later record landing in the same batch does not block.'
Test = 'admission::tests::a_reinstatement_is_blocked_by_an_assignment_in_its_own_batch'
File = 'crates/huginn-mind/src/admission.rs'
File = 'crates/huginn-mind/src/docs.rs'
Old = ' self.of_kind(kind).find(|(key, other)| later_than(base, other) && self.in_force(kind, key)).map(|(key, _)| key)'
New = ' self.image.iter().filter(|held| held.kind == kind).map(|held| (held.key.as_str(), &held.document)).find(|(key, other)| later_than(base, other) && self.in_force(kind, key)).map(|(key, _)| key)'
}