test(conformance): bump referee to 0.2.0-alpha.9; arm SEP-2575 diagnostic fixtures; fix post-dispatch -32021 HTTP status (#2399)

This commit is contained in:
Felix Weinberger 2026-07-02 13:17:08 +01:00 • committed by GitHub
commit 3c7ddafa05
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -199,6 +199,9 @@ describe('HTTP status mapping', () => {
});
it('keeps a handler-thrown unsupported-protocol-version error in-band on HTTP 200', async () => {
// A handler relaying a downstream peer's -32022 is not THIS server
// rejecting the caller's version; like the -32601 relay above it must
// not be re-mapped just because the ladder table maps that code.
const { server } = modernServer({
toolsCallHandler: async () => {
throw new ProtocolError(-32_022, 'Unsupported protocol version: 2099-01-01');
@ -210,6 +213,41 @@ describe('HTTP status mapping', () => {
expect(errorOf(await response.json())?.code).toBe(-32_022);
});
it('maps a post-dispatch -32021 (MissingRequiredClientCapability) to HTTP 400: the spec mandates that status per-error', async () => {
const { server } = modernServer({
toolsCallHandler: async () => {
throw new ProtocolError(-32_021, 'Missing required client capabilities: sampling', {
requiredCapabilities: { sampling: {} }
});
}
});
const transport = await connectedTransport(server);
const response = await transport.handleMessage(toolsCall());
expect(response.status).toBe(400);
// The spec shape: `requiredCapabilities` is a ClientCapabilities
// OBJECT, never an array.
expect(errorOf(await response.json())).toMatchObject({ code: -32_021, data: { requiredCapabilities: { sampling: {} } } });
});
it('leaves a post-dispatch -32021 on the already-open HTTP 200 stream when the handler streamed first', async () => {
// Once the lazy SSE upgrade has happened, the 200 is committed — and
// the error must still REACH the client as the stream's terminal
// frame rather than being swallowed by the status-mapping arm.
const { server } = modernServer({
toolsCallHandler: async ctx => {
await ctx.mcpReq.notify({ method: 'notifications/progress', params: { progressToken: 'capability-test', progress: 1 } });
throw new ProtocolError(-32_021, 'Missing required client capabilities: sampling');
}
});
const transport = await connectedTransport(server);
const response = await transport.handleMessage(toolsCall());
expect(response.status).toBe(200);
expect(response.headers.get('content-type')).toBe('text/event-stream');
const frames = (await response.text()).split('\n\n').filter(frame => frame.includes('data: '));
const terminal = frames.at(-1)!;
expect(JSON.parse(terminal.split('data: ')[1]!)).toMatchObject({ id: 1, error: { code: -32_021 } });
});
it('keeps handler-produced invalid-params errors in-band on HTTP 200 (never status-mapped)', async () => {
const { server } = modernServer({
toolsCallHandler: async () => {