Consider it done. The open-source AI agent that works out of the box · 想到,就能做到。开源、开箱即用的 AI Agent。
TypeScript agentai-agentai-assistantandroidclaude-codecodexelectroniosllmmacosreact-nativetypescriptwindows
fix: close test hygiene scanner gaps
MagicLizi433248f7ff0c
diff --git a/apps/desktop/src/main/hook-control/__tests__/transport-manager.test.ts b/apps/desktop/src/main/hook-control/__tests__/transport-manager.test.tsindex 34a1766528..b5b47a5b5e 100644--- a/apps/desktop/src/main/hook-control/__tests__/transport-manager.test.ts+++ b/apps/desktop/src/main/hook-control/__tests__/transport-manager.test.ts@@ -1446,6 +1446,7 @@ describe('hook-control transport + manager(真实 ws server)', () => {);await expect.poll(() => manager.snapshot().binding?.state, { timeout: 3000 }).toBe('confirmed');// 熬过看门狗时限: 已 confirmed 不该被误判超时+ // real-wait: this regression must cross the real watchdog deadline.await new Promise((r) => setTimeout(r, 200));expect(store.get().enabled).toBe(true);expect(manager.snapshot().binding?.state).toBe('confirmed');diff --git a/apps/desktop/src/main/maker-host/__tests__/pi-package-store-security.test.ts b/apps/desktop/src/main/maker-host/__tests__/pi-package-store-security.test.tsindex e22ff4a0ca..19f74649ad 100644--- a/apps/desktop/src/main/maker-host/__tests__/pi-package-store-security.test.ts+++ b/apps/desktop/src/main/maker-host/__tests__/pi-package-store-security.test.ts@@ -457,6 +457,7 @@ describe('Pi package executable-code boundary', () => {expect(processRuntime.killTree).toHaveBeenCalledOnce();}, { timeout: 1_000 });processRuntime.pendingTreeSettled?.();+ // real-wait: allow the real package-runtime watcher deadline to elapse.await new Promise((resolve) => setTimeout(resolve, 900));expect(failure).toBeUndefined();expect(runtime.pendingClose).not.toBeNull();diff --git a/apps/desktop/src/main/maker-ipc/__tests__/sendToSessionLock.test.ts b/apps/desktop/src/main/maker-ipc/__tests__/sendToSessionLock.test.tsindex f9bf9ad0c0..8140dc2cb3 100644--- a/apps/desktop/src/main/maker-ipc/__tests__/sendToSessionLock.test.ts+++ b/apps/desktop/src/main/maker-ipc/__tests__/sendToSessionLock.test.ts@@ -133,6 +133,7 @@ describe('sendToSessionLock', () => {const order: string[] = [];const a = withSendToSessionLock('s6', async () => {order.push('a:start');+ // real-wait: keep the first lock holder active while the queued call observes serialization.await new Promise((r) => setTimeout(r, 100));order.push('a:end');});diff --git a/apps/desktop/src/renderer/__tests__/runningTokenRatePopover.test.tsx b/apps/desktop/src/renderer/__tests__/runningTokenRatePopover.test.tsxindex 258f619711..d72e01db6a 100644--- a/apps/desktop/src/renderer/__tests__/runningTokenRatePopover.test.tsx+++ b/apps/desktop/src/renderer/__tests__/runningTokenRatePopover.test.tsx@@ -172,6 +172,7 @@ it.each(['Escape', 'close'] as const)(expect(screen.getByRole('dialog')).toBeTruthy();fireEvent.pointerLeave(trigger);fireEvent.pointerMove(trigger, { pointerType: 'mouse' });+ // real-wait: the popover dismissal uses the production 550ms hover grace period.await act(() => new Promise((resolve) => setTimeout(resolve, 550)));expect(screen.queryByRole('tooltip')).toBeNull();if (dismissal === 'Escape') {diff --git a/apps/desktop/src/renderer/components/chat/__tests__/ImageLightboxAnnotate.test.tsx b/apps/desktop/src/renderer/components/chat/__tests__/ImageLightboxAnnotate.test.tsxindex f8fb329afa..c549b617cb 100644--- a/apps/desktop/src/renderer/components/chat/__tests__/ImageLightboxAnnotate.test.tsx+++ b/apps/desktop/src/renderer/components/chat/__tests__/ImageLightboxAnnotate.test.tsx@@ -271,6 +271,7 @@ describe('ImageLightbox annotate mode', () => {// 等确认框退场后再次放弃并确认:恢复到基线(空)并退出标注模式。await act(async () => {+ // real-wait: verify the production confirmation-exit animation has completed.await new Promise((resolve) => setTimeout(resolve, 250));});await act(async () => {diff --git a/apps/desktop/src/renderer/features/right-sidebar/plugins/subagents/__tests__/SubagentsBody.test.tsx b/apps/desktop/src/renderer/features/right-sidebar/plugins/subagents/__tests__/SubagentsBody.test.tsxindex a46de8768d..9ee2a938b2 100644--- a/apps/desktop/src/renderer/features/right-sidebar/plugins/subagents/__tests__/SubagentsBody.test.tsx+++ b/apps/desktop/src/renderer/features/right-sidebar/plugins/subagents/__tests__/SubagentsBody.test.tsx@@ -472,6 +472,7 @@ describe('SubagentsBody', () => {await waitFor(() => expect(listCalls).toBe(1));// Several poll periods elapse while the first read is still outstanding.+ // real-wait: exercise the production polling interval while the request remains pending.await new Promise((resolve) => setTimeout(resolve, 3_500));expect(listCalls).toBe(1);@@ -506,6 +507,7 @@ describe('SubagentsBody', () => {view.unmount();const afterUnmount = listCalls;+ // real-wait: prove no scheduled production poll fires after unmount.await new Promise((resolve) => setTimeout(resolve, 2_500));expect(listCalls).toBe(afterUnmount);}, 15_000);diff --git a/apps/mobile/src/remote-desktop/__tests__/screen.test.tsx b/apps/mobile/src/remote-desktop/__tests__/screen.test.tsxindex 6d330d6756..2b97a30bef 100644--- a/apps/mobile/src/remote-desktop/__tests__/screen.test.tsx+++ b/apps/mobile/src/remote-desktop/__tests__/screen.test.tsx@@ -4087,6 +4087,7 @@ describe("remote desktop controls", () => {fixture.invoke.mockImplementation((...args) =>args[2][0].op === "frame"? new Promise((resolve) =>+ // real-wait: preserve the remote-frame timeout boundary used by the transport.setTimeout(() => resolve({ jpeg: "a".repeat(4000) }), 100),): original(...args),diff --git a/packages/lizi-im/src/telegram/__tests__/telegramIM.test.ts b/packages/lizi-im/src/telegram/__tests__/telegramIM.test.tsindex 48c4ab96a5..813a2ed48a 100644--- a/packages/lizi-im/src/telegram/__tests__/telegramIM.test.ts+++ b/packages/lizi-im/src/telegram/__tests__/telegramIM.test.ts@@ -497,6 +497,7 @@ describe('TelegramIM', () => {});const before = api.calls.filter((c) => c.method === 'sendMessage' && c.params.chat_id === '222').length;api.pushUpdates([privateMessage('still there?', 222, 91)]);+ // real-wait: cross the production cooldown window before checking that no reply is sent.await new Promise((r) => setTimeout(r, 200));const after = api.calls.filter((c) => c.method === 'sendMessage' && c.params.chat_id === '222').length;expect(after).toBe(before); // 冷却期内不再回@@ -788,6 +789,7 @@ describe('TelegramIM', () => {// 轮询确已停: 之后不再产生新的 getUpdates 调用。const pollsAtOffline = api.calls.filter((c) => c.method === 'getUpdates').length;+ // real-wait: allow the production polling interval to elapse after disconnect.await new Promise((r) => setTimeout(r, 50));expect(api.calls.filter((c) => c.method === 'getUpdates').length).toBe(pollsAtOffline);});@@ -1206,6 +1208,7 @@ describe('TelegramIM', () => {});api.pushUpdates([member(45), member(46)]);// 等 settle 触发进入下载(getFile 悬住), 此时游标不得越过 45+ // real-wait: exercise the production settle delay before inspecting the persisted cursor.await new Promise((r) => setTimeout(r, 1400));expect(events).toHaveLength(0);const persistedDuring = Number((ctx.secrets.get('telegram-updates-offset') ?? ':0').split(':')[1]);@@ -1243,6 +1246,7 @@ describe('TelegramIM', () => {// 关键断言是"三个成员合进同一个事件", 不是下载成功与否。expect(events[0].attachments.length + events[0].unsupported.length).toBe(3);// 静默窗后不再有第二个事件+ // real-wait: cross the production media aggregation quiet window.await new Promise((r) => setTimeout(r, 1300));expect(events).toHaveLength(1);});@@ -2391,6 +2395,7 @@ describe('TelegramIM', () => {expect(await im.reactToMessage('-100200|50', '👀')).toBeNull();// ambient 路径不消费成员命令(owner 裸命令走显式召唤通道, 另有用例)api.pushUpdates([groupMessage({ text: '/new', fromId: 222, messageId: 51 })]);+ // real-wait: let the production command dispatch debounce settle before asserting no event.await new Promise((r) => setTimeout(r, 100));expect(events).toHaveLength(1);// NO_REPLY 哨兵: 惰性占位下从头到尾零消息(不发送、无需删除 — 真零痕迹)@@ -2422,6 +2427,7 @@ describe('TelegramIM', () => {// 发出首条真实消息 → typing 循环停(不再有新的 sendChatAction)await im.sendText(OWNER_ID, '答复');const countAfterSend = api.calls.filter((c) => c.method === 'sendChatAction').length;+ // real-wait: allow the production typing loop interval to elapse after the reply.await new Promise((r) => setTimeout(r, 120));expect(api.calls.filter((c) => c.method === 'sendChatAction').length).toBe(countAfterSend);// 群触发同样 typing@@ -2683,6 +2689,7 @@ describe('TelegramIM', () => {await vi.waitFor(() => expect(events).toHaveLength(1));// 只有新鲜那条进了 turn; 陈旧那条静默消费。expect(events[0]).toMatchObject({ text: '刚发的' });+ // real-wait: cross the production stale-message quiet period before checking for duplicates.await new Promise((r) => setTimeout(r, 200));expect(events).toHaveLength(1);});@@ -2691,6 +2698,7 @@ describe('TelegramIM', () => {await connect();const before = api.calls.filter((c) => c.method === 'sendMessage').length;api.pushUpdates([privateMessage('在吗', 999, 82, 8 * 3_600)]);+ // real-wait: cross the production stale-message rejection window before checking for output.await new Promise((r) => setTimeout(r, 300));// 隔夜再回一句拒绝语同样是诈尸 —— 一条出站都不该有。expect(api.calls.filter((c) => c.method === 'sendMessage').length).toBe(before);diff --git a/packages/maker-core/src/agents/claude-code/__tests__/abort-stops-background-tasks.test.ts b/packages/maker-core/src/agents/claude-code/__tests__/abort-stops-background-tasks.test.tsindex 2cf2c667c2..faaa5c8525 100644--- a/packages/maker-core/src/agents/claude-code/__tests__/abort-stops-background-tasks.test.ts+++ b/packages/maker-core/src/agents/claude-code/__tests__/abort-stops-background-tasks.test.ts@@ -3207,6 +3207,7 @@ describe('ClaudeCodeAgent abort stops background wake tasks', () => {// 模拟 SDK 在 retry backoff 中不立即响应 interrupt(如全池冷却 503)。let interruptResolved = false;fakeQuery.interrupt.mockImplementation(async () => {+ // real-wait: keep interrupt pending to assert the in-flight guard.await new Promise((r) => setTimeout(r, 200));interruptResolved = true;});diff --git a/packages/maker-core/src/agents/codex/index.test.ts b/packages/maker-core/src/agents/codex/index.test.tsindex 7171f1298f..c8480c31e5 100644--- a/packages/maker-core/src/agents/codex/index.test.ts+++ b/packages/maker-core/src/agents/codex/index.test.ts@@ -10228,6 +10228,7 @@ describe('CodexAgent MCP thread context hooks', () => {const result = await Promise.race([iterator.next(),new Promise<never>((_, reject) => {+ // real-wait: enforce the production idle-stream close timeout after an app-server crash.const timer = setTimeout(() => reject(new Error('idle session event stream did not close')), 200);timer.unref?.();}),diff --git a/packages/maker-core/src/agents/pi/__tests__/pi-long-tool-lifecycle.test.ts b/packages/maker-core/src/agents/pi/__tests__/pi-long-tool-lifecycle.test.tsindex 34030ef3fc..884319abda 100644--- a/packages/maker-core/src/agents/pi/__tests__/pi-long-tool-lifecycle.test.ts+++ b/packages/maker-core/src/agents/pi/__tests__/pi-long-tool-lifecycle.test.ts@@ -90,6 +90,7 @@ vi.mock('../transport.js', async (importOriginal) => {return endOutput();}if (cmd.type === 'fixture_exit_with_descendant') {+ // real-wait: the child fixture must keep its pipe open for the descendant-lifecycle test.const child = spawn(process.execPath, ['-e', 'setTimeout(() => {}, 30000)'], {// libuv's Windows job kills non-detached children on parent exit.// This fixture specifically needs a surviving pipe owner; productiondiff --git a/packages/maker-core/src/maker.test.ts b/packages/maker-core/src/maker.test.tsindex fce31a195f..e9ca60ff33 100644--- a/packages/maker-core/src/maker.test.ts+++ b/packages/maker-core/src/maker.test.ts@@ -2554,6 +2554,7 @@ describe('Maker Pi runtime skill status', () => {vi.spyOn(fsPromises, 'realpath').mockImplementation(async (...args) => {if (!delayed) {delayed = true;+ // real-wait: keep the realpath operation pending to exercise the cancellation race.await new Promise((resolve) => setTimeout(resolve, 300));}return realRealpath(...args);diff --git a/packages/maker-remote-ssh/src/__tests__/remoteHostConnectRace.test.ts b/packages/maker-remote-ssh/src/__tests__/remoteHostConnectRace.test.tsindex 8de2ab8ac6..039a94ba70 100644--- a/packages/maker-remote-ssh/src/__tests__/remoteHostConnectRace.test.ts+++ b/packages/maker-remote-ssh/src/__tests__/remoteHostConnectRace.test.ts@@ -305,6 +305,7 @@ describe('RemoteHost arm/disconnect race', () => {// Before the fix these joined waitForTerminal() with no attempt in// flight and hung until a manual disconnect.const joined = Promise.all([host.connect(), host.connect()]);+ // real-wait: enforce the real connection timeout in this rekey race.const timedOut = new Promise((_, reject) => setTimeout(() => reject(new Error('connect hung after rekey')), 500));await expect(Promise.race([joined, timedOut])).resolves.toBeDefined();expect(host.getStatus()).toBe('ready');diff --git a/scripts/__tests__/check-test-hygiene.test.mjs b/scripts/__tests__/check-test-hygiene.test.mjsindex 3b9b8703fd..472a8a93eb 100644--- a/scripts/__tests__/check-test-hygiene.test.mjs+++ b/scripts/__tests__/check-test-hygiene.test.mjs@@ -33,6 +33,11 @@ test("scanTestSource counts only unjustified hits for each rule", () => {"vi.useFakeTimers();\nsetTimeout(tick, 5_000);",{ realWaits: 0 },],+ [+ "real wait after fake timers are restored",+ "vi.useFakeTimers();\nvi.useRealTimers();\nsetTimeout(tick, 5_000);",+ { realWaits: 1 },+ ],["source text read","const src = readFileSync(resolve(__dirname, '..', 'Sidebar.tsx'), 'utf8');",diff --git a/scripts/check-test-hygiene.mjs b/scripts/check-test-hygiene.mjsindex d39e912f31..b1d9ea3129 100644--- a/scripts/check-test-hygiene.mjs+++ b/scripts/check-test-hygiene.mjs@@ -31,6 +31,7 @@ export const TEST_FILE = /\.(?:test|spec)\.(?:ts|tsx|mts|mjs)$/;const NON_UNIT_TEST = /\.(?:integration|e2e|git-integration)\.(?:test|spec)\.|\.bench\./;export const RULES = ['resetModules', 'realWaits', 'sourceReads'];const REAL_WAIT_MIN_MS = 100;+const REAL_WAIT_PATTERN = /\bsetTimeout\s*\([^;\n]*?,\s*(\d[\d_]*)\s*\)|\b(?:sleep|delay|wait|waitMs|pause)\s*\(\s*(\d[\d_]*)\s*\)/g;/** Replace comments with spaces (keeping newlines) so matches ignore commented-out code. */export function stripComments(source) {@@ -92,6 +93,24 @@ function countMatches(code, lines, pattern, marker, accept = () => true) {return count;}+function countRealWaits(code, lines) {+ const timerEvents = [...code.matchAll(/\bvi\.(useFakeTimers|useRealTimers)\s*\(/g)];+ let timerIndex = 0;+ let fakeTimers = false;+ let count = 0;+ for (const match of code.matchAll(REAL_WAIT_PATTERN)) {+ while (timerIndex < timerEvents.length && timerEvents[timerIndex].index < match.index) {+ fakeTimers = timerEvents[timerIndex][1] === 'useFakeTimers';+ timerIndex += 1;+ }+ if (fakeTimers) continue;+ if (Number((match[1] ?? match[2]).replaceAll('_', '')) < REAL_WAIT_MIN_MS) continue;+ const line = lineOf(code, match.index);+ if (!hasJustification(lines, line, 'real-wait')) count += 1;+ }+ return count;+}+const IMPORT_CONTEXT = /(?:\bfrom|\bimport|\brequire|\.mock|\.doMock|\.unmock|\.importActual|\.importMock|\.glob)\s*\(?\s*$/;const SOURCE_EXT = /\.(?:tsx?|mts|cts|css|mjs|cjs|jsx?)$/;// Only anchors that point into the checkout count; generic names such as `root`@@ -158,16 +177,7 @@ export function scanTestSource(source, { isGuard = false } = {}) {const code = stripComments(source);const lines = source.split(/\r?\n/);const resetModules = countMatches(code, lines, /\bvi\.resetModules\s*\(/g, 'reset-modules');- const usesFakeTimers = /\bvi\.useFakeTimers\s*\(/.test(code);- const realWaits = usesFakeTimers- ? 0- : countMatches(- code,- lines,- /\bsetTimeout\s*\([^;\n]*?,\s*(\d[\d_]*)\s*\)|\b(?:sleep|delay|wait|waitMs|pause)\s*\(\s*(\d[\d_]*)\s*\)/g,- 'real-wait',- (match) => Number((match[1] ?? match[2]).replaceAll('_', '')) >= REAL_WAIT_MIN_MS,- );+ const realWaits = countRealWaits(code, lines);let sourceReads = 0;if (!isGuard && /\breadFileSync\b|\breadFile\s*\(|\?raw['"`]/.test(code)) {for (const match of code.matchAll(/(['"`])([^'"`\n$]+)\1/g)) {diff --git a/scripts/test-hygiene-baseline.json b/scripts/test-hygiene-baseline.jsonindex 38bc859422..ab05bcfa05 100644--- a/scripts/test-hygiene-baseline.json+++ b/scripts/test-hygiene-baseline.json@@ -517,9 +517,6 @@"apps/desktop/src/main/provider-group/__tests__/failoverSessionClose.test.ts": {"sourceReads": 1},- "apps/desktop/src/main/provider-group/__tests__/stores.test.ts": {- "resetModules": 1- },"apps/desktop/src/main/remote-agent/executor/__tests__/executor.test.ts": {"realWaits": 5},@@ -906,9 +903,6 @@"apps/desktop/src/renderer/__tests__/newMakerWorktreeSend.test.ts": {"sourceReads": 2},- "apps/desktop/src/renderer/__tests__/orcaModelWindowSelection.test.ts": {- "sourceReads": 1- },"apps/desktop/src/renderer/__tests__/pendingHandoffRecovery.test.ts": {"resetModules": 2},@@ -1026,9 +1020,6 @@"apps/desktop/src/renderer/__tests__/voiceInputEnterToSend.test.ts": {"sourceReads": 2},- "apps/desktop/src/renderer/__tests__/workdirBrowseRemoteSafety.test.ts": {- "sourceReads": 4- },"apps/desktop/src/renderer/__tests__/worktreeRemovalWarning.test.ts": {"sourceReads": 2},@@ -1080,9 +1071,6 @@"apps/desktop/src/renderer/features/bots/__tests__/botNavigation.test.ts": {"sourceReads": 6},- "apps/desktop/src/renderer/features/bots/__tests__/botPermissionSwitch.test.ts": {- "sourceReads": 1- },"apps/desktop/src/renderer/features/bots/__tests__/botStore.lifecycle.test.ts": {"resetModules": 2},diff --git a/scripts/test-workspaces.config.mjs b/scripts/test-workspaces.config.mjsindex cc15d7dda9..91d711f503 100644--- a/scripts/test-workspaces.config.mjs+++ b/scripts/test-workspaces.config.mjs@@ -114,6 +114,7 @@ const desktopGuardInclude = ['src/renderer/features/cc-agent/sidebar/__tests__/sessionCardReviewRegressions.test.ts','src/renderer/__tests__/orcaModelWindowSelection.test.ts','src/renderer/__tests__/workdirBrowseRemoteSafety.test.ts',+ 'src/renderer/__tests__/remoteAgentRelocationWiring.test.ts','src/renderer/features/bots/__tests__/botPermissionSwitch.test.ts','src/main/cindy-brain/__tests__/forgeOidcInstallEntry.test.ts','src/main/cindy-brain/__tests__/ghostDevRuntimeContract.test.ts',