Require store-backed metadata branch bootstrap

This commit is contained in:
Bryan Helmkamp 2026-04-01 20:57:24 -07:00
parent a169ba068d
commit 0cb5495ce9
No known key found for this signature in database
3 changed files with 25 additions and 21 deletions

View file

@ -71,24 +71,21 @@ impl RunLifecycle<WorkflowGraph> for GitLifecycle {
.await
.ok()
.flatten()
.and_then(|record| serde_json::to_vec_pretty(&record).ok())
.or_else(|| std::fs::read(self.run_dir.join("run.json")).ok());
.and_then(|record| serde_json::to_vec_pretty(&record).ok());
let start_json = self
.run_store
.get_start()
.await
.ok()
.flatten()
.and_then(|record| serde_json::to_vec_pretty(&record).ok())
.or_else(|| std::fs::read(self.run_dir.join("start.json")).ok());
.and_then(|record| serde_json::to_vec_pretty(&record).ok());
let sandbox_json = self
.run_store
.get_sandbox()
.await
.ok()
.flatten()
.and_then(|record| serde_json::to_vec_pretty(&record).ok())
.or_else(|| std::fs::read(self.run_dir.join("sandbox.json")).ok());
.and_then(|record| serde_json::to_vec_pretty(&record).ok());
let mut files: Vec<(&str, &[u8])> = Vec::new();
if let Some(ref data) = run_json {
files.push(("run.json", data));

View file

@ -1,10 +1,12 @@
use std::collections::HashMap;
use std::path::PathBuf;
use std::sync::Arc;
use chrono::Utc;
use fabro_agent::Sandbox;
use fabro_graphviz::graph::Graph as GvGraph;
use fabro_store::{DiskProjectingRunStore, InMemoryStore, Store};
use fabro_store::{DiskProjectingRunStore, InMemoryStore, RunStore, Store};
use fabro_types::run::RunRecord;
use crate::error::Result;
use crate::event::EventEmitter;
@ -37,10 +39,11 @@ async fn initialized(
options: InitializedOptions,
) -> Initialized {
std::fs::create_dir_all(&run_options.run_dir).expect("failed to create run dir");
let created_at = Utc::now();
let inner_store = InMemoryStore::default()
.create_run(
&run_options.run_id,
Utc::now(),
created_at,
Some(run_options.run_dir.to_string_lossy().as_ref()),
)
.await
@ -49,6 +52,23 @@ async fn initialized(
inner_store,
run_options.run_dir.clone(),
));
run_store
.put_run(&RunRecord {
run_id: run_options.run_id,
created_at,
settings: run_options.settings.clone(),
graph: graph.clone(),
workflow_slug: run_options.workflow_slug.clone(),
working_directory: PathBuf::from(sandbox.working_directory()),
host_repo_path: run_options
.host_repo_path
.as_ref()
.map(|path| path.display().to_string()),
base_branch: run_options.base_branch.clone(),
labels: run_options.labels.clone(),
})
.await
.expect("failed to seed run record in run store");
let emitter = bound_emitter(run_options.run_id, &emitter);
Initialized {
graph: graph.clone(),

View file

@ -10229,19 +10229,6 @@ async fn git_checkpoint_host_writes_shadow_branch() {
let run_dir = tempfile::tempdir().unwrap();
// Write graph.fabro so init_run can read it
std::fs::write(run_dir.path().join("graph.fabro"), "digraph {}").unwrap();
// Write run.json so init_run stores it on the metadata branch
let run_record_json = serde_json::json!({
"run_id": run_id,
"created_at": "2025-01-01T00:00:00Z",
"settings": {},
"graph": { "name": "ShadowBranchTest", "nodes": {}, "edges": [], "attrs": {} },
"working_directory": worktree_path.to_str().unwrap(),
});
std::fs::write(
run_dir.path().join("run.json"),
serde_json::to_string(&run_record_json).unwrap(),
)
.unwrap();
let emitter = EventEmitter::default();
let env: Arc<dyn fabro_agent::Sandbox> =