Files
adnaan 4da1e487c8 feat(llm): refactor prompt caching with capability detection and cache analysis
- Replace PromptCache with new CacheAnalysis and CacheStrategies modules for improved cache management
- Add capability detection system to LLMConfig for provider-specific features (OpenAI reasoning, Google thinking mode, prompt cache retention)
- Implement cache source tracking (provider-reported vs derived/estimated) in token usage reporting
- Add StablePrefixAnalysis and TextOnlyPrefixAnalysis for intelligent message prefix caching
- Introduce CacheStrategies with provider-specific implementations (OpenAI, Google, Anthropic)
- Update RequestCache, RequestExecution, and RequestSettings to use new cache strategy system
- Enhance StreamingService, StructuredService, and SyncService with improved cache handling
- Add ThinkingStrategy for managing reasoning token budgets across providers
- Update MessageConverter to support new cache analysis capabilities
- Add ProviderCompatibility checks for cache feature support
- Extend ContextStatsContent UI to display cache source information
- Add llmCapabilities test suite for provider feature detection
- Update agent loop and stream handling for new cache strategy integration
- Improve token usage conversion in IPC layer with cache source metadata
- Consolidate LLM configuration types and persistence logic
2026-04-30 21:51:42 +08:00

69 lines
1.9 KiB
TypeScript

/**
* Agent Loop 测试
* 测试 Agent 主循环逻辑
*/
import { beforeAll, describe, it, expect, vi } from 'vitest'
// Mock dependencies
vi.mock('@renderer/services/WorkspaceManager', () => ({
workspaceManager: {
getCurrentWorkspacePath: vi.fn(() => '/test/workspace'),
},
}))
let prepareLLMRequestMessages: typeof import('@renderer/agent/core/loop').prepareLLMRequestMessages
beforeAll(async () => {
vi.stubGlobal('self', globalThis)
;({ prepareLLMRequestMessages } = await import('@renderer/agent/core/loop'))
})
describe('Agent Loop', () => {
describe('System prompt propagation', () => {
it('removes inline system messages when a dedicated system prompt is provided', () => {
const result = prepareLLMRequestMessages([
{ role: 'system', content: 'You are helpful.' },
{ role: 'user', content: '你是谁' },
], 'You are helpful.')
expect(result).toEqual([
{ role: 'user', content: '你是谁' },
])
})
it('keeps messages unchanged when there is no dedicated system prompt', () => {
const messages = [
{ role: 'system' as const, content: 'You are helpful.' },
{ role: 'user' as const, content: '你是谁' },
]
expect(prepareLLMRequestMessages(messages, undefined)).toEqual(messages)
})
})
describe('Loop Detection', () => {
it('should detect infinite loops', () => {
// 测试循环检测逻辑
expect(true).toBe(true)
})
it('should allow reasonable retry attempts', () => {
// 测试合理的重试次数
expect(true).toBe(true)
})
})
describe('Error Handling', () => {
it('should handle tool execution errors', () => {
// 测试工具执行错误处理
expect(true).toBe(true)
})
it('should recover from transient failures', () => {
// 测试临时失败恢复
expect(true).toBe(true)
})
})
})