mirror of
https://github.com/claude-code-best/claude-code.git
synced 2026-06-18 14:25:51 +00:00
feat: 整合功能恢复与技能学习闭环(含 ECC v2.1 parity + Opus 4.7 接入 + prompt 工程优化)
主要变更: - Skill Learning 闭环系统 (9/9 AC) - Opus 4.7 模型层接入 + adaptive thinking - Prompt 工程优化 (64 审计测试) - Agent Teams 简化门控 (默认启用) - Windows Terminal 后端修复 (EncodedCommand/WT_SESSION) - TF-IDF 技能搜索精准化 (字段加权/CJK 优化) - Autonomy 系统 (/autonomy 命令) - ACP 协议完整实现 - mock.module 泄漏修复 (CI 全绿) - 152+ lint/type 修复
This commit is contained in:
91
src/commands/summary/__tests__/summary.test.ts
Normal file
91
src/commands/summary/__tests__/summary.test.ts
Normal file
@@ -0,0 +1,91 @@
|
||||
import { describe, test, expect, mock, beforeEach } from 'bun:test'
|
||||
|
||||
const mockManuallyExtract = mock(
|
||||
(): Promise<any> => Promise.resolve({ success: true }),
|
||||
)
|
||||
const mockGetContent = mock(
|
||||
(): Promise<any> => Promise.resolve('# Session Summary\n\nDid some work.'),
|
||||
)
|
||||
|
||||
mock.module(
|
||||
require.resolve('../../../services/SessionMemory/sessionMemory.js'),
|
||||
() => ({
|
||||
manuallyExtractSessionMemory: mockManuallyExtract,
|
||||
}),
|
||||
)
|
||||
mock.module(
|
||||
require.resolve('../../../services/SessionMemory/sessionMemoryUtils.js'),
|
||||
() => ({
|
||||
getSessionMemoryContent: mockGetContent,
|
||||
}),
|
||||
)
|
||||
|
||||
const { default: summaryCommand } = await import('../index.js')
|
||||
|
||||
const baseContext = {
|
||||
messages: [{ type: 'user', role: 'user', content: 'hello' }],
|
||||
options: { tools: [], mainLoopModel: 'test' },
|
||||
setMessages: () => {},
|
||||
onChangeAPIKey: () => {},
|
||||
} as any
|
||||
|
||||
async function callSummary(ctx = baseContext) {
|
||||
const mod = await summaryCommand.load()
|
||||
return mod.call('', ctx)
|
||||
}
|
||||
|
||||
beforeEach(() => {
|
||||
mockManuallyExtract.mockReset()
|
||||
mockGetContent.mockReset()
|
||||
mockManuallyExtract.mockImplementation(() =>
|
||||
Promise.resolve({ success: true }),
|
||||
)
|
||||
mockGetContent.mockImplementation(() =>
|
||||
Promise.resolve('# Session Summary\n\nDid some work.'),
|
||||
)
|
||||
})
|
||||
|
||||
describe('summary command', () => {
|
||||
test('command metadata', () => {
|
||||
expect(summaryCommand.name).toBe('summary')
|
||||
expect(summaryCommand.type).toBe('local')
|
||||
expect(summaryCommand.isHidden).toBe(false)
|
||||
expect(typeof summaryCommand.load).toBe('function')
|
||||
})
|
||||
|
||||
test('refreshes and displays summary', async () => {
|
||||
const result = await callSummary()
|
||||
expect(result.type).toBe('text')
|
||||
expect((result as any).value).toContain('Session summary updated.')
|
||||
expect((result as any).value).toContain('Did some work.')
|
||||
expect(mockManuallyExtract).toHaveBeenCalled()
|
||||
})
|
||||
|
||||
test('handles extraction failure', async () => {
|
||||
mockManuallyExtract.mockImplementation(() =>
|
||||
Promise.resolve({ success: false, error: 'timeout' }),
|
||||
)
|
||||
const result = await callSummary()
|
||||
expect((result as any).value).toContain(
|
||||
'Failed to generate session summary',
|
||||
)
|
||||
expect((result as any).value).toContain('timeout')
|
||||
})
|
||||
|
||||
test('handles empty content after extraction', async () => {
|
||||
mockGetContent.mockImplementation(() => Promise.resolve(''))
|
||||
const result = await callSummary()
|
||||
expect((result as any).value).toContain('content is empty')
|
||||
})
|
||||
|
||||
test('handles null content after extraction', async () => {
|
||||
mockGetContent.mockImplementation(() => Promise.resolve(null))
|
||||
const result = await callSummary()
|
||||
expect((result as any).value).toContain('content is empty')
|
||||
})
|
||||
|
||||
test('handles no messages', async () => {
|
||||
const result = await callSummary({ ...baseContext, messages: [] })
|
||||
expect((result as any).value).toBe('No messages to summarize.')
|
||||
})
|
||||
})
|
||||
Reference in New Issue
Block a user