Skip to content

The agent that grows with you

test(desktop): trim MCP polling tests to two invariants per fix

teknium1a02a3b980888
diff --git a/apps/desktop/src/lib/completion-poll.test.ts b/apps/desktop/src/lib/completion-poll.test.ts
index 62d5877e532..61b4d29b966 100644
--- a/apps/desktop/src/lib/completion-poll.test.ts
+++ b/apps/desktop/src/lib/completion-poll.test.ts
@@ -1,6 +1,6 @@
import { afterEach, describe, expect, it, vi } from 'vitest'
-import { createSerialTask, startCompletionPoll } from './completion-poll'
+import { startCompletionPoll } from './completion-poll'
function deferred<T>() {
let resolve!: (value: T) => void
@@ -37,43 +37,18 @@ describe('startCompletionPoll', () => {
stop()
})
- it('cancels stale publication and serializes a replacement lifecycle behind the active request', async () => {
+ it('stop suppresses a late publish and leaves no timer behind', async () => {
vi.useFakeTimers()
const first = deferred<string>()
- const second = deferred<string>()
- const producer = vi.fn((profile: string) => (profile === 'A' ? first.promise : second.promise))
- const serial = createSerialTask(producer)
- const publishA = vi.fn()
- const publishB = vi.fn()
-
- const stopA = startCompletionPoll({
- delayMs: 2_000,
- poll: signal => serial('A', signal),
- publish: publishA
- })
-
- await Promise.resolve()
- stopA()
-
- const stopB = startCompletionPoll({
- delayMs: 2_000,
- poll: signal => serial('B', signal),
- publish: publishB
- })
+ const publish = vi.fn()
+ const stop = startCompletionPoll({ delayMs: 2_000, poll: () => first.promise, publish })
await Promise.resolve()
- expect(producer).toHaveBeenCalledTimes(1)
+ stop()
first.resolve('stale')
await vi.advanceTimersByTimeAsync(0)
- expect(producer).toHaveBeenCalledTimes(2)
- expect(publishA).not.toHaveBeenCalled()
-
- second.resolve('fresh')
- await vi.advanceTimersByTimeAsync(0)
- expect(publishB).toHaveBeenCalledWith('fresh')
-
- stopB()
+ expect(publish).not.toHaveBeenCalled()
expect(vi.getTimerCount()).toBe(0)
})
})
diff --git a/apps/desktop/src/store/mcp-health.test.ts b/apps/desktop/src/store/mcp-health.test.ts
index 241cde396f5..86f8e94e89c 100644
--- a/apps/desktop/src/store/mcp-health.test.ts
+++ b/apps/desktop/src/store/mcp-health.test.ts
@@ -72,6 +72,8 @@ afterEach(() => {
})
describe('shouldNotifyOnTransition', () => {
+ // The full previous × next decision table: notify only on a TRANSITION into
+ // a bad state. Rechecks of an already-bad server stay quiet; ok never nudges.
it.each<[previous: Status | null, next: Status, notify: boolean]>([
[null, 'ok', false],
[null, 'needs-auth', true],
@@ -118,19 +120,28 @@ it('coalesces reconnects during a sweep into one fresh follow-up sweep', async (
expect(mocks.getHermesConfigRecord).toHaveBeenCalledTimes(2)
})
-it.each(['stop', 'disconnect'])('drops the queued sweep on %s', async action => {
- let release!: (config: Record<string, unknown>) => void
- mocks.getHermesConfigRecord.mockReturnValueOnce(new Promise(resolve => { release = resolve })).mockResolvedValue({ mcp_servers: {} })
+it('runs one follow-up when the active sweep fails through the handled config-error path', async () => {
+ let rejectFirst!: (err: Error) => void
+
+ const first = new Promise<Record<string, unknown>>((_resolve, reject) => {
+ rejectFirst = reject
+ })
+
+ mocks.getHermesConfigRecord.mockReturnValueOnce(first).mockResolvedValue({ mcp_servers: {} })
+
startMcpHealthChecker()
mocks.gatewayState.set('open')
- mocks.gatewayState.set('closed')
- mocks.gatewayState.set('open')
- if (action === 'stop') {stopMcpHealthChecker()}
- else {mocks.gatewayState.set('closed')}
+ for (let index = 0; index < 12; index += 1) {
+ mocks.gatewayState.set('closed')
+ mocks.gatewayState.set('open')
+ }
+
+ await flush()
+ expect(mocks.getHermesConfigRecord).toHaveBeenCalledTimes(1)
- release({ mcp_servers: {} })
+ rejectFirst(new Error('backend restarting'))
await flush()
await flush()
- expect(mocks.getHermesConfigRecord).toHaveBeenCalledTimes(1)
+ expect(mocks.getHermesConfigRecord).toHaveBeenCalledTimes(2)
})