From 49ee678117f79c49b91799b0db695f1761fe75b5 Mon Sep 17 00:00:00 2001 From: iris Date: Mon, 16 Nov 2026 05:13:19 +0100 Subject: [PATCH] name what is true in three more comments, and test the old event log's removal --- hive-agent/src/vacuum.rs | 41 +++++++++++++++++++++++++++ hive-c0re/src/coordinator.rs | 4 +-- hive-c0re/src/main.rs | 4 +-- nix/host-modules/hive-c0re/vhosts.nix | 4 +-- 4 files changed, 47 insertions(+), 6 deletions(-) diff --git a/hive-agent/src/vacuum.rs b/hive-agent/src/vacuum.rs index e4cdf8b24..b6eb2ad15 100644 --- a/hive-agent/src/vacuum.rs +++ b/hive-agent/src/vacuum.rs @@ -170,3 +170,44 @@ fn remove_old_event_log(harness: &Path) { } } } + +#[cfg(test)] +mod tests { + use super::remove_old_event_log; + + #[test] + fn the_old_event_log_and_its_wal_files_are_removed_and_nothing_else() { + let dir = tempfile::tempdir().unwrap(); + for name in [ + "hyperhive-events.sqlite", + "hyperhive-events.sqlite-wal", + "hyperhive-events.sqlite-shm", + "hyperhive-turn-stats.sqlite", + ] { + std::fs::write(dir.path().join(name), b"x").unwrap(); + } + remove_old_event_log(dir.path()); + assert!(!dir.path().join("hyperhive-events.sqlite").exists()); + assert!(!dir.path().join("hyperhive-events.sqlite-wal").exists()); + assert!(!dir.path().join("hyperhive-events.sqlite-shm").exists()); + assert!(dir.path().join("hyperhive-turn-stats.sqlite").exists()); + } + + #[test] + fn a_harness_dir_without_the_log_is_left_alone() { + let dir = tempfile::tempdir().unwrap(); + remove_old_event_log(dir.path()); + assert_eq!(std::fs::read_dir(dir.path()).unwrap().count(), 0); + } + + /// A removal that fails for another reason is logged and the rest still go. + #[test] + fn a_failed_removal_does_not_stop_the_others() { + let dir = tempfile::tempdir().unwrap(); + std::fs::create_dir(dir.path().join("hyperhive-events.sqlite")).unwrap(); + std::fs::write(dir.path().join("hyperhive-events.sqlite-wal"), b"x").unwrap(); + remove_old_event_log(dir.path()); + assert!(dir.path().join("hyperhive-events.sqlite").is_dir()); + assert!(!dir.path().join("hyperhive-events.sqlite-wal").exists()); + } +} diff --git a/hive-c0re/src/coordinator.rs b/hive-c0re/src/coordinator.rs index 10057f5f3..7ae234f3b 100644 --- a/hive-c0re/src/coordinator.rs +++ b/hive-c0re/src/coordinator.rs @@ -750,8 +750,8 @@ impl Coordinator { /// Per-agent harness-internal state dir. Bind-mounted RW into the /// agent container at `/agents/{name}/harness`. Holds sqlite dbs - /// and config files owned by the harness (`hyperhive-events.sqlite`, - /// `hyperhive-turn-stats.sqlite`, `hyperhive-model`) — kept separate + /// and config files owned by the harness (`hyperhive-turn-stats.sqlite`, + /// `hyperhive-model`) — kept separate /// from the agent-visible `state/` so claude's "my notes" view is /// uncluttered and the host vacuum has a clean sweep root. pub fn agent_harness_dir(name: &hive_types::Ident) -> PathBuf { diff --git a/hive-c0re/src/main.rs b/hive-c0re/src/main.rs index 41cc4522a..faee9ea59 100644 --- a/hive-c0re/src/main.rs +++ b/hive-c0re/src/main.rs @@ -321,8 +321,8 @@ async fn cmd_serve( swarm_agent_status::spawn(std::sync::Arc::clone(&coord)); // Squid's users file: the hashes of this hive's agents' proxy credentials. workers::squid_users::spawn(coord.shutdown_rx()); - // Per-agent events.sqlite + bash-tasks file cleanup now runs - // agent-side in the harness (`hive_agent::vacuum`): the files are + // Per-agent bash-tasks file cleanup, and the removal of the old event log, + // now run agent-side in the harness (`hive_agent::vacuum`): the files are // agent-owned, so host-side deletes hit PermissionDenied / readonly-db // under privsep. See issue tracker "perms borked". // (turn-stats.sqlite has no vacuum — it's one tiny row per turn, diff --git a/nix/host-modules/hive-c0re/vhosts.nix b/nix/host-modules/hive-c0re/vhosts.nix index 3fd4b7613..5085e4e4e 100644 --- a/nix/host-modules/hive-c0re/vhosts.nix +++ b/nix/host-modules/hive-c0re/vhosts.nix @@ -132,8 +132,8 @@ let }; }; - # Who is signed in, for the profile menu of the dashboard and the agent page - # (both are served from this vhost, so one location covers both). Authelia + # Who is signed in, for the profile menu of the dashboard (served from + # this vhost). Authelia # answers with the session's display name and e-mail; the swarm UI's # `/api/whoami` (../swarm-ui.nix) is the same location. `=` exact match, so # the `proxy_pass` URI replaces the request's, and it wins over `/api/`.