cc-haha/src/utils/taskNotificationPolicy.test.ts
程序员阿江(Relakkes) c2355205dc fix(agent): stabilize background task continuations
Fixes #870, #884, #886.

Route backgrounded sync Agent tool activity through the same parent-tagged event path as detached agents, recover incomplete tool-use streams with the non-streaming fallback, and suppress structured-output local-agent terminal notifications from re-entering the model.

Tested: bun test src/tools/AgentTool/agentToolUtils.test.ts src/utils/taskNotificationPolicy.test.ts src/services/api/streamFallback.test.ts src/server/__tests__/proxy-streaming.test.ts

Tested: bun run check:server

Confidence: high

Scope-risk: moderate
2026-06-23 00:09:35 +08:00

43 lines
1.6 KiB
TypeScript

import { describe, expect, test } from 'bun:test'
import {
parseTaskNotificationXml,
shouldForwardTaskNotificationToModel,
} from './taskNotificationPolicy.js'
describe('task notification policy', () => {
test('does not re-enter the model for local agent terminal notifications in structured output', () => {
const notification = parseTaskNotificationXml(`<task-notification>
<task-id>agent-1</task-id>
<task-type>local_agent</task-type>
<output-file>/tmp/agent-1.out</output-file>
<status>completed</status>
<summary>Agent "Probe" completed</summary>
</task-notification>`)
expect(shouldForwardTaskNotificationToModel(notification, { structuredOutput: true })).toBe(false)
})
test('keeps local agent notifications as model input for plain print mode', () => {
const notification = parseTaskNotificationXml(`<task-notification>
<task-id>agent-1</task-id>
<task-type>local_agent</task-type>
<output-file>/tmp/agent-1.out</output-file>
<status>completed</status>
<summary>Agent "Probe" completed</summary>
</task-notification>`)
expect(shouldForwardTaskNotificationToModel(notification, { structuredOutput: false })).toBe(true)
})
test('continues forwarding background shell notifications to the model', () => {
const notification = parseTaskNotificationXml(`<task-notification>
<task-id>bash-1</task-id>
<output-file>/tmp/bash-1.out</output-file>
<status>completed</status>
<summary>Background command "bun test" completed</summary>
</task-notification>`)
expect(shouldForwardTaskNotificationToModel(notification, { structuredOutput: true })).toBe(true)
})
})