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。

Merge pull request #6196 from makecindy/perf/ci-unit-test-throughput

Lizic90281e47dba
diff --cc apps/desktop/src/renderer/features/cc-agent/__tests__/CindyMakeSessionNotifications.test.ts
index 19e13e7f95,842aa2844f..36e03eed12
--- a/apps/desktop/src/renderer/features/cc-agent/__tests__/CindyMakeSessionNotifications.test.ts
+++ b/apps/desktop/src/renderer/features/cc-agent/__tests__/CindyMakeSessionNotifications.test.ts
@@@ -54,8 -105,8 +110,9 @@@ type NotificationSession =
const send = vi.fn();
const reviewTarget = vi.fn(async () => false);
const botTitle = vi.fn(async (): Promise<string | null> => null);
+const leadOfWorker = vi.fn<(workerSessionId: string) => string | null>(() => null);
beforeEach(() => { vi.clearAllMocks(); });
+ afterEach(cleanup);
function dispatcher(local: NotificationSession[], remote: NotificationSession[] = []) {
const bindings = {
@@@ -132,59 -180,42 +189,74 @@@ describe('disabled Make notification di
await Promise.resolve();
expect(send).toHaveBeenCalledWith('unknown', 'Unnamed task', 'error');
});
+ });
+
+ describe('sidebar system attention consumers', () => {
+ it('clears the viewed task on opening and window focus, replacing and removing its focus listener', () => {
+ const { Component, clearAttention } = attentionSidebar();
+ const view = render(createElement(Component, { viewedSessionId: 'first' }));
+ expect(clearAttention.mock.calls).toEqual([['first']]);
+ fireEvent(window, new Event('focus'));
+ expect(clearAttention.mock.calls).toEqual([['first'], ['first']]);
+
+ view.rerender(createElement(Component, { viewedSessionId: 'second' }));
+ clearAttention.mockClear();
+ fireEvent(window, new Event('focus'));
+ expect(clearAttention.mock.calls).toEqual([['second']]);
+
+ view.rerender(createElement(Component, { viewedSessionId: null }));
+ clearAttention.mockClear();
+ fireEvent(window, new Event('focus'));
+ expect(clearAttention).not.toHaveBeenCalled();
+ view.rerender(createElement(Component, { viewedSessionId: 'third' }));
+ clearAttention.mockClear();
+ view.unmount();
+ fireEvent(window, new Event('focus'));
+ expect(clearAttention).not.toHaveBeenCalled();
+ });
+
+ it('clears the clicked task, including re-opening the already active task', async () => {
+ const { Component, clearAttention } = attentionSidebar();
+ const view = render(createElement(Component, { viewedSessionId: 'shown' }));
+ clearAttention.mockClear();
+ await act(async () => fireEvent.click(screen.getByRole('button', { name: 'Open task' })));
+ expect(clearAttention.mock.calls).toEqual([['clicked']]);
- it('passes unfiltered local and remote metadata to notification dispatch', () => {
- let rawRemote: string | undefined;
- const props = new Map<string, string>();
- function visit(node: ts.Node): void {
- if (ts.isVariableDeclaration(node) && ts.isIdentifier(node.name) && node.name.text === 'remoteProjectSessionsRaw' && !rawRemote) {
- rawRemote = node.initializer?.getText(source);
- }
- if (ts.isJsxSelfClosingElement(node) && node.tagName.getText(source) === 'ExpandedView') {
- for (const attribute of node.attributes.properties) {
- if (ts.isJsxAttribute(attribute) && attribute.initializer && ts.isJsxExpression(attribute.initializer)) {
- props.set(attribute.name.getText(source), attribute.initializer.expression?.getText(source) ?? '');
- }
- }
- }
- ts.forEachChild(node, visit);
- }
- visit(source);
- expect(rawRemote).toContain('useSyncExternalStore');
- expect(rawRemote).toContain('remoteProjectsStore.getMergedRemoteSessions');
- expect(props.get('allSessionsForNotification')).toBe('allSessionsForAttentionRaw');
- expect(props.get('remoteSessionsForNotification')).toBe('remoteProjectSessionsRaw');
+ view.rerender(createElement(Component, { viewedSessionId: 'shown', clickedSessionId: 'shown' }));
+ clearAttention.mockClear();
+ await act(async () => fireEvent.click(screen.getByRole('button', { name: 'Open task' })));
+ expect(clearAttention.mock.calls).toEqual([['shown']]);
});
});
+
+describe('Orca Worker notification dispatch', () => {
+ const lead: NotificationSession = { id: 'lead', title: '重构登录', source: 'desktop', orcaRole: 'lead' };
+ const worker: NotificationSession = {
+ id: 'worker', title: 'Worker · developer', source: 'desktop', orcaRole: 'worker',
+ };
+
+ it('Worker 的完成仍不单独通知', () => {
+ leadOfWorker.mockReturnValue('lead');
+ dispatcher([lead, worker])('worker', 'done');
+ expect(send).not.toHaveBeenCalled();
+ });
+
+ it.each(['error', 'needs-reply'] as const)('Worker 的 %s 以「Lead 标题 · Worker 标题」单独通知', (kind) => {
+ leadOfWorker.mockReturnValue('lead');
+ dispatcher([lead, worker])('worker', kind);
+ expect(leadOfWorker).toHaveBeenCalledWith('worker');
+ expect(send).toHaveBeenCalledWith('worker', '重构登录 · Worker · developer', kind);
+ });
+
+ it('找不到 Lead 时退回 Worker 标题', () => {
+ leadOfWorker.mockReturnValue(null);
+ dispatcher([worker])('worker', 'error');
+ expect(send).toHaveBeenCalledWith('worker', 'Worker · developer', 'error');
+ });
+
+ it('远程控制另一台电脑的 Worker 不在范围内', () => {
+ leadOfWorker.mockReturnValue('lead');
+ dispatcher([], [{ ...worker, deviceLinkDeviceId: 'host' }])('worker', 'error');
+ expect(send).not.toHaveBeenCalled();
+ });
+});
diff --cc apps/desktop/src/renderer/features/cc-agent/sidebar/__tests__/SessionCard.visual.test.ts
index 7ddb2dfe3b,8119a025e3..5364540baf
--- a/apps/desktop/src/renderer/features/cc-agent/sidebar/__tests__/SessionCard.visual.test.ts
+++ b/apps/desktop/src/renderer/features/cc-agent/sidebar/__tests__/SessionCard.visual.test.ts
@@@ -164,14 -164,8 +164,10 @@@ vi.mock('@/hooks/useSessionPausedQueue'
vi.mock('@/lib/sessionAttentionStore', () => ({
useSessionAttentionKind: (sessionId: string) => mocks.attentionKindBySession.get(sessionId),
+ getSessionAttentionKinds: () => mocks.attentionKindBySession,
+ subscribeSessionAttention: () => () => undefined,
}));
- vi.mock('../../lib/scrollIntoNearestView', () => ({
- scrollIntoNearestView: vi.fn(),
- }));
-
vi.mock('@/lib/toast', () => ({
toast: {
success: vi.fn(),