Evenfire is an intelligence layer platform for running LLM agents that take real actions, on your infrastructure
TypeScript
test(mcp-host): pin the Codex proxy client pre-dispatch refusal codes (R4-L6)
Alfredo Lopez322d9327eb68
diff --git a/mcp-host/package-lock.json b/mcp-host/package-lock.jsonindex 679ca3bdb..05c8310a0 100644--- a/mcp-host/package-lock.json+++ b/mcp-host/package-lock.json@@ -1,12 +1,12 @@{"name": "clerum-mcp-host",- "version": "0.1.483",+ "version": "0.1.484","lockfileVersion": 3,"requires": true,"packages": {"": {"name": "clerum-mcp-host",- "version": "0.1.483",+ "version": "0.1.484","license": "SEE LICENSE IN LICENSE","dependencies": {"@anthropic-ai/sdk": "^0.32.0",diff --git a/mcp-host/package.json b/mcp-host/package.jsonindex 01f45cfd7..ea930d873 100644--- a/mcp-host/package.json+++ b/mcp-host/package.json@@ -1,6 +1,6 @@{"name": "clerum-mcp-host",- "version": "0.1.483",+ "version": "0.1.484","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 ecafab2c3..507a86543 100644--- a/mcp-host/src/llm/__tests__/codexLlmProxyClient.test.ts+++ b/mcp-host/src/llm/__tests__/codexLlmProxyClient.test.ts@@ -1,5 +1,7 @@import { describe, expect, it, vi } from 'vitest'import {+ LIMITS,+ VISUAL_LIMITS,buildCodexProxyEnvelope,hashCodexCompletionRequest,parseCodexCompletionRequest,@@ -13,6 +15,7 @@ import {import { CodexSubscriptionProvider } from '../codexSubscription'import { classifyFailoverClass } from '../failover/classify'import { CodexAuthorizeError } from '../providerAttemptAuthorizer'+import { PNG_2X2_BASE64 } from './codexImageFixtures'import { closedPortUrl, fetchFailure, silentServer } from './connectFailureFixtures'function sse(frames: unknown[]): ReadableStream<Uint8Array> {@@ -26,6 +29,49 @@ function sse(frames: unknown[]): ReadableStream<Uint8Array> {})}+// A well-formed V2 request with one image, authorized under its own hash.+function codexVisualInput() {+ const parsed = parseCodexCompletionRequest({+ schemaVersion: 'codex-completion-request.v2',+ requestId: 'req-visual',+ idempotencyKey: 'idem-visual',+ provider: 'codex-subscription',+ model: 'gpt-5.1',+ deadlineMs: 1000,+ messages: [+ {+ role: 'user',+ content: 'Describe the attached image',+ contentParts: [+ { type: 'text', text: 'Describe the attached image' },+ {+ type: 'image',+ mimeType: 'image/png',+ data: PNG_2X2_BASE64,+ source: { kind: 'attachment', attachmentId: 'att-1', messageId: 'msg-1' },+ },+ ],+ },+ ],+ })+ if (!parsed.ok) throw new Error(parsed.message)+ return {+ request: parsed.value,+ requestHash: hashCodexCompletionRequest(parsed.value),+ executionTicket: 'fixture-ticket',+ }+}+type CodexVisualInput = ReturnType<typeof codexVisualInput>++/** The fixture's single user message, with its parts. */+function codexVisualMessage(input: CodexVisualInput) {+ const [message] = input.request.messages+ if (!message || !('contentParts' in message) || !message.contentParts) {+ throw new Error('fixture message has no contentParts')+ }+ return { ...message, contentParts: message.contentParts }+}+describe('CodexLlmProxyClient', () => {it('sends the exact measured V2 envelope and refuses an independent deadline or hash', async () => {const parsed = parseCodexCompletionRequest({@@ -73,6 +119,77 @@ describe('CodexLlmProxyClient', () => {expect(fetchFn).toHaveBeenCalledOnce()})+ // Review R4-L6: the pre-dispatch refusals use the providers' canonical+ // mapping, so a conversation over the non-image budget is a context-length+ // refusal and an image count is not a size refusal.+ it.each([+ [+ 'text over the non-image budget',+ (input: CodexVisualInput) => {+ const message = codexVisualMessage(input)+ const text = 'x'.repeat(LIMITS.maxRequestBodyBytes)+ const parts = message.contentParts.map(part =>+ part.type === 'text' ? { ...part, text } : part+ )+ return {+ ...input,+ request: {+ ...input.request,+ messages: [{ ...message, content: text, contentParts: parts }],+ },+ }+ },+ {+ code: 'request_limit_exceeded',+ message: 'request exceeds maxRequestBodyBytes outside image data',+ },+ ],+ [+ 'more images than the contract allows',+ (input: CodexVisualInput) => {+ const message = codexVisualMessage(input)+ const image = message.contentParts.find(part => part.type === 'image')+ if (!image) throw new Error('fixture has no image part')+ const images = Array.from({ length: VISUAL_LIMITS.maxImages + 1 }, (_, i) => ({+ ...image,+ source: { kind: 'attachment' as const, attachmentId: `att-${i}`, messageId: 'msg-1' },+ }))+ const contentParts = [{ type: 'text' as const, text: message.content }, ...images]+ return {+ ...input,+ request: { ...input.request, messages: [{ ...message, contentParts }] },+ }+ },+ { code: 'invalid_request', message: `request exceeds ${VISUAL_LIMITS.maxImages} images` },+ ],+ [+ 'an envelope over the visual ceiling',+ (input: CodexVisualInput) => ({+ ...input,+ executionTicket: 't'.repeat(LIMITS.maxVisualRequestBodyBytes),+ }),+ { code: 'payload_too_large', message: 'proxy envelope exceeds maxVisualRequestBodyBytes' },+ ],+ ])('R4-L6 refuses %s before the proxy hop', async (_label, mutate, expected) => {+ const fetchFn = vi.fn<typeof fetch>(+ async () => new Response(sse([{ type: 'done', outcome: 'success' }]))+ )+ const client = new CodexLlmProxyClient({+ runtimeUrl: 'http://proxy/completions',+ readPlatformJwt: () => 'fixture-only',+ fetchFn,+ })+ const input = codexVisualInput()+ await expect(client.stream(mutate(input))).rejects.toMatchObject({+ ...expected,+ dispatched: false,+ })+ expect(fetchFn).not.toHaveBeenCalled()+ // Witness: the unmodified request reaches the proxy.+ await client.stream(input)+ expect(fetchFn).toHaveBeenCalledOnce()+ })+it.each(['html', 'json'])('keeps a %s 413 terminal rather than treating it as unavailable',async format => {