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(providers): wait for explicit configuration click after detection

xdc13a359bfab0
diff --git a/apps/desktop/scripts/fixtures/provider-detection/ui-page.mjs b/apps/desktop/scripts/fixtures/provider-detection/ui-page.mjs
index 9877802875..64f0d52f61 100644
--- a/apps/desktop/scripts/fixtures/provider-detection/ui-page.mjs
+++ b/apps/desktop/scripts/fixtures/provider-detection/ui-page.mjs
@@ -45,6 +45,7 @@ export default {
await page.getByPlaceholder(await ui.t('settings.providers.custom.fields.namePlaceholder')).fill('Cloudflare review');
await page.getByPlaceholder(await ui.t('settings.providers.custom.fields.apiKeyPlaceholder')).fill('fake-ui-key');
await page.getByPlaceholder(await ui.t('settings.providers.custom.fields.baseUrlPlaceholder')).fill(input);
+ await page.getByRole('button', { name: await ui.t('settings.providers.detection.configure'), exact: true }).click();
await page.getByRole('button', { name: await ui.t('settings.providers.wizard.next'), exact: true }).waitFor();
await ui.capture('normalized-handoff');
await page.getByRole('button', { name: await ui.t('settings.providers.wizard.next'), exact: true }).click();
@@ -129,6 +130,9 @@ export default {
if (['default', 'return', 'relay', 'litellm'].includes(ui.case)) {
await page.getByRole('button', { name: await ui.t('settings.providers.detection.keepCustom') }).waitFor();
await ui.capture('identified', { locator: page.getByRole('dialog') });
+ await page.waitForTimeout(1500);
+ assert.equal(await page.getByPlaceholder(await ui.t('settings.providers.custom.fields.baseUrlPlaceholder')).inputValue(), address);
+ await page.getByRole('button', { name: await ui.t('settings.providers.detection.configure'), exact: true }).click();
await page.getByText(await ui.t('settings.providers.wizard.nameLabel'), { exact: true }).waitFor();
assert.equal(await page.getByPlaceholder('sk-…').inputValue(), 'fake-ui-key');
await ui.capture('provider-connection', { locator: page.getByRole('dialog') });
diff --git a/apps/desktop/scripts/fixtures/provider-template-catalog/ui-page.mjs b/apps/desktop/scripts/fixtures/provider-template-catalog/ui-page.mjs
index ff832fb2e3..d26fee5c18 100644
--- a/apps/desktop/scripts/fixtures/provider-template-catalog/ui-page.mjs
+++ b/apps/desktop/scripts/fixtures/provider-template-catalog/ui-page.mjs
@@ -26,6 +26,11 @@ export default {
await ui.capture('ambiguous-stayed-custom');
return;
}
+ const configure = page.getByRole('button', { name: await ui.t('settings.providers.detection.configure'), exact: true });
+ await configure.waitFor();
+ await page.waitForTimeout(1500);
+ assert.equal(await page.evaluate(() => window.templateEvidence.handoff), undefined, 'Recognition alone must not navigate');
+ await configure.click();
await page.getByRole('button', { name: await ui.t('settings.providers.wizard.next'), exact: true }).waitFor();
assert.equal(await page.evaluate(() => window.templateEvidence.handoff.preset.id), item.providerId);
}
diff --git a/apps/desktop/scripts/provider-save-e2e.mjs b/apps/desktop/scripts/provider-save-e2e.mjs
index 998cf3b194..cb21b6cf8d 100644
--- a/apps/desktop/scripts/provider-save-e2e.mjs
+++ b/apps/desktop/scripts/provider-save-e2e.mjs
@@ -96,6 +96,12 @@ try {
await page.getByPlaceholder('Header-Name').first().fill('X-E2E-Marker');
await page.getByPlaceholder('value', { exact: true }).first().fill('preserved-through-wizard');
await page.getByPlaceholder('https://api.myprovider.com/v1').fill(origin + item.prefix + '/v1');
+ const configure = page.getByRole('button', { name: '前往配置', exact: true });
+ await configure.waitFor();
+ await page.waitForTimeout(1500);
+ assert.equal(await page.getByPlaceholder('https://api.myprovider.com/v1').inputValue(), origin + item.prefix + '/v1');
+ assert.equal(await page.getByRole('button', { name: '下一步', exact: true }).count(), 0, 'Recognition must wait for a click');
+ await configure.click();
const next = page.getByRole('button', { name: '下一步', exact: true });
await next.waitFor();
await page.screenshot({ path: path.join(out, `${results.length}-handoff.png`) });
diff --git a/apps/desktop/src/renderer/components/settings/ProviderConnectionDialog.tsx b/apps/desktop/src/renderer/components/settings/ProviderConnectionDialog.tsx
index 57369b9007..3da75235c2 100644
--- a/apps/desktop/src/renderer/components/settings/ProviderConnectionDialog.tsx
+++ b/apps/desktop/src/renderer/components/settings/ProviderConnectionDialog.tsx
@@ -969,7 +969,6 @@ export function ProviderConnectionDialog({
[i18n.language, setRtSynced],
);
- const detectionSuppressed = useRef(!!draft);
const [detection, setDetection] = useState<{ signature: string; preset?: ProviderPreset; pending?: boolean; ambiguous?: boolean; code?: string } | null>(null);
const discoveryCache = useRef(new Map<DialogAgentKind, { signature: string; promise: Promise<DetectionCatalog> }>(
draft?.catalog ? [[draft.agent, { signature: `${draft.agent}:${providerModelFetchRequestSignature(rt[draft.agent], authMode)}`,
@@ -1040,7 +1039,6 @@ export function ProviderConnectionDialog({
useEffect(() => {
if (editing || !onDetected || authMode === 'oauth' || saving || !dialog.open) return;
let live = true;
- let jump: ReturnType<typeof setTimeout> | undefined;
// Correlation only, scoped to this renderer; randomUUID requires a secure context.
const requestId = `detect-${Date.now()}-${++detectionRequestSequence}`;
const agent = activeTab;
@@ -1109,19 +1107,15 @@ export function ProviderConnectionDialog({
if (preset && !AGENTS.some(a => preset!.runtimes[a] &&
(a === agent || followsDefaultConnection(a, rtRef.current[a], rtRef.current[agent])))) preset = undefined;
setDetection({ signature, preset, ambiguous, code: catalog && !catalog.ok ? (catalog.code ?? 'UNKNOWN') : undefined });
- if (preset && !detectionSuppressed.current) jump = setTimeout(() => {
- if (live && !detectionSuppressed.current && detectionContext.current.signature === signature) enterDetectedProvider(preset);
- }, 1200);
});
}, 400);
return () => {
live = false;
clearTimeout(timer);
- clearTimeout(jump);
void window.electronAPI.maker.detectProvider?.({ requestId, cancel: true }).catch(() => undefined);
};
// A model selection/name change is not a new connection or a reason to restart detection.
- }, [detectionSignature, presets, editing, authMode, saving, dialog.open, !!onDetected, enterDetectedProvider, setRtSynced]);
+ }, [detectionSignature, presets, editing, authMode, saving, dialog.open, !!onDetected, setRtSynced]);
// 编辑态:回填各已配置 runtime 的已存明文密钥(用户本机自己的 key)——
// 让密钥框「能看」(eye 显形 / 可核对),而非空白遮罩;据此点亮「已保存」徽标。
@@ -2708,7 +2702,7 @@ export function ProviderConnectionDialog({
{detection.code && !detectionAuthFailed && <span className="text-[var(--error-fg)]">{t(`providerError.${detection.code}`)}</span>}
{detection.preset && <div className="flex flex-wrap gap-2">
<Button type="button" variant="secondary" onClick={() => enterDetectedProvider(detection.preset!)}>{t('settings.providers.detection.configure')}</Button>
- <Button type="button" variant="secondary" tone="quiet" onClick={() => { detectionSuppressed.current = true; setDetection(null); }}>{t('settings.providers.detection.keepCustom')}</Button>
+ <Button type="button" variant="secondary" tone="quiet" onClick={() => setDetection(null)}>{t('settings.providers.detection.keepCustom')}</Button>
</div>}
</div>
)}
diff --git a/apps/desktop/src/renderer/components/settings/__tests__/CustomProviderDialogAccessibility.test.tsx b/apps/desktop/src/renderer/components/settings/__tests__/CustomProviderDialogAccessibility.test.tsx
index 01822efd32..9243bd69e4 100644
--- a/apps/desktop/src/renderer/components/settings/__tests__/CustomProviderDialogAccessibility.test.tsx
+++ b/apps/desktop/src/renderer/components/settings/__tests__/CustomProviderDialogAccessibility.test.tsx
@@ -2230,6 +2230,9 @@ describe('new-connection identification', () => {
fetchProviderModels.mockResolvedValue({ ok: false, code: 'AUTH_INVALID' } as any);
fireEvent.change(screen.getByPlaceholderText('settings.providers.custom.fields.baseUrlPlaceholder'), { target: { value: url } });
await act(async () => { await vi.advanceTimersByTimeAsync(1600); });
+ expect(onDetected).not.toHaveBeenCalled();
+ fireEvent.click(screen.getByRole('button', { name: 'settings.providers.detection.configure' }));
+ await act(async () => {});
expect(onDetected).toHaveBeenCalledOnce();
expect(onDetected.mock.calls[0][0]).toMatchObject({ apiKey: '', preset: { id }, agent: 'pi' });
expect(fetchProviderModels).toHaveBeenCalledWith(expect.objectContaining({ apiKey: null }));
@@ -2265,12 +2268,13 @@ describe('new-connection identification', () => {
expect(screen.queryByText('settings.providers.detection.keyRequired')).toBeNull();
expect(screen.getByText('settings.providers.detection.custom')).toBeTruthy();
});
- it('waits 1.2 seconds and hands off the URL, key and selected models without saving', async () => {
+ it('only hands off after an explicit click, even long after identification succeeds', async () => {
const { onDetected, fetchProviderModels } = await openIdentification();
expect(onDetected).not.toHaveBeenCalled();
- await act(async () => { await vi.advanceTimersByTimeAsync(1199); });
+ await act(async () => { await vi.advanceTimersByTimeAsync(10000); });
expect(onDetected).not.toHaveBeenCalled();
- await act(async () => { await vi.advanceTimersByTimeAsync(1); });
+ fireEvent.click(screen.getByRole('button', { name: 'settings.providers.detection.configure' }));
+ await act(async () => {});
expect(onDetected).toHaveBeenCalledOnce();
expect(onDetected.mock.calls[0][0]).toMatchObject({ apiKey: 'fake-key', agent: 'pi', config: { runtimes: { pi: { baseUrl: 'https://api.deepseek.com', models: [{ id: 'private-model' }] } } } });
expect(fetchProviderModels).toHaveBeenCalledOnce();
@@ -2355,7 +2359,9 @@ describe('new-connection identification', () => {
codex: { baseUrl: 'https://api.deepseek.com', wireProtocol: 'openai-chat', models: [] },
} };
const { onDetected } = await openIdentification(available);
- await act(async () => { await vi.advanceTimersByTimeAsync(1200); });
+ expect(onDetected).not.toHaveBeenCalled();
+ fireEvent.click(screen.getByRole('button', { name: 'settings.providers.detection.configure' }));
+ await act(async () => {});
const value = onDetected.mock.calls[0][0];
expect(value.preset.runtimes['claude-code']).toMatchObject({ baseUrl: 'https://api.deepseek.com/anthropic', wireProtocol: 'anthropic-messages' });
expect(value.preset.runtimes.codex.wireProtocol).toBe('openai-chat');
@@ -2376,6 +2382,9 @@ describe('new-connection identification', () => {
fireEvent.change(screen.getByPlaceholderText('settings.providers.custom.fields.baseUrlPlaceholder'), { target: { value: 'https://api.deepseek.com' } });
fireEvent.change(screen.getByPlaceholderText('settings.providers.custom.fields.apiKeyPlaceholder'), { target: { value: 'fake-key' } });
await act(async () => { await vi.advanceTimersByTimeAsync(1600); });
+ expect(onDetected).not.toHaveBeenCalled();
+ fireEvent.click(screen.getByRole('button', { name: 'settings.providers.detection.configure' }));
+ await act(async () => {});
expect(onDetected).toHaveBeenCalledOnce();
const draft = onDetected.mock.calls[0][0];
expect(draft.agent).toBe('claude-code');
@@ -2529,7 +2538,8 @@ describe('new-connection identification', () => {
});
it('reuses the directory after returning to custom without restarting detection', async () => {
const { onDetected, fetchProviderModels } = await openIdentification();
- await act(async () => { await vi.advanceTimersByTimeAsync(1200); });
+ fireEvent.click(screen.getByRole('button', { name: 'settings.providers.detection.configure' }));
+ await act(async () => {});
const draft = onDetected.mock.calls[0][0];
cleanup();
fetchProviderModels.mockClear();
@@ -2562,16 +2572,18 @@ describe('new-connection identification', () => {
expect(onDetected).not.toHaveBeenCalled();
expect(screen.queryByRole('button', { name: 'settings.providers.detection.configure' })).toBeNull();
});
- it('does not navigate after unmount with a scheduled official handoff', async () => {
+ it('does not navigate after unmount with an identified provider', async () => {
const { onDetected } = await openIdentification();
cleanup();
await act(async () => { await vi.advanceTimersByTimeAsync(2000); });
expect(onDetected).not.toHaveBeenCalled();
});
- it('uses the current name when the user edits it during the jump delay', async () => {
+ it('uses the current name when the user edits it before clicking configure', async () => {
const { onDetected } = await openIdentification();
fireEvent.change(screen.getByPlaceholderText('settings.providers.custom.fields.namePlaceholder'), { target: { value: 'Latest name' } });
- await act(async () => { await vi.advanceTimersByTimeAsync(1200); });
+ expect(onDetected).not.toHaveBeenCalled();
+ fireEvent.click(screen.getByRole('button', { name: 'settings.providers.detection.configure' }));
+ await act(async () => {});
expect(onDetected).toHaveBeenCalledOnce();
expect(onDetected.mock.calls[0][0].config.name).toBe('Latest name');
});
@@ -2585,6 +2597,9 @@ describe('new-connection identification', () => {
fireEvent.change(key, { target: { value: 'new-fake-key' } });
await act(async () => { finish({ ok: true, models: [{ id: 'obsolete-model', name: 'Obsolete' }] }); });
await act(async () => { await vi.advanceTimersByTimeAsync(1600); });
+ expect(onDetected).not.toHaveBeenCalled();
+ fireEvent.click(screen.getByRole('button', { name: 'settings.providers.detection.configure' }));
+ await act(async () => {});
expect(onDetected).toHaveBeenCalledOnce();
expect(onDetected.mock.calls[0][0].apiKey).toBe('new-fake-key');
expect(onDetected.mock.calls[0][0].config.runtimes.pi.models.map((m: { id: string }) => m.id)).not.toContain('obsolete-model');
diff --git a/docs/product-rules/provider-auto-detection.md b/docs/product-rules/provider-auto-detection.md
index 88c65717f8..3a4232976d 100644
--- a/docs/product-rules/provider-auto-detection.md
+++ b/docs/product-rules/provider-auto-detection.md
@@ -12,9 +12,9 @@
未识别的自定义连接默认只保存 Pi;已有独立引擎草稿字段不覆盖,已识别预设仍按预设绑定。
2. 输入稳定 400 ms 后,先按当前供应商目录匹配完整官方地址;未匹配时执行固定系统探测,
同时读取通用模型目录。名称、模型勾选变化不重新探测。
-3. 只有唯一结果且该预设含可用引擎配置时显示“已识别为…”,保留 1200 ms,
- 然后进入已有供应商连接步骤。用户可以立即前往或继续自定义;不会自动保存。
-4. 名称、URL、key、请求头、各 Runtime 草稿和模型选择随跳转保留。返回自定义后不再自动跳转。
+3. 只有唯一结果且该预设含可用引擎配置时显示“已识别为…”,等待用户点击前往按钮,
+ 才进入已有供应商连接步骤。不倒计时或自动跳转;用户也可继续自定义,不会自动保存。
+4. 名称、URL、key、请求头、各 Runtime 草稿和模型选择随跳转保留。返回自定义后保留草稿并停留在表单。
用户打开模型选择等子弹层或正在保存时不强制跳转。
5. 未识别、证据冲突、预设没有可绑定的引擎配置时保留自定义。成功取得的模型首次直接加入模型区;
没有结果时由用户点击“获取模型列表”重试,也可手动添加。失败显示分类原因,不能据此断言站点不能调用。
@@ -90,7 +90,7 @@ Pi 由保存流程写入已验证或用户保留的协议,不在真实任务
## 验证与限制
自动化覆盖五种充分/不足/冲突证据、路径绑定、区域排序、鉴权隔离、超时/取消/超限响应、
-模型别名补全、延迟跳转、取消跳转、陈旧响应、模型选择和返回草稿。
+模型别名补全、等待不跳转、点击后交接、陈旧响应、模型选择和返回草稿。
UI 单页夹具使用真实组件和模拟 Host,覆盖官方匹配、Sub2API 匹配、自定义目录成功、失败后手动添加。
浅色/深色、窄窗口、各语言及模拟 Windows 平台的结果随 PR 附证据。