Skip to content

The fastest, cheapest, most efficient open-source agent harness. Run more than 500 agents on a $10 VPS.

fix(tests): send the bearer the process validates, not each suite's own literal

M3gA-Mindcd075887bffa
diff --git a/tests/raw_coverage/connectivity_raw_coverage_e2e.rs b/tests/raw_coverage/connectivity_raw_coverage_e2e.rs
index 1cfc15995a..2c5ca0c3aa 100644
--- a/tests/raw_coverage/connectivity_raw_coverage_e2e.rs
+++ b/tests/raw_coverage/connectivity_raw_coverage_e2e.rs
@@ -104,6 +104,20 @@ fn ensure_rpc_auth() {
});
}
+/// The bearer this process actually validates.
+///
+/// `core::auth::RPC_TOKEN` is a process-global `OnceLock` and `init_rpc_token`
+/// returns early once it is set — deliberately, so a second call cannot 401 live
+/// clients. Since `tests/raw_coverage/` is one aggregated binary, only the first
+/// suite to reach `ensure_rpc_auth` pins its own `TEST_RPC_TOKEN`; every other
+/// suite sending its literal gets a 401 and trips its own `assert_eq!` (#6112).
+/// Ask the auth module what it settled on instead of assuming we won the race.
+fn rpc_bearer() -> &'static str {
+ ensure_rpc_auth();
+ openhuman_core::core::auth::get_rpc_token()
+ .expect("ensure_rpc_auth initialises the token subsystem on the line above")
+}
+
async fn serve_rpc() -> (
SocketAddr,
tokio::task::JoinHandle<Result<(), std::io::Error>>,
@@ -169,8 +183,8 @@ async fn rpc(rpc_base: &str, id: i64, method: &str, params: Value) -> Value {
.expect("client");
let response = client
.post(rpc_base)
- .bearer_auth(TEST_RPC_TOKEN)
- .header(AUTHORIZATION, format!("Bearer {TEST_RPC_TOKEN}"))
+ .bearer_auth(rpc_bearer())
+ .header(AUTHORIZATION, format!("Bearer {}", rpc_bearer()))
.json(&json!({
"jsonrpc": "2.0",
"id": id,
diff --git a/tests/raw_coverage/rpc_bearer_hygiene_e2e.rs b/tests/raw_coverage/rpc_bearer_hygiene_e2e.rs
new file mode 100644
index 0000000000..a921c7de5e
--- /dev/null
+++ b/tests/raw_coverage/rpc_bearer_hygiene_e2e.rs
@@ -0,0 +1,64 @@
+//! #6112 regression guard: no aggregated suite may send a hard-coded bearer.
+//!
+//! `core::auth::RPC_TOKEN` is a process-global `OnceLock` and `init_rpc_token`
+//! returns early once it is set — deliberately, so a second call cannot 401 live
+//! clients. Since `tests/raw_coverage/` is one binary, only the first suite to
+//! initialise it pins its own `TEST_RPC_TOKEN`; any suite that then sends its own
+//! literal is answered `401` and trips its own `assert_eq!(status, OK)`. Which
+//! suites fail depends on libtest scheduling, so the failure is load-dependent
+//! and invisible to CI, which runs one process per module filter.
+//!
+//! The fix is for every suite to send `get_rpc_token()` — the token the process
+//! actually validates — rather than the literal it hoped to install. This scans
+//! the sibling sources for the literal form so a *new* suite cannot reintroduce
+//! it, which a runtime assertion in one file could not do.
+
+use std::path::Path;
+
+/// Substrings that mean "this suite sends its own literal".
+const FORBIDDEN: &[&str] = &[
+ "bearer_auth(TEST_RPC_TOKEN)",
+ "Bearer {TEST_RPC_TOKEN}",
+];
+
+#[test]
+fn no_raw_coverage_suite_sends_a_hard_coded_bearer() {
+ let dir = Path::new(env!("CARGO_MANIFEST_DIR")).join("tests/raw_coverage");
+ let mut offenders = Vec::new();
+ let mut scanned = 0usize;
+
+ for entry in std::fs::read_dir(&dir).expect("tests/raw_coverage must be readable") {
+ let path = entry.expect("dir entry").path();
+ if path.extension().and_then(|e| e.to_str()) != Some("rs") {
+ continue;
+ }
+ if path.file_name().and_then(|n| n.to_str()) == Some("rpc_bearer_hygiene_e2e.rs") {
+ continue; // this file names the literals on purpose
+ }
+ let source = std::fs::read_to_string(&path).expect("suite source must be readable");
+ scanned += 1;
+ for needle in FORBIDDEN {
+ if source.contains(needle) {
+ offenders.push(format!(
+ "{}: sends {needle} — use the process token instead",
+ path.file_name().and_then(|n| n.to_str()).unwrap_or("?")
+ ));
+ }
+ }
+ }
+
+ // An empty scan is a failure, not a pass: if the glob ever stops matching,
+ // this test would otherwise report clean having read nothing.
+ assert!(
+ scanned > 10,
+ "expected to scan the raw_coverage suites, only saw {scanned} file(s) in {}",
+ dir.display()
+ );
+ assert!(
+ offenders.is_empty(),
+ "raw_coverage suites must send `core::auth::get_rpc_token()`, not their own \
+ `TEST_RPC_TOKEN` literal — only the first suite in the process wins that race \
+ (#6112):\n {}",
+ offenders.join("\n ")
+ );
+}
diff --git a/tests/raw_coverage/tool_registry_approval_raw_coverage_e2e.rs b/tests/raw_coverage/tool_registry_approval_raw_coverage_e2e.rs
index 2fb608c48d..6e921fa60e 100644
--- a/tests/raw_coverage/tool_registry_approval_raw_coverage_e2e.rs
+++ b/tests/raw_coverage/tool_registry_approval_raw_coverage_e2e.rs
@@ -102,6 +102,20 @@ fn ensure_rpc_auth() {
});
}
+/// The bearer this process actually validates.
+///
+/// `core::auth::RPC_TOKEN` is a process-global `OnceLock` and `init_rpc_token`
+/// returns early once it is set — deliberately, so a second call cannot 401 live
+/// clients. Since `tests/raw_coverage/` is one aggregated binary, only the first
+/// suite to reach `ensure_rpc_auth` pins its own `TEST_RPC_TOKEN`; every other
+/// suite sending its literal gets a 401 and trips its own `assert_eq!` (#6112).
+/// Ask the auth module what it settled on instead of assuming we won the race.
+fn rpc_bearer() -> &'static str {
+ ensure_rpc_auth();
+ openhuman_core::core::auth::get_rpc_token()
+ .expect("ensure_rpc_auth initialises the token subsystem on the line above")
+}
+
async fn serve_rpc() -> (
std::net::SocketAddr,
tokio::task::JoinHandle<Result<(), std::io::Error>>,
@@ -199,7 +213,7 @@ async fn rpc(rpc_base: &str, id: i64, method: &str, params: Value) -> Value {
let url = format!("{}/rpc", rpc_base.trim_end_matches('/'));
let response = client
.post(&url)
- .header(AUTHORIZATION, format!("Bearer {TEST_RPC_TOKEN}"))
+ .header(AUTHORIZATION, format!("Bearer {}", rpc_bearer()))
.json(&json!({
"jsonrpc": "2.0",
"id": id,
diff --git a/tests/raw_coverage/tools_approval_channels_raw_coverage_e2e.rs b/tests/raw_coverage/tools_approval_channels_raw_coverage_e2e.rs
index 2c0cbc1e09..bf841b3dd8 100644
--- a/tests/raw_coverage/tools_approval_channels_raw_coverage_e2e.rs
+++ b/tests/raw_coverage/tools_approval_channels_raw_coverage_e2e.rs
@@ -367,6 +367,20 @@ fn ensure_rpc_auth() {
});
}
+/// The bearer this process actually validates.
+///
+/// `core::auth::RPC_TOKEN` is a process-global `OnceLock` and `init_rpc_token`
+/// returns early once it is set — deliberately, so a second call cannot 401 live
+/// clients. Since `tests/raw_coverage/` is one aggregated binary, only the first
+/// suite to reach `ensure_rpc_auth` pins its own `TEST_RPC_TOKEN`; every other
+/// suite sending its literal gets a 401 and trips its own `assert_eq!` (#6112).
+/// Ask the auth module what it settled on instead of assuming we won the race.
+fn rpc_bearer() -> &'static str {
+ ensure_rpc_auth();
+ openhuman_core::core::auth::get_rpc_token()
+ .expect("ensure_rpc_auth initialises the token subsystem on the line above")
+}
+
async fn serve_rpc() -> (
std::net::SocketAddr,
tokio::task::JoinHandle<Result<(), std::io::Error>>,
@@ -729,7 +743,7 @@ async fn rpc(rpc_base: &str, id: i64, method: &str, params: Value) -> Value {
let url = format!("{}/rpc", rpc_base.trim_end_matches('/'));
let response = client
.post(&url)
- .header(AUTHORIZATION, format!("Bearer {TEST_RPC_TOKEN}"))
+ .header(AUTHORIZATION, format!("Bearer {}", rpc_bearer()))
.json(&json!({
"jsonrpc": "2.0",
"id": id,
diff --git a/tests/raw_coverage/worker_b_raw_coverage_e2e.rs b/tests/raw_coverage/worker_b_raw_coverage_e2e.rs
index cd9ffb28fd..63c32fd71c 100644
--- a/tests/raw_coverage/worker_b_raw_coverage_e2e.rs
+++ b/tests/raw_coverage/worker_b_raw_coverage_e2e.rs
@@ -104,6 +104,20 @@ fn ensure_rpc_auth() {
});
}
+/// The bearer this process actually validates.
+///
+/// `core::auth::RPC_TOKEN` is a process-global `OnceLock` and `init_rpc_token`
+/// returns early once it is set — deliberately, so a second call cannot 401 live
+/// clients. Since `tests/raw_coverage/` is one aggregated binary, only the first
+/// suite to reach `ensure_rpc_auth` pins its own `TEST_RPC_TOKEN`; every other
+/// suite sending its literal gets a 401 and trips its own `assert_eq!` (#6112).
+/// Ask the auth module what it settled on instead of assuming we won the race.
+fn rpc_bearer() -> &'static str {
+ ensure_rpc_auth();
+ openhuman_core::core::auth::get_rpc_token()
+ .expect("ensure_rpc_auth initialises the token subsystem on the line above")
+}
+
async fn serve_rpc() -> (
SocketAddr,
tokio::task::JoinHandle<Result<(), std::io::Error>>,
@@ -277,7 +291,7 @@ async fn rpc(rpc_base: &str, id: i64, method: &str, params: Value) -> Value {
let url = format!("{}/rpc", rpc_base.trim_end_matches('/'));
let response = client
.post(&url)
- .header(AUTHORIZATION, format!("Bearer {TEST_RPC_TOKEN}"))
+ .header(AUTHORIZATION, format!("Bearer {}", rpc_bearer()))
.json(&json!({
"jsonrpc": "2.0",
"id": id,