Evenfire is an intelligence layer platform for running LLM agents that take real actions, on your infrastructure
TypeScript
fix(e2e): flush quiet watch headers through the proxy
Alfredo Lopez77ddf3f78a76
diff --git a/scripts/e2e/_lib/hcc-watch-api-proxy.mjs b/scripts/e2e/_lib/hcc-watch-api-proxy.mjsindex 398b47b47..46b2b2daf 100644--- a/scripts/e2e/_lib/hcc-watch-api-proxy.mjs+++ b/scripts/e2e/_lib/hcc-watch-api-proxy.mjs@@ -125,6 +125,9 @@ export function createProxy({},incoming => {response.writeHead(incoming.statusCode, incoming.headers)+ // A quiet watch must establish before its first event, or the+ // client's LIST-to-WATCH pairing remains blocked until a churn cut.+ response.flushHeaders()if (watch && request.method === 'GET') {const observer = bookmarks.open(kind, incoming.headers, incoming.statusCode)incoming.on('data', chunk => observer.write(chunk))diff --git a/scripts/tests/hcc-watch-api-proxy.test.mjs b/scripts/tests/hcc-watch-api-proxy.test.mjsindex e4e6f4562..89a311727 100644--- a/scripts/tests/hcc-watch-api-proxy.test.mjs+++ b/scripts/tests/hcc-watch-api-proxy.test.mjs@@ -33,6 +33,65 @@ let frontlet upstreamTlslet publicConfig+test(+ 'quiet upstream WATCH headers reach the client before its first body event',+ { timeout: 5000 },+ async () => {+ const controlDir = mkdtempSync(join(tmpdir(), 'hcc-quiet-watch-'))+ let upstreamResponse+ const upstream = https.createServer(upstreamTls, (_request, response) => {+ upstreamResponse = response+ response.writeHead(200, { 'content-type': 'application/json' })+ response.flushHeaders()+ })+ let proxy+ let client+ try {+ await new Promise(resolveListen => upstream.listen(0, '127.0.0.1', resolveListen))+ proxy = createProxy({+ ...front,+ upstreamCa: upstreamTls.cert,+ upstreamHost: '127.0.0.1',+ upstreamPort: upstream.address().port,+ allowedPaths: [],+ controlDir,+ periodMs: 60000,+ minAgeMs: 60000,+ })+ await new Promise(resolveListen => proxy.server.listen(0, '127.0.0.1', resolveListen))+ const headers = new Promise((resolveHeaders, rejectHeaders) => {+ client = https.get(+ {+ hostname: '127.0.0.1',+ port: proxy.server.address().port,+ path: mcpPath,+ servername: 'proxy-fixture.test-fixture.svc',+ ca: front.cert,+ rejectUnauthorized: true,+ },+ resolveHeaders+ )+ client.once('error', rejectHeaders)+ })+ // No upstream body is emitted until this assertion succeeds. A buffered+ // header block therefore cannot pass by riding along with an initial event.+ const response = await bounded(headers, 'quiet WATCH headers were not forwarded', 1000)+ assert.equal(response.statusCode, 200)+ assert.equal(response.headers['content-type'], 'application/json')+ const firstEvent = once(response, 'data')+ upstreamResponse.write('first-watch-event\n')+ const [bytes] = await bounded(firstEvent, 'first WATCH event was not forwarded')+ assert.equal(bytes.toString(), 'first-watch-event\n')+ } finally {+ client?.destroy()+ proxy?.close()+ upstream.closeAllConnections()+ await new Promise(resolveClose => upstream.close(resolveClose))+ rmSync(controlDir, { recursive: true, force: true })+ }+ }+)+test('upstream error records discard messages, headers, bodies and unrecognised codes', () => {const marker = 'synthetic-sensitive-material-must-not-appear'for (const code of ['ECONNRESET', 'ERR_TLS_CERT_ALTNAME_INVALID', marker, undefined]) {