Consider it done. The open-source AI agent that works out of the box · 想到,就能做到。开源、开箱即用的 AI Agent。
TypeScript agentai-agentai-assistantandroidclaude-codecodexelectroniosllmmacosreact-nativetypescriptwindows
test: cover awaited timer helpers and voice action anchoring
MagicLizic45f2afd840f
diff --git a/apps/desktop/src/renderer/components/new-chat/__tests__/chatInputAnnotationAbort.test.tsx b/apps/desktop/src/renderer/components/new-chat/__tests__/chatInputAnnotationAbort.test.tsxindex 23bc871d55..b332f47ac0 100644--- a/apps/desktop/src/renderer/components/new-chat/__tests__/chatInputAnnotationAbort.test.tsx+++ b/apps/desktop/src/renderer/components/new-chat/__tests__/chatInputAnnotationAbort.test.tsx@@ -203,6 +203,38 @@ it('locks editor and attachments for the whole voice run, but keeps permissions}});+// #374 / voiceInputButtonAnchor: the real toolbar must keep the voice control+// immediately beside the main action while listening, submitting, refining,+// and returning to idle. A source-text guard could miss a misplaced rendered+// control or a state branch that reintroduces the button jump.+it('keeps the voice button anchored beside the main action through its lifecycle', async () => {+ const view = renderComposer({ isAgentBusy: true });+ await waitFor(() => expect(h.editor).not.toBeNull());++ for (const state of ['listening', 'submitting', 'refining', 'idle'] as const) {+ h.voiceState = state;+ await act(async () => { view.rerender(<ChatInput {...view.props} isAgentBusy />); });+ const root = document.querySelector<HTMLElement>('[data-chat-input-root]')!;+ expect(root).not.toBeNull();+ const voice = root.querySelector<HTMLButtonElement>('button[aria-pressed]')!;+ expect(voice).not.toBeNull();+ const actions = [...root.querySelectorAll('button')]+ .filter((button) => {+ const label = button.getAttribute('aria-label') ?? '';+ return button === voice || label.startsWith('newChat.sendButton.');+ });+ const voiceIndex = actions.indexOf(voice);+ expect(voiceIndex, state).toBeGreaterThanOrEqual(0);+ expect(actions.slice(voiceIndex + 1), state).toHaveLength(1);+ expect(actions[voiceIndex + 1]?.getAttribute('aria-label'), state)+ .toMatch(/^newChat\.sendButton\.(queue|send|stop)$/);+ if (state !== 'idle') {+ expect(actions[voiceIndex - 1]?.getAttribute('aria-label'), state)+ .toBe('newChat.sendButton.stop');+ }+ }+});+// 9bc20cf894 / composerMorphScope: choosing a model used to drop focus to body.// Generic MorphPopover tests supply their own target and miss ChatInput's wiring.// Minimal unit input: one real selector choice, then focus returns to the live editor.diff --git a/scripts/__tests__/check-test-hygiene.test.mjs b/scripts/__tests__/check-test-hygiene.test.mjsindex 5bcbd53612..3dbdb4b083 100644--- a/scripts/__tests__/check-test-hygiene.test.mjs+++ b/scripts/__tests__/check-test-hygiene.test.mjs@@ -115,6 +115,9 @@ test("scanTestSource counts only unjustified hits for each rule", () => {["promise timer namespace alias keeps the duration", "import timers from 'timers/promises'; const promises = timers; await promises.setTimeout(1_000);", { realWaits: 1 }],["short promise timer ignores its numeric return value", "import { setTimeout } from 'node:timers/promises'; await setTimeout(20, 1_000);", { realWaits: 0 }],["promise timer wrapper uses its first argument", "import { setTimeout as delay } from 'node:timers/promises'; const tick = ms => delay(ms); await tick(1_000);", { realWaits: 1 }],+ ["block-bodied async promise timer wrapper uses its first argument", "import { setTimeout as delay } from 'node:timers/promises'; const tick = async ms => { await delay(ms); }; await tick(1_000);", { realWaits: 1 }],+ ["block-bodied async promise timer wrapper keeps short waits below the threshold", "import { setTimeout as delay } from 'node:timers/promises'; const tick = async ms => { await delay(ms); }; await tick(20);", { realWaits: 0 }],+ ["block-bodied async wrapper does not double count a constant inner wait", "import { setTimeout as delay } from 'node:timers/promises'; const tick = async () => { await delay(1_000); }; await tick(20);", { realWaits: 1 }],["promise timer namespace wrapper uses its first argument", "import * as timers from 'node:timers/promises'; const tick = ms => timers.setTimeout(ms); await tick(1_000);", { realWaits: 1 }],["short promise timer wrapper stays below the threshold", "import { setTimeout as delay } from 'node:timers/promises'; const tick = ms => delay(ms); await tick(20);", { realWaits: 0 }],["promise timer wrapper does not double count a constant inner wait", "import { setTimeout as delay } from 'node:timers/promises'; const tick = () => delay(1_000); await tick(20);", { realWaits: 1 }],diff --git a/scripts/check-test-hygiene.mjs b/scripts/check-test-hygiene.mjsindex 1918e04175..8b23702a1e 100644--- a/scripts/check-test-hygiene.mjs+++ b/scripts/check-test-hygiene.mjs@@ -453,22 +453,41 @@ function staticWaitCalls(code) {// one. Do not follow arbitrary control flow, callbacks or external helpers.function wrapperTimer(fn) {if (!fn?.body) return null;- const body = ts.isBlock(fn.body)- ? fn.body.statements.find(ts.isReturnStatement)?.expression : fn.body;- if (!body) return null;const timerCall = node => {if (!node || !ts.isCallExpression(node)) return null;if (callbackTimer(node.expression)) return { call: node, kind: 'callback' };if (isPromiseTimer(node.expression)) return { call: node, kind: 'promise' };return null;};+ const body = ts.isBlock(fn.body)+ ? fn.body.statements.find(ts.isReturnStatement)?.expression : fn.body;+ if (!body && !ts.isBlock(fn.body)) return null;const direct = timerCall(body);if (direct) return direct;- if (!ts.isNewExpression(body) || body.expression.getText(source) !== 'Promise') return null;- const executor = body.arguments?.[0];- if (!executor || !isFunction(executor)) return null;- const candidates = ts.isBlock(executor.body) ? executor.body.statements.map(statement => statement.expression) : [executor.body];- return candidates.map(timerCall).find(Boolean) ?? null;+ const promiseTimer = node => {+ if (!node || !ts.isNewExpression(node) || node.expression.getText(source) !== 'Promise') return null;+ const executor = node.arguments?.[0];+ if (!executor || !isFunction(executor)) return null;+ const candidates = ts.isBlock(executor.body) ? executor.body.statements.map(statement => statement.expression) : [executor.body];+ return candidates.map(timerCall).find(Boolean) ?? null;+ };+ const directPromise = promiseTimer(body);+ if (directPromise) return directPromise;+ if (!ts.isBlock(fn.body)) return null;+ // A common async wrapper awaits a timer in an expression statement rather+ // than returning it. Follow only awaits in this wrapper body, never nested+ // functions, and let the outer call map its parameter to the timer delay.+ let awaited = null;+ const visit = node => {+ if (awaited || isFunction(node)) return;+ if (ts.isAwaitExpression(node)) {+ awaited = timerCall(node.expression) ?? promiseTimer(node.expression);+ if (awaited) return;+ }+ ts.forEachChild(node, visit);+ };+ visit(fn.body);+ return awaited;}const waits = [];for (const call of calls) {