From fda00115864eddfc9153c0a61f012fea2ab1c701 Mon Sep 17 00:00:00 2001 From: King Star Date: Sat, 20 Jun 2026 02:59:11 +0800 Subject: [PATCH] Fix custom header schema freshness --- .../client/draft-result-fields.test.ts | 6 +- .../client/http-custom-headers.test.ts | 82 ++++++++++++++++++- src/scenarios/client/http-custom-headers.ts | 2 +- 3 files changed, 86 insertions(+), 4 deletions(-) diff --git a/src/scenarios/client/draft-result-fields.test.ts b/src/scenarios/client/draft-result-fields.test.ts index 1fdc6d44..df52adee 100644 --- a/src/scenarios/client/draft-result-fields.test.ts +++ b/src/scenarios/client/draft-result-fields.test.ts @@ -184,7 +184,11 @@ describe('http-custom-headers mock results (2026-07-28)', () => { method: 'tools/list', params: {} }); - expect(list.body.result).toMatchObject(CACHEABLE_FIELDS); + expect(list.body.result).toMatchObject({ + resultType: 'complete', + cacheScope: 'private' + }); + expect(list.body.result.ttlMs).toBeGreaterThan(0); const call = await post(serverUrl, { jsonrpc: '2.0', diff --git a/src/scenarios/client/http-custom-headers.test.ts b/src/scenarios/client/http-custom-headers.test.ts index 8a68f22a..0d50ad45 100644 --- a/src/scenarios/client/http-custom-headers.test.ts +++ b/src/scenarios/client/http-custom-headers.test.ts @@ -18,8 +18,8 @@ async function post( serverUrl: string, body: object, headers: Record = {} -): Promise { - await fetch(serverUrl, { +): Promise<{ status: number; body: any }> { + const response = await fetch(serverUrl, { method: 'POST', headers: { 'Content-Type': 'application/json', @@ -28,6 +28,7 @@ async function post( }, body: JSON.stringify(body) }); + return { status: response.status, body: await response.json() }; } function idsOf(checks: { id: string }[]): Set { @@ -150,6 +151,83 @@ describe('HttpCustomHeadersScenario (SEP-2243) check IDs', () => { await scenario.stop(); } }); + + it('serves a fresh tools/list TTL before requiring schema-derived custom headers', async () => { + const scenario = new HttpCustomHeadersScenario(); + const { serverUrl } = await scenario.start(testScenarioContext()); + try { + const toolsList = await post(serverUrl, { + jsonrpc: '2.0', + id: 1, + method: 'tools/list' + }); + const schemaIsFresh = toolsList.body.result.ttlMs > 0; + + const nonAscii = 'Hello, 世界'; + const nonAsciiB64 = Buffer.from(nonAscii, 'utf-8').toString('base64'); + await post( + serverUrl, + { + jsonrpc: '2.0', + id: 2, + method: 'tools/call', + params: { + name: 'test_custom_headers', + arguments: { + region: 'us-west1', + priority: 42, + non_ascii_val: nonAscii, + query: 'SELECT 1' + } + } + }, + schemaIsFresh + ? { + 'Mcp-Method': 'tools/call', + 'Mcp-Name': 'test_custom_headers', + 'Mcp-Param-Region': 'us-west1', + 'Mcp-Param-Priority': '42', + 'Mcp-Param-NonAscii': `=?base64?${nonAsciiB64}?=` + } + : {} + ); + await post( + serverUrl, + { + jsonrpc: '2.0', + id: 3, + method: 'tools/call', + params: { + name: 'test_custom_headers_null', + arguments: { + region: 'us-east1', + priority: 1, + verbose: null, + query: 'SELECT 1' + } + } + }, + schemaIsFresh + ? { + 'Mcp-Method': 'tools/call', + 'Mcp-Name': 'test_custom_headers_null', + 'Mcp-Param-Region': 'us-east1', + 'Mcp-Param-Priority': '1' + } + : {} + ); + + expect(toolsList.body.result.ttlMs).toBeGreaterThan(0); + const checks = scenario.getChecks(); + for (const id of CUSTOM_HEADERS_DECLARED_CHECK_IDS) { + const statuses = statusesFor(checks, id); + expect(statuses.length, id).toBeGreaterThan(0); + expect(statuses, id).not.toContain('FAILURE'); + } + } finally { + await scenario.stop(); + } + }); }); describe('HttpInvalidToolHeadersScenario (SEP-2243) check IDs', () => { diff --git a/src/scenarios/client/http-custom-headers.ts b/src/scenarios/client/http-custom-headers.ts index b445dc01..4f5c315c 100644 --- a/src/scenarios/client/http-custom-headers.ts +++ b/src/scenarios/client/http-custom-headers.ts @@ -277,7 +277,7 @@ export class HttpCustomHeadersScenario extends BaseHttpScenario { id: request.id, result: { resultType: 'complete', - ttlMs: 0, + ttlMs: 300000, cacheScope: 'private', tools: [ {