Skip to main content

to_body

Function to_body 

Source
pub fn to_body(
    path: &Path,
    issue: Option<String>,
    milestone: Option<String>,
) -> Result<HandoverBody, String>
Expand description

The journal body of a local record. issue and milestone are the publisher’s to say: a handover record has no field for either.

What crosses is the body and a few facts about the work — never a path of the author’s disk, because the receiving checkout is somewhere else and a path from another machine is at best noise. The body is bounded at MAX_HANDOVER_BYTES and an empty one is refused, since a handover whose body says nothing hands nothing over. A placeholder front-matter value (none, DETACHED) is read as the absence it stands for.

use majordomus_cli::mesh::handover::to_body;
use majordomus_cli::mesh::journal::HandoverBody;

let dir = tempfile::tempdir().unwrap();
let path = dir.path().join("20260915T100000Z--feature-x--abcdef1--0011.md");
std::fs::write(
    &path,
    "---\ntask_id: t-1\nbranch: DETACHED\nhead: abcdef1234\nworktree: /home/someone/repo\n\
     ---\n\n# Objective\nship\n",
)
.unwrap();

let body = to_body(&path, Some("#184".into()), None).unwrap();
assert_eq!(body.task.as_deref(), Some("t-1"));
assert_eq!(body.branch, None, "DETACHED is the absence of a branch, not a branch");
assert_eq!(body.issue.as_deref(), Some("#184"));
assert_eq!(body.id, HandoverBody::digest_of(&body.body));
assert!(!serde_json::to_string(&body).unwrap().contains("/home/someone"));

// a record whose body says nothing hands nothing over
std::fs::write(&path, "---\ntask_id: t-1\n---\n\n").unwrap();
assert!(to_body(&path, None, None).is_err());