Evenfire is an intelligence layer platform for running LLM agents that take real actions, on your infrastructure
TypeScript
test: pin canonical envelope refusal codes and the request logger
Alfredo Lopez9dea750ea657
diff --git a/control-api/package-lock.json b/control-api/package-lock.jsonindex 681d569f4..3a52cd988 100644--- a/control-api/package-lock.json+++ b/control-api/package-lock.json@@ -1,12 +1,12 @@{"name": "clerum-control-api",- "version": "0.1.682",+ "version": "0.1.683","lockfileVersion": 3,"requires": true,"packages": {"": {"name": "clerum-control-api",- "version": "0.1.682",+ "version": "0.1.683","dependencies": {"@clerum/display-field": "file:../packages/display-field","@clerum/grok-provider-attempt-contract": "file:../packages/grok-provider-attempt-contract",diff --git a/control-api/package.json b/control-api/package.jsonindex e82aab44f..a552b0270 100644--- a/control-api/package.json+++ b/control-api/package.json@@ -1,6 +1,6 @@{"name": "clerum-control-api",- "version": "0.1.682",+ "version": "0.1.683","description": "Internal Clerum control plane REST API + UI for managing CRDs and secrets","main": "dist/main.js","engines": {diff --git a/control-api/test/routes.mcp-host.llmProviderAttempts.test.ts b/control-api/test/routes.mcp-host.llmProviderAttempts.test.tsindex 5b0476eb4..450e29b32 100644--- a/control-api/test/routes.mcp-host.llmProviderAttempts.test.ts+++ b/control-api/test/routes.mcp-host.llmProviderAttempts.test.ts@@ -744,6 +744,37 @@ describe('authorize raw-body scan before JSON.parse', () => {expect(JSON.stringify(args)).not.toContain(marker)}}, 60_000)++ // Review R3 nit b: the refusal is logged through the request-scoped logger,+ // which carries the correlationId, as the global error handler does.+ it('logs a body refusal through req.log when the request has one', async () => {+ const requestWarn = vi.fn()+ const app = express()+ app.use((req, _res, next) => {+ // `Request.log` is declared by middleware/correlationId.ts.+ ;(req as { log?: unknown }).log = { warn: requestWarn }+ next()+ })+ const api = express.Router()+ api.use(createMcpHostLlmProviderAttemptRoutes({ getResource: vi.fn() } as never))+ app.use('/api/v1', api)+ const res = await request(app)+ .post('/api/v1/mcp-host/llm/provider-attempts/authorize')+ .set(headers({ 'content-encoding': 'gzip' }))+ .send(Buffer.from(gzipSync('{}')))+ expect(res.status).toBe(415)+ // Witness: the request logger received the refusal.+ expect(requestWarn).toHaveBeenCalledExactlyOnceWith({+ event: 'llm_provider_attempt_body_refused',+ type: 'encoding.unsupported',+ status: 415,+ })+ const moduleRefusals = mockLogWarn.mock.calls.filter(+ ([fields]) => (fields as { event?: string })?.event === 'llm_provider_attempt_body_refused'+ )+ expect(moduleRefusals).toEqual([])+ expect(authorizer.authorizeLlmProviderAttempt).not.toHaveBeenCalled()+ })})describe('resolveHostAssignedAssignment', () => {diff --git a/mcp-host/package-lock.json b/mcp-host/package-lock.jsonindex e27c32cf6..660e6c099 100644--- a/mcp-host/package-lock.json+++ b/mcp-host/package-lock.json@@ -1,12 +1,12 @@{"name": "clerum-mcp-host",- "version": "0.1.479",+ "version": "0.1.480","lockfileVersion": 3,"requires": true,"packages": {"": {"name": "clerum-mcp-host",- "version": "0.1.479",+ "version": "0.1.480","license": "SEE LICENSE IN LICENSE","dependencies": {"@anthropic-ai/sdk": "^0.32.0",diff --git a/mcp-host/package.json b/mcp-host/package.jsonindex 566043608..8efd07c91 100644--- a/mcp-host/package.json+++ b/mcp-host/package.json@@ -1,6 +1,6 @@{"name": "clerum-mcp-host",- "version": "0.1.479",+ "version": "0.1.480","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__/grokLlmProxyClient.test.ts b/mcp-host/src/llm/__tests__/grokLlmProxyClient.test.tsindex e6166b844..fa3484335 100644--- a/mcp-host/src/llm/__tests__/grokLlmProxyClient.test.ts+++ b/mcp-host/src/llm/__tests__/grokLlmProxyClient.test.ts@@ -1,6 +1,7 @@import { describe, expect, it, vi } from 'vitest'import {LIMITS as GROK_LIMITS,+ GROK_VISUAL_LIMITS,buildGrokProxyEnvelope,hashGrokCompletionRequest,parseGrokCompletionRequest,@@ -75,6 +76,15 @@ function visualInput() {}type VisualInput = ReturnType<typeof visualInput>+/** The fixture's single user message, with its parts. */+function visualMessage(input: VisualInput) {+ 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 }+}+const STREAM_INPUT = {executionTicket: 'ticket-123456',requestHash: 'a'.repeat(64),@@ -156,6 +166,50 @@ describe('GrokLlmProxyClient', () => {(input: VisualInput) => ({ ...input, executionTicket: 'short' }),{ code: 'invalid_request', message: 'executionTicket is invalid' },],+ // Review R3 nit c: the envelope refusal uses the providers' canonical+ // mapping, so an image count is not a size refusal.+ [+ 'more images than the contract allows',+ (input: VisualInput) => {+ const message = visualMessage(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: GROK_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 ${GROK_VISUAL_LIMITS.maxImages} images`,+ },+ ],+ [+ 'text over the non-image budget',+ (input: VisualInput) => {+ const message = visualMessage(input)+ const text = 'x'.repeat(GROK_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',+ },+ ],])('T-G4c-5 refuses %s before the proxy hop', async (_label, mutate, expected) => {const fetchFn = vi.fn<typeof fetch>(async () => new Response(sse([{ type: 'done', outcome: 'success' }]))