Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
56 changes: 56 additions & 0 deletions packages/acp-bridge/src/bridge.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import type {
Agent,
InitializeResponse,
LoadSessionResponse,
PromptRequest,
PromptResponse,
ResumeSessionResponse,
} from '@agentclientprotocol/sdk';
Expand All @@ -41,6 +42,7 @@ import {
import { MAX_WORKSPACE_PATH_LENGTH } from './workspacePaths.js';
import { createHttpAcpBridge } from './bridge.js';
import type { ChannelFactory } from './channel.js';
import type { BridgeTelemetry } from './bridgeOptions.js';
import { createInMemoryChannel } from './inMemoryChannel.js';
import type { BridgeEvent } from './eventBus.js';
import { ApprovalMode } from '@qwen-code/qwen-code-core';
Expand Down Expand Up @@ -89,6 +91,60 @@ describe('createHttpAcpBridge', () => {
);
});

it('uses bridge telemetry for channel/session/prompt dispatch and prompt metadata injection', async () => {
const handle = makeChannel();
const operations: string[] = [];
const telemetry: BridgeTelemetry = {
captureContext: () => ({ captured: true }),
async runWithContext(_captured, fn) {
return await fn();
},
async withSpan(operation, _attributes, fn) {
operations.push(operation);
return await fn();
},
event() {},
injectPromptContext(request) {
const meta =
(request as { _meta?: Record<string, unknown> })._meta ?? {};
return {
...request,
_meta: {
...meta,
'qwen.telemetry.traceparent': 'daemon-traceparent',
},
};
},
};
const bridge = makeBridge({
channelFactory: async () => handle.channel,
telemetry,
});
const session = await bridge.spawnOrAttach({ workspaceCwd: WS_A });

await bridge.sendPrompt(session.sessionId, {
sessionId: session.sessionId,
prompt: [{ type: 'text', text: 'hello' }],
_meta: {
keep: 'value',
'qwen.telemetry.traceparent': 'client-spoof',
},
} as PromptRequest);

expect(operations).toEqual(
expect.arrayContaining([
'channel.spawn',
'channel.initialize',
'session.new',
'prompt.dispatch',
]),
);
expect(handle.agent.promptCalls[0]!._meta).toMatchObject({
keep: 'value',
'qwen.telemetry.traceparent': 'daemon-traceparent',
});
});

it('forwards childEnvOverrides to the channelFactory at spawn time (#4247 R6 line 216)', async () => {
// Round 6 (wenshao R5 line 216): pre-fix `runQwenServe` set
// `process.env` globally to pass the MCP budget config to the
Expand Down
Loading