From 2b28703d16d6f178392639664c269ccda8087172 Mon Sep 17 00:00:00 2001 From: Meta Vens Date: Wed, 6 May 2026 13:49:56 +0100 Subject: [PATCH] Remove state ledger JSON migration hatches --- .../src/bin/epiphany-state-ledger-store.rs | 18 +-- epiphany-core/src/bin/epiphany-state.rs | 35 +---- epiphany-core/src/lib.rs | 2 - epiphany-core/src/state_ledger.rs | 137 ++---------------- state/ledgers.msgpack | Bin 49373 -> 49693 bytes state/map.yaml | 2 +- 6 files changed, 15 insertions(+), 179 deletions(-) diff --git a/epiphany-core/src/bin/epiphany-state-ledger-store.rs b/epiphany-core/src/bin/epiphany-state-ledger-store.rs index d0ba9e7a..ef869174 100644 --- a/epiphany-core/src/bin/epiphany-state-ledger-store.rs +++ b/epiphany-core/src/bin/epiphany-state-ledger-store.rs @@ -5,8 +5,6 @@ use epiphany_core::EpiphanyLedgerEvidenceRecord; use epiphany_core::add_state_branch; use epiphany_core::append_state_evidence; use epiphany_core::close_state_branch; -use epiphany_core::migrate_state_ledgers_to_cultcache; -use epiphany_core::project_state_ledgers_to_json; use epiphany_core::state_ledger_status; use std::collections::BTreeMap; use std::env; @@ -19,20 +17,6 @@ fn main() -> Result<()> { std::process::exit(2); }; match command.as_str() { - "migrate-json" => { - let branches = require_path_arg(&mut args, "--branches")?; - let evidence = require_path_arg(&mut args, "--evidence")?; - let store = require_path_arg(&mut args, "--store")?; - print_json(&migrate_state_ledgers_to_cultcache( - branches, evidence, store, - )?)?; - } - "project-json" => { - let store = require_path_arg(&mut args, "--store")?; - let branches = require_path_arg(&mut args, "--branches")?; - let evidence = require_path_arg(&mut args, "--evidence")?; - print_json(&project_state_ledgers_to_json(store, branches, evidence)?)?; - } "status" => { let store = require_path_arg(&mut args, "--store")?; print_json(&state_ledger_status(store)?)?; @@ -150,6 +134,6 @@ fn print_json(value: &T) -> Result<()> { fn print_usage() { eprintln!( - "usage: epiphany-state-ledger-store ..." + "usage: epiphany-state-ledger-store ..." ); } diff --git a/epiphany-core/src/bin/epiphany-state.rs b/epiphany-core/src/bin/epiphany-state.rs index 970f621b..dd1bcdaa 100644 --- a/epiphany-core/src/bin/epiphany-state.rs +++ b/epiphany-core/src/bin/epiphany-state.rs @@ -6,12 +6,10 @@ use epiphany_core::add_state_branch; use epiphany_core::append_state_evidence; use epiphany_core::close_state_branch; use epiphany_core::load_state_ledger; -use epiphany_core::migrate_state_ledgers_to_cultcache; use std::collections::BTreeMap; use std::env; use std::fs; use std::path::Path; -use std::path::PathBuf; fn main() -> Result<()> { let root = env::current_dir().context("failed to resolve current directory")?; @@ -25,35 +23,6 @@ fn main() -> Result<()> { }; match command.as_str() { "status" => print_status(&root, &map_path, &ledger_store)?, - "migrate-json" => { - let mut branches = None; - let mut evidence = None; - let mut store = None; - parse_named_args(&mut args, |name, value| match name { - "--branches" => { - branches = Some(PathBuf::from(value)); - Ok(()) - } - "--evidence" => { - evidence = Some(PathBuf::from(value)); - Ok(()) - } - "--store" => { - store = Some(PathBuf::from(value)); - Ok(()) - } - other => anyhow::bail!("unexpected argument {other}"), - })?; - let branches = branches.unwrap_or_else(|| state_dir.join("branches.json")); - let evidence = evidence.unwrap_or_else(|| state_dir.join("evidence.jsonl")); - let store = store.unwrap_or_else(|| ledger_store.clone()); - println!( - "{}", - serde_json::to_string_pretty(&migrate_state_ledgers_to_cultcache( - branches, evidence, store - )?)? - ); - } "add-evidence" => { let mut evidence_type = None; let mut status = None; @@ -237,7 +206,5 @@ fn parse_named_args( } fn print_usage() { - eprintln!( - "usage: epiphany-state ..." - ); + eprintln!("usage: epiphany-state ..."); } diff --git a/epiphany-core/src/lib.rs b/epiphany-core/src/lib.rs index d28f906f..cfc6255f 100644 --- a/epiphany-core/src/lib.rs +++ b/epiphany-core/src/lib.rs @@ -109,6 +109,4 @@ pub use state_ledger::add_state_branch; pub use state_ledger::append_state_evidence; pub use state_ledger::close_state_branch; pub use state_ledger::load_state_ledger; -pub use state_ledger::migrate_state_ledgers_to_cultcache; -pub use state_ledger::project_state_ledgers_to_json; pub use state_ledger::state_ledger_status; diff --git a/epiphany-core/src/state_ledger.rs b/epiphany-core/src/state_ledger.rs index b0a9a3a3..3556e8cf 100644 --- a/epiphany-core/src/state_ledger.rs +++ b/epiphany-core/src/state_ledger.rs @@ -1,4 +1,3 @@ -use anyhow::Context; use anyhow::Result; use anyhow::anyhow; use cultcache_rs::CultCache; @@ -8,7 +7,6 @@ use serde::Deserialize; use serde::Serialize; use serde_json::Value; use std::collections::BTreeMap; -use std::fs; use std::path::Path; pub const STATE_LEDGER_STORE_TYPE: &str = "epiphany.state_ledger"; @@ -52,42 +50,6 @@ pub struct EpiphanyLedgerEvidenceRecord { pub extra: BTreeMap, } -#[derive(Clone, Debug, Default, PartialEq, Serialize, Deserialize)] -struct BranchProjection { - pub branches: Vec, - #[serde(flatten)] - pub extra: BTreeMap, -} - -pub fn migrate_state_ledgers_to_cultcache( - branches_path: impl AsRef, - evidence_path: impl AsRef, - store_path: impl AsRef, -) -> Result { - let branches_path = branches_path.as_ref(); - let evidence_path = evidence_path.as_ref(); - let store_path = store_path.as_ref(); - let branch_raw = fs::read_to_string(branches_path) - .with_context(|| format!("failed to read {}", branches_path.display()))?; - let branches: BranchProjection = serde_json::from_str(&branch_raw) - .with_context(|| format!("failed to decode {}", branches_path.display()))?; - let evidence = read_evidence_jsonl(evidence_path)?; - let entry = EpiphanyStateLedgerEntry { - schema_version: STATE_LEDGER_SCHEMA_VERSION.to_string(), - branches: branches.branches, - evidence, - extra: branches.extra, - }; - let mut cache = state_ledger_cache(store_path)?; - cache.put(STATE_LEDGER_KEY, &entry)?; - Ok(serde_json::json!({ - "ok": true, - "store": store_path, - "branches": entry.branches.len(), - "evidence": entry.evidence.len(), - })) -} - pub fn state_ledger_status(store_path: impl AsRef) -> Result { let store_path = store_path.as_ref(); if !store_path.exists() { @@ -204,47 +166,6 @@ pub fn close_state_branch( })) } -pub fn project_state_ledgers_to_json( - store_path: impl AsRef, - branches_path: impl AsRef, - evidence_path: impl AsRef, -) -> Result { - let entry = load_state_ledger(store_path.as_ref())?; - let branches_path = branches_path.as_ref(); - let evidence_path = evidence_path.as_ref(); - if let Some(parent) = branches_path.parent() { - fs::create_dir_all(parent)?; - } - fs::write( - branches_path, - format!( - "{}\n", - serde_json::to_string_pretty(&BranchProjection { - branches: entry.branches.clone(), - extra: entry.extra.clone(), - })? - ), - ) - .with_context(|| format!("failed to write {}", branches_path.display()))?; - if let Some(parent) = evidence_path.parent() { - fs::create_dir_all(parent)?; - } - let mut lines = String::new(); - for record in &entry.evidence { - lines.push_str(&serde_json::to_string(record)?); - lines.push('\n'); - } - fs::write(evidence_path, lines) - .with_context(|| format!("failed to write {}", evidence_path.display()))?; - Ok(serde_json::json!({ - "ok": true, - "branchesPath": branches_path, - "evidencePath": evidence_path, - "branches": entry.branches.len(), - "evidence": entry.evidence.len(), - })) -} - fn state_ledger_cache(store_path: &Path) -> Result { let mut cache = CultCache::new(); cache.register_entry_type::()?; @@ -261,24 +182,6 @@ fn default_state_ledger() -> EpiphanyStateLedgerEntry { } } -fn read_evidence_jsonl(path: &Path) -> Result> { - let raw = - fs::read_to_string(path).with_context(|| format!("failed to read {}", path.display()))?; - let mut records = Vec::new(); - for (index, line) in raw.lines().enumerate() { - if line.trim().is_empty() { - continue; - } - let record: EpiphanyLedgerEvidenceRecord = serde_json::from_str(line) - .with_context(|| format!("failed to decode {} line {}", path.display(), index + 1))?; - validate_evidence(&record).with_context(|| { - format!("invalid evidence at {} line {}", path.display(), index + 1) - })?; - records.push(record); - } - Ok(records) -} - fn validate_branch(branch: &EpiphanyBranchRecord) -> Result<()> { if branch.id.trim().is_empty() { return Err(anyhow!("branch id must be non-empty")); @@ -314,39 +217,23 @@ mod tests { use tempfile::tempdir; #[test] - fn state_ledgers_migrate_and_append_native_evidence() -> Result<()> { + fn state_ledgers_add_branch_and_append_native_evidence() -> Result<()> { let temp = tempdir()?; - let branches = temp.path().join("branches.json"); - let evidence = temp.path().join("evidence.jsonl"); let store = temp.path().join("ledgers.msgpack"); - fs::write( - &branches, - serde_json::json!({ - "branches": [{ - "id": "main", - "hypothesis": "Typed state reduces drift.", - "status": "active", - "artifacts": ["state/map.yaml"], - "notes": "test" - }] - }) - .to_string(), - )?; - fs::write( - &evidence, - serde_json::to_string(&EpiphanyLedgerEvidenceRecord { - ts: "2026-05-06T00:00:00+00:00".to_string(), - evidence_type: "test".to_string(), - status: "ok".to_string(), - note: "The initial ledger record exists.".to_string(), - branch: None, + add_state_branch( + &store, + EpiphanyBranchRecord { + id: "main".to_string(), + hypothesis: "Typed state reduces drift.".to_string(), + status: "active".to_string(), + artifacts: vec!["state/map.yaml".to_string()], + notes: "test".to_string(), extra: BTreeMap::new(), - })? + "\n", + }, )?; - migrate_state_ledgers_to_cultcache(&branches, &evidence, &store)?; let entry = load_state_ledger(&store)?; assert_eq!(entry.branches.len(), 1); - assert_eq!(entry.evidence.len(), 1); + assert_eq!(entry.evidence.len(), 0); append_state_evidence( &store, EpiphanyLedgerEvidenceRecord { @@ -358,7 +245,7 @@ mod tests { extra: BTreeMap::new(), }, )?; - assert_eq!(load_state_ledger(&store)?.evidence.len(), 2); + assert_eq!(load_state_ledger(&store)?.evidence.len(), 1); Ok(()) } } diff --git a/state/ledgers.msgpack b/state/ledgers.msgpack index a79295a2099494803801685b77987e7be2d86f8f..c4c2f16e90c0d207fe186d5abf07a89260c2543b 100644 GIT binary patch delta 287 zcmYk1J5Iwu5Qb$^)6pUZ(Z-1}B*<<}!z&;`MYpU6d%@XV?M#4FfW!fiEJ4K~5L7f4 z$Dp9(7)Y!M1>IkK|LgO%^K{p_U!HsadR}=5f~%LeV7{r7W+6!GQPUlKd}k8|V!;?z zm>1|^`*42*V^ui8%ILmz<_u*kp%g4jq_kdoT)h7835ktE(B=}1MQ=p#I8QC+kWDJi zg!jQ75{Uv2ggl2?7kR9j!l`j^;)IrEA1_pnS|a!uQpBz9!46uU?fT^fLAJTO1rEs? rP1pvE1+&sc*N