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(navigation): open partner list on first entry after restart (#4685)

Chris Zhangf45345bbd13b
diff --git a/apps/desktop/src/renderer/components/layout/__tests__/MainEntryRedirect.test.tsx b/apps/desktop/src/renderer/components/layout/__tests__/MainEntryRedirect.test.tsx
index 5f5e8f51f2..d9b534793b 100644
--- a/apps/desktop/src/renderer/components/layout/__tests__/MainEntryRedirect.test.tsx
+++ b/apps/desktop/src/renderer/components/layout/__tests__/MainEntryRedirect.test.tsx
@@ -1,10 +1,11 @@
// @vitest-environment jsdom
import { transferableAbortController } from 'node:util';
-import { cleanup, render, screen, act } from '@testing-library/react';
+import { cleanup, render, screen, act, fireEvent } from '@testing-library/react';
import { createMemoryRouter, Outlet, RouterProvider, useLocation } from 'react-router-dom';
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';
import { MainViewHistoryProvider } from '@/contexts/MainViewHistoryContext';
import { readMainEntryRoute, rememberMainEntry } from '@/lib/mainEntryPreference';
+import { useActiveMainView } from '@/hooks/useActiveMainView';
import { BotsListView } from '@/features/bots/BotsListView';
import { MainEntryRedirect, useRememberMainEntry } from '../MainEntryRedirect';
@@ -13,8 +14,9 @@ vi.mock('@/contexts/AuthContext', () => ({ useAuth: () => auth }));
function Layout() {
useRememberMainEntry();
+ const { navigateToView } = useActiveMainView();
const location = useLocation();
- return <><output data-testid="route">{location.pathname}{location.search}</output><Outlet /></>;
+ return <><button onClick={() => navigateToView('bots')}>Partners</button><button onClick={() => navigateToView('cc-agent')}>Tasks</button><output data-testid="route">{location.pathname}{location.search}</output><Outlet /></>;
}
function launch(path = '/') {
const router = createMemoryRouter([{ element: <Layout />, children: [
@@ -48,6 +50,30 @@ describe('main entry startup', () => {
expect(JSON.stringify(localStorage)).not.toContain('private-bot');
expect(JSON.stringify(localStorage)).not.toContain('private-task');
});
+ it('opens the unselected partner list after restarting from tasks', () => {
+ launch('/bots/dash/session/dash-main');
+ fireEvent.click(screen.getByText('Tasks'));
+ expect(screen.getByTestId('route').textContent).toBe('/cc-agent');
+ cleanup();
+ launch();
+ fireEvent.click(screen.getByText('Partners'));
+ expect(screen.getByTestId('route').textContent).toBe('/bots/list');
+ expect(screen.getByRole('main').childElementCount).toBe(0);
+ });
+ it('returns to the selected partner when switching areas without restarting', () => {
+ launch('/bots/dash/session/dash-main');
+ fireEvent.click(screen.getByText('Tasks'));
+ fireEvent.click(screen.getByText('Partners'));
+ expect(screen.getByTestId('route').textContent).toBe('/bots/dash/session/dash-main');
+ });
+ it('does not restore the previous account partner through the area switcher', async () => {
+ const app = launch('/bots/dash/session/dash-main');
+ auth.dataOwnerId = 'account-b';
+ app.rerender();
+ await act(() => app.router.navigate('/cc-agent'));
+ fireEvent.click(screen.getByText('Partners'));
+ expect(screen.getByTestId('route').textContent).toBe('/bots/list');
+ });
it('keeps the task index behavior for no record and after returning to tasks', async () => {
const app = launch();
expect(screen.getByTestId('route').textContent).toBe('/cc-agent');
diff --git a/apps/desktop/src/renderer/hooks/useActiveMainView.ts b/apps/desktop/src/renderer/hooks/useActiveMainView.ts
index 2aa9d5a28a..da09c2a27e 100644
--- a/apps/desktop/src/renderer/hooks/useActiveMainView.ts
+++ b/apps/desktop/src/renderer/hooks/useActiveMainView.ts
@@ -14,6 +14,7 @@
* URL 派生由本 hook 维护;各视图最后位置由账号级 MainViewHistoryProvider 共享,
* 避免侧栏滚动段卸载后丢失返回位置。未提供 Provider 时使用实例内记忆。
* 自动化页保留当前视图归属,但不覆盖任务返回位置。
+ * 无运行期伙伴位置时进入 /bots/list,不自动选择伙伴。
* 伙伴创建页的返回位置使用 /bots,由入口解析最近有效伙伴,不恢复创建表单。
* [PROTOCOL]: 变更时更新此头部,然后检查 CLAUDE.md
*/
@@ -38,7 +39,7 @@ const VIEWS: ViewDef[] = [
{ key: 'cc-agent', to: '/cc-agent', prefixes: ['/cc-agent'] },
{ key: 'issues', to: '/issues', prefixes: ['/issues'] },
{ key: 'plugins', to: '/plugins', prefixes: ['/plugins', '/skillhub'] },
- { key: 'bots', to: '/bots', prefixes: ['/bots'] },
+ { key: 'bots', to: '/bots/list', prefixes: ['/bots'] },
];
const DEFAULT_KEY: MainViewKey = 'cc-agent';