Evenfire is an intelligence layer platform for running LLM agents that take real actions, on your infrastructure
TypeScript
test: require a size-refusal 413 and a proxy body limit above the contract cap (#731)
Alfredo Lopez4f2b7d7e3a6c
diff --git a/codex-llm-proxy/test/server.security.test.ts b/codex-llm-proxy/test/server.security.test.tsindex 9f0d1d663..a6050f5ad 100644--- a/codex-llm-proxy/test/server.security.test.ts+++ b/codex-llm-proxy/test/server.security.test.ts@@ -2,6 +2,7 @@ import { generateKeyPairSync } from 'node:crypto'import jwt from 'jsonwebtoken'import request from 'supertest'import {+ LIMITS,hashCodexCompletionRequestV1,parseCodexCompletionRequestV1,} from '@clerum/llm-provider-attempt-contract'@@ -426,6 +427,27 @@ describe('codex-llm-proxy startup config', () => {expect(loaded.controlApiServiceName).toBe('codex-llm-proxy')})+ // #731 — the envelope carries the contract-capped `request` plus the ticket,+ // the hash and the deadline. A body limit equal to the contract cap refuses,+ // as a 413, requests the contract itself accepts.+ it('T-R2-6b defaults the body limit to the contract request cap plus a 16 KiB envelope allowance', () => {+ expect(loadConfig(base).maxBodyBytes).toBe(LIMITS.maxRequestBodyBytes + 16 * 1024)+ })++ it('T-R2-6c does not refuse a request at the contract cap with a real ticket as payload_too_large', async () => {+ const { runtimeApp } = createProxyApps(config({ maxBodyBytes: loadConfig(base).maxBodyBytes }))+ const atCap = { pad: 'x'.repeat(LIMITS.maxRequestBodyBytes - '{"pad":""}'.length) }+ expect(Buffer.byteLength(JSON.stringify(atCap), 'utf8')).toBe(LIMITS.maxRequestBodyBytes)+ const res = await request(runtimeApp)+ .post('/internal/runtime/v1/codex/completions')+ .set('Authorization', `Bearer ${platformToken()}`)+ .send({ executionTicket: ticket(), requestHash: 'a'.repeat(64), request: atCap })+ expect(res.body.error).not.toBe('payload_too_large')+ expect(res.status).not.toBe(413)+ // Witness: the body parser accepted the envelope and the route answered.+ expect(typeof res.body.error).toBe('string')+ })+it.each([undefined, '', ' '])('fails at startup when the control-api URL is %j',value => {diff --git a/grok-llm-proxy/test/server.security.test.ts b/grok-llm-proxy/test/server.security.test.tsindex 41adcd868..415f27ee0 100644--- a/grok-llm-proxy/test/server.security.test.ts+++ b/grok-llm-proxy/test/server.security.test.ts@@ -3,6 +3,7 @@ import jwt from 'jsonwebtoken'import { generateKeyPairSync } from 'node:crypto'import request from 'supertest'import {+ LIMITS,hashGrokCompletionRequestV1,parseGrokCompletionRequestV1,} from '@clerum/grok-provider-attempt-contract'@@ -429,6 +430,27 @@ describe('grok-llm-proxy startup config', () => {expect(loaded.controlApiServiceName).toBe('grok-llm-proxy')})+ // #731 — the envelope carries the contract-capped `request` plus the ticket,+ // the hash and the deadline. A body limit equal to the contract cap refuses,+ // as a 413, requests the contract itself accepts.+ it('T-R2-6b-grok defaults the body limit to the contract request cap plus a 16 KiB envelope allowance', () => {+ expect(loadConfig(base).maxBodyBytes).toBe(LIMITS.maxRequestBodyBytes + 16 * 1024)+ })++ it('T-R2-6c-grok does not refuse a request at the contract cap with a real ticket as payload_too_large', async () => {+ const { runtimeApp } = createProxyApps(config({ maxBodyBytes: loadConfig(base).maxBodyBytes }))+ const atCap = { pad: 'x'.repeat(LIMITS.maxRequestBodyBytes - '{"pad":""}'.length) }+ expect(Buffer.byteLength(JSON.stringify(atCap), 'utf8')).toBe(LIMITS.maxRequestBodyBytes)+ const res = await request(runtimeApp)+ .post('/internal/runtime/v1/grok/completions')+ .set('Authorization', `Bearer ${platformToken()}`)+ .send({ executionTicket: ticket(), requestHash: 'a'.repeat(64), request: atCap })+ expect(res.body.error).not.toBe('payload_too_large')+ expect(res.status).not.toBe(413)+ // Witness: the body parser accepted the envelope and the route answered.+ expect(typeof res.body.error).toBe('string')+ })+it.each([undefined, '', ' '])('fails at startup when the control-api URL is %j', value => {expect(() => loadConfig({ ...base, GROK_LLM_PROXY_CONTROL_API_URL: value })).toThrow(/GROK_LLM_PROXY_CONTROL_API_URL/diff --git a/mcp-host/package-lock.json b/mcp-host/package-lock.jsonindex 25015b338..e9ff67041 100644--- a/mcp-host/package-lock.json+++ b/mcp-host/package-lock.json@@ -1,12 +1,12 @@{"name": "clerum-mcp-host",- "version": "0.1.389",+ "version": "0.1.390","lockfileVersion": 3,"requires": true,"packages": {"": {"name": "clerum-mcp-host",- "version": "0.1.389",+ "version": "0.1.390","license": "SEE LICENSE IN LICENSE","dependencies": {"@anthropic-ai/sdk": "^0.32.0",diff --git a/mcp-host/package.json b/mcp-host/package.jsonindex 97d70cb8a..727b96eab 100644--- a/mcp-host/package.json+++ b/mcp-host/package.json@@ -1,6 +1,6 @@{"name": "clerum-mcp-host",- "version": "0.1.389",+ "version": "0.1.390","description": "MCP Host - reads Host CRD and provides LLM access via OpenAI/Claude","main": "dist/main.js","engines": {diff --git a/mcp-host/src/llm/__tests__/codexLlmProxyClient.test.ts b/mcp-host/src/llm/__tests__/codexLlmProxyClient.test.tsindex f292d3b8a..ac07c7ec7 100644--- a/mcp-host/src/llm/__tests__/codexLlmProxyClient.test.ts+++ b/mcp-host/src/llm/__tests__/codexLlmProxyClient.test.ts@@ -108,6 +108,45 @@ describe('CodexLlmProxyClient', () => {expect(classifyFailoverClass(classified.code, classified.retryable)).toBeNull()})+ // #731 — the proxy's body parser refuses an envelope over its limit with+ // `reject(res, 413, 'payload_too_large')` (codex-llm-proxy/src/server.ts).+ // That is a size refusal of this conversation, not a failed API call.+ it('T-R2-6a classifies the proxy 413 payload_too_large as ContextLengthExceeded', async () => {+ const fetchFn = vi.fn().mockResolvedValue({+ ok: false,+ status: 413,+ json: async () => ({ error: 'payload_too_large' }),+ })+ const client = new CodexLlmProxyClient({+ runtimeUrl: resolveCodexProxyRuntimeUrl(+ 'http://codex-llm-proxy.control-plane.svc.cluster.local:8080'+ ),+ readPlatformJwt: () => 'platform-jwt',+ fetchFn: fetchFn as unknown as typeof fetch,+ })+ const err = await client+ .stream({ executionTicket: 'ticket-123456', requestHash: 'a'.repeat(64), request: {} })+ .then(+ () => undefined,+ (e: unknown) => e+ )+ expect(fetchFn).toHaveBeenCalledTimes(1)+ expect(err).toMatchObject({+ code: 'payload_too_large',+ message: 'proxy stream failed with 413 (payload_too_large)',+ })++ const classified = new CodexSubscriptionProvider('gpt-5.3-codex', {} as never).classifyError(+ err+ )+ expect(classified).toMatchObject({+ code: LlmErrorCode.ContextLengthExceeded,+ retryable: false,+ providerCode: 'payload_too_large',+ })+ expect(classifyFailoverClass(classified.code, classified.retryable)).toBeNull()+ })+it('refuses a runtime URL that is not absolute', () => {expect(() =>diff --git a/mcp-host/src/llm/__tests__/grokLlmProxyClient.test.ts b/mcp-host/src/llm/__tests__/grokLlmProxyClient.test.tsindex fa1269c01..30480c963 100644--- a/mcp-host/src/llm/__tests__/grokLlmProxyClient.test.ts+++ b/mcp-host/src/llm/__tests__/grokLlmProxyClient.test.ts@@ -187,6 +187,34 @@ describe('GrokLlmProxyClient', () => {expect(classifyFailoverClass(classified.code, classified.retryable)).toBeNull()})+ // #731 — the proxy's body parser refuses an envelope over its limit with+ // `reject(res, 413, 'payload_too_large')` (grok-llm-proxy/src/server.ts).+ // That is a size refusal of this conversation, not a failed API call.+ it('T-R2-6a-grok classifies the proxy 413 payload_too_large as ContextLengthExceeded', async () => {+ const fetchFn = vi.fn().mockResolvedValue({+ ok: false,+ status: 413,+ json: async () => ({ error: 'payload_too_large' }),+ })+ const err = await client(fetchFn)+ .stream(STREAM_INPUT)+ .then(+ () => undefined,+ (e: unknown) => e+ )+ expect(fetchFn).toHaveBeenCalledTimes(1)+ expect(err).toBeInstanceOf(GrokProxyError)+ expect(err).toMatchObject({ code: 'payload_too_large' })++ const classified = new GrokSubscriptionProvider('grok-4.6', {} as never).classifyError(err)+ expect(classified).toMatchObject({+ code: LlmErrorCode.ContextLengthExceeded,+ retryable: false,+ providerCode: 'payload_too_large',+ })+ expect(classifyFailoverClass(classified.code, classified.retryable)).toBeNull()+ })+it('fails closed when the proxy emits an SSE error frame after headers', async () => {const fetchFn = vi.fn().mockResolvedValue({ok: true,