From 64b2bb6dbe283e661389854dd25bf4deace6c8f9 Mon Sep 17 00:00:00 2001 From: Meta Vens Date: Fri, 14 Aug 2026 12:15:05 +0200 Subject: [PATCH] Complete keyed RepoModel semantic operations --- epiphany-core/src/repo_model_documents.rs | 59 ++++++++++++++++++++++- 1 file changed, 58 insertions(+), 1 deletion(-) diff --git a/epiphany-core/src/repo_model_documents.rs b/epiphany-core/src/repo_model_documents.rs index c6aa3cbf..541d10e8 100644 --- a/epiphany-core/src/repo_model_documents.rs +++ b/epiphany-core/src/repo_model_documents.rs @@ -132,6 +132,7 @@ pub enum EpiphanyRepoModelMutationOperation { PutNode { node: EpiphanyMemoryNode }, RetireNode { node_id: String }, PutEdge { edge: EpiphanyMemoryEdge }, + RetireEdge { edge_id: String }, PutSummary { summary: EpiphanyMemorySummary }, PutFrontier { item: RepoFrontierItem }, } @@ -335,6 +336,7 @@ pub fn plan_repo_model_mutation( .iter() .filter_map(|operation| match operation { EpiphanyRepoModelMutationOperation::PutEdge { edge } => Some(edge.id.clone()), + EpiphanyRepoModelMutationOperation::RetireEdge { edge_id } => Some(edge_id.clone()), _ => None, }) .collect::>(); @@ -453,6 +455,25 @@ pub fn plan_repo_model_mutation( .0, )?; } + EpiphanyRepoModelMutationOperation::RetireEdge { edge_id } => { + require_semantic_id(edge_id, "RepoModel edge")?; + let mut edge = edges + .get(edge_id) + .cloned() + .ok_or_else(|| anyhow!("RepoModel mutation retires a missing edge"))?; + let existing = cache + .get_envelope::(edge_id)? + .ok_or_else(|| anyhow!("RepoModel edge lost its envelope"))?; + insert_strong_envelope(&mut strong, existing)?; + edge.lifecycle = epiphany_state_model::EpiphanyMemoryLifecycle::Retired; + edges.insert(edge_id.clone(), edge.clone()); + insert_envelope( + &mut writes, + cache + .prepare_entry(edge_id, &EpiphanyRepoModelEdgeDocument::new(&edge)?)? + .0, + )?; + } EpiphanyRepoModelMutationOperation::PutSummary { summary } => { require_semantic_id(&summary.id, "RepoModel summary")?; if !staged_domain_ids.contains(&summary.domain_id) { @@ -590,6 +611,7 @@ fn repo_model_operation_identity( EpiphanyRepoModelMutationOperation::PutNode { node } => ("node", &node.id), EpiphanyRepoModelMutationOperation::RetireNode { node_id } => ("node", node_id), EpiphanyRepoModelMutationOperation::PutEdge { edge } => ("edge", &edge.id), + EpiphanyRepoModelMutationOperation::RetireEdge { edge_id } => ("edge", edge_id), EpiphanyRepoModelMutationOperation::PutSummary { summary } => ("summary", &summary.id), EpiphanyRepoModelMutationOperation::PutFrontier { item } => ("frontier", &item.id), }; @@ -1028,8 +1050,43 @@ mod tests { let view = assemble_repo_model_view(&store)?; assert_eq!(view.domains, [domain]); assert_eq!(view.nodes, [left, right]); - assert_eq!(view.edges, [edge]); + assert_eq!(view.edges, [edge.clone()]); assert_eq!(view.summaries, [summary]); + + let retire = EpiphanyRepoModelMutationProposal::new( + "proposal-retire-edge", + vec![EpiphanyRepoModelMutationOperation::RetireEdge { + edge_id: "edge-flow".into(), + }], + )?; + let retire_plan = plan_repo_model_mutation(&store, &retire)?; + let retire_provenance = cache.prepare_entry(&retire.proposal_id, &retire)?.0; + assert!(matches!( + crate::commit_operator_mind_mutation( + &store, + retire_provenance, + "Modeling.repo_model_mutation", + retire_plan.strong_reads, + retire_plan.writes, + "2026-08-14T00:00:02Z", + )?, + crate::EpiphanyMindCommitOutcome::Committed(_) + )); + assert_eq!( + assemble_repo_model_view(&store)?.edges[0].lifecycle, + EpiphanyMemoryLifecycle::Retired + ); + + let duplicate = EpiphanyRepoModelMutationProposal::new( + "proposal-duplicate-edge", + vec![ + EpiphanyRepoModelMutationOperation::PutEdge { edge }, + EpiphanyRepoModelMutationOperation::RetireEdge { + edge_id: "edge-flow".into(), + }, + ], + )?; + assert!(plan_repo_model_mutation(&store, &duplicate).is_err()); Ok(()) } }