Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions loom-daemon/src/forge_check_claim.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1838,6 +1838,22 @@ mod tests {

let garbage = write_exec(dir.path(), "gh-garbage.sh", "echo 'not json'");
assert_eq!(read_claim_labels(&garbage, dir.path(), 42), LabelLeg::Unknown);

// #14775: direct stub-execution evidence — the classifications above
// came from a CLI that actually ran, not from a shed answering
// `Unknown` before any invocation (the parallel-fixture interference
// this test pins down).
let ran = dir.path().join("stub-ran");
let counting = write_exec(
dir.path(),
"gh-counting.sh",
&format!(
r#"echo ran >> '{}'; echo '{{"labels":[{{"name":"loom:issue"}}]}}'"#,
ran.display()
),
);
assert_eq!(read_claim_labels(&counting, dir.path(), 42), LabelLeg::Clean);
assert!(ran.is_file(), "the stub itself executed");
}

#[test]
Expand Down
98 changes: 98 additions & 0 deletions loom-daemon/src/forge_gateway/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,44 @@ fn serial() -> std::sync::MutexGuard<'static, ()> {
.unwrap_or_else(std::sync::PoisonError::into_inner)
}

/// #14775: a fixture that moves the process-global gateway state
/// ([`set_active`] through `Refresher::pass_with`) runs its body in a child
/// copy of this test binary. The `serial` mutex above only orders publishers
/// inside this module; the synthetic gateway leaks past it to every other
/// fixture of this process — an unscoped reader-only read elsewhere answers
/// `host_has_read_pool()` with it and sheds before its fake CLI can answer.
/// The public test names stay as wrappers, so the default suite and focused
/// filters still exercise each body.
fn in_a_child_process(child: &str) {
let output = std::process::Command::new(std::env::current_exe().unwrap())
.args([
"--exact",
&format!("forge_gateway::tests::{child}"),
"--ignored",
"--test-threads=1",
"--format",
"pretty",
"--color",
"never",
])
.output()
.unwrap();
let stdout = String::from_utf8_lossy(&output.stdout);
let stderr = String::from_utf8_lossy(&output.stderr);
let single_pass = "test result: ok. 1 passed; 0 failed; 0 ignored; 0 measured;";
assert!(
output.status.success() && stdout.lines().any(|line| line.starts_with(single_pass)),
"gateway fixture child `{child}` did not run exactly one passing test ({})\nstdout:\n{stdout}\nstderr:\n{stderr}",
output.status,
);
}

#[test]
#[should_panic(expected = "test result: ok. 0 passed; 0 failed;")]
fn a_missing_gateway_child_is_refused_even_with_a_successful_exit() {
in_a_child_process("missing_gateway_fixture_child");
}

fn cfg(owners: &[(&str, &str)]) -> Value {
let refs: serde_json::Map<String, Value> = owners
.iter()
Expand Down Expand Up @@ -210,6 +248,15 @@ fn a_profile_carries_the_key_and_api_host_privately() {

#[test]
fn a_pass_publishes_each_owner_and_rewrites_api_host_on_every_publish() {
in_a_child_process("a_pass_publishes_each_owner_and_rewrites_api_host_on_every_publish_child");
}

/// The body of
/// [`a_pass_publishes_each_owner_and_rewrites_api_host_on_every_publish`],
/// in its own process: it publishes into the shared `DAEMON` singleton.
#[test]
#[ignore = "run in a child process by a_pass_publishes_each_owner_and_rewrites_api_host_on_every_publish"]
fn a_pass_publishes_each_owner_and_rewrites_api_host_on_every_publish_child() {
let _serial = serial();
let tmp = tempfile::tempdir().unwrap();
let ws = tmp.path();
Expand All @@ -234,6 +281,25 @@ fn a_pass_publishes_each_owner_and_rewrites_api_host_on_every_publish() {
let env = agent_env();
assert_eq!(env[1], (DIR_ENV, Some(base.clone().into_os_string())));

// #14775: with this synthetic gateway live, the production reader-only
// guard sheds an unscoped claim-label read (`Unknown`) and never
// consults the CLI — the exact interference running this body in a
// child keeps out of every unrelated fixture of the parent process.
assert!(any_live());
let inert = ws.join("gh-inert");
let ran = ws.join("inert-ran");
std::fs::write(&inert, format!("#!/bin/sh\necho ran > '{}'\n", ran.display())).unwrap();
{
use std::os::unix::fs::PermissionsExt;
std::fs::set_permissions(&inert, std::fs::Permissions::from_mode(0o755)).unwrap();
}
assert_eq!(
crate::forge_check_claim::read_claim_labels(&inert, ws, 42),
crate::forge_check_claim::LabelLeg::Unknown,
"a live gateway sheds an unscoped reader-only read"
);
assert!(!ran.exists(), "the inert CLI never ran: the read was shed, not sent");

// Nothing due within the republish interval.
assert_eq!(
r.pass_with(ws, &cfg(&[("gwt-a", "file:/k/a"), ("gwt-b", "file:/k/b")]), now, &fake),
Expand Down Expand Up @@ -261,6 +327,14 @@ fn a_pass_publishes_each_owner_and_rewrites_api_host_on_every_publish() {
/// on disk is picked up without a daemon restart.
#[test]
fn a_replaced_gh_is_reported_on_the_next_refresh() {
in_a_child_process("a_replaced_gh_is_reported_on_the_next_refresh_child");
}

/// The body of [`a_replaced_gh_is_reported_on_the_next_refresh`], in its own
/// process: it publishes into the shared `DAEMON` singleton (#14775).
#[test]
#[ignore = "run in a child process by a_replaced_gh_is_reported_on_the_next_refresh"]
fn a_replaced_gh_is_reported_on_the_next_refresh_child() {
let _serial = serial();
let tmp = tempfile::tempdir().unwrap();
let ws = tmp.path();
Expand All @@ -287,6 +361,14 @@ fn a_replaced_gh_is_reported_on_the_next_refresh() {

#[test]
fn an_old_gh_publishes_nothing_and_removes_what_was_there() {
in_a_child_process("an_old_gh_publishes_nothing_and_removes_what_was_there_child");
}

/// The body of [`an_old_gh_publishes_nothing_and_removes_what_was_there`],
/// in its own process: it moves the shared `DAEMON` singleton (#14775).
#[test]
#[ignore = "run in a child process by an_old_gh_publishes_nothing_and_removes_what_was_there"]
fn an_old_gh_publishes_nothing_and_removes_what_was_there_child() {
let _serial = serial();
let tmp = tempfile::tempdir().unwrap();
let ws = tmp.path();
Expand All @@ -305,6 +387,14 @@ fn an_old_gh_publishes_nothing_and_removes_what_was_there() {

#[test]
fn a_dropped_owner_s_profile_is_removed() {
in_a_child_process("a_dropped_owner_s_profile_is_removed_child");
}

/// The body of [`a_dropped_owner_s_profile_is_removed`], in its own process:
/// it publishes into the shared `DAEMON` singleton (#14775).
#[test]
#[ignore = "run in a child process by a_dropped_owner_s_profile_is_removed"]
fn a_dropped_owner_s_profile_is_removed_child() {
let _serial = serial();
let tmp = tempfile::tempdir().unwrap();
let ws = tmp.path();
Expand Down Expand Up @@ -361,6 +451,14 @@ fn a_live_profile_routes_reads_as_the_gateway_reader() {
/// agent is told about a gateway.
#[test]
fn with_the_gateway_unset_routing_is_byte_identical_to_today() {
in_a_child_process("with_the_gateway_unset_routing_is_byte_identical_to_today_child");
}

/// The body of [`with_the_gateway_unset_routing_is_byte_identical_to_today`],
/// in its own process: it moves the shared `DAEMON` singleton (#14775).
#[test]
#[ignore = "run in a child process by with_the_gateway_unset_routing_is_byte_identical_to_today"]
fn with_the_gateway_unset_routing_is_byte_identical_to_today_child() {
let _serial = serial();
let tmp = tempfile::tempdir().unwrap();
let ws = tmp.path();
Expand Down
Loading