Skip to content

armgit / cindy

Public Imported from GitHub
0

Consider it done. The open-source AI agent that works out of the box · 想到,就能做到。开源、开箱即用的 AI Agent。

fix(desktop): 补齐 Opus 5 客户端两处缺口并补充测试 (#381)

zhanghengxd8568743859d2
diff --git a/apps/desktop/src/main/__tests__/claudeLocalSessions.test.ts b/apps/desktop/src/main/__tests__/claudeLocalSessions.test.ts
index 0e69e9aaad..dff67615f1 100644
--- a/apps/desktop/src/main/__tests__/claudeLocalSessions.test.ts
+++ b/apps/desktop/src/main/__tests__/claudeLocalSessions.test.ts
@@ -372,6 +372,28 @@ describe('parseClaudeCodeMessageLine', () => {
expect(rows[0].agentMeta).toMatchObject({ model: 'claude-opus-4-8' });
});
+ it('normalizes opus-5 [1m] wire model id to catalog id', () => {
+ const rows = parseClaudeCodeMessageLine(
+ line({
+ type: 'assistant',
+ uuid: 'assistant-opus5',
+ message: {
+ id: 'msg_opus5',
+ model: 'claude-opus-5[1m]',
+ stop_reason: 'end_turn',
+ usage: { input_tokens: 1, output_tokens: 1 },
+ content: [{ type: 'text', text: 'ok' }],
+ },
+ }),
+ 10,
+ sdkSessionId,
+ 'claude-sonnet-4-6',
+ );
+
+ expect(rows).toHaveLength(1);
+ expect(rows[0].agentMeta).toMatchObject({ model: 'claude-opus-5' });
+ });
+
it('maps Claude task notifications back to tool_result instead of user text', () => {
const rows = parseClaudeCodeMessageLine(
line({
diff --git a/apps/desktop/src/main/git-review/__tests__/diffReader.test.ts b/apps/desktop/src/main/git-review/__tests__/diffReader.test.ts
index 66516c7ae7..f451a9e2a8 100644
--- a/apps/desktop/src/main/git-review/__tests__/diffReader.test.ts
+++ b/apps/desktop/src/main/git-review/__tests__/diffReader.test.ts
@@ -144,7 +144,8 @@ describe('git-review diffReader', () => {
isTooLarge: false,
});
expect(diff?.size).toBe(outsidePath.length);
- expect(diff?.rawPatch).toContain(`+${outsidePath}`);
+ // git 把 symlink 目标以 POSIX 分隔符写入 blob,Windows 路径按同规则规范化后比较。
+ expect(diff?.rawPatch).toContain(`+${outsidePath.split(path.sep).join('/')}`);
} finally {
await fs.rm(outsidePath, { force: true });
}
diff --git a/apps/desktop/src/main/maker-host/claude-local-sessions.ts b/apps/desktop/src/main/maker-host/claude-local-sessions.ts
index 994128d251..ca52353b98 100644
--- a/apps/desktop/src/main/maker-host/claude-local-sessions.ts
+++ b/apps/desktop/src/main/maker-host/claude-local-sessions.ts
@@ -992,6 +992,7 @@ function usageTokenCount(usage: unknown): number {
function normalizeClaudeModel(raw: string): string {
const model = raw.trim();
if (!model) return '';
+ if (model.includes('opus-5')) return 'claude-opus-5';
if (model.includes('opus-4-8')) return 'claude-opus-4-8';
if (model.includes('opus-4-7')) return 'claude-opus-4-7';
if (model.includes('opus-4-6')) return 'claude-opus-4-6';
diff --git a/apps/desktop/src/renderer/__tests__/addProviderWizardPresetEntry.test.tsx b/apps/desktop/src/renderer/__tests__/addProviderWizardPresetEntry.test.tsx
index 5b32c00d68..a8b693715d 100644
--- a/apps/desktop/src/renderer/__tests__/addProviderWizardPresetEntry.test.tsx
+++ b/apps/desktop/src/renderer/__tests__/addProviderWizardPresetEntry.test.tsx
@@ -49,6 +49,7 @@ vi.mock('@/components/icons/ProviderLogoMark', () => ({
}));
import { AddProviderWizard } from '@/components/settings/AddProviderWizard';
+import { createCustomProvider } from '@/lib/customProviders';
const anthropicProvider = {
id: 'anthropic',
@@ -153,6 +154,7 @@ describe('AddProviderWizard — preset 直达', () => {
expect(screen.getByText('settings.providers.wizard.fetchFailed')).not.toBeNull(),
);
// 降级:推荐模型仍在清单里,完成按钮可用(不被空列表堵死)。
+ expect(screen.getByText('Claude Opus 5')).not.toBeNull();
expect(screen.getByText('Claude Sonnet 5')).not.toBeNull();
expect(screen.getByText('Claude Haiku 4.5')).not.toBeNull();
expect(
@@ -161,6 +163,40 @@ describe('AddProviderWizard — preset 直达', () => {
).toBe(false);
});
+ it('官方 API 预设:完成保存 → 模型带目录口径 contextWindow(Codex P1 回归)', async () => {
+ render(
+ React.createElement(AddProviderWizard, {
+ providers: [anthropicProvider],
+ entry: { kind: 'builtin' as const, providerId: 'anthropic' },
+ onOpenCustomForm: vi.fn(),
+ onClose: vi.fn(),
+ onDone: vi.fn(),
+ }),
+ );
+
+ fireEvent.click(await screen.findByText('settings.providers.wizard.useApiKey'));
+ await waitFor(() =>
+ expect(screen.getByText('settings.providers.wizard.nameLabel')).not.toBeNull(),
+ );
+ fireEvent.change(screen.getByPlaceholderText('sk-…'), { target: { value: 'sk-test' } });
+ fireEvent.click(screen.getByText('settings.providers.wizard.next'));
+ await waitFor(() => expect(screen.getByText('Claude Opus 5')).not.toBeNull());
+ fireEvent.click(screen.getByText('settings.providers.wizard.finish'));
+
+ // 保存产物必须带预设声明的 contextWindow:它是唯一窗口来源,缺省会落
+ // 200k 默认导致 1M 模型丢 [1m] 路由(toSdkModelString 按窗口剥后缀)。
+ await waitFor(() => expect(createCustomProvider).toHaveBeenCalledTimes(1));
+ const config = vi.mocked(createCustomProvider).mock.calls[0][0];
+ const models = config.runtimes['claude-code']?.models ?? [];
+ expect(models).toEqual(
+ expect.arrayContaining([
+ expect.objectContaining({ id: 'claude-opus-5', contextWindow: 1_000_000 }),
+ expect.objectContaining({ id: 'claude-sonnet-5', contextWindow: 1_000_000 }),
+ expect.objectContaining({ id: 'claude-haiku-4-5', contextWindow: 200_000 }),
+ ]),
+ );
+ });
+
it('presetId 不存在 → 回落目录第一步', async () => {
renderWizard('nonexistent');
diff --git a/apps/desktop/src/renderer/components/settings/AddProviderWizard.tsx b/apps/desktop/src/renderer/components/settings/AddProviderWizard.tsx
index e20ec628ae..6dcfadcd21 100644
--- a/apps/desktop/src/renderer/components/settings/AddProviderWizard.tsx
+++ b/apps/desktop/src/renderer/components/settings/AddProviderWizard.tsx
@@ -82,9 +82,13 @@ const OFFICIAL_API_PRESETS: Record<string, ProviderPreset> = {
runtimes: {
'claude-code': {
baseUrl: 'https://api.anthropic.com',
+ // contextWindow 必须与目录(providers.json)一致:保存时它是窗口的唯一来源
+ // (拉取的模型列表不带窗口),缺省会落 200k 默认 → toSdkModelString 剥掉
+ // 1M 模型的 [1m] 路由,用户拿到 1/5 窗口。
models: [
- { id: 'claude-sonnet-5', name: 'Claude Sonnet 5' },
- { id: 'claude-haiku-4-5', name: 'Claude Haiku 4.5' },
+ { id: 'claude-opus-5', name: 'Claude Opus 5', contextWindow: 1_000_000 },
+ { id: 'claude-sonnet-5', name: 'Claude Sonnet 5', contextWindow: 1_000_000 },
+ { id: 'claude-haiku-4-5', name: 'Claude Haiku 4.5', contextWindow: 200_000 },
],
},
},
diff --git a/apps/desktop/src/shared/__tests__/modelMismatch.test.ts b/apps/desktop/src/shared/__tests__/modelMismatch.test.ts
index 149e46f721..d293bc2f3f 100644
--- a/apps/desktop/src/shared/__tests__/modelMismatch.test.ts
+++ b/apps/desktop/src/shared/__tests__/modelMismatch.test.ts
@@ -8,6 +8,8 @@ describe('canonicalModelFamilyKey', () => {
expect(canonicalModelFamilyKey('claude-opus-4-8-20260301')).toBe('opus-4-8');
expect(canonicalModelFamilyKey('us.anthropic.claude-fable-5-20260115')).toBe('fable-5');
expect(canonicalModelFamilyKey('Claude-Sonnet-5-LATEST')).toBe('sonnet-5');
+ expect(canonicalModelFamilyKey('claude-opus-5[1m]')).toBe('opus-5');
+ expect(canonicalModelFamilyKey('claude-opus-4-5')).toBe('opus-4-5');
});
it('点横等价,非字符串 / 空串安全返回空', () => {
@@ -50,6 +52,11 @@ describe('detectClaudeModelMismatch', () => {
{ model: 'claude-fable-5-20260115', outputTokens: 500 },
]),
).toBeNull();
+ expect(
+ detectClaudeModelMismatch('claude-opus-5', [
+ { model: 'claude-opus-5[1m]', outputTokens: 500 },
+ ]),
+ ).toBeNull();
});
it('所选非 Anthropic 家族(网关 / 订阅直连)→ 不判定', () => {