Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,13 @@ describe('qwen serve live journal recovery', () => {
expect(replayText).toContain('chunk-19');

await prompt;

// Gate the fixture's session-close ack in default CI: the only other
// consumer of this path is the opt-in loadtest, so without this call a
// drifted close method name or ack shape would rot silently.
await expect(
activeDaemon.client.closeSession(created.sessionId),
).resolves.toBeUndefined();
} finally {
await activeDaemon?.dispose();
activeDaemon = undefined;
Expand Down
42 changes: 42 additions & 0 deletions integration-tests/fixtures/mock-acp-child/agent.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,12 @@ import {
PROTOCOL_VERSION,
RequestError,
} from '@agentclientprotocol/sdk';
import {
EXTERNAL_TOOL_GUARD_READY_META_KEY,
EXTERNAL_TOOL_GUARD_REQUIRED_VALUE,
PRIVATE_EXTERNAL_TOOL_GUARD_ENV,
PRIVATE_EXTERNAL_TOOL_GUARD_PROVIDER_ENV,
} from '@qwen-code/acp-bridge/externalToolGuard';
import { Writable, Readable } from 'node:stream';

// Protect the stdout NDJSON pipe — any console method that writes to
Expand All @@ -40,6 +46,23 @@ const delayMs = parseInt(process.env.MOCK_ACP_PROMPT_DELAY_MS || '100', 10);
const emitChunks = parseInt(process.env.MOCK_ACP_EMIT_CHUNKS || '3', 10);
let sessionCounter = 0;

// The daemon installs its built-in tool guard for every session and passes
// this private marker to the child it spawns; the child must consume the
// marker and acknowledge it in the initialize response, or the daemon refuses
// the session. Mirror the production child (runAcpAgent) so sessions created
// through this mock pass the same handshake.
const externalToolGuardRequired =
process.env[PRIVATE_EXTERNAL_TOOL_GUARD_ENV] ===
EXTERNAL_TOOL_GUARD_REQUIRED_VALUE;
delete process.env[PRIVATE_EXTERNAL_TOOL_GUARD_ENV];
delete process.env[PRIVATE_EXTERNAL_TOOL_GUARD_PROVIDER_ENV];

// SERVE_CONTROL_EXT_METHODS.sessionClose from @qwen-code/acp-bridge/status,
// hardcoded because that module runtime-imports @qwen-code/qwen-code-core
// and would pull core's whole barrel into this lightweight fixture. Drift
// fails loudly: the daemon's session close errors when this stops matching.
const SESSION_CLOSE_EXT_METHOD = 'qwen/control/session/close';

new AgentSideConnection(
(connection) => ({
async initialize() {
Expand All @@ -48,6 +71,14 @@ new AgentSideConnection(
agentInfo: { name: 'mock-acp', version: '0.0.1' },
authMethods: [],
agentCapabilities: {},
...(externalToolGuardRequired
? {
_meta: {
[EXTERNAL_TOOL_GUARD_READY_META_KEY]:
EXTERNAL_TOOL_GUARD_REQUIRED_VALUE,
},
}
: {}),
};
},

Expand Down Expand Up @@ -90,6 +121,17 @@ new AgentSideConnection(
},

async cancel() {},

async extMethod(method, params) {
if (method === SESSION_CLOSE_EXT_METHOD) {
// The daemon's DELETE /session/:id forwards this ext method down the
// ACP channel; ack with the production success shape so teardown
// completes. The mock keeps no per-session state to drain.
const { sessionId } = params;
return { sessionId, closed: true };
}
throw RequestError.methodNotFound(method);
},
}),
ndJsonStream(Writable.toWeb(process.stdout), Readable.toWeb(process.stdin)),
);
Expand Down
Loading