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): keep login available after backup token expires

Dash035653de4ec8
diff --git a/apps/desktop/src/renderer/__tests__/githubAccountCard.test.tsx b/apps/desktop/src/renderer/__tests__/githubAccountCard.test.tsx
index f019a8235a..7ec6fa2f67 100644
--- a/apps/desktop/src/renderer/__tests__/githubAccountCard.test.tsx
+++ b/apps/desktop/src/renderer/__tests__/githubAccountCard.test.tsx
@@ -58,6 +58,21 @@ it('refreshes credential changes and ignores an older in-flight response', async
expect(screen.getByText(prefix + 'token')).toBeTruthy();
});
+it.each(['gh-cli', 'token'])(
+ 'keeps login available after %s authentication fails',
+ async (source) => {
+ window.electronAPI = {
+ gitContext: {
+ githubConnection: async () => ({ status: 'auth', source }),
+ onGithubConnected: () => () => {},
+ },
+ } as any;
+ render(<GithubAccountCard onConnected={() => {}} />);
+ expect(await screen.findByText('connect')).toBeTruthy();
+ expect(screen.getByText(prefix + 'auth')).toBeTruthy();
+ },
+);
+
it('does not misrepresent a network failure as a request to log in', async () => {
window.electronAPI = {
gitContext: {
diff --git a/apps/desktop/src/renderer/features/cc-agent/GithubAccountCard.tsx b/apps/desktop/src/renderer/features/cc-agent/GithubAccountCard.tsx
index 37dff6c4a6..5998b7c312 100644
--- a/apps/desktop/src/renderer/features/cc-agent/GithubAccountCard.tsx
+++ b/apps/desktop/src/renderer/features/cc-agent/GithubAccountCard.tsx
@@ -46,9 +46,7 @@ export function GithubAccountCard({ onConnected }: { onConnected(): void }) {
)}
<div className="flex gap-2">
<GithubConnectButton
- visible={
- state?.status === 'missing' || (state?.status === 'auth' && state.source !== 'token')
- }
+ visible={state?.status === 'missing' || state?.status === 'auth'}
onConnected={() => {
void refresh();
onConnected();
diff --git a/apps/desktop/src/renderer/features/plugin/__tests__/GhostPluginDetailSections.test.tsx b/apps/desktop/src/renderer/features/plugin/__tests__/GhostPluginDetailSections.test.tsx
index 21df54bab3..3ab0a12550 100644
--- a/apps/desktop/src/renderer/features/plugin/__tests__/GhostPluginDetailSections.test.tsx
+++ b/apps/desktop/src/renderer/features/plugin/__tests__/GhostPluginDetailSections.test.tsx
@@ -222,52 +222,55 @@ describe('Ghost plugin detail sections', () => {
);
expect(verify).not.toHaveBeenCalled();
});
- it('connects GitHub and reloads the installed plugin settings after authorization', async () => {
- vi.stubGlobal(
- 'ResizeObserver',
- class {
- observe() {}
- unobserve() {}
- disconnect() {}
- },
- );
- Object.assign(window.electronAPI, {
- gitContext: {
- githubConnection: async () => ({ status: 'missing' }),
- onGithubConnected: () => () => {},
- githubSetupStatus: async () => ({ phase: 'connected' }),
- startGithubSetup: async () => ({ phase: 'connected' }),
- },
- });
- const { unmount } = render(
- <GhostPluginDetailView
- ghost={
- {
- manifest: { id: 'cindy-github' },
- enabled: true,
- trust: { ...detail.trust, publisherName: 'Cindy Plugin Market' },
- } as any
- }
- detail={{ ...detail, id: 'cindy-github', hasSettingsUi: true }}
- panelStatus={null}
- onBack={vi.fn()}
- onToggle={vi.fn()}
- onUse={vi.fn()}
- onUpdate={vi.fn()}
- onUpdateFromFile={vi.fn()}
- onUninstall={vi.fn()}
- toggleDisabled={false}
- />,
- );
- const previousSettings = screen.getByTestId('ghost-settings-webview');
- fireEvent.click(await screen.findByText('ccAgent.gitContext.pr.setup.stages.login.title'));
- fireEvent.click(await screen.findByText('ccAgent.gitContext.pr.setup.connect'));
- await waitFor(() =>
- expect(screen.getByTestId('ghost-settings-webview')).not.toBe(previousSettings),
- );
- expect(screen.getByText('ccAgent.gitContext.pr.setup.done')).toBeTruthy();
- unmount();
- });
+ it.each([{ status: 'missing' }, { status: 'auth', source: 'token' }])(
+ 'connects GitHub from $status and reloads the installed plugin settings after authorization',
+ async (connection) => {
+ vi.stubGlobal(
+ 'ResizeObserver',
+ class {
+ observe() {}
+ unobserve() {}
+ disconnect() {}
+ },
+ );
+ Object.assign(window.electronAPI, {
+ gitContext: {
+ githubConnection: async () => connection,
+ onGithubConnected: () => () => {},
+ githubSetupStatus: async () => ({ phase: 'connected' }),
+ startGithubSetup: async () => ({ phase: 'connected' }),
+ },
+ });
+ const { unmount } = render(
+ <GhostPluginDetailView
+ ghost={
+ {
+ manifest: { id: 'cindy-github' },
+ enabled: true,
+ trust: { ...detail.trust, publisherName: 'Cindy Plugin Market' },
+ } as any
+ }
+ detail={{ ...detail, id: 'cindy-github', hasSettingsUi: true }}
+ panelStatus={null}
+ onBack={vi.fn()}
+ onToggle={vi.fn()}
+ onUse={vi.fn()}
+ onUpdate={vi.fn()}
+ onUpdateFromFile={vi.fn()}
+ onUninstall={vi.fn()}
+ toggleDisabled={false}
+ />,
+ );
+ const previousSettings = screen.getByTestId('ghost-settings-webview');
+ fireEvent.click(await screen.findByText('ccAgent.gitContext.pr.setup.stages.login.title'));
+ fireEvent.click(await screen.findByText('ccAgent.gitContext.pr.setup.connect'));
+ await waitFor(() =>
+ expect(screen.getByTestId('ghost-settings-webview')).not.toBe(previousSettings),
+ );
+ expect(screen.getByText('ccAgent.gitContext.pr.setup.done')).toBeTruthy();
+ unmount();
+ },
+ );
it('uses the shared Cindy Switch for the plugin enabled control', () => {
vi.stubGlobal(
'ResizeObserver',