|
5 | 5 | // across requests, and a 2026-07-28 listen stream across clients. |
6 | 6 |
|
7 | 7 | import { afterEach, beforeEach, describe, expect, it, vi } from "vitest"; |
| 8 | +import { connect as connectTcp } from "node:net"; |
8 | 9 | import { |
9 | 10 | Client, |
10 | 11 | StreamableHTTPClientTransport, |
@@ -83,27 +84,47 @@ describe("Streamable HTTP", () => { |
83 | 84 | }, |
84 | 85 | ); |
85 | 86 |
|
86 | | - it("sends a 2026-07-28 listener the updates another client's write makes", async () => { |
87 | | - const url = (await start()).url; |
88 | | - const listener = await connect(url, ERAS[0][1]); |
89 | | - const writer = await connect(url, ERAS[0][1]); |
90 | | - try { |
91 | | - const updated = new Promise<string>((resolve) => { |
92 | | - listener.setNotificationHandler( |
93 | | - "notifications/resources/updated", |
94 | | - (notification) => resolve(notification.params.uri), |
95 | | - ); |
96 | | - }); |
97 | | - const subscription = await listener.listen({ |
98 | | - resourceSubscriptions: [RESOURCE_URI], |
| 87 | + it.each(ERAS)( |
| 88 | + "sends a 2026-07-28 listener the updates a %s writer makes", |
| 89 | + async (_, negotiation) => { |
| 90 | + const url = (await start()).url; |
| 91 | + const listener = await connect(url, ERAS[0][1]); |
| 92 | + const writer = await connect(url, negotiation); |
| 93 | + try { |
| 94 | + const updated = new Promise<string>((resolve) => { |
| 95 | + listener.setNotificationHandler( |
| 96 | + "notifications/resources/updated", |
| 97 | + (notification) => resolve(notification.params.uri), |
| 98 | + ); |
| 99 | + }); |
| 100 | + const subscription = await listener.listen({ |
| 101 | + resourceSubscriptions: [RESOURCE_URI], |
| 102 | + }); |
| 103 | + await call(writer, "create_entities", { entities: [alice] }); |
| 104 | + expect(await updated).toBe(RESOURCE_URI); |
| 105 | + await subscription.close(); |
| 106 | + } finally { |
| 107 | + await listener.close(); |
| 108 | + await writer.close(); |
| 109 | + } |
| 110 | + }, |
| 111 | + ); |
| 112 | + |
| 113 | + it("answers a malformed request target 404 and keeps serving", async () => { |
| 114 | + const url = new URL((await start()).url); |
| 115 | + const reply = await new Promise<string>((resolve, reject) => { |
| 116 | + const socket = connectTcp(Number(url.port), url.hostname, () => |
| 117 | + socket.write("GET //[ HTTP/1.1\r\nHost: localhost\r\n\r\n"), |
| 118 | + ); |
| 119 | + socket.setEncoding("utf8"); |
| 120 | + socket.once("data", (chunk: string) => { |
| 121 | + socket.destroy(); |
| 122 | + resolve(chunk); |
99 | 123 | }); |
100 | | - await call(writer, "create_entities", { entities: [alice] }); |
101 | | - expect(await updated).toBe(RESOURCE_URI); |
102 | | - await subscription.close(); |
103 | | - } finally { |
104 | | - await listener.close(); |
105 | | - await writer.close(); |
106 | | - } |
| 124 | + socket.once("error", reject); |
| 125 | + }); |
| 126 | + expect(reply).toMatch(/^HTTP\/1\.1 404/); |
| 127 | + expect((await fetch(new URL("/other", url))).status).toBe(404); |
107 | 128 | }); |
108 | 129 |
|
109 | 130 | it("answers 404 off the MCP path and 403 to a foreign Origin", async () => { |
|
0 commit comments