diff --git a/crates/huginn-mind/src/admission.rs b/crates/huginn-mind/src/admission.rs index 96b39f9..01eb96e 100644 --- a/crates/huginn-mind/src/admission.rs +++ b/crates/huginn-mind/src/admission.rs @@ -39,7 +39,7 @@ use schemars::JsonSchema; use serde::{Deserialize, Serialize}; use serde_json::Value; -use crate::docs::{CitationRole, Docs, Staged, citations, kind_of_id, line_of, outcome_citations}; +use crate::docs::{CitationRole, Docs, Staged, citations, kind_of_id, outcome_citations}; use crate::mind::{HuginnMindEpoch, Mind, unavailable}; use crate::persona::{self, HuginnPersonaEntry, PersonaPutOutcome}; use crate::receipt::{self, CommitOutcome, PipelineProvenance}; @@ -598,7 +598,7 @@ fn check(docs: &Docs, staged: &Staged, mind: &Slug) -> Result<(), MindRefusal> { actual: stewardship.sequence, }); } - if docs.rival_in_force(key, &staged.document).is_some() { + if docs.stewardships_of(mind, &stewardship.repo, None).iter().any(|(other, _)| *other != key) { return Err(MindRefusal::AlreadyStewarded { repo: stewardship.repo.0.clone() }); } Ok(()) @@ -770,16 +770,11 @@ fn resolution_rule(docs: &Docs, resolution: &PipelineResolution) -> Result<(), M && subject_kind == K::Resolution && let Some(D::Resolution(reinstating)) = docs.find(K::Resolution, subject_id) && let Some(base) = docs.find(reinstating.subject.kind, &reinstating.subject.id.0) - && let Some(rival) = docs.rival_in_force(&reinstating.subject.id.0, base) + && let Some(later) = docs.later_in_force(base) { - // The repo already has a steward, earlier or later: the admission - // refusal for the same fact, from the same owner. - if let D::Stewardship(base) = base { - return Err(MindRefusal::AlreadyStewarded { repo: base.repo.0.clone() }); - } return Err(MindRefusal::WouldReinstateOverLater { subject: reinstating.subject.id.0.clone(), - later: rival.into(), + later: later.into(), }); } // Withdrawing a run's closure puts the run back in force, and a run in @@ -799,12 +794,11 @@ fn resolution_rule(docs: &Docs, resolution: &PipelineResolution) -> Result<(), M } } match &resolution.outcome { - ResolutionOutcome::Superseded { by } => { - let Some(subject) = docs.find(subject_kind, subject_id) else { return Ok(()) }; - let line = line_of(subject); + ResolutionOutcome::Superseded { by } if subject_kind == K::CutSpec => { + let Some(D::CutSpec(subject)) = docs.find(K::CutSpec, subject_id) else { return Ok(()) }; for supersessor in by { - if let Some(next) = docs.find(subject_kind, &supersessor.id.0) - && (line.is_none() || line != line_of(next)) + if let Some(D::CutSpec(spec)) = docs.find(K::CutSpec, &supersessor.id.0) + && spec.cut != subject.cut { return Err(incompatible()); } @@ -1556,8 +1550,7 @@ mod tests { /// Q19 A's rationale, which the cap alone does not carry: a withdrawal /// never re-raises an earlier record over a later one. The repo went away /// and came back, so withdrawing the hand-off's withdrawal would put the - /// first assignment back in force beside the second: the repo already has - /// a steward. + /// first assignment back in force beside the second. #[test] fn a_withdrawal_does_not_reinstate_a_stewardship_over_a_later_one() { let mut mind = seeded(); @@ -1565,11 +1558,12 @@ mod tests { let D::HandOff(mut back) = hand_off(OTHER_INSTANCE, INSTANCE, REPO, &[]) else { panic!() }; back.handed_on = eureka_pipeline::Date("2026-09-17".into()); committed(admit(&mut mind, vec![D::HandOff(back)])); + let first = format!("{INSTANCE}:stewardship:gamecult_-epiphany.n1"); let again = format!("{INSTANCE}:stewardship:gamecult_-epiphany.n2"); let withdrawal = format!("{INSTANCE}:resolution:stewardship.gamecult_-epiphany.n1.n1"); assert_eq!( refusal(admit(&mut mind, vec![resolution(r(K::Resolution, &withdrawal), withdrawn())])), - MindRefusal::AlreadyStewarded { repo: REPO.into() } + MindRefusal::WouldReinstateOverLater { subject: first, later: again.clone() } ); let docs = Docs::from_image(mind.envelopes()).unwrap(); let in_force = docs.stewardships_of(&slug(INSTANCE), &repo(REPO), None).iter().map(|(key, _)| *key).collect::>(); @@ -1687,33 +1681,6 @@ mod tests { assert_eq!(in_force, vec![stewardship_key(1)]); } - /// One assignment stands per repo, whichever record a withdrawal would put - /// back: reinstating the later of two withdrawn assignments while the - /// earlier is back in force is refused, and the next assignment then meets - /// exactly the one that stands. - #[test] - fn a_withdrawal_does_not_reinstate_a_stewardship_beside_an_earlier_one() { - let mut mind = seeded(); - let n1 = stewardship_key(1); - let n2 = stewardship_key(2); - let first = format!("{INSTANCE}:resolution:stewardship.gamecult_-epiphany.n1.n1"); - let second = format!("{INSTANCE}:resolution:stewardship.gamecult_-epiphany.n2.n1"); - committed(admit(&mut mind, vec![resolution(r(K::Stewardship, &n1), withdrawn())])); - committed(admit(&mut mind, vec![stewardship_n(INSTANCE, REPO, 2)])); - committed(admit(&mut mind, vec![resolution(r(K::Stewardship, &n2), withdrawn())])); - committed(admit(&mut mind, vec![resolution(r(K::Resolution, &first), withdrawn())])); - assert_eq!( - refusal(admit(&mut mind, vec![resolution(r(K::Resolution, &second), withdrawn())])), - MindRefusal::AlreadyStewarded { repo: REPO.into() } - ); - let in_force = docs_of(&mind).stewardships_of(&slug(INSTANCE), &repo(REPO), None).iter().map(|(key, _)| key.to_string()).collect::>(); - assert_eq!(in_force, vec![n1], "the reinstated assignment stands alone"); - assert_eq!( - refusal(admit(&mut mind, vec![stewardship_n(INSTANCE, REPO, 3)])), - MindRefusal::AlreadyStewarded { repo: REPO.into() } - ); - } - /// And it reads the batch: the assignment that stands later than the one /// a withdrawal would reinstate may be landing beside that withdrawal, /// derived by a hand-off in the same batch. @@ -1727,7 +1694,7 @@ mod tests { hand_off_on(OTHER_INSTANCE, INSTANCE, "2026-09-17"), resolution(r(K::Resolution, &withdrawal), withdrawn()), ])), - MindRefusal::AlreadyStewarded { repo: REPO.into() } + MindRefusal::WouldReinstateOverLater { subject: stewardship_key(1), later: stewardship_key(2) } ); } @@ -2822,245 +2789,6 @@ mod tests { committed(admit(&mut mind, vec![spec_on("1", OTHER_REPO)])); } - /// Another campaign, opened with `repos`, and its own target revision 1 naming `named`. - fn other_campaign(repos: &[&str], named: &[&str]) -> Vec { - let D::Campaign(mut campaign) = campaign(repos) else { panic!("a campaign") }; - campaign.slug = "other-campaign".into(); - let D::Target(mut target) = target(1, &[INVARIANT]) else { panic!("a target") }; - target.campaign = "other-campaign".into(); - target.repos = named.iter().map(|name| repo(name)).collect(); - vec![D::Campaign(campaign), D::Target(target)] - } - - #[test] - fn another_campaigns_target_does_not_widen_membership() { - let mut mind = seeded(); - committed(admit(&mut mind, other_campaign(&[REPO], &[REPO, OTHER_REPO]))); - assert_eq!(refusal(admit(&mut mind, vec![spec_on("1", OTHER_REPO)])), MindRefusal::RepoNotInCampaign { repo: OTHER_REPO.into() }); - } - - #[test] - fn a_target_is_superseded_only_within_its_campaign() { - let mut mind = seeded(); - committed(admit(&mut mind, repo_revision(2, &[REPO, OTHER_REPO]))); - committed(admit(&mut mind, other_campaign(&[REPO], &[]))); - let foreign = r(K::Target, "other-campaign:target:r1"); - assert_eq!( - refusal(admit(&mut mind, vec![resolution(r(K::Target, &id("target", "r2")), superseded(&[foreign]))])), - MindRefusal::IncompatibleResolution { subject_kind: K::Target, outcome: "Superseded".into() } - ); - // Nothing was written: r2 still names the repos, and its own revision still lands. - committed(admit(&mut mind, vec![spec_on("1", OTHER_REPO)])); - committed(admit(&mut mind, repo_revision(3, &[REPO, OTHER_REPO]))); - } - - /// A target of the first campaign (`CAMPAIGN`) at `revision`, naming no repos. - fn own_target(revision: u32) -> D { - target(revision, &[INVARIANT]) - } - - const FOREIGN_TARGET: &str = "other-campaign:target:r1"; - - fn supersession_refused(outcome: PipelineAdmissionOutcome, subject_kind: K) -> bool { - refusal(outcome) == MindRefusal::IncompatibleResolution { subject_kind, outcome: "Superseded".into() } - } - - #[test] - fn a_foreign_target_in_the_same_batch_does_not_supersede() { - let mut mind = seeded(); - let mut batch = other_campaign(&[REPO], &[]); - batch.push(resolution(r(K::Target, &id("target", "r1")), superseded(&[r(K::Target, FOREIGN_TARGET)]))); - assert!(supersession_refused(admit(&mut mind, batch), K::Target)); - } - - #[test] - fn every_supersessor_of_a_target_is_checked_whichever_is_foreign() { - for foreign_first in [false, true] { - let mut mind = seeded(); - committed(admit(&mut mind, other_campaign(&[REPO], &[]))); - let own = r(K::Target, &id("target", "r2")); - let foreign = r(K::Target, FOREIGN_TARGET); - let by = if foreign_first { [foreign, own] } else { [own, foreign] }; - let batch = vec![own_target(2), resolution(r(K::Target, &id("target", "r1")), superseded(&by))]; - assert!(supersession_refused(admit(&mut mind, batch), K::Target), "foreign first: {foreign_first}"); - } - } - - #[test] - fn a_new_campaigns_target_in_its_own_batch_is_not_closed_by_a_foreign_one() { - let mut mind = seeded(); - let mut batch = other_campaign(&[REPO], &[]); - batch.push(resolution(r(K::Target, FOREIGN_TARGET), superseded(&[r(K::Target, &id("target", "r1"))]))); - assert!(supersession_refused(admit(&mut mind, batch), K::Target)); - } - - #[test] - fn a_cut_spec_is_superseded_only_within_its_campaign() { - let mut mind = seeded(); - committed(admit(&mut mind, vec![spec_on("1", REPO)])); - let mut batch = other_campaign(&[REPO], &[]); - let D::CutSpec(mut foreign) = spec_on("1", REPO) else { panic!("a spec") }; - foreign.campaign = "other-campaign".into(); - batch.push(D::CutSpec(foreign)); - committed(admit(&mut mind, batch)); - let lone = vec![resolution(r(K::CutSpec, &id("cut_spec", "cut-1.r1")), superseded(&[r(K::CutSpec, "other-campaign:cut_spec:cut-1.r1")]))]; - assert!(supersession_refused(admit(&mut mind, lone), K::CutSpec)); - // Nothing was written: this campaign's own revision still lands. - let D::CutSpec(mut next) = spec_on("1", REPO) else { panic!("a spec") }; - next.revision = 2; - let this = r(K::CutSpec, &id("cut_spec", "cut-1.r2")); - committed(admit(&mut mind, vec![D::CutSpec(next), resolution(r(K::CutSpec, &id("cut_spec", "cut-1.r1")), superseded(&[this]))])); - } - - #[test] - fn a_ruling_is_superseded_by_a_ruling_of_any_campaign() { - let mut mind = seeded(); - committed(admit(&mut mind, vec![D::Ruling(ruling("old"))])); - let mut batch = other_campaign(&[REPO], &[]); - let mut foreign = ruling("new"); - foreign.campaign = "other-campaign".into(); - batch.push(D::Ruling(foreign)); - batch.push(resolution(r(K::Ruling, &id("ruling", "old")), superseded(&[r(K::Ruling, "other-campaign:ruling:new")]))); - committed(admit(&mut mind, batch)); - } - - /// The slug that shares its dash prefix with `CAMPAIGN` (`eureka-state`). - const RIVAL: &str = "eureka-substrate"; - - /// Revision `revision` of the rival campaign's target, with its campaign when it is - /// the first and the supersession of its predecessor when it is not. - fn rival_revision(revision: u32) -> Vec { - let D::Target(mut named) = target(revision, &[INVARIANT]) else { panic!("a target") }; - named.campaign = RIVAL.into(); - let mut batch = Vec::new(); - if revision == 1 { - let D::Campaign(mut opened) = campaign(&[REPO]) else { panic!("a campaign") }; - opened.slug = RIVAL.into(); - batch.push(D::Campaign(opened)); - } - batch.push(D::Target(named)); - if revision > 1 { - let previous = r(K::Target, &format!("{RIVAL}:target:r{}", revision - 1)); - batch.push(resolution(previous, superseded(&[r(K::Target, &format!("{RIVAL}:target:r{revision}"))]))); - } - batch - } - - /// Both campaigns at revision 3, so each one's target in force is above revision 1. - fn both_campaigns_at_revision_three() -> Mind { - let mut mind = seeded(); - for revision in 2..=3 { - committed(admit(&mut mind, repo_revision(revision, &[REPO]))); - } - for revision in 1..=3 { - committed(admit(&mut mind, rival_revision(revision))); - } - mind - } - - #[test] - fn a_target_is_not_superseded_by_a_campaign_sharing_its_prefix_or_a_higher_revision() { - for (subject, supersessor) in [ - (id("target", "r3"), format!("{RIVAL}:target:r3")), - (format!("{RIVAL}:target:r3"), id("target", "r3")), - ] { - let mut mind = both_campaigns_at_revision_three(); - let lone = vec![resolution(r(K::Target, &subject), superseded(&[r(K::Target, &supersessor)]))]; - assert!(supersession_refused(admit(&mut mind, lone), K::Target), "{subject} by {supersessor}"); - } - // A foreign revision above the subject's is no likelier to pass. - let mut mind = seeded(); - committed(admit(&mut mind, repo_revision(2, &[REPO]))); - for revision in 1..=4 { - committed(admit(&mut mind, rival_revision(revision))); - } - let lone = vec![resolution(r(K::Target, &id("target", "r2")), superseded(&[r(K::Target, &format!("{RIVAL}:target:r4"))]))]; - assert!(supersession_refused(admit(&mut mind, lone), K::Target)); - } - - #[test] - fn a_stewardship_is_superseded_only_on_its_own_instance_and_repo_line() { - let mut mind = seeded(); - committed(admit(&mut mind, vec![stewardship(INSTANCE, OTHER_REPO)])); - let epiphany = format!("{INSTANCE}:stewardship:gamecult_-epiphany.n1"); - let huginn = format!("{INSTANCE}:stewardship:gamecult_-huginn.n1"); - let lone = vec![resolution(r(K::Stewardship, &epiphany), superseded(&[r(K::Stewardship, &huginn)]))]; - assert!(supersession_refused(admit(&mut mind, lone), K::Stewardship)); - // Nothing was written: the repo's own next assignment still supersedes it. - let next = format!("{INSTANCE}:stewardship:gamecult_-epiphany.n2"); - committed(admit(&mut mind, vec![ - stewardship_n(INSTANCE, REPO, 2), - resolution(r(K::Stewardship, &epiphany), superseded(&[r(K::Stewardship, &next)])), - ])); - } - - /// Re-homing work is how Self routes it (ruling `supersession-lineage-3`): - /// a gap follow-up of one campaign is superseded by its successor in the - /// campaign that owns the work now, and the typed edge survives. - #[test] - fn a_follow_up_is_superseded_by_one_re_homed_to_another_campaign() { - let mut mind = seeded(); - let source = r(K::Target, &id("target", "r1")); - committed(admit(&mut mind, vec![follow_up("gap-session-id", source.clone())])); - let mut batch = rival_revision(1); - let D::FollowUp(mut foreign) = follow_up("gap-session-id", source) else { panic!("a follow-up") }; - foreign.campaign = RIVAL.into(); - batch.push(D::FollowUp(foreign)); - batch.push(resolution( - r(K::FollowUp, &id("follow_up", "gap-session-id")), - superseded(&[r(K::FollowUp, &format!("{RIVAL}:follow_up:gap-session-id"))]), - )); - committed(admit(&mut mind, batch)); - let docs = docs_of(&mind); - assert!(!docs.in_force(K::FollowUp, &id("follow_up", "gap-session-id"))); - assert!(docs.in_force(K::FollowUp, &format!("{RIVAL}:follow_up:gap-session-id"))); - } - - #[test] - fn supersession_on_its_own_line_commits_for_every_kind() { - let source = r(K::Target, &id("target", "r1")); - let mut mind = seeded(); - committed(admit(&mut mind, repo_revision(2, &[REPO]))); - let mut mind = seeded(); - committed(admit(&mut mind, vec![spec_on("1", REPO)])); - let D::CutSpec(mut next) = spec_on("1", REPO) else { panic!("a spec") }; - next.revision = 2; - committed(admit(&mut mind, vec![ - D::CutSpec(next), - resolution(r(K::CutSpec, &id("cut_spec", "cut-1.r1")), superseded(&[r(K::CutSpec, &id("cut_spec", "cut-1.r2"))])), - ])); - let mut mind = seeded(); - committed(admit(&mut mind, vec![follow_up("old", source.clone())])); - committed(admit(&mut mind, vec![ - follow_up("new", source), - resolution(r(K::FollowUp, &id("follow_up", "old")), superseded(&[r(K::FollowUp, &id("follow_up", "new"))])), - ])); - let mut mind = seeded(); - let epiphany = format!("{INSTANCE}:stewardship:gamecult_-epiphany"); - committed(admit(&mut mind, vec![ - stewardship_n(INSTANCE, REPO, 2), - resolution(r(K::Stewardship, &format!("{epiphany}.n1")), superseded(&[r(K::Stewardship, &format!("{epiphany}.n2"))])), - ])); - let mut mind = seeded(); - committed(admit(&mut mind, vec![D::Ruling(ruling("old"))])); - committed(admit(&mut mind, vec![ - D::Ruling(ruling("new")), - resolution(r(K::Ruling, &id("ruling", "old")), superseded(&[r(K::Ruling, &id("ruling", "new"))])), - ])); - } - - #[test] - fn a_ruling_of_one_campaign_is_superseded_by_a_ruling_of_a_prefix_sharing_campaign() { - let mut mind = seeded(); - committed(admit(&mut mind, vec![D::Ruling(ruling("old"))])); - let mut batch = rival_revision(1); - let mut foreign = ruling("new"); - foreign.campaign = RIVAL.into(); - batch.push(D::Ruling(foreign)); - batch.push(resolution(r(K::Ruling, &id("ruling", "old")), superseded(&[r(K::Ruling, &format!("{RIVAL}:ruling:new"))]))); - committed(admit(&mut mind, batch)); - } - #[test] fn a_hand_off_derives_this_minds_side_only() { let key = format!("{INSTANCE}:hand_off:{OTHER_INSTANCE}.gamecult_-epiphany.2026-09-16"); diff --git a/crates/huginn-mind/src/docs.rs b/crates/huginn-mind/src/docs.rs index f7af836..c124719 100644 --- a/crates/huginn-mind/src/docs.rs +++ b/crates/huginn-mind/src/docs.rs @@ -7,7 +7,7 @@ use cultcache_rs::CultCacheEnvelope; use eureka_pipeline::{ - Label, OrgRepo, PipelineCampaign, PipelineDocument, PipelineKind, PipelineRef, PipelineResolution, PipelineRun, PipelineStewardship, ResolutionOutcome, + OrgRepo, PipelineCampaign, PipelineDocument, PipelineKind, PipelineRef, PipelineResolution, PipelineRun, PipelineStewardship, ResolutionOutcome, RunOperator, Short, Slug, }; use schemars::JsonSchema; @@ -224,17 +224,12 @@ impl Docs { .collect() } - /// The in-force record, other than `base_key`, that cannot stand beside - /// `base` on its line: the one question "may this record be in force" - /// asks, whether `base` is being admitted (a stewardship's - /// `AlreadyStewarded`) or put back in force by a withdrawal. A line holds - /// one stewardship at a time, so any other stands in its way; a revision - /// is only displaced by a later one. - pub(crate) fn rival_in_force(&self, base_key: &str, base: &PipelineDocument) -> Option<&str> { + /// 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)| *key != base_key && rivals(base, other) && self.in_force(kind, key)) - .map(|(key, _)| key) + self.of_kind(kind).find(|(key, other)| later_than(base, other) && self.in_force(kind, key)).map(|(key, _)| key) } /// The in-force run, other than `run_key`, that holds `claim`: the one @@ -304,57 +299,22 @@ impl Docs { } } -/// The line a record belongs to (rulings `supersession-lineage-2` and `-3`): the one place -/// lineage is decided. A record supersedes, and is reinstated over, only a record -/// of its own line. `None` is a kind the resolution matrix never lets be -/// superseded; the match names every kind, so a new kind fails to compile until -/// its line is stated. -#[derive(Clone, Copy, Debug, PartialEq, Eq)] -pub(crate) enum Lineage<'a> { - /// A target: the campaign. - Campaign(&'a Slug), - /// A cut spec: the campaign and the cut. - Cut(&'a Slug, &'a Label), - /// A stewardship: the instance and the repo. - Assignment(&'a Slug, &'a OrgRepo), - /// A ruling or a follow-up: operator directions and re-homed work cut - /// across campaigns. - Global, -} - -pub(crate) fn line_of(document: &PipelineDocument) -> Option> { +/// 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 document { - D::Target(target) => Some(Lineage::Campaign(&target.campaign)), - D::CutSpec(spec) => Some(Lineage::Cut(&spec.campaign, &spec.cut)), - D::Stewardship(stewardship) => Some(Lineage::Assignment(&stewardship.instance, &stewardship.repo)), - D::Ruling(_) | D::FollowUp(_) => Some(Lineage::Global), - D::Campaign(_) - | D::Question(_) - | D::CutReport(_) - | D::Verdict(_) - | D::Finding(_) - | D::Resolution(_) - | D::Instance(_) - | D::HandOff(_) - | D::Run(_) => None, - } -} - -/// Whether `other` cannot stand in force beside `base`, being on `base`'s line: -/// any other stewardship of an instance and repo, a later revision of a target -/// or cut spec. A resolution is never a base here: the cap in `resolution_rule` -/// refuses the withdrawal that would reinstate one first. -fn rivals(base: &PipelineDocument, other: &PipelineDocument) -> bool { - use PipelineDocument as D; - let Some(line) = line_of(base) else { return false }; - if line_of(other) != Some(line) { - return false; - } match (base, other) { - (D::Stewardship(_), D::Stewardship(_)) => true, - (D::Target(base), D::Target(other)) => other.revision > base.revision, - (D::CutSpec(base), D::CutSpec(other)) => other.revision > base.revision, + (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, } } @@ -541,51 +501,3 @@ pub(crate) fn citations(document: &PipelineDocument) -> Vec<(CitationRole, Pipel } edges } - -#[cfg(test)] -mod tests { - use super::*; - use crate::fixtures::*; - use PipelineDocument as D; - use PipelineKind as K; - - fn held(kind: K, key: String, document: D) -> Held { - Held { kind, key, document } - } - - fn named(campaign: &str, revision: u32, repos: &[&str]) -> (String, D) { - let D::Target(mut target) = target(revision, &[INVARIANT]) else { panic!("a target") }; - target.campaign = campaign.into(); - target.repos = repos.iter().map(|name| repo(name)).collect(); - (format!("{campaign}:target:r{revision}"), D::Target(target)) - } - - /// Membership is the highest-revision target of this campaign that is in - /// force and names repos. The image is built by hand because admission - /// cannot reach it: a revision above 1 supersedes its predecessor in its - /// own batch, a target is superseded only within its campaign, and an - /// empty revision after a repo-naming one is refused, so through admission - /// a closed repo-naming target is always older than the in-force one. - /// - /// Taking the lowest revision instead of the highest changes nothing there - /// either (one target per campaign is in force), so that mutation is - /// equivalent and not pinned. - #[test] - fn repos_in_force_is_this_campaigns_in_force_naming_target() { - let D::Campaign(this) = campaign(&[REPO]) else { panic!("a campaign") }; - let (in_force_key, in_force) = named(CAMPAIGN, 1, &[REPO, OTHER_REPO]); - let (closed_key, closed) = named(CAMPAIGN, 2, &["GameCult/Closed"]); - let (foreign_key, foreign) = named("other-campaign", 3, &["GameCult/Foreign"]); - let closing = resolution(r(K::Target, &closed_key), superseded(&[r(K::Target, &in_force_key)])); - let docs = Docs { - image: vec![ - held(K::Target, in_force_key, in_force), - held(K::Target, closed_key, closed), - held(K::Target, foreign_key, foreign), - held(K::Resolution, id("resolution", "target.r2.n1"), closing), - ], - batch: Vec::new(), - }; - assert_eq!(docs.repos_in_force(&this), [repo(REPO), repo(OTHER_REPO)], "neither the closed higher revision nor another campaign's higher target decides"); - } -}