MCPcopy Create free account
hub / github.com/UsefulSoftwareCo/executor / serveMutableSpec

Function serveMutableSpec

e2e/scenarios/openapi-update-spec.test.ts:69–99  ·  view source on GitHub ↗
(initial: string)

Source from the content-addressed store, hash-verified

67
68/** A real 127.0.0.1 server whose served spec can be swapped mid-scenario. */
69const serveMutableSpec = (initial: string) =>
70 Effect.acquireRelease(
71 Effect.callback<{
72 readonly url: string;
73 readonly setBody: (body: string) => void;
74 readonly close: () => void;
75 }>((resume) => {
76 let body = initial;
77 const server = createServer((_request, response) => {
78 response.writeHead(200, { "content-type": "application/json" });
79 response.end(body);
80 });
81 server.listen(0, "127.0.0.1", () => {
82 const address = server.address();
83 const port = typeof address === "object" && address ? address.port : 0;
84 resume(
85 Effect.succeed({
86 url: `http://127.0.0.1:${port}/spec.json`,
87 setBody: (next: string) => {
88 body = next;
89 },
90 close: () => {
91 server.close();
92 server.closeAllConnections();
93 },
94 }),
95 );
96 });
97 }),
98 (server) => Effect.sync(server.close),
99 );
100
101scenario(
102 "OpenAPI · updating the spec rebuilds tools without re-adding the integration",

Callers 1

Calls 6

resumeFunction · 0.85
endMethod · 0.80
listenMethod · 0.80
addressMethod · 0.80
closeMethod · 0.65
syncMethod · 0.65

Tested by

no test coverage detected