From 9298371f95317f87a39c3dfe2780d005571011a5 Mon Sep 17 00:00:00 2001 From: Meta Vens Date: Thu, 22 Oct 2026 17:38:04 +0200 Subject: [PATCH] Target gains repos: a campaign's repo set changes by target revision PipelineTarget.repos (additive, `= absent`, epoch stays v2) names the campaign's whole repo set from that revision on; repos_in_force is the one owner of cut_spec membership and replaces the direct campaign.repos check; a revision past the first may not empty the set its predecessor named (EmptyRepos on the target id). Golden line and regenerated schemas follow in the next commit (ruling campaign-repo-set-home). Co-Authored-By: Claude Sonnet 5.5 --- crates/eureka-pipeline/src/lib.rs | 75 +++++++++++++++++++++---- crates/huginn-mind/src/admission.rs | 87 ++++++++++++++++++++++++++++- crates/huginn-mind/src/docs.rs | 19 ++++++- crates/huginn-mind/src/fixtures.rs | 1 + crates/huginn-mind/src/refusal.rs | 1 + crates/mind-body/src/testkit.rs | 1 + crates/mind-body/tests/wake.rs | 1 + 7 files changed, 173 insertions(+), 12 deletions(-) diff --git a/crates/eureka-pipeline/src/lib.rs b/crates/eureka-pipeline/src/lib.rs index 07c6857..d19d192 100644 --- a/crates/eureka-pipeline/src/lib.rs +++ b/crates/eureka-pipeline/src/lib.rs @@ -491,16 +491,17 @@ macro_rules! unit_enums { )*}; } -/// RS-L closing fix 4: `campaign.repos` refuses two entries naming the same +/// RS-L closing fix 4: a repo list refuses two entries naming the same /// repository by identity, not by raw spelling, so `GameCult/Epiphany` and /// `gamecult/epiphany` in one list refuse exactly as one entry twice would. -/// This is a cross-element invariant on `PipelineCampaign` alone, not a -/// per-type format rule any other `value_types!` struct shares, so it is -/// wired in as that struct's one `=> extra` hook rather than folded into -/// `Bounded for OrgRepo` or the list bound in `bounded_field!`. -fn campaign_repos_are_distinct(campaign: &PipelineCampaign, at: &str) -> Result<(), PipelineRefusal> { +/// This is a cross-element invariant on the lists alone, not a per-type format +/// rule any other `value_types!` struct shares, so it is wired in as the +/// `=> extra` hook of the two structs that carry a repo list +/// (`PipelineCampaign.repos` and `PipelineTarget.repos`) rather than folded +/// into `Bounded for OrgRepo` or the list bound in `bounded_field!`. +fn repos_are_distinct(repos: &[OrgRepo], at: &str) -> Result<(), PipelineRefusal> { let mut seen = std::collections::HashSet::new(); - for repo in &campaign.repos { + for repo in repos { if !seen.insert(repo.identity()) { return Err(PipelineRefusal::DuplicateRepo { field: format!("{at}.repos"), @@ -511,6 +512,14 @@ fn campaign_repos_are_distinct(campaign: &PipelineCampaign, at: &str) -> Result< Ok(()) } +fn campaign_repos_are_distinct(campaign: &PipelineCampaign, at: &str) -> Result<(), PipelineRefusal> { + repos_are_distinct(&campaign.repos, at) +} + +fn target_repos_are_distinct(target: &PipelineTarget, at: &str) -> Result<(), PipelineRefusal> { + repos_are_distinct(&target.repos, at) +} + /// The most lines one read anchor may span. const READ_WINDOW_MAX_LINES: u32 = 100; @@ -625,10 +634,12 @@ value_types! { } pub struct PipelineCampaign { slug: Slug, title: Title, repos: Vec[8], working_branch: Short, target_doc: DocRef } => campaign_repos_are_distinct + /// `repos`, when non-empty, is the campaign's whole repo set from this + /// revision on; empty keeps the previous set (ruling campaign-repo-set-home). pub struct PipelineTarget { campaign: Slug, revision: u32, invariants: Vec[32], not_in_scope: Vec[32], - canonical_implementations: Vec[16], doc: DocRef, - } + canonical_implementations: Vec[16], repos: Vec[16] = absent, doc: DocRef, + } => target_repos_are_distinct pub struct PipelineQuestion { campaign: Slug, label: Label, title: Title, question: Para, options: Vec[8], recommended: Label, depends: Vec[8], raised_in: Option, asked_on: Date, @@ -1238,7 +1249,7 @@ mod tests { (D::Target(PipelineTarget { campaign: slug(CAMPAIGN), revision: 2, invariants: vec![TargetInvariant { label: l("mind-admits"), statement: "Only admission writes.".into() }], - not_in_scope: vec!["Eve browsing".into()], canonical_implementations: vec!["CultLib".into()], doc: doc_ref(), + not_in_scope: vec!["Eve browsing".into()], canonical_implementations: vec!["CultLib".into()], repos: vec![], doc: doc_ref(), }), format!("{CAMPAIGN}:target:r2")), (D::Question(PipelineQuestion { campaign: slug(CAMPAIGN), label: l("Q1"), title: t("Who owns the state?"), question: "Who owns the state?".into(), @@ -1506,6 +1517,9 @@ mod tests { let mut f = finding_sample(); f.locations[0].symbol = Some("&1153090498".into()); out.push(("finding.location-symbol".into(), D::Finding(f))); + let PipelineDocument::Target(mut target) = samples().remove(1).0 else { unreachable!() }; + target.repos = vec![OrgRepo("GameCult/Epiphany".into()), OrgRepo("GameCult/Huginn".into())]; + out.push(("target.repos".into(), D::Target(target))); out } @@ -3163,6 +3177,47 @@ mod tests { assert_eq!(PipelineDocument::Finding(finding).validate(), Ok(())); } + #[test] + fn target_repos_absent_decode_and_round_trip() -> Result<()> { + // The MCP door: a JSON target with no `repos` key decodes to an empty list. + let PipelineDocument::Target(sample) = samples().remove(1).0 else { unreachable!() }; + let mut json = serde_json::to_value(PipelineDocument::Target(sample.clone()))?; + assert!(json["value"].get("repos").is_none(), "an empty repos is not written"); + let PipelineDocument::Target(decoded) = serde_json::from_value::(json.clone())? else { unreachable!() }; + assert!(decoded.repos.is_empty()); + assert!(!rmp_serde::to_vec_named(&PipelineDocument::Target(sample.clone()))?.windows(5).any(|window| window == b"repos")); + + let mut named = sample; + named.repos = vec![OrgRepo("GameCult/Epiphany".into()), OrgRepo("GameCult/Huginn".into())]; + let document = PipelineDocument::Target(named); + document.validate()?; + json = serde_json::to_value(&document)?; + assert_eq!(serde_json::from_value::(json)?, document); + let packed = rmp_serde::to_vec_named(&document)?; + assert_eq!(rmp_serde::from_slice::(&packed)?, document); + assert!(packed.windows(5).any(|window| window == b"repos"), "the repos key is written"); + Ok(()) + } + + #[test] + fn target_repos_bounded_and_distinct() { + let with_repos = |repos: Vec| { + let PipelineDocument::Target(mut target) = samples().remove(1).0 else { unreachable!() }; + target.repos = repos; + PipelineDocument::Target(target).validate() + }; + let distinct = |count: usize| (0..count).map(|index| OrgRepo(format!("GameCult/Repo{index}"))).collect::>(); + assert_eq!(with_repos(distinct(16)), Ok(())); + assert_eq!( + with_repos(distinct(17)), + Err(PipelineRefusal::FieldBound { field: "target.repos".into(), limit: 16, actual: 17 }) + ); + assert_eq!( + with_repos(vec![OrgRepo("GameCult/Huginn".into()), OrgRepo("gamecult/huginn".into())]), + Err(PipelineRefusal::DuplicateRepo { field: "target.repos".into(), repo: "gamecult/huginn".into() }) + ); + } + /// The marker needs an `Absent` spelling; the two impls say what absent is. #[test] fn absent_is_none_and_empty() { diff --git a/crates/huginn-mind/src/admission.rs b/crates/huginn-mind/src/admission.rs index 8d55f90..01eb96e 100644 --- a/crates/huginn-mind/src/admission.rs +++ b/crates/huginn-mind/src/admission.rs @@ -456,6 +456,15 @@ fn check(docs: &Docs, staged: &Staged, mind: &Slug) -> Result<(), MindRefusal> { D::Target(target) => { let predecessor = D::Target(eureka_pipeline::PipelineTarget { revision: target.revision.wrapping_sub(1), ..target.clone() }); revision_rule(docs, K::Target, key, target.revision, &predecessor)?; + // A revision past the first may not empty the repo set its predecessor + // named: empty means "keep the previous set", and that would silently + // narrow it to the campaign's opening set (ruling campaign-repo-set-home). + if target.repos.is_empty() && target.revision > 1 { + let named = matches!(docs.find(K::Target, &pipeline_key(&predecessor)?), Some(D::Target(previous)) if !previous.repos.is_empty()); + if named { + return Err(MindRefusal::EmptyRepos { campaign: key.into() }); + } + } unique_labels("target.invariants", target.invariants.iter().map(|invariant| invariant.label.0.as_str())) } D::Question(question) => { @@ -492,7 +501,7 @@ fn check(docs: &Docs, staged: &Staged, mind: &Slug) -> Result<(), MindRefusal> { let Some(campaign) = campaign else { return Err(MindRefusal::MissingReference { kind: K::Campaign, id: spec.campaign.0.clone() }); }; - if !campaign.repos.contains(&spec.repo) { + if !docs.repos_in_force(campaign).contains(&spec.repo) { return Err(MindRefusal::RepoNotInCampaign { repo: spec.repo.0.clone() }); } for ruling in &spec.rulings { @@ -2704,6 +2713,82 @@ mod tests { assert_eq!(refusal(admit(&mut mind, vec![D::CutSpec(spec)])), MindRefusal::RepoNotInCampaign { repo: OTHER_REPO.into() }); } + /// A target revision naming repos, and the supersession of its predecessor. + fn repo_revision(revision: u32, repos: &[&str]) -> Vec { + let D::Target(mut named) = target(revision, &[INVARIANT]) else { panic!() }; + named.repos = repos.iter().map(|name| repo(name)).collect(); + let previous = r(K::Target, &id("target", &format!("r{}", revision - 1))); + let this = r(K::Target, &id("target", &format!("r{revision}"))); + vec![D::Target(named), resolution(previous, superseded(&[this]))] + } + + fn spec_on(cut: &str, repo_name: &str) -> D { + let mut spec = cut_spec(cut, 1); + spec.repo = repo(repo_name); + D::CutSpec(spec) + } + + #[test] + fn a_target_revision_adds_a_repo_a_spec_may_name() { + let mut mind = seeded(); + assert_eq!(refusal(admit(&mut mind, vec![spec_on("1", OTHER_REPO)])), MindRefusal::RepoNotInCampaign { repo: OTHER_REPO.into() }); + committed(admit(&mut mind, repo_revision(2, &[REPO, OTHER_REPO]))); + committed(admit(&mut mind, vec![spec_on("1", OTHER_REPO)])); + + // The same revision, supersession and spec in one batch. + let mut fresh = seeded(); + let mut batch = repo_revision(2, &[REPO, OTHER_REPO]); + batch.push(spec_on("1", OTHER_REPO)); + committed(admit(&mut fresh, batch)); + } + + #[test] + fn a_target_revision_removes_a_repo() { + let mut mind = seeded(); + committed(admit(&mut mind, vec![spec_on("1", REPO)])); + committed(admit(&mut mind, repo_revision(2, &[OTHER_REPO]))); + let spec_id = id("cut_spec", "cut-1.r1"); + let spec_view = mind.view(&r(K::CutSpec, &spec_id)).expect("a valid ref").expect("the spec is held"); + assert_eq!(spec_view.status, crate::query::PipelineStatus::InForce, "spec 1 r1 stays in force"); + committed(admit(&mut mind, vec![D::CutReport(cut_report("1", 1))])); + committed(admit(&mut mind, vec![resolution(r(K::CutSpec, &spec_id), withdrawn())])); + + let mut second = cut_spec("1", 2); + second.repo = repo(REPO); + let revised = id("cut_spec", "cut-1.r2"); + assert_eq!( + refusal(admit(&mut mind, vec![D::CutSpec(second), resolution(r(K::CutSpec, &spec_id), superseded(&[r(K::CutSpec, &revised)]))])), + MindRefusal::RepoNotInCampaign { repo: REPO.into() } + ); + committed(admit(&mut mind, vec![spec_on("2", OTHER_REPO)])); + } + + #[test] + fn a_target_revision_cannot_silently_drop_its_repos() { + let mut mind = seeded(); + committed(admit(&mut mind, repo_revision(2, &[REPO, OTHER_REPO]))); + assert_eq!( + refusal(admit(&mut mind, repo_revision(3, &[]))), + MindRefusal::EmptyRepos { campaign: id("target", "r3") } + ); + // Nothing was written: the restating revision takes the same key. + committed(admit(&mut mind, repo_revision(3, &[REPO, OTHER_REPO]))); + // An empty revision whose predecessor named none keeps the campaign's set. + let mut plain = seeded(); + committed(admit(&mut plain, repo_revision(2, &[]))); + } + + #[test] + fn a_repo_revision_replays_idempotently() { + let mut mind = seeded(); + let (first, _) = committed(admit(&mut mind, repo_revision(2, &[REPO, OTHER_REPO]))); + assert_eq!( + admit(&mut mind, repo_revision(2, &[REPO, OTHER_REPO])), + PipelineAdmissionOutcome::AlreadyAdmitted { receipt_id: first } + ); + committed(admit(&mut mind, vec![spec_on("1", OTHER_REPO)])); + } + #[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 2427338..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::{ - OrgRepo, PipelineDocument, PipelineKind, PipelineRef, PipelineResolution, PipelineRun, PipelineStewardship, ResolutionOutcome, + OrgRepo, PipelineCampaign, PipelineDocument, PipelineKind, PipelineRef, PipelineResolution, PipelineRun, PipelineStewardship, ResolutionOutcome, RunOperator, Short, Slug, }; use schemars::JsonSchema; @@ -182,6 +182,23 @@ impl Docs { }) } + /// The repos a campaign's cuts may name: the repo set of the highest-revision + /// in-force target of `campaign.slug` that names one, else the campaign's own + /// opening set. The one owner of membership (ruling campaign-repo-set-home). + pub(crate) fn repos_in_force<'a>(&'a self, campaign: &'a PipelineCampaign) -> &'a [OrgRepo] { + self.of_kind(PipelineKind::Target) + .filter_map(|(key, document)| match document { + PipelineDocument::Target(target) + if target.campaign == campaign.slug && !target.repos.is_empty() && self.in_force(PipelineKind::Target, key) => + { + Some(target) + } + _ => None, + }) + .max_by_key(|target| target.revision) + .map_or(campaign.repos.as_slice(), |target| target.repos.as_slice()) + } + /// The resolution that closes the document, if any: the views' status, /// derived where admission derives whether there is one at all. pub(crate) fn closing_resolution(&self, kind: PipelineKind, id: &str) -> Option<(&str, &PipelineResolution)> { diff --git a/crates/huginn-mind/src/fixtures.rs b/crates/huginn-mind/src/fixtures.rs index 86cb827..77dbd45 100644 --- a/crates/huginn-mind/src/fixtures.rs +++ b/crates/huginn-mind/src/fixtures.rs @@ -155,6 +155,7 @@ pub(crate) fn target(revision: u32, invariants: &[&str]) -> PipelineDocument { .collect(), not_in_scope: vec![], canonical_implementations: vec![], + repos: vec![], doc: doc_ref(), }) } diff --git a/crates/huginn-mind/src/refusal.rs b/crates/huginn-mind/src/refusal.rs index e85113a..150f652 100644 --- a/crates/huginn-mind/src/refusal.rs +++ b/crates/huginn-mind/src/refusal.rs @@ -41,6 +41,7 @@ pub enum MindRefusal { InvalidOptions { question: String }, InvalidChoice { ruling: String, choice: String }, QuoteWithoutOperator { ruling: String }, + /// `campaign` names the refused document: a campaign, or a target revision that empties its predecessor's repos. EmptyRepos { campaign: String }, RepoNotInCampaign { repo: String }, UnknownDependency { cut: String }, diff --git a/crates/mind-body/src/testkit.rs b/crates/mind-body/src/testkit.rs index d00db01..2c27bf6 100644 --- a/crates/mind-body/src/testkit.rs +++ b/crates/mind-body/src/testkit.rs @@ -214,6 +214,7 @@ fn target() -> PipelineDocument { invariants: vec![TargetInvariant { label: "run-is-the-grant".into(), statement: "A run is the grant.".into() }], not_in_scope: vec![], canonical_implementations: vec![], + repos: vec![], doc: doc_ref(), }) } diff --git a/crates/mind-body/tests/wake.rs b/crates/mind-body/tests/wake.rs index c535391..58ffe12 100644 --- a/crates/mind-body/tests/wake.rs +++ b/crates/mind-body/tests/wake.rs @@ -116,6 +116,7 @@ fn seed() -> Vec { invariants: vec![TargetInvariant { label: "run-is-the-grant".into(), statement: "A run is the grant.".into() }], not_in_scope: vec![], canonical_implementations: vec![], + repos: vec![], doc: doc_ref(), }), ]