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(desktop): 收窄重启提示中的伙伴任务范围并补测试

Dash9af3f7e8cd7e
diff --git a/apps/desktop/src/main/localDb/__tests__/sessionActiveTurn.test.ts b/apps/desktop/src/main/localDb/__tests__/sessionActiveTurn.test.ts
index 670da13d96..53a1595687 100644
--- a/apps/desktop/src/main/localDb/__tests__/sessionActiveTurn.test.ts
+++ b/apps/desktop/src/main/localDb/__tests__/sessionActiveTurn.test.ts
@@ -567,7 +567,7 @@ describe('sessionActiveTurn', () => {
const client = createTestDbClient();
const startedAt = Date.now() - 10_000;
await seedSession(client, 's-desktop', { startedAt });
- for (const role of ['canonical', 'history', 'delegation', 'group', 'channel']) {
+ for (const role of ['canonical', 'delegation', 'routine', 'channel', 'history', 'group', 'thread']) {
await seedSession(client, `bot-${role}`, { startedAt, source: 'bot' });
await client.exec(
'INSERT INTO bot_session_links (id, bot_id, session_id, role, created_at) VALUES (?, ?, ?, ?, ?)',
@@ -579,8 +579,9 @@ describe('sessionActiveTurn', () => {
expect((await listInterruptedResumeCandidateRows()).map((r) => r.sessionId).sort()).toEqual([
'bot-canonical',
+ 'bot-channel',
'bot-delegation',
- 'bot-history',
+ 'bot-routine',
's-desktop',
]);
// 侧栏红点不展示伙伴任务,口径不变。
diff --git a/apps/desktop/src/main/localDb/interruptedResumeCandidates.ts b/apps/desktop/src/main/localDb/interruptedResumeCandidates.ts
index 07ce797c3a..48c04ef66b 100644
--- a/apps/desktop/src/main/localDb/interruptedResumeCandidates.ts
+++ b/apps/desktop/src/main/localDb/interruptedResumeCandidates.ts
@@ -2,7 +2,7 @@
* 启动「继续上次中断的任务」弹窗的数据源。
*
* 中断判定完全复用 listInterruptedPendingRows(startedAt > endedAt 且早于本进程启动),
- * 并额外纳入伙伴的主对话、历史与委派任务(它们不在普通任务列表,但同样会被中断),
+ * 并额外纳入可继续的伙伴任务(主对话、委派、例行与渠道专线;来源是 bot,不在桌面来源白名单里),
* 这里只为每个中断会话补两项展示素材:
* - interruptedAt:中断那一轮最后一条落库消息的时间(崩溃时刻无从得知,最后一次
* 落库是最接近的可观察值);该轮没有任何落库消息时回退到 turn 开始时间;
diff --git a/apps/desktop/src/main/localDb/sessionActiveTurn.ts b/apps/desktop/src/main/localDb/sessionActiveTurn.ts
index 7e6e5e6ed4..65d20f5055 100644
--- a/apps/desktop/src/main/localDb/sessionActiveTurn.ts
+++ b/apps/desktop/src/main/localDb/sessionActiveTurn.ts
@@ -391,13 +391,14 @@ export async function listInterruptedPendingRows(
options.includeBotTasks
? or(
listedSource,
- // 伙伴的主对话、历史与委派任务有自己的页面,可以继续;群专线与 IM 专线
- // 是隐藏专线,由群聊 / 渠道收口,不单独提示。
+ // 能走普通「继续」路径的伙伴任务:主对话、委派任务有自己的页面,例行与渠道
+ // 专线列在普通任务列表里。history 只读(botSessionInputGuard 拒绝发送),群与
+ // 私聊话题专线是隐藏专线,由群聊 / 私聊收口,都不提示。
and(
eq(sessions.source, 'bot'),
sql`EXISTS (SELECT 1 FROM ${botSessionLinks}
WHERE ${botSessionLinks.sessionId} = ${sessions.id}
- AND ${botSessionLinks.role} IN ('canonical', 'history', 'delegation'))`,
+ AND ${botSessionLinks.role} IN ('canonical', 'delegation', 'routine', 'channel'))`,
),
)
: listedSource,
diff --git a/apps/desktop/src/renderer/features/cc-agent/__tests__/InterruptedTasksResumeDialog.test.tsx b/apps/desktop/src/renderer/features/cc-agent/__tests__/InterruptedTasksResumeDialog.test.tsx
index 3463be3fc2..6fcb50b054 100644
--- a/apps/desktop/src/renderer/features/cc-agent/__tests__/InterruptedTasksResumeDialog.test.tsx
+++ b/apps/desktop/src/renderer/features/cc-agent/__tests__/InterruptedTasksResumeDialog.test.tsx
@@ -14,11 +14,13 @@ import { CONTINUE_AFTER_APP_EXIT_PROMPT } from '../../../../shared/interruptedTu
import { InterruptedTasksResumeDialog } from '../InterruptedTasksResumeDialog';
const sendUiTrigger = vi.hoisted(() => vi.fn(async () => {}));
+// 弹窗按数据所有者缓存加载结果并记「已处理」,每个用例用独立所有者。
+const auth = vi.hoisted(() => ({ dataOwnerId: 'owner-1' }));
vi.mock('react-i18next', () => ({
useTranslation: () => ({ t: (key: string) => key }),
}));
-vi.mock('@/contexts/AuthContext', () => ({ useAuth: () => ({ dataOwnerId: 'owner-1' }) }));
+vi.mock('@/contexts/AuthContext', () => ({ useAuth: () => auth }));
vi.mock('@/lib/scrollbarAutoHide', () => ({ flashScrollbar: () => {} }));
vi.mock('@/lib/makerChatStore', () => ({ makerChatStore: { sendUiTrigger } }));
vi.mock('@/lib/toast', () => ({ toast: { error: vi.fn() } }));
@@ -77,4 +79,46 @@ describe('InterruptedTasksResumeDialog', () => {
await waitFor(() => expect(sendUiTrigger).toHaveBeenCalledTimes(1));
expect(sendUiTrigger).toHaveBeenCalledWith('s-a', CONTINUE_AFTER_APP_EXIT_PROMPT);
});
+ it('labels companion tasks with the companion name and still opens when the roster read fails', async () => {
+ const now = Date.now();
+ const botSession = {
+ id: 'bot-s',
+ title: '伙伴主任务',
+ source: 'bot',
+ agentKind: 'cc',
+ workingDir: '/code/workdir-name',
+ workspaceKind: 'project',
+ createdAt: new Date(now).toISOString(),
+ };
+ const candidates = [{ sessionId: 'bot-s', interruptedAt: now - 60_000, activity: null }];
+ const mount = (bots: () => Promise<unknown>) =>
+ Object.assign(window, {
+ electronAPI: {
+ localDb: {
+ bots: { list: bots },
+ sessions: {
+ interruptedResumeCandidates: async () => candidates,
+ getMany: async () => [botSession],
+ },
+ },
+ },
+ });
+
+ auth.dataOwnerId = 'owner-bot-name';
+ mount(async () => [{ name: '小助理', sessions: [{ id: 'bot-s' }] }]);
+ render(<InterruptedTasksResumeDialog />);
+ await screen.findByRole('alertdialog');
+ expect(screen.getByText(/小助理/)).toBeTruthy();
+ expect(screen.queryByText(/workdir-name/)).toBeNull();
+ cleanup();
+
+ auth.dataOwnerId = 'owner-bot-name-fails';
+ mount(async () => {
+ throw new Error('roster unavailable');
+ });
+ render(<InterruptedTasksResumeDialog />);
+ await screen.findByRole('alertdialog');
+ expect(screen.getByText('伙伴主任务')).toBeTruthy();
+ expect(screen.getByText(/workdir-name/)).toBeTruthy();
+ });
});