/** * Deterministic loopback HTTP fixture for the web-fetch snapshot scenario: a * small HTML page (headings, named entities, a GFM table, nested formatting) * on a fixed port, so recording and keyless replay drive the REAL * `dsh-web-fetch-local` transport and `dsh-tool-web` markdown rendering * without external network. The port is fixed because the fetched URL is part * of the recorded model transcript. */ import { createServer } from 'node:http' /** Fixed loopback port the scenario prompt points `web_fetch` at. */ const PORT = 43117 const PAGE = ` Menu

Café menu

Prices include service & tax — updated daily.

DrinkPrice
Espresso€2
Flat white€3

See today’s specials.

` /** Cordis plugin name. */ export const name = 'web-fetch-fixture-server' /** * Start the fixture server on 127.0.0.1 and register its shutdown. * @param ctx - Cordis context; the effect disposes the server with the fiber. */ export async function apply(ctx) { const server = createServer((req, res) => { if (req.url === '/menu.html') { res.writeHead(200, { 'content-type': 'text/html; charset=utf-8' }) res.end(PAGE) return } res.writeHead(404, { 'content-type': 'text/plain; charset=utf-8' }) res.end('not found') }) await new Promise((resolve, reject) => { server.once('error', reject) server.listen(PORT, '127.0.0.1', () => resolve(undefined)) }) // The fixture must never hold the process open past protocol shutdown. server.unref() ctx.effect(() => async () => { await new Promise((resolve, reject) => { server.close(error => error ? reject(error) : resolve(undefined)) // Stop accepting first so a connection cannot arrive after the forced close. server.closeAllConnections() }) }, 'web-fetch-fixture-server') }