Consider it done. The open-source AI agent that works out of the box · 想到,就能做到。开源、开箱即用的 AI Agent。
TypeScript agentai-agentai-assistantandroidclaude-codecodexelectroniosllmmacosreact-nativetypescriptwindows
test(teammates): 覆盖 todo-daily-check 远程动作与开关兼容分支
zqchris0e430875c4ab
diff --git a/apps/desktop/src/main/localDb/ipc/__tests__/botRemoteResourceTodos.test.ts b/apps/desktop/src/main/localDb/ipc/__tests__/botRemoteResourceTodos.test.tsindex 19d7668b08..53d9102ee5 100644--- a/apps/desktop/src/main/localDb/ipc/__tests__/botRemoteResourceTodos.test.ts+++ b/apps/desktop/src/main/localDb/ipc/__tests__/botRemoteResourceTodos.test.ts@@ -2,10 +2,13 @@ import { afterEach, beforeEach, expect, it, vi } from 'vitest';import { mkdtemp, rm } from 'node:fs/promises';import os from 'node:os';import path from 'node:path';-const env = vi.hoisted(() => ({ visible: true, current: true, access: vi.fn(), get: vi.fn() }));+const env = vi.hoisted(() => ({ visible: true, current: true, access: vi.fn(), get: vi.fn(),+ dailyRead: vi.fn(), dailySet: vi.fn(), broadcast: vi.fn() }));+vi.mock('../../../routines/service.js', () => ({ routineTools: { todoCheckEnabled: env.dailyRead, setTodoCheck: env.dailySet } }));vi.mock('../../../agent-island/service.js', () => ({ getAgentIslandService: () => null }));vi.mock('../../../maker-ipc/botRemoteResourceInvalidation.js', () => ({scheduleBotRemoteResourceChangedForSession: vi.fn(),+ broadcastBotRemoteResourceChanged: env.broadcast,}));vi.mock('../../../maker-ipc/workingStatus.js', () => ({ getWorkingStatusCopy: vi.fn() }));vi.mock('../../client/current.js', () => ({ getDbClient: () => null }));@@ -48,6 +51,9 @@ beforeEach(async () => {env.current = true;env.get.mockReset();env.access.mockReset();+ env.dailyRead.mockReset().mockResolvedValue(false);+ env.dailySet.mockReset().mockImplementation(async (_botId: string, enabled: boolean) => enabled);+ env.broadcast.mockReset();env.get.mockImplementation(async (id: string) =>id === 'bot-one' && env.visible ? source : null,);@@ -171,3 +177,30 @@ it('projects the next deferral expiry even when the deferred item is absent fromexpect(page.items[0].id).not.toBe(later.id);expect(page.nextDeferredAt).toBe(until);});++it('reads and switches the weekday todo check only for a visible teammate on the current account', async () => {+ // 「每天帮我查一次」:手机与别的电脑读 dailyCheck 字段、经 todo-daily-check 动作开关宿主的内置例行任务。+ const daily = (input: Record<string, unknown>, resourceRef = ref) =>+ remoteResourceRegistry.invoke(context, { client, collectionId: 'teammates', resourceRef, actionId: 'todo-daily-check', input });+ env.dailyRead.mockResolvedValueOnce(true);+ expect((await remoteResourceRegistry.get(context, { client, ref })).blocks?.[0].data).toMatchObject({ dailyCheck: true });+ // The routine engine not ready (paused teammate): todos still load, the switch stays hidden.+ env.dailyRead.mockRejectedValueOnce(new Error('The teammate is paused'));+ expect((await remoteResourceRegistry.get(context, { client, ref })).blocks?.[0].data).not.toHaveProperty('dailyCheck');++ expect(await daily({ enabled: true })).toMatchObject({ dailyCheck: true });+ expect(env.dailySet).toHaveBeenLastCalledWith('bot-one', true);+ expect(env.broadcast).toHaveBeenLastCalledWith('bot-one');++ await expect(daily({ enabled: 'yes' })).rejects.toMatchObject({ code: 'INVALID_PARAMS' });+ env.visible = false;+ await expect(daily({ enabled: true })).rejects.toMatchObject({ code: 'NOT_FOUND' });+ env.visible = true;+ await expect(daily({ enabled: true }, { ...ref, id: 'bot-one' })).rejects.toMatchObject({ code: 'NOT_FOUND' });+ expect(env.dailySet).toHaveBeenCalledTimes(1);++ // The account changes while the host switches it: no result crosses accounts, no broadcast.+ env.dailySet.mockImplementationOnce(async () => { env.current = false; return false; });+ await expect(daily({ enabled: false })).rejects.toMatchObject({ code: 'NOT_FOUND' });+ expect(env.broadcast).toHaveBeenCalledTimes(1);+});diff --git a/apps/desktop/src/renderer/features/bots/__tests__/botGlancePopover.test.tsx b/apps/desktop/src/renderer/features/bots/__tests__/botGlancePopover.test.tsxindex 545af148bb..91278961a2 100644--- a/apps/desktop/src/renderer/features/bots/__tests__/botGlancePopover.test.tsx+++ b/apps/desktop/src/renderer/features/bots/__tests__/botGlancePopover.test.tsx@@ -91,6 +91,7 @@ const dailyCheck = vi.fn(async (_botId: string, enabled?: boolean) => (dailyOn =beforeEach(() => {items = [];dailyOn = false;+ dailyCheck.mockImplementation(async (_botId: string, enabled?: boolean) => (dailyOn = enabled ?? dailyOn));h.local = [];h.remote = [];h.delegations = [];@@ -161,6 +162,28 @@ describe('BotGlanceButton', () => {await waitFor(() => expect(toggle.getAttribute('aria-checked')).toBe('false'));});+ it('keeps the switch when the host refuses it, and hides it for a teammate on an older desktop', async () => {+ dailyCheck.mockImplementation(async (_botId: string, enabled?: boolean) => {+ if (enabled !== undefined) throw new Error('The teammate is paused');+ return false;+ });+ await openGlance();+ const toggle = (await screen.findByTestId('bot-glance-daily-check')).querySelector('[role="switch"]')!;+ fireEvent.click(toggle);+ await waitFor(() => expect(h.toastError).toHaveBeenCalledWith('bots.glance.dailyCheckFailed'));+ expect(toggle.getAttribute('aria-checked')).toBe('false');+ cleanup();++ // Another computer whose host predates the switch: its todo page has no dailyCheck field.+ const invoke = window.electronAPI.deviceLink.invoke as ReturnType<typeof vi.fn>;+ invoke.mockResolvedValue({ blocks: [{ primitive: 'teammate-todos', data: { items: [], total: 0 } }] });+ render(<BotGlanceButton bot={{ ...bot, deviceId: 'mini', deviceName: 'Mac-mini' }} cloudHome={false} />);+ await waitFor(() => expect(invoke).toHaveBeenCalled());+ fireEvent.click(screen.getByTestId('bot-glance-button'));+ expect(await screen.findByTestId('bot-glance-check')).toBeTruthy();+ expect(screen.queryByTestId('bot-glance-daily-check')).toBeNull();+ });+it('lights the entry dot for a due todo until 近况 is opened, and marks the row itself', async () => {items = [todo('due', { sourceDeadline: { kind: 'date', date: today, timeZone: 'UTC' } }), todo('later')];render(<BotGlanceButton bot={bot} cloudHome={false} />);