drop legacy /state mount for manager (#604)

This commit is contained in:
damocles 2026-05-29 21:09:16 +02:00 committed by Mara
commit dc99e64b2d
4 changed files with 60 additions and 62 deletions

View file

@ -196,14 +196,15 @@ pub fn write_payload(agent: &str, host_path: &Path, message: &str) -> Result<(),
}
/// Container-visible state prefix the caller's `file_path` must live
/// under. Sub-agents see their state at `/agents/<name>/state/`;
/// the manager keeps the legacy `/state/` mount (see
/// `lifecycle::set_nspawn_flags`). Auto-file paths use the same
/// prefix so the round-trip is symmetric.
/// under. Every agent sees its state at `/agents/<container>/state/`
/// (see `lifecycle::set_nspawn_flags`). Auto-file paths use the same
/// prefix so the round-trip is symmetric. The manager logical name
/// maps to its container name (`hm1nd`) per `lifecycle::MANAGER_NAME` —
/// the pre-#604 legacy `/state/` alias is gone.
#[must_use]
pub fn container_state_prefix(agent: &str) -> String {
if agent == hive_sh4re::MANAGER_AGENT {
"/state/".to_owned()
format!("/agents/{}/state/", crate::lifecycle::MANAGER_NAME)
} else {
format!("/agents/{agent}/state/")
}
@ -275,18 +276,23 @@ mod tests {
}
#[test]
fn manager_uses_legacy_state_prefix() {
// The manager container mounts its state at `/state/` (legacy),
// not `/agents/manager/state/`. Same host path; different
// container-visible path. resolve_host_path needs to know.
assert_eq!(container_state_prefix("manager"), "/state/");
let p = resolve_host_path("manager", "/state/reminders/x.md").unwrap();
fn manager_uses_container_name_prefix() {
// Post-#604: manager's container view of its state is at
// `/agents/<MANAGER_NAME>/state/` (= `/agents/hm1nd/state/`),
// same as every other agent — the legacy bare `/state/` mount
// was dropped from lifecycle::set_nspawn_flags.
assert_eq!(container_state_prefix("manager"), "/agents/hm1nd/state/");
let p = resolve_host_path("manager", "/agents/hm1nd/state/reminders/x.md").unwrap();
// NB: the host path still resolves under `agents/manager/`
// (Coordinator::agent_notes_dir takes the broker LOGICAL name).
// That's a pre-existing manager-logical-vs-container-name
// discrepancy tracked separately in #162; out of scope here.
assert_eq!(
p,
PathBuf::from("/var/lib/hyperhive/agents/manager/state/reminders/x.md")
);
// And the sub-agent prefix must NOT be accepted for the manager.
assert!(resolve_host_path("manager", "/agents/manager/state/x.md").is_err());
// And the legacy `/state/` prefix must NOT be accepted anymore.
assert!(resolve_host_path("manager", "/state/x.md").is_err());
}
#[test]