Skip to content

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

fix: keep Rust E2E green on Bash 3

Steven Enamakel3bf93af7827a
diff --git a/scripts/__tests__/rust-e2e-enumeration.test.mjs b/scripts/__tests__/rust-e2e-enumeration.test.mjs
index b3b811c648..39e511670f 100644
--- a/scripts/__tests__/rust-e2e-enumeration.test.mjs
+++ b/scripts/__tests__/rust-e2e-enumeration.test.mjs
@@ -78,7 +78,7 @@ exec "$@"
* @param {number} opts.listStatus what it exits with
* @param {string} [opts.failTest] a case whose run should fail
*/
-function runSuite({ listStdout, listStatus, failTest = "" }) {
+function runSuite({ listStdout, listStatus, failTest = "", includeExtraArgs = true }) {
const dir = fs.mkdtempSync(path.join(os.tmpdir(), "rust-e2e-enumeration-"));
const runLog = path.join(dir, "runs.log");
fs.writeFileSync(path.join(dir, "cargo"), CARGO_STUB, { mode: 0o755 });
@@ -98,7 +98,8 @@ function runSuite({ listStdout, listStatus, failTest = "" }) {
// bash before 4.4 (macOS /bin/bash is 3.2) treats an empty "${a[@]}" as
// unbound under `set -u`, which would fail these tests locally for a
// reason unrelated to enumeration.
- "EXTRA_ARGS=(--nocapture)",
+ `EXTRA_ARGS=(${includeExtraArgs ? "--nocapture" : ""})`,
+ `HAS_EXTRA_ARGS=${includeExtraArgs ? 1 : 0}`,
extractFunction("run_json_rpc_e2e_suite"),
// A plain statement, exactly as the runner's suite loop calls it. Inside an
// `if` condition bash suspends errexit for the whole function body, which
@@ -144,8 +145,8 @@ function runSuite({ listStdout, listStatus, failTest = "" }) {
return { ...result, runs };
}
-const runOf = (name) =>
- `test --manifest-path Cargo.toml --features voice --test json_rpc_e2e ${name} -- --exact --test-threads=1 --nocapture`;
+const runOf = (name, includeExtraArgs = true) =>
+ `test --manifest-path Cargo.toml --features voice --test json_rpc_e2e ${name} -- --exact --test-threads=1${includeExtraArgs ? " --nocapture" : ""}`;
test("a listing that fails before printing any name fails the suite", () => {
// The case from #6236: the target does not compile, so there is nothing to
@@ -204,6 +205,17 @@ test("a successful listing runs each case once, in its own process, with EXTRA_A
assert.deepEqual(res.runs, [runOf("scenario_a"), runOf("scenario_b")]);
});
+test("an empty EXTRA_ARGS array is safe under Bash nounset", () => {
+ const res = runSuite({
+ listStdout: "scenario_a: test\n",
+ listStatus: 0,
+ includeExtraArgs: false,
+ });
+
+ assert.equal(res.status, 0, res.output);
+ assert.deepEqual(res.runs, [runOf("scenario_a", false)]);
+});
+
test("a failing case still fails the suite, and nothing after it runs", () => {
// Pins behaviour the fix must not lose. The loop now reads a here-string
// instead of a process substitution; a failing case must still stop it.
@@ -222,7 +234,7 @@ test("mcp_registry_e2e runs serially because its module state is process-global"
const source = fs.readFileSync(runner, "utf8");
const start = source.indexOf('if [ "$suite" = "mcp_registry_e2e" ]');
assert.ok(start >= 0, "MCP registry target has an explicit runner branch");
- const end = source.indexOf(" if [ \"${#EXTRA_ARGS[@]}\" -gt 0 ]", start);
+ const end = source.indexOf(' if [ "$HAS_EXTRA_ARGS" -eq 1 ]', start);
assert.ok(end > start, "MCP registry branch ends before the generic suite runner");
assert.match(
source.slice(start, end),
diff --git a/scripts/test-rust-e2e.sh b/scripts/test-rust-e2e.sh
index 8ab4738dc8..5c50608d00 100755
--- a/scripts/test-rust-e2e.sh
+++ b/scripts/test-rust-e2e.sh
@@ -84,6 +84,7 @@ fi
# Everything after `--` is forwarded to cargo test as test-binary args.
SUITES=()
EXTRA_ARGS=()
+HAS_EXTRA_ARGS=0
while [ $# -gt 0 ]; do
case "$1" in
--suite)
@@ -100,10 +101,14 @@ while [ $# -gt 0 ]; do
--)
shift
EXTRA_ARGS+=("$@")
+ if [ "$#" -gt 0 ]; then
+ HAS_EXTRA_ARGS=1
+ fi
break
;;
*)
EXTRA_ARGS+=("$1")
+ HAS_EXTRA_ARGS=1
shift
;;
esac
@@ -249,7 +254,7 @@ run_json_rpc_e2e_suite() {
bash "$SCRIPT_DIR/ci-cancel-aware.sh" "$CARGO_BIN" test \
--manifest-path Cargo.toml --features "$PRODUCT_FEATURES" \
--test json_rpc_e2e "$test_name" -- \
- --exact --test-threads=1 "${EXTRA_ARGS[@]}"
+ --exact --test-threads=1 ${EXTRA_ARGS[@]+"${EXTRA_ARGS[@]}"}
done <<<"$test_names"
}
@@ -290,7 +295,7 @@ for suite in "${SUITES[@]}"; do
continue
fi
- if [ "${#EXTRA_ARGS[@]}" -gt 0 ]; then
+ if [ "$HAS_EXTRA_ARGS" -eq 1 ]; then
echo "[rust-e2e] $CARGO_BIN test --manifest-path Cargo.toml --test $suite -- ${EXTRA_ARGS[*]}"
bash "$SCRIPT_DIR/ci-cancel-aware.sh" "$CARGO_BIN" test \
--manifest-path Cargo.toml --features "$PRODUCT_FEATURES" \
diff --git a/tests/agent_harness_e2e.rs b/tests/agent_harness_e2e.rs
index 7350bface5..d1f9fd44c8 100644
--- a/tests/agent_harness_e2e.rs
+++ b/tests/agent_harness_e2e.rs
@@ -75,6 +75,7 @@ fn env_lock() -> std::sync::MutexGuard<'static, ()> {
static SCRIPTED_COMPLETIONS: OnceLock<Mutex<std::collections::VecDeque<Value>>> = OnceLock::new();
static CAPTURED_COMPLETION_REQUESTS: OnceLock<Mutex<Vec<Value>>> = OnceLock::new();
+const SCRIPT_DISCOVERED_MCP_TOOL: &str = "__script_discovered_mcp_tool__";
fn with_scripted<T>(f: impl FnOnce(&mut std::collections::VecDeque<Value>) -> T) -> T {
let m = SCRIPTED_COMPLETIONS.get_or_init(|| Mutex::new(Default::default()));
@@ -326,7 +327,7 @@ async fn scripted_chat_completions(
}
let next = with_scripted(|q| q.pop_front());
- let Some(entry) = next else {
+ let Some(mut entry) = next else {
let message = json!({ "role": "assistant", "content": "default scripted completion" });
return completion_response(streaming, message);
};
@@ -345,6 +346,19 @@ async fn scripted_chat_completions(
.into_response();
}
+ if let Some(tool_calls) = entry.get_mut("toolCalls").and_then(Value::as_array_mut) {
+ for call in tool_calls {
+ if call.get("name").and_then(Value::as_str) != Some(SCRIPT_DISCOVERED_MCP_TOOL) {
+ continue;
+ }
+ let name = scripted_discovered_mcp_tool_name(&body).unwrap_or_else(|| {
+ panic!("the next model request did not advertise the searched MCP action")
+ });
+ call["name"] = json!(name);
+ call["id"] = json!(format!("call_{name}"));
+ }
+ }
+
let content = entry.get("content").and_then(Value::as_str).unwrap_or("");
let mut message = json!({ "role": "assistant", "content": content });
if let Some(tool_calls) = entry.get("toolCalls").and_then(Value::as_array) {
@@ -4129,19 +4143,14 @@ async fn orchestrator_calls_a_connected_mcp_tool_directly_inner() {
reset_script(Vec::new());
let stack = boot_stack().await;
// Connecting also writes the tool cache the orchestrator's surface reads.
- let server_id = declare_and_connect_registry_echo_server(&stack.rpc_base, 940).await;
- let action = openhuman_core::mcp::registry::action_tool::searchable_name(
- &server_id,
- REGISTRY_MCP_SERVER,
- "echo",
- );
+ declare_and_connect_registry_echo_server(&stack.rpc_base, 940).await;
reset_script(vec![
tool_call_completion(
"tool_search",
json!({ "query": "echo message on my connected MCP server" }),
),
- tool_call_completion(&action, json!({ "message": MCP_ECHO_CANARY })),
+ tool_call_completion(SCRIPT_DISCOVERED_MCP_TOOL, json!({ "message": MCP_ECHO_CANARY })),
text_completion("The MCP tool answered."),
]);
let mut events = spawn_sse_collector(format!(
@@ -4191,6 +4200,8 @@ async fn orchestrator_calls_a_connected_mcp_tool_directly_inner() {
Some("chat_done"),
"the direct MCP turn must finish: {done}"
);
+ let action = scripted_discovered_mcp_tool_name_from_requests(&requests)
+ .expect("the searched MCP action was advertised to the model");
let search = tool_result_text(&requests, "tool_search").expect("search result");
assert!(
search.contains(&action),
@@ -4222,6 +4233,39 @@ async fn orchestrator_calls_a_connected_mcp_tool_directly_inner() {
stack.shutdown();
}
+#[cfg(feature = "mcp")]
+fn scripted_discovered_mcp_tool_name(body: &Value) -> Option<String> {
+ let native = body
+ .pointer("/tools")
+ .and_then(Value::as_array)
+ .into_iter()
+ .flatten()
+ .find_map(|tool| {
+ let function = tool.get("function")?;
+ let description = function.get("description")?.as_str()?;
+ let properties = function.pointer("/parameters/properties")?.as_object()?;
+ if description.starts_with("MCP server ") && properties.contains_key("message") {
+ function.get("name")?.as_str().map(str::to_owned)
+ } else {
+ None
+ }
+ });
+ native.or_else(|| {
+ advertised_tool_names(&json!({ "body": body }))
+ .into_iter()
+ .find(|name| name.starts_with("mcp_") && !name.starts_with("mcp_registry_"))
+ })
+}
+
+#[cfg(feature = "mcp")]
+fn scripted_discovered_mcp_tool_name_from_requests(requests: &[Value]) -> Option<String> {
+ requests
+ .iter()
+ .rev()
+ .find_map(|request| request.get("body"))
+ .and_then(scripted_discovered_mcp_tool_name)
+}
+
// ── #5821: the tool-policy boundary is APPENDED, not prepended ──────────────
//
// Lives here rather than in `tests/raw_coverage/`: `raw_coverage_all` declares