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(github): show guidance when browser launch returns failure

Dasha7dc1c12ba20
diff --git a/apps/desktop/src/renderer/__tests__/githubSetup.test.tsx b/apps/desktop/src/renderer/__tests__/githubSetup.test.tsx
index 33d66f4bd6..7313a65189 100644
--- a/apps/desktop/src/renderer/__tests__/githubSetup.test.tsx
+++ b/apps/desktop/src/renderer/__tests__/githubSetup.test.tsx
@@ -76,7 +76,7 @@ describe('GitHub setup UI', () => {
it('requires the connect action, shows the code and opens only GitHub device authorization', async () => {
const start = vi.fn(async () => ({ phase: 'authorizing', userCode: 'ABCD-1234' }));
const status = vi.fn(async () => ({ phase: 'idle' }));
- const openExternal = vi.fn();
+ const openExternal = vi.fn(async () => ({ success: true }));
window.electronAPI = {
gitContext: { githubSetupStatus: status, startGithubSetup: start },
openExternal,
@@ -128,6 +128,29 @@ describe('GitHub setup UI', () => {
expect(screen.queryByText(`${key}.connect`)).toBeNull();
});
+ it.each(['result', 'rejection'])(
+ 'shows manual-open guidance after browser %s failure and clears it on retry',
+ async (failure) => {
+ const openExternal = vi.fn().mockResolvedValue({ success: true });
+ if (failure === 'result') openExternal.mockResolvedValueOnce({ success: false });
+ else openExternal.mockRejectedValueOnce(new Error('browser unavailable'));
+ window.electronAPI = {
+ gitContext: {
+ githubSetupStatus: async () => ({ phase: 'authorizing', userCode: 'ABCD-1234' }),
+ },
+ openExternal,
+ } as any;
+ render(<GithubSetupDialog onClose={() => {}} />);
+ fireEvent.click(await screen.findByText(`${key}.openBrowser`));
+ expect(await screen.findByRole('alert')).toHaveProperty('textContent', `${key}.openFailed`);
+ expect(screen.getByText('ABCD-1234')).toBeTruthy();
+ expect(screen.getByText('github.com/login/device')).toBeTruthy();
+ fireEvent.click(screen.getByText(`${key}.openBrowser`));
+ await waitFor(() => expect(screen.queryByRole('alert')).toBeNull());
+ expect(openExternal).toHaveBeenCalledTimes(2);
+ },
+ );
+
it('keeps action failures visible and offers a retry', async () => {
window.electronAPI = {
gitContext: {
diff --git a/apps/desktop/src/renderer/features/cc-agent/GithubSetupDialog.tsx b/apps/desktop/src/renderer/features/cc-agent/GithubSetupDialog.tsx
index 051f22f3b8..e892ea1879 100644
--- a/apps/desktop/src/renderer/features/cc-agent/GithubSetupDialog.tsx
+++ b/apps/desktop/src/renderer/features/cc-agent/GithubSetupDialog.tsx
@@ -111,8 +111,8 @@ export function GithubSetupDialog({
const openBrowser = async () => {
setOpening(true);
try {
- await window.electronAPI.openExternal('https://github.com/login/device');
- setFeedback(undefined);
+ const result = await window.electronAPI.openExternal('https://github.com/login/device');
+ setFeedback(result.success ? undefined : 'openFailed');
} catch {
setFeedback('openFailed');
} finally {