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): guide missing Pi components to About (#6586)

guyong-zapo26daef02d293
diff --git a/apps/desktop/src/renderer/__tests__/vendorAuthGateRemoteCache.test.tsx b/apps/desktop/src/renderer/__tests__/vendorAuthGateRemoteCache.test.tsx
index ec763b9069..de75fa7599 100644
--- a/apps/desktop/src/renderer/__tests__/vendorAuthGateRemoteCache.test.tsx
+++ b/apps/desktop/src/renderer/__tests__/vendorAuthGateRemoteCache.test.tsx
@@ -10,15 +10,17 @@ import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';
import type { ProviderView } from '@cindy/model-providers';
const confirm = vi.fn(async () => true);
+const navigate = vi.fn();
+const revalidate = vi.fn();
const cachedProviders = vi.fn<(deviceId: string) => unknown>(() => null);
-vi.mock('react-router-dom', () => ({ useNavigate: () => vi.fn() }));
+vi.mock('react-router-dom', () => ({ useNavigate: () => navigate }));
vi.mock('react-i18next', () => ({ useTranslation: () => ({ t: (key: string) => key }) }));
vi.mock('@/components/ui/confirm-dialog-provider', () => ({
useConfirmDialog: () => ({ confirm }),
}));
vi.mock('@/hooks/useVendorReadiness', () => ({
- useVendorReadiness: () => ({ revalidate: vi.fn() }),
+ useVendorReadiness: () => ({ revalidate }),
}));
vi.mock('@/features/device-link/remoteProjectsStore', () => ({
remoteProjectsStore: { getDeviceName: () => 'Mac mini' },
@@ -41,17 +43,19 @@ const provider = (over: Partial<ProviderView>): ProviderView =>
...over,
}) as ProviderView;
-const invoke = vi.fn(async (_deviceId: string, channel: string) => {
+const defaultInvoke = async (_deviceId: string, channel: string) => {
if (channel === 'maker:agent:status') return { binaryReady: true, authReady: true };
if (channel === 'maker:provider:list') return { providers: [provider({})] };
- throw new Error(`unexpected channel ${channel}`);
-});
+ throw new Error('unexpected channel ' + channel);
+};
+const invoke = vi.fn(defaultInvoke);
function channels(): string[] {
return invoke.mock.calls.map((call) => call[1]);
}
beforeEach(() => {
+ invoke.mockImplementation(defaultInvoke);
vi.stubGlobal('electronAPI', { deviceLink: { invoke } });
});
@@ -59,6 +63,8 @@ afterEach(() => {
vi.unstubAllGlobals();
invoke.mockClear();
confirm.mockClear();
+ navigate.mockClear();
+ revalidate.mockReset();
cachedProviders.mockReset();
cachedProviders.mockReturnValue(null);
});
@@ -107,3 +113,55 @@ describe('useVendorAuthGate device-link 来源快照复用', () => {
expect(channels().sort()).toEqual(['maker:agent:status', 'maker:provider:list']);
});
});
+
+describe('useVendorAuthGate 本机恢复引导', () => {
+ it('Pi 组件缺失时确认进入设置 → 关于', async () => {
+ revalidate.mockResolvedValue('binary-missing');
+ const { result } = renderHook(() => useVendorAuthGate());
+
+ await expect(result.current.checkAndConfirm('pi')).resolves.toEqual({ proceed: false });
+ expect(confirm).toHaveBeenCalledTimes(1);
+ expect(navigate).toHaveBeenCalledExactlyOnceWith('/settings?tab=about');
+ });
+
+ it('Pi 组件缺失时取消不导航', async () => {
+ revalidate.mockResolvedValue('binary-missing');
+ confirm.mockResolvedValueOnce(false);
+ const { result } = renderHook(() => useVendorAuthGate());
+
+ await expect(result.current.checkAndConfirm('pi')).resolves.toEqual({ proceed: false });
+ expect(navigate).not.toHaveBeenCalled();
+ });
+
+ it('Pi 来源不足仍进入模型供应商页', async () => {
+ revalidate.mockResolvedValue('unauthenticated');
+ const { result } = renderHook(() => useVendorAuthGate());
+
+ await expect(result.current.checkAndConfirm('pi')).resolves.toEqual({ proceed: false });
+ expect(navigate).toHaveBeenCalledExactlyOnceWith('/settings?tab=providers');
+ });
+
+ it('远程 Pi 缺少组件时只显示信息,不导航控制端设置', async () => {
+ invoke.mockImplementation(async (_deviceId: string, channel: string) => {
+ if (channel === 'maker:agent:status') return { binaryReady: false, authReady: true };
+ if (channel === 'maker:provider:list')
+ return {
+ providers: [
+ provider({
+ agents: ['pi'],
+ routing: { pi: { upstream: '', authStrategy: 'none' } },
+ models: { pi: [] },
+ }),
+ ],
+ };
+ throw new Error('unexpected channel ' + channel);
+ });
+ const { result } = renderHook(() => useVendorAuthGate());
+
+ await expect(result.current.checkAndConfirm('pi', { deviceId: 'dev' })).resolves.toEqual({
+ proceed: false,
+ });
+ expect(confirm).toHaveBeenCalledTimes(1);
+ expect(navigate).not.toHaveBeenCalled();
+ });
+});
diff --git a/apps/desktop/src/renderer/hooks/useVendorAuthGate.ts b/apps/desktop/src/renderer/hooks/useVendorAuthGate.ts
index 82c88c0699..d8c900f4f4 100644
--- a/apps/desktop/src/renderer/hooks/useVendorAuthGate.ts
+++ b/apps/desktop/src/renderer/hooks/useVendorAuthGate.ts
@@ -47,7 +47,7 @@ interface DialogCopy {
}
type GatePurpose = 'send' | 'voice-input';
-type SettingsTab = 'api-keys' | 'connections' | 'providers';
+type SettingsTab = 'api-keys' | 'connections' | 'providers' | 'about';
type CopyKey =
| 'no-source'
@@ -102,7 +102,7 @@ function buildCopy(t: (key: string) => string): Record<CopyKey, DialogCopy> {
description: t('logic.confirm.piBinaryMissingDescription'),
confirmText: t('logic.confirm.goToSettings'),
cancelText: t('logic.confirm.cancel'),
- settingsTab: 'providers',
+ settingsTab: 'about',
},
};
}
diff --git a/apps/desktop/src/renderer/i18n/locales/en/common.json b/apps/desktop/src/renderer/i18n/locales/en/common.json
index 8265c3dd99..d481c3ccb2 100644
--- a/apps/desktop/src/renderer/i18n/locales/en/common.json
+++ b/apps/desktop/src/renderer/i18n/locales/en/common.json
@@ -14968,7 +14968,7 @@
"codexBinaryMissingTitle": "Codex component not ready",
"codexBinaryMissingDescription": "The Codex component is not ready yet, so this feature cannot be used. Try again later or check the Codex connection in Settings → Providers.",
"piBinaryMissingTitle": "Pi component not ready",
- "piBinaryMissingDescription": "The Pi component is not ready yet, so this feature cannot be used. Try again later or check the Pi connection in Settings → Providers.",
+ "piBinaryMissingDescription": "The Pi component is not ready yet, so this feature cannot be used. Try again later, or open Settings → About to manage or restore Pi.",
"goToSettings": "Open Settings",
"remoteCodexBinaryMissingTitle": "Codex component not ready on the remote device",
"remotePiBinaryMissingTitle": "Pi component not ready on the remote device",
diff --git a/apps/desktop/src/renderer/i18n/locales/ja/common.json b/apps/desktop/src/renderer/i18n/locales/ja/common.json
index 9e37284174..f9ab535588 100644
--- a/apps/desktop/src/renderer/i18n/locales/ja/common.json
+++ b/apps/desktop/src/renderer/i18n/locales/ja/common.json
@@ -14914,7 +14914,7 @@
"codexBinaryMissingTitle": "Codex コンポーネントの準備ができていません",
"codexBinaryMissingDescription": "Codex コンポーネントの準備がまだできていないため、この機能は使用できません。しばらくしてから再試行するか、「設定 → プロバイダー」で Codex の接続状態を確認してください。",
"piBinaryMissingTitle": "Pi コンポーネントの準備ができていません",
- "piBinaryMissingDescription": "Pi コンポーネントの準備がまだできていないため、この機能は使用できません。しばらくしてから再試行するか、「設定 → プロバイダー」で Pi の接続状態を確認してください。",
+ "piBinaryMissingDescription": "Pi コンポーネントの準備がまだできていないため、この機能は使用できません。しばらくしてから再試行するか、「設定 → 情報」で Pi を管理または復元してください。",
"goToSettings": "設定を開く",
"remoteCodexBinaryMissingTitle": "リモートデバイスの Codex コンポーネントが未準備です",
"remotePiBinaryMissingTitle": "リモートデバイスの Pi コンポーネントが未準備です",
diff --git a/apps/desktop/src/renderer/i18n/locales/ko/common.json b/apps/desktop/src/renderer/i18n/locales/ko/common.json
index c5cb3fa4f6..078a067a41 100644
--- a/apps/desktop/src/renderer/i18n/locales/ko/common.json
+++ b/apps/desktop/src/renderer/i18n/locales/ko/common.json
@@ -14914,7 +14914,7 @@
"codexBinaryMissingTitle": "Codex 구성 요소가 준비되지 않음",
"codexBinaryMissingDescription": "Codex 구성 요소가 아직 준비되지 않아 이 기능을 사용할 수 없습니다. 잠시 후 다시 시도하거나 설정 → 제공자에서 Codex 연결 상태를 확인하세요.",
"piBinaryMissingTitle": "Pi 구성 요소가 준비되지 않음",
- "piBinaryMissingDescription": "Pi 구성 요소가 아직 준비되지 않아 이 기능을 사용할 수 없습니다. 잠시 후 다시 시도하거나 설정 → 제공자에서 Pi 연결 상태를 확인하세요.",
+ "piBinaryMissingDescription": "Pi 구성 요소가 아직 준비되지 않아 이 기능을 사용할 수 없습니다. 잠시 후 다시 시도하거나 설정 → 정보에서 Pi를 관리하거나 복원하세요.",
"goToSettings": "설정 열기",
"remoteCodexBinaryMissingTitle": "원격 기기의 Codex 구성 요소가 준비되지 않음",
"remotePiBinaryMissingTitle": "원격 기기의 Pi 구성 요소가 준비되지 않음",
diff --git a/apps/desktop/src/renderer/i18n/locales/zh-CN/common.json b/apps/desktop/src/renderer/i18n/locales/zh-CN/common.json
index d5539146e3..5942e182d3 100644
--- a/apps/desktop/src/renderer/i18n/locales/zh-CN/common.json
+++ b/apps/desktop/src/renderer/i18n/locales/zh-CN/common.json
@@ -14914,7 +14914,7 @@
"codexBinaryMissingTitle": "Codex 组件未就绪",
"codexBinaryMissingDescription": "Codex 组件尚未准备好,暂时无法使用这个功能。请稍后重试,或前往「模型供应商」检查 Codex 连接状态。",
"piBinaryMissingTitle": "Pi 组件未就绪",
- "piBinaryMissingDescription": "Pi 组件尚未准备好,暂时无法使用这个功能。请稍后重试,或前往「模型供应商」检查 Pi 连接状态。",
+ "piBinaryMissingDescription": "Pi 组件尚未准备好,暂时无法使用这个功能。请稍后重试,或前往「设置 → 关于」管理或恢复 Pi。",
"goToSettings": "前往设置",
"remoteCodexBinaryMissingTitle": "远程电脑 Codex 组件未就绪",
"remotePiBinaryMissingTitle": "远程电脑 Pi 组件未就绪",
diff --git a/apps/desktop/src/renderer/i18n/locales/zh-TW/common.json b/apps/desktop/src/renderer/i18n/locales/zh-TW/common.json
index adee4fde9e..3b94f559b0 100644
--- a/apps/desktop/src/renderer/i18n/locales/zh-TW/common.json
+++ b/apps/desktop/src/renderer/i18n/locales/zh-TW/common.json
@@ -14914,7 +14914,7 @@
"codexBinaryMissingTitle": "Codex 元件未就緒",
"codexBinaryMissingDescription": "Codex 元件尚未準備好,暫時無法使用這個功能。請稍後重試,或前往「模型供應商」檢查 Codex 連線狀態。",
"piBinaryMissingTitle": "Pi 元件未就緒",
- "piBinaryMissingDescription": "Pi 元件尚未準備好,暫時無法使用這個功能。請稍後重試,或前往「模型供應商」檢查 Pi 連線狀態。",
+ "piBinaryMissingDescription": "Pi 元件尚未準備好,暫時無法使用這個功能。請稍後重試,或前往「設定 → 關於」管理或恢復 Pi。",
"goToSettings": "前往設定",
"remoteCodexBinaryMissingTitle": "遠端電腦 Codex 元件未就緒",
"remotePiBinaryMissingTitle": "遠端電腦 Pi 元件未就緒",