Consider it done. The open-source AI agent that works out of the box · 想到,就能做到。开源、开箱即用的 AI Agent。
TypeScript agentai-agentai-assistantandroidclaude-codecodexelectroniosllmmacosreact-nativetypescriptwindows
fix(wecom): 修正自动化通知账号边界
david549d5035ac40
diff --git a/apps/desktop/src/main/__tests__/wecomGroupNotification.test.ts b/apps/desktop/src/main/__tests__/wecomGroupNotification.test.tsindex 97ea48fb59..45ca608a39 100644--- a/apps/desktop/src/main/__tests__/wecomGroupNotification.test.ts+++ b/apps/desktop/src/main/__tests__/wecomGroupNotification.test.ts@@ -1,4 +1,4 @@-import { beforeEach, describe, expect, it, vi } from 'vitest';+import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';vi.mock('electron', () => ({ipcMain: { handle: vi.fn() },@@ -21,6 +21,7 @@ vi.mock('../security/trustedAppRenderer', () => ({}));import { WecomGroupNotificationService, __testing } from '../wecomGroupNotification';+import { activateImAccountBoundary, deactivateImAccountBoundary } from '../im/accountBoundary';function response(body: unknown, status = 200): Response {return new Response(JSON.stringify(body), {@@ -51,8 +52,11 @@ function createSecrets(initialUrl: string | null = null, initialEnabled: stringdescribe('WeCom group notification security boundary', () => {beforeEach(() => {vi.clearAllMocks();+ activateImAccountBoundary();});+ afterEach(() => activateImAccountBoundary());+it('accepts only the official HTTPS webhook endpoint with one key parameter', () => {expect(() =>__testing.parseWebhookUrl('https://qyapi.weixin.qq.com/cgi-bin/webhook/send?key=0123456789'),@@ -216,6 +220,34 @@ describe('WeCom group notification security boundary', () => {expect(bodies[1]).toContain('second');});+ it('does not send a queued publish through a replacement account webhook', async () => {+ let releaseFirst: (() => void) | undefined;+ const firstUrl = 'https://qyapi.weixin.qq.com/cgi-bin/webhook/send?key=account-one';+ const secondUrl = 'https://qyapi.weixin.qq.com/cgi-bin/webhook/send?key=account-two';+ const secrets = createSecrets(firstUrl);+ const fetchImpl = vi.fn(async () => {+ await new Promise<void>((resolve) => {+ releaseFirst = resolve;+ });+ return response({ errcode: 0 });+ });+ const service = new WecomGroupNotificationService(fetchImpl, secrets);++ const first = service.publishMarkdown('first');+ const second = service.publishMarkdown('second');+ await vi.waitFor(() => expect(fetchImpl).toHaveBeenCalledOnce());++ deactivateImAccountBoundary();+ secrets.write(WEBHOOK_SECRET_NAME, secondUrl);+ activateImAccountBoundary();+ releaseFirst?.();++ await expect(first).resolves.toBeUndefined();+ await expect(second).rejects.toThrow('IM account changed');+ expect(fetchImpl).toHaveBeenCalledOnce();+ expect(fetchImpl).toHaveBeenCalledWith(firstUrl, expect.any(Object));+ });+it('clears both the webhook and its master switch', () => {const url = 'https://qyapi.weixin.qq.com/cgi-bin/webhook/send?key=abcdefgh';const secrets = createSecrets(url, 'true');diff --git a/apps/desktop/src/main/scheduler-host/__tests__/project-automation-loader.test.ts b/apps/desktop/src/main/scheduler-host/__tests__/project-automation-loader.test.tsnew file mode 100644index 0000000000..5c8292e6d2--- /dev/null+++ b/apps/desktop/src/main/scheduler-host/__tests__/project-automation-loader.test.ts@@ -0,0 +1,77 @@+import { describe, expect, it } from 'vitest';++import type { Schedule } from '@cindy/maker-scheduler';++import {+ __testing,+ schedulesDiffer,+ type ProjectScheduleConfig,+} from '../project-automation-loader';++const workingDir = 'C:\\project';++function projectConfig(overrides: Partial<ProjectScheduleConfig> = {}): ProjectScheduleConfig {+ return {+ id: 'daily',+ name: 'Daily',+ prompt: 'Run checks',+ cronExpr: '0 9 * * *',+ notify: { desktop: true, feishu: false },+ ...overrides,+ };+}++function projectSchedule(notify: Schedule['notify']): Schedule {+ return {+ id: 'schedule-1',+ name: 'Daily',+ prompt: 'Run checks',+ source: 'project',+ projectConfigId: 'daily',+ kind: 'cron',+ cronExpr: '0 9 * * *',+ timezone: 'Asia/Shanghai',+ recurring: true,+ manual: false,+ agentKind: 'claude-code',+ workspaceKind: 'project',+ workingDir,+ useWorktree: false,+ persistentSession: false,+ silentWhenIdle: false,+ notify,+ status: 'active',+ createdAt: 1,+ updatedAt: 1,+ };+}++describe('project automation WeCom group notification reconciliation', () => {+ it('emits an explicit false update when the project disables the channel', () => {+ const input = __testing.scheduleConfigToUpdateInput(+ projectConfig({ notify: { desktop: true, feishu: false, wecomGroup: false } }),+ workingDir,+ );++ expect(input.notify).toEqual({+ desktop: true,+ feishu: false,+ wecomGroup: false,+ });+ });++ it('updates a previously enabled channel and stays stable after it is disabled', () => {+ const config = projectConfig();++ expect(+ schedulesDiffer(+ projectSchedule({ desktop: true, feishu: false, wecomGroup: true }),+ config,+ workingDir,+ ),+ ).toBe(true);+ expect(+ schedulesDiffer(projectSchedule({ desktop: true, feishu: false }), config, workingDir),+ ).toBe(false);+ });+});diff --git a/apps/desktop/src/main/scheduler-host/project-automation-loader.ts b/apps/desktop/src/main/scheduler-host/project-automation-loader.tsindex 10c5c083f5..297bb7e7fe 100644--- a/apps/desktop/src/main/scheduler-host/project-automation-loader.ts+++ b/apps/desktop/src/main/scheduler-host/project-automation-loader.ts@@ -506,7 +506,7 @@ export function schedulesDiffer((schedule.preRunHook?.timeoutMs ?? undefined) !== (expected.preRunHook?.timeoutMs ?? undefined) ||schedule.notify.desktop !== expected.notify?.desktop ||schedule.notify.feishu !== expected.notify?.feishu ||- schedule.notify.wecomGroup !== expected.notify?.wecomGroup+ !!schedule.notify.wecomGroup !== !!expected.notify?.wecomGroup);}@@ -516,10 +516,14 @@ function normalizeNotify(return {desktop: notify?.desktop ?? true,feishu: notify?.feishu ?? false,- ...(notify?.wecomGroup === true ? { wecomGroup: true } : {}),+ wecomGroup: notify?.wecomGroup ?? false,};}+export const __testing = {+ scheduleConfigToUpdateInput,+};+function sameWorkingDir(a: string | undefined, b: string): boolean {if (!a) return false;const left = path.resolve(a);diff --git a/apps/desktop/src/main/wecomGroupNotification.ts b/apps/desktop/src/main/wecomGroupNotification.tsindex 418ec8d729..5d65ce3098 100644--- a/apps/desktop/src/main/wecomGroupNotification.ts+++ b/apps/desktop/src/main/wecomGroupNotification.ts@@ -199,10 +199,15 @@ export class WecomGroupNotificationService implements WecomGroupNotificationPublif (!this.getState().enabled) {throw new Error('WECOM_GROUP_NOTIFICATIONS_DISABLED');}+ const accountGeneration = captureImAccountGeneration();+ if (accountGeneration === null) throw new ImAccountScopeClosedError();+ const url = this.requireStoredUrl();return this.enqueue(async () => {- const url = this.requireStoredUrl();const chunks = splitUtf8(markdown.trim() || 'Cindy 通知');for (const chunk of chunks) {+ if (!isImAccountGenerationCurrent(accountGeneration)) {+ throw new ImAccountScopeClosedError();+ }await this.send(url, chunk);}});