diff --git a/mcp-client-ruby/client.rb b/mcp-client-ruby/client.rb index 38067aaa..069468f5 100644 --- a/mcp-client-ruby/client.rb +++ b/mcp-client-ruby/client.rb @@ -244,6 +244,7 @@ def anthropic_client rescue Interrupt # Ctrl-C: stop without a backtrace; `ensure` still cleans up. puts + exit 130 rescue => e warn "Error: #{e.message}" exit 1 diff --git a/tests/README.md b/tests/README.md index 84fa66c1..098329e1 100644 --- a/tests/README.md +++ b/tests/README.md @@ -40,7 +40,7 @@ The fake API picks a script from the query text and checks every request the cli Finally the client must exit 0 on `quit`. A client that does one tool round and stops, drops `tools` on the follow-up call, sends one `tool_result` per message, gets the turn cap wrong, drops what a tool returned, forgets the conversation, keeps a failed query or an empty reply, or ignores `stop_reason` passes the no-key test and fails this one. -A second run checks Ctrl-C: the helper starts the client in a process group of its own, sends `SIGINT` to the group at the `Query:` prompt, as a terminal does, and leaves stdin open. The client must exit within 15 seconds without printing a backtrace. `quit` and EOF are the clean exits, so the exit status isn't checked; a client that hangs on a blocked stdin read, or never reaches the prompt, fails here. +A second run checks Ctrl-C: the helper starts the client in a process group of its own, sends `SIGINT` to the group at the `Query:` prompt, as a terminal does, and leaves stdin open. The client must exit within 15 seconds, without printing a backtrace and with a non-zero status: `quit` and EOF are the clean exits, and Ctrl-C isn't one. A client that hangs on a blocked stdin read, never reaches the prompt, or exits 0 fails here. All five clients are covered, including Rust: it calls the Messages API directly, so it honours `ANTHROPIC_BASE_URL` like the official SDKs do. diff --git a/tests/helpers/tool-loop-test.ts b/tests/helpers/tool-loop-test.ts index 3b7f61ce..3956c533 100644 --- a/tests/helpers/tool-loop-test.ts +++ b/tests/helpers/tool-loop-test.ts @@ -51,8 +51,8 @@ * here and passes the no-key test. * * A second client process checks that Ctrl-C at the prompt stops the client - * promptly and without a backtrace. `quit` and EOF are the clean exits; Ctrl-C - * only has to stop it, not hang on a blocked stdin read. + * promptly, non-zero and without a backtrace. `quit` and EOF are the clean + * exits; Ctrl-C only has to stop it, not hang on a blocked stdin read. * * Usage: node tool-loop-test.js [args...] */ @@ -593,8 +593,8 @@ function runClient( /** * Starts the client, sends SIGINT to its process group at the prompt, as a - * terminal's Ctrl-C does, and checks that it exits without a backtrace. - * stdin stays open. + * terminal's Ctrl-C does, and checks that it exits non-zero without a + * backtrace. stdin stays open. */ function runInterrupted(command: string, args: string[], baseUrl: string): Promise { return new Promise((resolve) => { @@ -625,10 +625,13 @@ function runInterrupted(command: string, args: string[], baseUrl: string): Promi }, INTERRUPT_TIMEOUT_MS); }); child.stderr.on("data", (chunk) => (stderr += chunk)); - child.on("close", () => { + child.on("close", (code, signal) => { clearTimeout(startup); clearTimeout(timer); if (!timer) check(false, "Ctrl-C: client showed its prompt"); + // Not 0: Ctrl-C isn't a clean exit. Clients exit 130 or die by SIGINT, + // but `uv run` reports a SIGINT death as 2. + check(code !== 0, `Ctrl-C: client exited non-zero (got ${signal ?? code})`); // Python's traceback, or Ruby's uncaught `...: Interrupt`. check(!/Traceback|KeyboardInterrupt|: Interrupt\b/.test(stderr), "Ctrl-C: client printed no backtrace"); resolve();