Skip to content

Evenfire is an intelligence layer platform for running LLM agents that take real actions, on your infrastructure

TypeScript

test(llm-proxy): one cause code per control-api connect failure (RED, #720)

Alfredo Lopez3be3b4e4c7dd
diff --git a/codex-llm-proxy/test/server.security.test.ts b/codex-llm-proxy/test/server.security.test.ts
index a1ff63014..448d4acc2 100644
--- a/codex-llm-proxy/test/server.security.test.ts
+++ b/codex-llm-proxy/test/server.security.test.ts
@@ -1010,10 +1010,15 @@ describe('codex-llm-proxy attempt telemetry', () => {
.set('Authorization', `Bearer ${platformToken()}`)
.send(completionBody(providerAttemptId, tamper))
const metricsText = (await request(apps.probeApp).get('/metrics')).text
- const lines = [...info.mock.calls, ...warn.mock.calls]
- .map(call => call[0] as unknown as Record<string, unknown>)
- .filter(entry => entry?.event === 'codex_proxy_attempt_finished')
- return { res, receipts, lines, metricsText }
+ const logged = [...info.mock.calls, ...warn.mock.calls].map(
+ call => call[0] as unknown as Record<string, unknown>
+ )
+ const lines = logged.filter(entry => entry?.event === 'codex_proxy_attempt_finished')
+ const unreachable = logged.filter(
+ entry => entry?.event === 'codex_proxy_control_api_unreachable'
+ )
+ const causeCodeLines = logged.filter(entry => entry && 'causeCode' in entry)
+ return { res, receipts, lines, unreachable, causeCodeLines, metricsText }
} finally {
info.mockRestore()
warn.mockRestore()
@@ -1258,7 +1263,7 @@ describe('codex-llm-proxy attempt telemetry', () => {
const { port } = closed.address() as AddressInfo
await new Promise<void>(resolve => closed.close(() => resolve()))
const upstreamFetch = vi.fn(upstream(1, 0))
- const { res, lines, metricsText } = await run(
+ const { res, lines, unreachable, causeCodeLines, metricsText } = await run(
'att-control-down',
0,
0,
@@ -1288,6 +1293,11 @@ describe('codex-llm-proxy attempt telemetry', () => {
httpStatus: 503,
})
expectNoForbiddenKeys(lines[0]!)
+ // Review R1-M2: the hop line counts the failure; the cause code is on the
+ // attempt line only, so one failure never reads as two.
+ expect(unreachable).toHaveLength(1)
+ expect('causeCode' in unreachable[0]!).toBe(false)
+ expect(causeCodeLines).toEqual([lines[0]])
expect(failureCount(metricsText, 'control_plane_unavailable')).toBe(1)
expect(failureCount(metricsText, 'other')).toBe(0)
})
diff --git a/grok-llm-proxy/test/server.security.test.ts b/grok-llm-proxy/test/server.security.test.ts
index dc1ddc98c..d2dc1634e 100644
--- a/grok-llm-proxy/test/server.security.test.ts
+++ b/grok-llm-proxy/test/server.security.test.ts
@@ -981,10 +981,15 @@ describe('grok-llm-proxy attempt telemetry', () => {
.set('Authorization', `Bearer ${platformToken()}`)
.send(completionBody(options.providerAttemptId, options.tamper))
const metricsText = (await request(apps.probeApp).get('/metrics')).text
- const lines = [...info.mock.calls, ...warn.mock.calls]
- .map(call => call[0] as unknown as Record<string, unknown>)
- .filter(entry => entry?.event === 'grok_proxy_attempt_finished')
- return { res, receipts, lines, metricsText }
+ const logged = [...info.mock.calls, ...warn.mock.calls].map(
+ call => call[0] as unknown as Record<string, unknown>
+ )
+ const lines = logged.filter(entry => entry?.event === 'grok_proxy_attempt_finished')
+ const unreachable = logged.filter(
+ entry => entry?.event === 'grok_proxy_control_api_unreachable'
+ )
+ const causeCodeLines = logged.filter(entry => entry && 'causeCode' in entry)
+ return { res, receipts, lines, unreachable, causeCodeLines, metricsText }
} finally {
info.mockRestore()
warn.mockRestore()
@@ -1096,7 +1101,7 @@ describe('grok-llm-proxy attempt telemetry', () => {
const { port } = closed.address() as AddressInfo
await new Promise<void>(resolve => closed.close(() => resolve()))
const upstreamFetch = vi.fn(upstream(1, 0))
- const { res, lines, metricsText } = await run({
+ const { res, lines, unreachable, causeCodeLines, metricsText } = await run({
providerAttemptId: 'att-control-down',
fetchFn: upstreamFetch as unknown as typeof fetch,
controlApiClient: new ControlApiClient({
@@ -1120,6 +1125,11 @@ describe('grok-llm-proxy attempt telemetry', () => {
httpStatus: 503,
})
expectNoForbiddenKeys(lines[0]!)
+ // Review R1-M2: the hop line counts the failure; the cause code is on the
+ // attempt line only, so one failure never reads as two.
+ expect(unreachable).toHaveLength(1)
+ expect('causeCode' in unreachable[0]!).toBe(false)
+ expect(causeCodeLines).toEqual([lines[0]])
expect(failureCount(metricsText, 'control_plane_unavailable')).toBe(1)
expect(failureCount(metricsText, 'other')).toBe(0)
})