qwen-code/packages/web-shell/client/adapters/toolClassification.test.ts
Dragon 1fec09423b
fix: support context-inheriting subagents in headless mode (#7378)
* fix(core): support headless fork subagents

* fix(desktop): avoid false background agent events

---------

Co-authored-by: Claude <noreply@anthropic.com>
2026-07-21 12:33:13 +00:00

71 lines
2.1 KiB
TypeScript

import { describe, expect, it } from 'vitest';
import type { ACPToolCall } from './types';
import { isBackgroundSubAgentToolCall } from './toolClassification';
function agentTool(args: Record<string, unknown> = {}): ACPToolCall {
return {
callId: 'agent-1',
toolName: 'agent',
args,
status: 'completed',
};
}
describe('isBackgroundSubAgentToolCall', () => {
it('treats an ordinary agent as background when the flag is omitted', () => {
expect(isBackgroundSubAgentToolCall(agentTool())).toBe(true);
});
it('does not infer fork background status from args alone', () => {
// Args alone do not expose whether the runtime is interactive or headless.
// The effective background status is covered by the rawOutput test below.
expect(
isBackgroundSubAgentToolCall(agentTool({ subagent_type: 'fork' })),
).toBe(false);
});
it('keeps an explicit foreground agent out of the background group', () => {
expect(
isBackgroundSubAgentToolCall(agentTool({ run_in_background: false })),
).toBe(false);
});
it('keeps caller-owned working_dir launches in the foreground by default', () => {
expect(
isBackgroundSubAgentToolCall(
agentTool({ working_dir: '.qwen/worktrees/review' }),
),
).toBe(false);
});
it('does not change named teammate classification', () => {
expect(isBackgroundSubAgentToolCall(agentTool({ name: 'reviewer' }))).toBe(
false,
);
});
it.each([undefined, true])(
'keeps nested Agent calls in the foreground when the flag is %s',
(runInBackground) => {
expect(
isBackgroundSubAgentToolCall({
...agentTool(
runInBackground === undefined
? {}
: { run_in_background: runInBackground },
),
parentToolCallId: 'parent-agent',
}),
).toBe(false);
},
);
it('trusts the runtime background status when present', () => {
expect(
isBackgroundSubAgentToolCall({
...agentTool({ run_in_background: false }),
rawOutput: { type: 'task_execution', status: 'background' },
}),
).toBe(true);
});
});