pub fn materialize(root: &Path, view: &HandoverView) -> Result<PathBuf, String>Expand description
Write a consumed handover into root’s handovers directory, or return the record that
already holds it. The record’s worktree is mesh:<origin runtime>: it resolves as
another checkout’s handover on the same branch.
This is the half that turns a message into continuity: after it, majordomus handover --resolve on this checkout finds the other machine’s handover through the ordinary
resolution and nothing downstream has to know the mesh exists. It is written to be
repeatable — consuming the same handover twice yields the one record — and defensively,
because every value in it was written by another runtime: the front matter and the file
name admit only what their parts are, so neither a key nor a path can be smuggled in
through a branch name or a timestamp.
use majordomus_cli::mesh::handover::{directory, materialize, to_body};
use majordomus_cli::mesh::journal::StreamId;
use majordomus_cli::mesh::state::HandoverView;
let tmp = tempfile::tempdir().unwrap();
let root = tmp.path().join("checkout");
std::fs::create_dir_all(&root).unwrap();
assert!(std::process::Command::new("git")
.arg("-C").arg(&root).args(["init", "-q"]).status().unwrap().success());
let src = tmp.path().join("20260915T100000Z--feature-x--abcdef1--0011.md");
std::fs::write(&src, "---\nbranch: feature/x\nhead: abcdef1234\n---\n\n# Objective\nship\n")
.unwrap();
let stream = StreamId::parse(&format!("{}-{}-{}", "a".repeat(32), "b".repeat(16), "c".repeat(16)))
.unwrap();
let view = HandoverView {
id: to_body(&src, None, None).unwrap().id,
stream,
runtime: format!("{}-{}", "a".repeat(32), "b".repeat(16)),
published_lamport: 1,
handover: to_body(&src, None, None).unwrap(),
consumed_by: vec![],
};
let written = materialize(&root, &view).unwrap();
assert_eq!(written.parent(), Some(directory(&root).as_path()));
assert_eq!(materialize(&root, &view).unwrap(), written, "one handover, one record");
assert!(std::fs::read_to_string(&written).unwrap().contains("worktree: mesh:"));