diff --git a/epiphany-core/src/pipeline_documents.rs b/epiphany-core/src/pipeline_documents.rs index ffb8816c..b3355ca3 100644 --- a/epiphany-core/src/pipeline_documents.rs +++ b/epiphany-core/src/pipeline_documents.rs @@ -21,18 +21,16 @@ use cultcache_rs::{CultCache, CultCacheEnvelope, DatabaseEntry}; use schemars::JsonSchema; use serde::{Deserialize, Serialize}; -pub const PIPELINE_SCHEMA_EPOCH: &str = "epiphany.pipeline.epoch.v1"; - /// Typed refusals of the pipeline documents. Bounds, formats and key identity -/// are the document half (D2); `ForeignEpoch` and `ForeignStore` are raised by -/// the decode and envelope-validation paths that still live here, and D2 hands -/// them to the organ when admission moves there. +/// are the document half (D2); `ForeignStore` is raised by the decode path that +/// still lives here, and D2 hands it to the organ when admission moves there. +/// Identity, the schema epoch and the `ForeignEpoch` refusal are the organ's +/// (D2), and Cut 8 writes them there against a store a test can construct. #[derive(Clone, Debug, PartialEq, Eq)] pub enum PipelineRefusal { FieldBound { field: String, limit: u32, actual: u32 }, InvalidFormat { field: String, value: String }, InvalidIdentity { kind: PipelineKind, key: String, expected: String }, - ForeignEpoch { found: String, expected: String }, ForeignStore { r#type: String }, } @@ -244,7 +242,6 @@ macro_rules! unit_enums { unit_enums! { EvidenceKind { Command, Test, Mutation, Probe, SourceRead, Capture } - Faculty { SelfFaculty, Imagination, Hands, Soul, MindSteward, Eyes, Operator } ClaimOutcome { Holds, Falsified, Unproven } FindingConfidence { Confirmed, Plausible } FindingSeverity { Blocker, High, Medium, Low } @@ -328,9 +325,6 @@ value_types! { item: Line, why_it_can_wait: Line, owner: Short, } pub struct PipelineResolution { subject: PipelineRef, outcome: ResolutionOutcome, rationale: Para, resolved_on: Date } - - /// Who declared an admission. Attribution only; no rule trusts it (D4). - pub struct PipelineProvenance { faculty: Faculty, agent: Short, session: Short, tool: Short } } /// A reference to another document. The id is parsed as a full pipeline id of @@ -439,13 +433,13 @@ macro_rules! pipeline_kinds { } } - /// Registers every type a pipeline store may hold: the ten kinds, the - /// store identity, admission provenance, and the commit receipt. - #[cfg_attr(not(test), expect(dead_code, reason = "the organ registers its mind's types through this"))] + /// Registers every type the document tests put in a cache: the ten + /// kinds and the commit receipt. Test scaffolding until the organ + /// registers its mind's types (Cut 8), which is why it is `cfg(test)` + /// rather than a live path wearing a dead-code waiver. + #[cfg(test)] pub(crate) fn register_pipeline_document_types(cache: &mut CultCache) -> Result<()> { $(cache.register_entry_type::<$document>()?;)* - cache.register_entry_type::()?; - cache.register_entry_type::()?; cache.register_entry_type::()?; Ok(()) } @@ -475,21 +469,6 @@ pipeline_kinds! { "epiphany.pipeline.resolution.v1", "EpiphanyPipelineResolutionDocument"; } -/// The store's schema identity, keyed by its epoch string (D2). -#[derive(Clone, Debug, PartialEq, Eq, DatabaseEntry)] -#[cultcache(type = "epiphany.pipeline.identity.v1", schema = "EpiphanyPipelineIdentity")] -pub(crate) struct EpiphanyPipelineIdentity { - #[cultcache(key = 0)] - pub(crate) schema_epoch: String, -} - -#[derive(Clone, Debug, PartialEq, Eq, DatabaseEntry)] -#[cultcache(type = "epiphany.pipeline.provenance.v1", schema = "EpiphanyPipelineProvenance")] -pub(crate) struct EpiphanyPipelineProvenance { - #[cultcache(key = 0)] - pub(crate) value: PipelineProvenance, -} - /// Parses a full document id. `::` for every kind but /// `campaign`, which is keyed by its slug alone. The segment count is exact, /// the kind segment must match `kind`, and both the campaign and the local @@ -597,17 +576,6 @@ pub fn pipeline_key(document: &PipelineDocument) -> Result Result<()> { - if envelope.r#type == EpiphanyPipelineIdentity::TYPE { - let identity: EpiphanyPipelineIdentity = rmp_serde::from_slice(&envelope.payload)?; - if identity.schema_epoch != PIPELINE_SCHEMA_EPOCH || envelope.key != identity.schema_epoch { - return Err(PipelineRefusal::ForeignEpoch { - found: identity.schema_epoch, - expected: PIPELINE_SCHEMA_EPOCH.into(), - } - .into()); - } - return Ok(()); - } let document = PipelineDocument::decode(envelope)?; document.validate()?; let expected = pipeline_key(&document)?; @@ -821,6 +789,26 @@ mod tests { Ok(()) } + /// Soul F2: a decode is type-matched in both directions. The round-trip + /// test above pins the positive match; this pins the refusal, so an + /// envelope belonging to another kind can never be decoded as whichever + /// pipeline kind happens to parse its payload. The commit receipt is the + /// sharp case: a pipeline store may legitimately hold one, and it is still + /// not a document. + #[test] + fn decode_refuses_an_envelope_of_a_foreign_type() -> Result<()> { + let cache = schema_cache()?; + let foreign = ::TYPE; + assert!(!foreign.starts_with("epiphany.pipeline."), "{foreign} is a foreign type id"); + let mut envelope = campaign_sample().prepare(&cache)?; + envelope.r#type = foreign.into(); + assert_eq!( + PipelineDocument::decode(&envelope), + Err(PipelineRefusal::ForeignStore { r#type: foreign.into() }) + ); + Ok(()) + } + #[test] fn bounds_refuse_in_utf8_bytes() { let PipelineDocument::Campaign(mut campaign) = campaign_sample() else { unreachable!() }; diff --git a/epiphany-core/src/runtime_spine.rs b/epiphany-core/src/runtime_spine.rs index d303f76d..bba56585 100644 --- a/epiphany-core/src/runtime_spine.rs +++ b/epiphany-core/src/runtime_spine.rs @@ -8751,6 +8751,50 @@ pub(crate) mod tests { Ok(()) } + /// Soul F4: the spine store and a pipeline store are different stores, and + /// the spine cache refuses the latter *by type* — it registers its own + /// types and nothing else. The epoch checks beside this one cannot stand in + /// for it: a pipeline store carries no runtime or Mind identity at all, so + /// `validate_runtime_store_epoch` returns `Ok` and the registry is the only + /// thing left refusing. + #[test] + fn runtime_spine_cache_refuses_a_pipeline_store() -> Result<()> { + let temp = tempfile::tempdir()?; + let store = temp.path().join("pipeline.cc"); + let mut pipeline = CultCache::new(); + crate::pipeline_documents::register_pipeline_document_types(&mut pipeline)?; + let campaign = crate::PipelineDocument::Campaign(crate::PipelineCampaign { + slug: "eureka-state".into(), + title: "Eureka pipeline state".into(), + repos: vec!["GameCult/Epiphany".into()], + working_branch: "codex/eureka-pipeline-state".into(), + target_doc: crate::DocRef { + path: "notes/eureka-pipeline-state-target.md".into(), + start_line: 1, + end_line: 9, + commit: "5f98228d".into(), + }, + }); + let envelope = campaign.prepare(&pipeline)?; + assert!( + envelope.r#type.starts_with("epiphany.pipeline."), + "the sample is a pipeline document: {}", + envelope.r#type + ); + let mut backing = runtime_spine_backing_store(&store)?; + backing.push(&envelope)?; + + assert!( + validate_runtime_store_epoch(&runtime_spine_backing_store(&store)?.pull_all()?).is_ok(), + "the epoch check passes a pipeline store, so only the registry refuses it" + ); + let error = runtime_spine_cache(&store) + .and_then(|mut runtime| runtime.pull_all_backing_stores()) + .unwrap_err(); + assert!(error.to_string().contains("epiphany.pipeline."), "{error:#}"); + Ok(()) + } + #[test] fn coordinator_terminal_receipts_preserve_exact_immutable_run_basis() -> Result<()> { let temp = tempfile::tempdir()?;