mirror of
https://github.com/claude-code-best/claude-code.git
synced 2026-06-24 17:15:50 +00:00
fix: harden bounded agent communication review fixes
CodeRabbit and Codecov surfaced real gaps in UDS framing, peer discovery, mailbox retention, and summary context coverage. This tightens those paths without suppressing review or coverage signals. Constraint: PR #369 must address CodeRabbit and Codecov findings without warning suppression or fake fallbacks Rejected: Suppress Codecov or CodeRabbit warnings | leaves real receive-path and test-isolation gaps Rejected: Add unreachable feature-gated tests | bun:bundle keeps those branches compile-time gated in local tests Confidence: high Scope-risk: moderate Directive: Keep UDS auth-token rejection outside feature flags; do not reintroduce inline token fallbacks Tested: bun test --coverage --coverage-reporter lcov --coverage-dir coverage; bun run test:all; bun run lint; bun run build; bun run build:vite; bun audit; git diff --cached --check Not-tested: Remote Codecov/CodeRabbit refreshed reports until pushed
This commit is contained in:
133
src/services/AgentSummary/__tests__/agentSummary.test.ts
Normal file
133
src/services/AgentSummary/__tests__/agentSummary.test.ts
Normal file
@@ -0,0 +1,133 @@
|
||||
import {
|
||||
afterAll,
|
||||
afterEach,
|
||||
beforeEach,
|
||||
describe,
|
||||
expect,
|
||||
mock,
|
||||
test,
|
||||
} from 'bun:test'
|
||||
import { debugMock } from '../../../../tests/mocks/debug'
|
||||
import { logMock } from '../../../../tests/mocks/log'
|
||||
import { asAgentId } from '../../../types/ids.js'
|
||||
import type { CacheSafeParams } from '../../../utils/forkedAgent.js'
|
||||
|
||||
const transcriptMessages = [
|
||||
{ type: 'user', message: { content: 'start' }, uuid: 'u1' },
|
||||
{
|
||||
type: 'assistant',
|
||||
message: { content: [{ type: 'text', text: 'working' }] },
|
||||
uuid: 'a1',
|
||||
},
|
||||
{ type: 'user', message: { content: 'continue' }, uuid: 'u2' },
|
||||
]
|
||||
|
||||
let poorModeActive = false
|
||||
let forkCalls = 0
|
||||
let updateCalls: Array<{ taskId: string; summary: string }> = []
|
||||
let transcript = { messages: transcriptMessages }
|
||||
const sessionStorageSnapshot = {
|
||||
...(require('../../../utils/sessionStorage.ts') as Record<string, unknown>),
|
||||
}
|
||||
|
||||
mock.module('src/commands/poor/poorMode.js', () => ({
|
||||
isPoorModeActive: () => poorModeActive,
|
||||
}))
|
||||
|
||||
mock.module('src/tasks/LocalAgentTask/LocalAgentTask.js', () => ({
|
||||
updateAgentSummary: (taskId: string, summary: string) => {
|
||||
updateCalls.push({ taskId, summary })
|
||||
},
|
||||
}))
|
||||
|
||||
mock.module(
|
||||
'@claude-code-best/builtin-tools/tools/AgentTool/runAgent.js',
|
||||
() => ({
|
||||
filterIncompleteToolCalls: <T>(messages: T) => messages,
|
||||
}),
|
||||
)
|
||||
|
||||
mock.module('src/utils/debug.js', debugMock)
|
||||
mock.module('src/utils/log.js', logMock)
|
||||
|
||||
mock.module('src/utils/forkedAgent.js', () => ({
|
||||
runForkedAgent: async () => {
|
||||
forkCalls += 1
|
||||
return {
|
||||
messages: [
|
||||
{
|
||||
type: 'assistant',
|
||||
message: {
|
||||
content: [{ type: 'text', text: 'Reading udsClient.ts' }],
|
||||
},
|
||||
},
|
||||
],
|
||||
}
|
||||
},
|
||||
}))
|
||||
|
||||
mock.module('src/utils/sessionStorage.js', () => ({
|
||||
...sessionStorageSnapshot,
|
||||
getAgentTranscript: async () => transcript,
|
||||
}))
|
||||
|
||||
afterAll(() => {
|
||||
mock.module('src/utils/sessionStorage.js', () =>
|
||||
require('../../../utils/sessionStorage.ts'),
|
||||
)
|
||||
})
|
||||
|
||||
describe('startAgentSummarization', () => {
|
||||
const realSetTimeout = globalThis.setTimeout
|
||||
const realClearTimeout = globalThis.clearTimeout
|
||||
let scheduled:
|
||||
| ((...args: Parameters<TimerHandler & ((...args: unknown[]) => void)>) => void)
|
||||
| undefined
|
||||
|
||||
beforeEach(() => {
|
||||
poorModeActive = false
|
||||
forkCalls = 0
|
||||
updateCalls = []
|
||||
transcript = { messages: transcriptMessages }
|
||||
scheduled = undefined
|
||||
globalThis.setTimeout = ((callback: TimerHandler) => {
|
||||
scheduled = callback as (...args: unknown[]) => void
|
||||
return 1 as unknown as ReturnType<typeof setTimeout>
|
||||
}) as unknown as typeof setTimeout
|
||||
globalThis.clearTimeout = (() => undefined) as typeof clearTimeout
|
||||
})
|
||||
|
||||
afterEach(() => {
|
||||
globalThis.setTimeout = realSetTimeout
|
||||
globalThis.clearTimeout = realClearTimeout
|
||||
})
|
||||
|
||||
test('summarizes bounded transcript once and skips unchanged fingerprints', async () => {
|
||||
const { startAgentSummarization } = await import('../agentSummary.js')
|
||||
|
||||
const handle = startAgentSummarization(
|
||||
'task-1',
|
||||
asAgentId('a0000000000000000'),
|
||||
{
|
||||
forkContextMessages: [{ type: 'user', message: { content: 'old' } }],
|
||||
model: 'claude-test',
|
||||
} as unknown as CacheSafeParams,
|
||||
() => undefined,
|
||||
)
|
||||
|
||||
expect(typeof scheduled).toBe('function')
|
||||
await scheduled!()
|
||||
|
||||
expect(forkCalls).toBe(1)
|
||||
expect(updateCalls).toEqual([
|
||||
{ taskId: 'task-1', summary: 'Reading udsClient.ts' },
|
||||
])
|
||||
|
||||
await scheduled!()
|
||||
|
||||
expect(forkCalls).toBe(1)
|
||||
expect(updateCalls).toHaveLength(1)
|
||||
|
||||
handle.stop()
|
||||
})
|
||||
})
|
||||
Reference in New Issue
Block a user