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(test): make a skipped test target audible and assert RPC reachability\n\nTwo findings from the e2e coverage audit, both of the same shape: something\nreports green having checked nothing.\n\n1. An unmet `required-features` skip is now announced.\n\nFour tests/*.rs targets carry `required-features`, and every gate they name is\ndefault-OFF for contributors. Cargo treats the two ways of selecting a target\ndifferently, and only one is safe:\n\n - naming it (`cargo test --test json_rpc_e2e`) is a hard error when the\n features are unmet -- verified: "target `json_rpc_e2e` in package\n `openhuman` requires the features: `voice`", exit 101. CI names its\n targets one at a time, so CI cannot lose one this way;\n - globbing (a bare `cargo test`, or `--tests`) drops the target SILENTLY and\n exits 0. That is what a contributor runs.\n\n`json_rpc_e2e` alone is >12k lines of RPC contract coverage and\n`raw_coverage_all` aggregates ~76 suites, so a green local run can have\ncompiled and run neither and look identical to one that did.\n\nbuild.rs now reads the manifest and emits one `cargo::warning=` naming what the\ncurrent feature set will skip and the flag that would run it. A build-script\nwarning rather than a failing test, because cargo captures the output of a\nPASSING test -- a warning printed there would itself be invisible. A warning\nrather than an error, because a contributor build legitimately omits these\ngates; the goal is that the omission is never a surprise. The manifest is\nparsed rather than hard-coded so a target added later is covered without\nanyone remembering this file, which is why the module list beside it is\nglobbed too.\n\n2. `assert_rpc_completed` now asserts something.\n\nIt checked that the response carried `result` OR `error` -- true of every\nwell-formed JSON-RPC response, including `unknown method: openhuman.whatever`.\nRoughly 90 methods across four tests were probed through it, so the whole\nregistry could have been deleted and this file would still have passed.\n\nIt now rejects a response whose error is `dispatch::UNKNOWN_METHOD_PREFIX`, and\ntakes that prefix from the shared constant so the probe cannot drift from the\nemit site. An error is still tolerated, deliberately: these loops call each\nmethod with empty params, so a registered method usually answers with a\nvalidation failure -- that is a completed dispatch, and the strongest thing an\nargument-less probe can honestly claim.\n\nChecked, not assumed: all 10 tests in the file still pass, so no call site was\npassing only because the helper was vacuous. Those ~90 surfaces are genuinely\nreachable.\n\nRevert-check: unregistering the memory_sources controllers in core/all.rs\nfails the reachability test at worker_c_modules_e2e.rs:254 with\n"openhuman.memory_sources_list: the core does not serve this method ...\nGot: unknown method: openhuman.memory_sources_list". The old helper passed that\nsame response. Restored; core/all.rs is byte-identical to main.\n
M3gA-Mind95774b5d3f51
diff --git a/build.rs b/build.rsindex 63deef49a5..f7c5b2e5ae 100644--- a/build.rs+++ b/build.rs@@ -12,13 +12,43 @@//! We glob the directory at build time (rather than hand-maintaining a `mod`//! list) so that any newly added `tests/raw_coverage/*.rs` file is picked up//! automatically and cannot be silently skipped.+//!+//! # Second job: make an unmet `required-features` skip audible+//!+//! Four `tests/*.rs` targets carry `required-features` (see `[[test]]` in+//! `Cargo.toml`), and every one of those features is default-OFF for+//! contributors. Cargo treats the two ways of selecting a target differently,+//! and only one of them is safe:+//!+//! - **Naming it** — `cargo test --test json_rpc_e2e` — is a hard error when+//! the features are unmet (`target ... requires the features: voice`,+//! exit 101). CI names its targets one at a time, so CI cannot lose one this+//! way.+//! - **Globbing** — a bare `cargo test`, or `cargo test --tests` — filters the+//! target out **silently and exits 0**. That is what a contributor runs, and+//! it reports a green suite having compiled and run none of them.+//!+//! `json_rpc_e2e` alone is >12k lines of RPC contract coverage, and+//! `raw_coverage_all` aggregates ~76 suites. A green run that skipped both+//! reads exactly like a green run that did not, which is how untested code+//! comes to look covered.+//!+//! So [`warn_about_silently_skipped_test_targets`] emits a `cargo::warning=`+//! naming what this feature configuration will skip. A build-script warning is+//! used rather than a failing test on purpose: cargo captures the output of a+//! *passing* test, so a warning printed there would itself be invisible, while+//! build-script warnings are shown unconditionally. It warns rather than fails+//! because a contributor build legitimately omits these gates — the goal is+//! that the omission is never a surprise, not that it is forbidden.+use std::collections::BTreeMap;use std::env;use std::fs;use std::path::Path;fn main() {let manifest_dir = env::var("CARGO_MANIFEST_DIR").expect("CARGO_MANIFEST_DIR must be set");+ warn_about_silently_skipped_test_targets(Path::new(&manifest_dir));let tests_dir = Path::new(&manifest_dir).join("tests");let raw_dir = tests_dir.join("raw_coverage");@@ -67,3 +97,127 @@ fn main() {let out_path = Path::new(&out_dir).join("raw_coverage_mods.rs");fs::write(&out_path, generated).expect("failed to write raw_coverage_mods.rs");}++/// The env var cargo sets for an enabled feature: upper-cased, `-` to `_`.+fn feature_env_var(feature: &str) -> String {+ format!(+ "CARGO_FEATURE_{}",+ feature.to_uppercase().replace(['-', '.'], "_")+ )+}++/// Emit one `cargo::warning=` naming every `[[test]]` target this feature+/// configuration will silently drop from a globbed `cargo test`.+///+/// The manifest is parsed rather than hard-coded so a target added later is+/// covered without anyone remembering to update this list — the same reason+/// the module list above is globbed instead of hand-maintained.+fn warn_about_silently_skipped_test_targets(manifest_dir: &Path) {+ let manifest_path = manifest_dir.join("Cargo.toml");+ println!("cargo:rerun-if-changed={}", manifest_path.display());+ let Ok(manifest) = fs::read_to_string(&manifest_path) else {+ // A source-only build tree may not ship the manifest we expect; the+ // module list above already tolerates that shape.+ return;+ };++ let mut skipped: BTreeMap<String, Vec<String>> = BTreeMap::new();+ for (target, required) in gated_test_targets(&manifest) {+ let missing: Vec<String> = required+ .iter()+ .filter(|feature| {+ let var = feature_env_var(feature);+ // Re-run when the feature set changes, so switching profiles+ // re-emits (or clears) the warning instead of leaving a stale+ // cached result.+ println!("cargo:rerun-if-env-changed={var}");+ env::var_os(&var).is_none()+ })+ .cloned()+ .collect();+ if !missing.is_empty() {+ skipped.insert(target, missing);+ }+ }+ if skipped.is_empty() {+ return;+ }++ let detail = skipped+ .iter()+ .map(|(target, missing)| format!("{target} (needs {})", missing.join(" + ")))+ .collect::<Vec<_>>()+ .join(", ");+ let all: Vec<&str> = {+ let mut features: Vec<&str> = skipped+ .values()+ .flat_map(|missing| missing.iter().map(String::as_str))+ .collect();+ features.sort_unstable();+ features.dedup();+ features+ };+ let features_flag = all.join(",");+ // One warning rather than one per target: this fires on every build in a+ // configuration that omits the gates, and four lines of it would train+ // people to scroll past.+ println!(+ "cargo:warning=A globbed `cargo test` SILENTLY SKIPS these targets in this feature \+ configuration and still exits 0: {detail}. Run them with `--features {features_flag}`, \+ or use the product set: cargo test --features \"$(bash \+ scripts/ci/product-features.sh)\". Naming a target explicitly (cargo test --test \+ json_rpc_e2e) errors instead of skipping — only the globbed form is silent."+ );+}++/// Every `[[test]]` target in `manifest` that declares `required-features`.+///+/// Deliberately a small hand parse: `build.rs` has no dependencies, and adding+/// a TOML crate to the build graph to read four lines would cost every build.+/// The shape it accepts is the shape the manifest uses — `[[test]]`, then+/// `name = "..."` and `required-features = [...]` before the next table.+fn gated_test_targets(manifest: &str) -> Vec<(String, Vec<String>)> {+ let mut found = Vec::new();+ let mut in_test_table = false;+ let mut name: Option<String> = None;+ let mut required: Option<Vec<String>> = None;++ let flush = |name: &mut Option<String>,+ required: &mut Option<Vec<String>>,+ found: &mut Vec<(String, Vec<String>)>| {+ if let (Some(name), Some(required)) = (name.take(), required.take()) {+ found.push((name, required));+ }+ };++ for line in manifest.lines() {+ let line = line.trim();+ if line.starts_with('[') {+ // Any new table ends the current `[[test]]` block.+ flush(&mut name, &mut required, &mut found);+ in_test_table = line == "[[test]]";+ continue;+ }+ if !in_test_table {+ continue;+ }+ if let Some(value) = line.strip_prefix("name") {+ if let Some(value) = value.trim_start().strip_prefix('=') {+ name = Some(value.trim().trim_matches('"').to_string());+ }+ } else if let Some(value) = line.strip_prefix("required-features") {+ if let Some(value) = value.trim_start().strip_prefix('=') {+ let inner = value.trim().trim_start_matches('[').trim_end_matches(']');+ required = Some(+ inner+ .split(',')+ .map(|feature| feature.trim().trim_matches('"').to_string())+ .filter(|feature| !feature.is_empty())+ .collect(),+ );+ }+ }+ }+ flush(&mut name, &mut required, &mut found);+ found+}diff --git a/tests/worker_c_modules_e2e.rs b/tests/worker_c_modules_e2e.rsindex c54c61ceb4..bfbc410a0b 100644--- a/tests/worker_c_modules_e2e.rs+++ b/tests/worker_c_modules_e2e.rs@@ -17,6 +17,7 @@ use serde_json::{json, Value};use tempfile::{tempdir, TempDir};use openhuman_core::core::auth::{init_rpc_token, CORE_TOKEN_ENV_VAR};+use openhuman_core::core::dispatch::UNKNOWN_METHOD_PREFIX;use openhuman_core::core::jsonrpc::build_core_http_router;const TEST_RPC_TOKEN: &str = "worker-c-modules-e2e-token";@@ -218,10 +219,40 @@ fn error_message<'a>(value: &'a Value, context: &str) -> &'a str {.unwrap_or_else(|| panic!("{context}: expected JSON-RPC error with message: {value}"))}+/// Assert that `value` is a JSON-RPC response for a method the core actually+/// serves.+///+/// This used to assert only that the envelope carried `result` **or** `error`,+/// which every well-formed JSON-RPC response does — including+/// `unknown method: openhuman.whatever`. The reachability loops below call ~90+/// methods through this helper, so all of them could have been deleted from the+/// registry and this file would still have passed.+///+/// An error is still tolerated, and deliberately: these loops call each method+/// with empty params, so a registered method usually answers with a validation+/// failure. That is a *completed dispatch* — the method resolved, took the+/// params and rejected them — and it is the strongest thing a probe with no+/// arguments can honestly assert. What must not happen is the request never+/// reaching a handler at all, which is exactly what+/// [`UNKNOWN_METHOD_PREFIX`] marks.fn assert_rpc_completed(value: &Value, context: &str) {+ let error = match (value.get("result"), value.get("error")) {+ (Some(_), None) => return,+ (None, Some(error)) => error,+ (Some(_), Some(_)) => panic!(+ "{context}: response carries BOTH result and error, which is not a valid \+ JSON-RPC envelope: {value}"+ ),+ (None, None) => panic!("{context}: response carries neither result nor error: {value}"),+ };+ let message = error+ .get("message")+ .and_then(Value::as_str)+ .unwrap_or_default();assert!(- value.get("result").is_some() || value.get("error").is_some(),- "{context}: expected JSON-RPC result or error envelope: {value}"+ !message.contains(UNKNOWN_METHOD_PREFIX),+ "{context}: the core does not serve this method, so the surface is NOT reachable \+ — the registry entry is missing or its namespace was renamed. Got: {message}");}