Watch
0
0
Fork
You've already forked hyperhive
0
hyperhive/hive-subagent-mcp/tests/run_entry.rs
atlas afe6026d44 subagent: keep runs at +1000 when their cgroup is unavailable
Without a run cgroup (no delegation, setup failed, or one create
failed) a subagent run was started plain at oom_score_adj 0, below the
+500 the unit gave it before. Every run of the daemon now goes through
the entry wrapper; it sets +1000 and enters the cgroup only when there
is one. run_cgroup::entry takes the cgroup as an Option.
2026-10-13 12:25:27 +02:00

41 lines
1.7 KiB
Rust

//! The daemon binary as a run's entry wrapper (`run_cgroup::RunCgroup::entry`
//! sets these variables; its unit test pins the names).
use std::process::Command;
#[test]
fn the_entry_enters_the_cgroup_raises_the_score_and_execs_the_program() {
let cgroup = std::env::temp_dir().join(format!("hive-run-entry-{}", std::process::id()));
std::fs::create_dir_all(&cgroup).expect("fake cgroup");
let out = Command::new(env!("CARGO_BIN_EXE_hive-subagent-daemon"))
// Stands in for `claude`: prints what it was started with.
.env("HIVE_RUN_ENTRY_PROGRAM", "/bin/sh")
.env("HIVE_RUN_ENTRY_CGROUP", &cgroup)
.env("HIVE_RUN_ENTRY_OOM_SCORE_ADJ", "1000")
.args([
"-c",
r#"printf '%s|%s|%s' "$(cat /proc/self/oom_score_adj)" "${HIVE_RUN_ENTRY_CGROUP-unset}" "$1""#,
"sh",
"an-arg",
])
.output()
.expect("the binary runs");
let procs = std::fs::read_to_string(cgroup.join("cgroup.procs"));
std::fs::remove_dir_all(&cgroup).ok();
assert!(out.status.success(), "{out:?}");
assert_eq!(String::from_utf8_lossy(&out.stdout), "1000|unset|an-arg");
assert_eq!(procs.expect("cgroup.procs written"), "0");
}
#[test]
fn the_entry_without_a_cgroup_still_raises_the_score() {
let out = Command::new(env!("CARGO_BIN_EXE_hive-subagent-daemon"))
.env("HIVE_RUN_ENTRY_PROGRAM", "/bin/sh")
.env_remove("HIVE_RUN_ENTRY_CGROUP")
.env("HIVE_RUN_ENTRY_OOM_SCORE_ADJ", "1000")
.args(["-c", "cat /proc/self/oom_score_adj"])
.output()
.expect("the binary runs");
assert!(out.status.success(), "{out:?}");
assert_eq!(String::from_utf8_lossy(&out.stdout).trim(), "1000");
}