From 2d21c0f95bf4307242c1dcbbb38e5a3201ae18a0 Mon Sep 17 00:00:00 2001 From: zouying Date: Wed, 5 Aug 2026 00:09:35 +0800 Subject: [PATCH] test(mcp): pin the auth-tool expiresAt to the effective wait timeout MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Both suites construct the tool with a 100ms timeout override, but the assertions only bounded expiresAt by the 15-minute default — and the lower bound compared against Date.now() taken after the run, which turns into a flake the moment the test body outlives the override. Bound by the window around the run instead: expiresAt must equal emit time + the effective timeout. --- .../agent-core-v2/test/agent/mcp/tools/auth.test.ts | 12 ++++++++---- packages/agent-core/test/mcp/auth-tool.test.ts | 12 ++++++++---- 2 files changed, 16 insertions(+), 8 deletions(-) diff --git a/packages/agent-core-v2/test/agent/mcp/tools/auth.test.ts b/packages/agent-core-v2/test/agent/mcp/tools/auth.test.ts index 2a49d89b0a..a4798d807f 100644 --- a/packages/agent-core-v2/test/agent/mcp/tools/auth.test.ts +++ b/packages/agent-core-v2/test/agent/mcp/tools/auth.test.ts @@ -51,6 +51,7 @@ describe('createMcpAuthTool', () => { complete: async () => undefined, cancel: async () => undefined, })); + const before = Date.now(); const { result, updates } = runTool({ oauthService, reconnect: async () => { @@ -69,11 +70,14 @@ describe('createMcpAuthTool', () => { serverName: 'notion', authorizationUrl: 'https://example.com/authorize?state=abc', }); - // The deadline is absolute (now + wait timeout), so hosts never mirror - // the engine-side constant. + // The deadline is absolute (emit time + the effective wait timeout — the + // 100ms override here, not the 15-minute default), so hosts render from + // data instead of mirroring the engine constant. Bounding by the time + // window around the run keeps the assertion exact without depending on + // how long the test body takes. const { expiresAt } = authUpdate?.customData as { expiresAt?: number }; - expect(expiresAt).toBeGreaterThan(Date.now()); - expect(expiresAt).toBeLessThanOrEqual(Date.now() + 15 * 60 * 1000); + expect(expiresAt).toBeGreaterThanOrEqual(before + 100); + expect(expiresAt).toBeLessThanOrEqual(Date.now() + 100); }); it('falls through to reconnect when the provider reports already-authorized', async () => { diff --git a/packages/agent-core/test/mcp/auth-tool.test.ts b/packages/agent-core/test/mcp/auth-tool.test.ts index 824377d4b0..30f7e0738d 100644 --- a/packages/agent-core/test/mcp/auth-tool.test.ts +++ b/packages/agent-core/test/mcp/auth-tool.test.ts @@ -55,6 +55,7 @@ describe('createMcpAuthTool', () => { complete: async () => undefined, cancel: async () => undefined, })); + const before = Date.now(); const { result, updates } = runTool({ oauthService, reconnect: async () => { @@ -73,11 +74,14 @@ describe('createMcpAuthTool', () => { serverName: 'notion', authorizationUrl: 'https://example.com/authorize?state=abc', }); - // The deadline is absolute (now + wait timeout), so hosts never mirror - // the engine-side constant. + // The deadline is absolute (emit time + the effective wait timeout — the + // 100ms override here, not the 15-minute default), so hosts render from + // data instead of mirroring the engine constant. Bounding by the time + // window around the run keeps the assertion exact without depending on + // how long the test body takes. const { expiresAt } = authUpdate?.customData as { expiresAt?: number }; - expect(expiresAt).toBeGreaterThan(Date.now()); - expect(expiresAt).toBeLessThanOrEqual(Date.now() + 15 * 60 * 1000); + expect(expiresAt).toBeGreaterThanOrEqual(before + 100); + expect(expiresAt).toBeLessThanOrEqual(Date.now() + 100); }); it('falls through to reconnect when the provider reports already-authorized', async () => {