Evenfire is an intelligence layer platform for running LLM agents that take real actions, on your infrastructure
TypeScript
test(llm-proxies): pin the SSE rate_limited frame and a finalize connect failure (#720)
Alfredo Lopeze9831915983f
diff --git a/codex-llm-proxy/test/controlApiClient.test.ts b/codex-llm-proxy/test/controlApiClient.test.tsindex 461d64173..374fe15dd 100644--- a/codex-llm-proxy/test/controlApiClient.test.ts+++ b/codex-llm-proxy/test/controlApiClient.test.ts@@ -313,6 +313,27 @@ describe('ControlApiClient control-plane reachability', () => {})})+ it('G1-4f maps a refused finalize connection the same way', async () => {+ // finalizeQuietly logs this error; its causeCode is what reaches+ // codex_proxy_finalize_failed.+ const url = await closedPortUrl()+ await expect(+ clientAt(url).finalize({+ attemptReceipt: 'a'.repeat(64),+ receipt: {+ schemaVersion: 'codex-attempt-receipt.v1',+ providerAttemptId: 'att-1',+ requestHash: 'b'.repeat(64),+ outcome: 'success',+ },+ })+ ).rejects.toMatchObject({+ name: 'ControlApiClientError',+ code: 'control_plane_unavailable',+ causeCode: 'ECONNREFUSED',+ })+ })+it.each(['ENOTFOUND', 'EAI_AGAIN', 'EHOSTUNREACH', 'ENETUNREACH', 'UND_ERR_CONNECT_TIMEOUT'])('G1-4b maps a %s fetch failure to control_plane_unavailable',async code => {diff --git a/codex-llm-proxy/test/server.security.test.ts b/codex-llm-proxy/test/server.security.test.tsindex 169c6f853..8c98b55fe 100644--- a/codex-llm-proxy/test/server.security.test.ts+++ b/codex-llm-proxy/test/server.security.test.ts@@ -1276,6 +1276,28 @@ describe('codex-llm-proxy attempt telemetry', () => {})})+ it('(g1-1d) delivers an upstream 429 after a keepalive as an SSE rate_limited frame', async () => {+ const { res, lines } = await run('att-rate-sse', 0, 0, undefined, undefined, {+ fetchFn: (async () => {+ await new Promise(resolve => setTimeout(resolve, 60))+ return new Response('slow down', { status: 429, headers: { 'retry-after': '7' } })+ }) as typeof fetch,+ configOverrides: { heartbeatIntervalMs: 20 },+ })+ expect(res.status).toBe(200)+ // Witness: a keepalive went out first, so the 429 can only travel as a frame.+ expect(keepaliveCount(res.text)).toBeGreaterThanOrEqual(1)+ // The frame carries the code alone: no Retry-After, no upstream status.+ expect(res.text.endsWith('data: {"type":"error","code":"rate_limited"}\n\n')).toBe(true)+ expect(res.headers['retry-after']).toBeUndefined()+ expect(lines).toHaveLength(1)+ expect(lines[0]).toMatchObject({+ code: 'rate_limited',+ details: { retryAfterSeconds: 7 },+ deliveredAs: 'sse_error',+ })+ })+// G1-4 (#720): a redeem whose connection nothing accepted (control-api or// its gateway restarting) is reported as the control plane being down.it('(g1-4a) answers 503 control_plane_unavailable when redeem cannot connect', async () => {diff --git a/grok-llm-proxy/test/controlApiClient.test.ts b/grok-llm-proxy/test/controlApiClient.test.tsindex 8b33b4298..ec9440cf1 100644--- a/grok-llm-proxy/test/controlApiClient.test.ts+++ b/grok-llm-proxy/test/controlApiClient.test.ts@@ -320,6 +320,27 @@ describe('ControlApiClient control-plane reachability', () => {})})+ it('G1-4f maps a refused finalize connection the same way', async () => {+ // finalizeQuietly logs this error; its causeCode is what reaches+ // grok_proxy_finalize_failed.+ const url = await closedPortUrl()+ await expect(+ clientAt(url).finalize({+ attemptReceipt: 'a'.repeat(64),+ receipt: {+ schemaVersion: 'grok-attempt-receipt.v1',+ providerAttemptId: 'att-1',+ requestHash: 'b'.repeat(64),+ outcome: 'success',+ },+ })+ ).rejects.toMatchObject({+ name: 'ControlApiClientError',+ code: 'control_plane_unavailable',+ causeCode: 'ECONNREFUSED',+ })+ })+it.each(['ENOTFOUND', 'EAI_AGAIN', 'EHOSTUNREACH', 'ENETUNREACH', 'UND_ERR_CONNECT_TIMEOUT'])('G1-4b maps a %s fetch failure to control_plane_unavailable',async code => {diff --git a/grok-llm-proxy/test/server.security.test.ts b/grok-llm-proxy/test/server.security.test.tsindex 197b4e7ac..dde4a658e 100644--- a/grok-llm-proxy/test/server.security.test.ts+++ b/grok-llm-proxy/test/server.security.test.ts@@ -1115,6 +1115,29 @@ describe('grok-llm-proxy attempt telemetry', () => {})})+ it('(g1-1d) delivers an upstream 429 after a keepalive as an SSE rate_limited frame', async () => {+ const { res, lines } = await run({+ providerAttemptId: 'att-rate-sse',+ fetchFn: (async () => {+ await new Promise(resolve => setTimeout(resolve, 60))+ return new Response('slow down', { status: 429, headers: { 'retry-after': '7' } })+ }) as typeof fetch,+ configOverrides: { heartbeatIntervalMs: 20 },+ })+ expect(res.status).toBe(200)+ // Witness: a keepalive went out first, so the 429 can only travel as a frame.+ expect(keepaliveCount(res.text)).toBeGreaterThanOrEqual(1)+ // The frame carries the code alone: no Retry-After, no upstream status.+ expect(res.text.endsWith('data: {"type":"error","code":"rate_limited"}\n\n')).toBe(true)+ expect(res.headers['retry-after']).toBeUndefined()+ expect(lines).toHaveLength(1)+ expect(lines[0]).toMatchObject({+ code: 'rate_limited',+ details: { retryAfterSeconds: 7 },+ deliveredAs: 'sse_error',+ })+ })+// G1-4 (#720): a redeem whose connection nothing accepted (control-api or// its gateway restarting) is reported as the control plane being down.it('(g1-4a) answers 503 control_plane_unavailable when redeem cannot connect', async () => {