Evenfire is an intelligence layer platform for running LLM agents that take real actions, on your infrastructure
TypeScript
test(authorize): pin the parser caps, the principal key and the visual-scan boundaries
Alfredo Lopez487d198d571e
diff --git a/control-api/package-lock.json b/control-api/package-lock.jsonindex e4e0ab292..f91636e53 100644--- a/control-api/package-lock.json+++ b/control-api/package-lock.json@@ -1,12 +1,12 @@{"name": "clerum-control-api",- "version": "0.1.723",+ "version": "0.1.724","lockfileVersion": 3,"requires": true,"packages": {"": {"name": "clerum-control-api",- "version": "0.1.723",+ "version": "0.1.724","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 896900c13..50219ce5d 100644--- a/control-api/package.json+++ b/control-api/package.json@@ -1,6 +1,6 @@{"name": "clerum-control-api",- "version": "0.1.723",+ "version": "0.1.724","description": "Internal Clerum control plane REST API + UI for managing CRDs and secrets","main": "dist/main.js","engines": {diff --git a/control-api/test/llmProviderAttemptBodyAdmission.test.ts b/control-api/test/llmProviderAttemptBodyAdmission.test.tsindex 89293e49c..e52333980 100644--- a/control-api/test/llmProviderAttemptBodyAdmission.test.ts+++ b/control-api/test/llmProviderAttemptBodyAdmission.test.ts@@ -422,6 +422,41 @@ describe('AuthorizeBodyAdmission FIFO and verified-principal share', () => {expect(gate.snapshot()).toEqual({ inFlight: 0, queued: 0, principals: 0 })})+ it('gives the same signed subject on a different Host set its own share', async () => {+ const gate = queuedGate()+ const holder = gate.tryAcquire({ sub: 'same-sub', hostRefs: ['host-a'] })+ expect(holder).not.toBeNull()+ const parser = vi.fn<RequestHandler>((_request, _response, next) => next())+ const sameHost = gate.run(+ fakeRequest() as never,+ fakeResponse() as never,+ parser,+ async () => undefined,+ {+ sub: 'same-sub',+ hostRefs: ['host-a'],+ }+ )+ // host-a now holds its two positions; host-b must still be queued, not refused.+ const otherHostRes = fakeResponse()+ const otherHost = gate.run(+ fakeRequest() as never,+ otherHostRes as never,+ parser,+ async () => undefined,+ {+ sub: 'same-sub',+ hostRefs: ['host-b'],+ }+ )+ expect(otherHostRes.body).toBeUndefined()+ expect(gate.snapshot()).toEqual({ inFlight: 1, queued: 2, principals: 2 })+ holder?.()+ await Promise.all([sameHost, otherHost])+ expect(parser).toHaveBeenCalledTimes(2)+ expect(gate.snapshot()).toEqual({ inFlight: 0, queued: 0, principals: 0 })+ })+it.each(['aborted', 'close'] as const)('removes a queued %s once, cleans its wait hooks and serves the next request',async event => {diff --git a/control-api/test/routes.mcp-host.llmProviderAttempts.ordinaryParserCap.test.ts b/control-api/test/routes.mcp-host.llmProviderAttempts.ordinaryParserCap.test.tsnew file mode 100644index 000000000..c7872e30b--- /dev/null+++ b/control-api/test/routes.mcp-host.llmProviderAttempts.ordinaryParserCap.test.ts@@ -0,0 +1,28 @@+import { describe, expect, it, vi } from 'vitest'+import express from 'express'+import {+ AUTHORIZE_TEXT_BODY_BYTES,+ createMcpHostLlmProviderAttemptRoutes,+} from '../src/routes/mcp-host/llmProviderAttempts.routes.js'++// selectAuthorizeBudget only sends declared lengths <= AUTHORIZE_TEXT_BODY_BYTES+// to the uncharged parser, so no HTTP request can exceed its limit through the+// route; the limit is defense in depth and can only be pinned at construction.+describe('authorize ordinary parser cap', () => {+ it('builds the uncharged parser with the text envelope and the retained one with the visual envelope', () => {+ const json = vi.spyOn(express, 'json')+ try {+ createMcpHostLlmProviderAttemptRoutes({ getResource: vi.fn() } as never)+ expect(json).toHaveBeenCalledTimes(2)+ const limits = json.mock.calls+ .map(([options]) => options?.limit as number)+ .sort((a, b) => a - b)+ expect(AUTHORIZE_TEXT_BODY_BYTES).toBe(8_404_992)+ expect(limits[0]).toBe(8_404_992)+ expect(limits[1]).toBeGreaterThan(8_404_992)+ for (const [options] of json.mock.calls) expect(options?.inflate).toBe(false)+ } finally {+ json.mockRestore()+ }+ })+})diff --git a/mcp-host/package-lock.json b/mcp-host/package-lock.jsonindex 5084bf3fe..9a07b3343 100644--- a/mcp-host/package-lock.json+++ b/mcp-host/package-lock.json@@ -1,12 +1,12 @@{"name": "clerum-mcp-host",- "version": "0.1.491",+ "version": "0.1.492","lockfileVersion": 3,"requires": true,"packages": {"": {"name": "clerum-mcp-host",- "version": "0.1.491",+ "version": "0.1.492","license": "SEE LICENSE IN LICENSE","dependencies": {"@anthropic-ai/sdk": "^0.32.0",diff --git a/mcp-host/package.json b/mcp-host/package.jsonindex b4e1ff97d..894f4eb5d 100644--- a/mcp-host/package.json+++ b/mcp-host/package.json@@ -1,6 +1,6 @@{"name": "clerum-mcp-host",- "version": "0.1.491",+ "version": "0.1.492","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__/imageSource.emptyParts.test.ts b/mcp-host/src/llm/__tests__/imageSource.emptyParts.test.tsnew file mode 100644index 000000000..e95744f25--- /dev/null+++ b/mcp-host/src/llm/__tests__/imageSource.emptyParts.test.ts@@ -0,0 +1,21 @@+import { describe, expect, it } from 'vitest'+import type { ChatMessage } from '../../core/types'+import { projectMessage } from '../imageSource'++// An empty contentParts array is "no parts": the turn stays V1 byte-identical.+describe('projectMessage with an empty contentParts array', () => {+ it('keeps a user turn byte-identical to V1 and keeps its content', () => {+ const message = { role: 'user', content: 'hello', contentParts: [] } as ChatMessage+ expect(JSON.stringify(projectMessage(message, 'codex_request_invalid'))).toBe(+ JSON.stringify({ role: 'user', content: 'hello' })+ )+ })++ it('does not refuse an assistant turn that carries no parts', () => {+ const message = { role: 'assistant', content: 'done', contentParts: [] } as ChatMessage+ expect(projectMessage(message, 'codex_request_invalid')).toEqual({+ role: 'assistant',+ content: 'done',+ })+ })+})diff --git a/packages/grok-provider-attempt-contract/index.test.cjs b/packages/grok-provider-attempt-contract/index.test.cjsindex 1fb72b738..a76bd91b3 100644--- a/packages/grok-provider-attempt-contract/index.test.cjs+++ b/packages/grok-provider-attempt-contract/index.test.cjs@@ -1579,6 +1579,13 @@ test('parity: shared container-reader branches return the same exact verdict inconst validJpeg = [...SOI, ...sof(0xc0, 8, 6), ...sos, ...scan, ...EOI]const corpus = [['png, well formed', png(validPng), accepted(validPng.length, 3, 2)],+ // Eight or more bytes with one wrong signature byte and otherwise valid+ // chunks: the signature check alone must refuse it.+ [+ 'png, wrong last signature byte',+ png([...SIG.slice(0, 7), 0x0b, ...ihdr(3, 2), ...idat, ...iend]),+ invalid('PNG signature is missing'),+ ],['png, zero width', png([...SIG, ...ihdr(0, 2), ...idat, ...iend]), invalid('PNG dimensions must be positive')],['png, zero height', png([...SIG, ...ihdr(3, 0), ...idat, ...iend]), invalid('PNG dimensions must be positive')],[@@ -1665,6 +1672,17 @@ test('parity: shared container-reader branches return the same exact verdict injpeg([...SOI, 0xff, 0xc0, 0x00, 0x04, 0x08, 0x00, ...sos, ...scan, ...EOI]),invalid('JPEG frame header is truncated'),],+ // SOF length boundary: 7 is one byte short of length+P+Y+X+Nf, 8 is the minimum.+ [+ 'jpeg, 7-byte frame header',+ jpeg([...SOI, 0xff, 0xc0, 0x00, 0x07, 0x08, 0x00, 0x06, 0x00, 0x08, ...sos, ...scan, ...EOI]),+ invalid('JPEG frame header is truncated'),+ ],+ [+ 'jpeg, 8-byte frame header is the minimum accepted',+ jpeg([...SOI, 0xff, 0xc0, 0x00, 0x08, 0x08, 0x00, 0x06, 0x00, 0x08, 0x01, ...sos, ...scan, ...EOI]),+ accepted(2 + 10 + 14 + 2 + 2, 8, 6),+ ],['jpeg, zero width',jpeg([...SOI, ...sof(0xc0, 0, 6), ...sos, ...scan, ...EOI]),