The fastest, cheapest, most efficient open-source agent harness. Run more than 500 agents on a $10 VPS.
Rust agent-orchestrationai-agentsai-assistantdesktopllmlocal-firstmcppersonal-aiprivacyrustsecond-braintauri
fix(tests): send the bearer the process validates, not each suite's own literal\n\n`core::auth::RPC_TOKEN` is a process-global `OnceLock` and `init_rpc_token`\nreturns early once it is set — deliberately, so a second call cannot 401 live\nclients. That early return is load-bearing and is not touched here.\n\nSince `tests/raw_coverage/` became one aggregated binary, only the first suite\nto reach `ensure_rpc_auth()` pins the bearer for the whole process. The other\nthree kept sending `Bearer <their own TEST_RPC_TOKEN>`, got 401, and tripped\ntheir own `assert_eq!(status, OK)`. Which suites lose depends on libtest\nscheduling.\n\nEach suite now asks `get_rpc_token()` what the process settled on. Each still\nseeds `CORE_TOKEN_ENV_VAR` with its own literal, so a suite that does win the\nrace is unaffected — it simply no longer assumes it won.\n\nThe guard is a source scan rather than a runtime assertion. A runtime assertion\npasses whenever its own file happens to win the race, so it could not fail\ndeterministically, and it could not see a new suite reintroducing the literal.\nIt asserts it read more than ten files, so an empty scan fails instead of\nsilently passing.\n\nAll four token-holding suites in one process:\n\n before: 63 passed; 12 failed (11 x 401, plus the new guard)\n after: 74 passed; 1 failed\n\nThe survivor is a different defect and is reported separately:\n`tools_channels_raw_coverage_e2e.rs:58` `#[path]`-includes\n`tools_approval_channels_raw_coverage_e2e.rs` while build.rs also globs it in,\nso that file is compiled twice into one binary and the copies race on process\nglobals — `left: 0, right: 1` on a subscriber count, not an HTTP status. The\ninclude is upstream (#4721) and this diff is auth-only; it fails identically\nwith these four files reverted.\n\nTest-only. No production code changes.\n\nCloses #6112\n\nClaude-Session: https://claude.ai/code/session_01Rx5Fzc5keoeUQB3MwMFqMM\n
M3gA-Mindf5ec43d3922d
diff --git a/tests/raw_coverage/connectivity_raw_coverage_e2e.rs b/tests/raw_coverage/connectivity_raw_coverage_e2e.rsindex 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.rsnew file mode 100644index 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.rsindex 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.rsindex 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.rsindex 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,