Skip to content

Commit e7e98e8

Browse files
committed
test(mcp): cover cancellation along the full MCP stdio route
The existing cancellation tests stop at a stub handler or at the executor. This one runs the default session, router, and executor against a stand-in daemon transport, so a hop that drops the call's signal fails it. The SRC-5 test title now names #1596. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_016qAu53rMak1bXMuR5U2gF4
1 parent c81772a commit e7e98e8

2 files changed

Lines changed: 51 additions & 1 deletion

File tree

‎src/__tests__/cli-exit-paths.test.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -239,7 +239,7 @@ test('a failed `is` predicate exits non-zero, whatever answered it', async () =>
239239
assert.ok(!output.includes('Passed'), 'a failed assertion must never render as passed');
240240
});
241241

242-
test('a failing `test` suite exits 1 through the flushed exit path', async () => {
242+
test('#1596: a failing `test` suite exits 1 through the flushed exit path', async () => {
243243
const flow = path.join(mkdtempForTestSync('agent-device-failing-suite-'), 'login.ad');
244244
fs.writeFileSync(flow, 'open "Demo"\n');
245245
const restoreEnv = installIsolatedCliTestEnv();
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
import assert from 'node:assert/strict';
2+
import { afterEach, test, vi } from 'vitest';
3+
import * as daemonClient from '@agent-device/daemon-client';
4+
import { createMcpStdioSession } from '../server.ts';
5+
6+
afterEach(() => {
7+
vi.restoreAllMocks();
8+
});
9+
10+
// The whole production route of a cancellation: stdio session, payload boundary, router, tool
11+
// executor, and the daemon transport the call's client sends through. Only the transport is a
12+
// stand-in, so a hop that drops the call's signal leaves the request running and fails this test.
13+
test('notifications/cancelled aborts the daemon request of a running tools/call and writes nothing', async () => {
14+
const signals: Array<AbortSignal | undefined> = [];
15+
let settled = false;
16+
vi.spyOn(daemonClient, 'createEnsuredDaemonTransport').mockReturnValue(
17+
async (_req, context) =>
18+
await new Promise((_resolve, reject) => {
19+
signals.push(context?.signal);
20+
context?.signal?.addEventListener('abort', () => {
21+
settled = true;
22+
reject(context.signal?.reason);
23+
});
24+
}),
25+
);
26+
const writes: unknown[] = [];
27+
const session = createMcpStdioSession({ write: (message) => writes.push(message) });
28+
29+
session.receive(
30+
`${JSON.stringify({
31+
jsonrpc: '2.0',
32+
id: 41,
33+
method: 'tools/call',
34+
params: { name: 'devices', arguments: {} },
35+
})}\n`,
36+
);
37+
await vi.waitFor(() => assert.equal(signals.length, 1));
38+
session.receive(
39+
`${JSON.stringify({
40+
jsonrpc: '2.0',
41+
method: 'notifications/cancelled',
42+
params: { requestId: 41 },
43+
})}\n`,
44+
);
45+
await session.end();
46+
47+
assert.equal(signals[0]?.aborted, true);
48+
assert.equal(settled, true);
49+
assert.deepEqual(writes, []);
50+
});

0 commit comments

Comments
 (0)