use std::fs;
use std::process::Command;
#[test]
fn queue_scenarios_execute_compiler_and_exact_host_handlers_with_stubbed_clocks() {
let root = std::env::temp_dir().join(format!("noxid-wo24-scenarios-{}", std::process::id()));
let _ = fs::remove_dir_all(&root);
fs::create_dir_all(root.join("server/queues")).expect("create queue project");
fs::write(
root.join("Noxid.toml"),
"[app]\ntitle = \"Queue scenarios\"\n",
)
.expect("write config");
fs::write(
root.join("server/queues/Echo.nox"),
r#"queue Echo {
payload { message: String }
handler { return message }
retry: 2
backoff: 15s
scenario CompilerHandler {
description: "executes without Postgres against a fixed clock"
clock: "2026-08-29T12:00:00Z"
when: enqueue(message: "hello")
expect: value == "hello", attempts == 1, refusal == ""
}
}
"#,
)
.expect("write compiler queue");
fs::write(
root.join("server/queues/Hosted.nox"),
r#"queue Hosted {
payload { tenant: String }
retry: 1
backoff: 1m
scenario ExactStub {
description: "never executes the live host"
given: Hosted = "indexed"
clock: "2026-08-29T12:01:00Z"
when: enqueue(tenant: "acme")
expect: value == "indexed", attempts == 1
}
}
"#,
)
.expect("write hosted queue");
fs::write(
root.join("server/host.js"),
"throw new Error(\"REAL_QUEUE_HOST_EXECUTED\");\n",
)
.expect("write hostile host");
let output = Command::new(env!("CARGO_BIN_EXE_noxid"))
.args(["test", ".", "--gate", "--json"])
.current_dir(&root)
.output()
.expect("run queue scenarios");
let stdout = String::from_utf8_lossy(&output.stdout);
let stderr = String::from_utf8_lossy(&output.stderr);
assert!(output.status.success(), "{stdout}\n{stderr}");
assert!(
stdout.contains("\"summary\":{\"total\":2,\"passed\":2,\"failed\":0,\"unsupported\":0}")
);
assert!(stdout.contains("\"semanticUnit\":\"queue:Echo\""));
assert!(stdout.contains("\"semanticUnit\":\"queue:Hosted\""));
assert!(!stdout.contains("REAL_QUEUE_HOST_EXECUTED"));
let _ = fs::remove_dir_all(root);
}