Skip to content

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

TypeScript

test(contracts): require one exported envelope allowance for every consumer (#739)

Alfredo Lopeze701dade89b3
diff --git a/codex-llm-proxy/test/server.security.test.ts b/codex-llm-proxy/test/server.security.test.ts
index 0ba3e27a5..6e54c4c58 100644
--- a/codex-llm-proxy/test/server.security.test.ts
+++ b/codex-llm-proxy/test/server.security.test.ts
@@ -3,6 +3,7 @@ import jwt from 'jsonwebtoken'
import request from 'supertest'
import { describe, expect, it, vi } from 'vitest'
import {
+ ENVELOPE_ALLOWANCE_BYTES as CONTRACT_ENVELOPE_ALLOWANCE_BYTES,
LIMITS,
hashCodexCompletionRequestV1,
parseCodexCompletionRequestV1,
@@ -553,6 +554,13 @@ describe('codex-llm-proxy startup config', () => {
expect(loadConfig(base).maxBodyBytes).toBe(LIMITS.maxRequestBodyBytes + 16 * 1024)
})
+ // R11 — the allowance has one source, the contract, shared with control-api
+ // and mcp-host. A literal here could drift from theirs.
+ it('T-R11-codex takes the envelope allowance from the contract', () => {
+ expect(CONTRACT_ENVELOPE_ALLOWANCE_BYTES).toBe(16 * 1024)
+ expect(ENVELOPE_ALLOWANCE_BYTES).toBe(CONTRACT_ENVELOPE_ALLOWANCE_BYTES)
+ })
+
// R9-3 (L-3) — a lower override would answer 413 to requests the contract
// accepts, so it is refused at startup, as the visual override is.
it('T-R9-3 refuses a body limit below the contract request cap plus the envelope allowance', () => {
diff --git a/control-api/package-lock.json b/control-api/package-lock.json
index 4085715ec..8c7473d69 100644
--- a/control-api/package-lock.json
+++ b/control-api/package-lock.json
@@ -1,12 +1,12 @@
{
"name": "clerum-control-api",
- "version": "0.1.623",
+ "version": "0.1.624",
"lockfileVersion": 3,
"requires": true,
"packages": {
"": {
"name": "clerum-control-api",
- "version": "0.1.623",
+ "version": "0.1.624",
"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.json
index 712b64b13..33e6ea007 100644
--- a/control-api/package.json
+++ b/control-api/package.json
@@ -1,6 +1,6 @@
{
"name": "clerum-control-api",
- "version": "0.1.623",
+ "version": "0.1.624",
"description": "Internal Clerum control plane REST API + UI for managing CRDs and secrets",
"main": "dist/main.js",
"engines": {
diff --git a/control-api/test/services.llmProviderAttemptAuthorizer.test.ts b/control-api/test/services.llmProviderAttemptAuthorizer.test.ts
index b17ac8419..f5bc7dbb4 100644
--- a/control-api/test/services.llmProviderAttemptAuthorizer.test.ts
+++ b/control-api/test/services.llmProviderAttemptAuthorizer.test.ts
@@ -1,7 +1,9 @@
import { beforeEach, describe, expect, it, vi } from 'vitest'
import { readFileSync } from 'node:fs'
import { createRequire } from 'node:module'
+import { ENVELOPE_ALLOWANCE_BYTES as GROK_CONTRACT_ENVELOPE_ALLOWANCE_BYTES } from '@clerum/grok-provider-attempt-contract'
import {
+ ENVELOPE_ALLOWANCE_BYTES as CODEX_CONTRACT_ENVELOPE_ALLOWANCE_BYTES,
LIMITS,
VISUAL_LIMITS,
hashCodexCompletionRequestV1,
@@ -1201,6 +1203,14 @@ describe('authorizeLlmProviderAttempt', () => {
return request
}
+ // R11 — this authorizer serves Codex and Grok attempts, and both proxies
+ // and mcp-host import the same allowance from the contracts.
+ it('T-R11-control-api takes the envelope allowance from the contracts', () => {
+ expect(CODEX_CONTRACT_ENVELOPE_ALLOWANCE_BYTES).toBe(16 * 1024)
+ expect(AUTHORIZE_ENVELOPE_ALLOWANCE_BYTES).toBe(CODEX_CONTRACT_ENVELOPE_ALLOWANCE_BYTES)
+ expect(AUTHORIZE_ENVELOPE_ALLOWANCE_BYTES).toBe(GROK_CONTRACT_ENVELOPE_ALLOWANCE_BYTES)
+ })
+
it('T-R3-3a authorizes a request just under the cap although the whole body is over it', async () => {
const request = requestOfBytes(LIMITS.maxRequestBodyBytes - 64)
const payload = body({ request })
diff --git a/grok-llm-proxy/test/server.security.test.ts b/grok-llm-proxy/test/server.security.test.ts
index ed58c64b8..92c007545 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 {
+ ENVELOPE_ALLOWANCE_BYTES as CONTRACT_ENVELOPE_ALLOWANCE_BYTES,
LIMITS,
hashGrokCompletionRequestV1,
parseGrokCompletionRequestV1,
@@ -438,6 +439,13 @@ describe('grok-llm-proxy startup config', () => {
expect(loadConfig(base).maxBodyBytes).toBe(LIMITS.maxRequestBodyBytes + 16 * 1024)
})
+ // R11 — the allowance has one source, the contract, shared with control-api
+ // and mcp-host. A literal here could drift from theirs.
+ it('T-R11-grok takes the envelope allowance from the contract', () => {
+ expect(CONTRACT_ENVELOPE_ALLOWANCE_BYTES).toBe(16 * 1024)
+ expect(ENVELOPE_ALLOWANCE_BYTES).toBe(CONTRACT_ENVELOPE_ALLOWANCE_BYTES)
+ })
+
// R9-3 (L-3) — a lower override would answer 413 to requests the contract
// accepts, so it is refused at startup.
it('T-R9-3-grok refuses a body limit below the contract request cap plus the envelope allowance', () => {
diff --git a/mcp-host/package-lock.json b/mcp-host/package-lock.json
index c3449d463..1dc4ddb34 100644
--- a/mcp-host/package-lock.json
+++ b/mcp-host/package-lock.json
@@ -1,12 +1,12 @@
{
"name": "clerum-mcp-host",
- "version": "0.1.426",
+ "version": "0.1.427",
"lockfileVersion": 3,
"requires": true,
"packages": {
"": {
"name": "clerum-mcp-host",
- "version": "0.1.426",
+ "version": "0.1.427",
"license": "SEE LICENSE IN LICENSE",
"dependencies": {
"@anthropic-ai/sdk": "^0.32.0",
diff --git a/mcp-host/package.json b/mcp-host/package.json
index 5142b8e21..0603a6bd6 100644
--- a/mcp-host/package.json
+++ b/mcp-host/package.json
@@ -1,6 +1,6 @@
{
"name": "clerum-mcp-host",
- "version": "0.1.426",
+ "version": "0.1.427",
"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__/providerAttemptAuthorizer.test.ts b/mcp-host/src/llm/__tests__/providerAttemptAuthorizer.test.ts
index 10836ddd4..7d983fd49 100644
--- a/mcp-host/src/llm/__tests__/providerAttemptAuthorizer.test.ts
+++ b/mcp-host/src/llm/__tests__/providerAttemptAuthorizer.test.ts
@@ -1,5 +1,9 @@
import { describe, expect, it, vi } from 'vitest'
-import { LIMITS } from '@clerum/llm-provider-attempt-contract'
+import { ENVELOPE_ALLOWANCE_BYTES as GROK_CONTRACT_ENVELOPE_ALLOWANCE_BYTES } from '@clerum/grok-provider-attempt-contract'
+import {
+ ENVELOPE_ALLOWANCE_BYTES as CODEX_CONTRACT_ENVELOPE_ALLOWANCE_BYTES,
+ LIMITS,
+} from '@clerum/llm-provider-attempt-contract'
import { LlmErrorCode } from '../../core/errors'
import { CodexSubscriptionProvider } from '../codexSubscription'
import { classifyFailoverClass } from '../failover/classify'
@@ -19,11 +23,6 @@ const validAuthorize = {
expiresAt: '2026-08-20T10:00:00.000Z',
}
-// control-api's `AUTHORIZE_ENVELOPE_ALLOWANCE_BYTES`
-// (`llmProviderAttemptAuthorizer.ts`): the room it grants the envelope around
-// a request at the contract cap.
-const CONTROL_API_ENVELOPE_ALLOWANCE_BYTES = 16 * 1024
-
// The envelope `codexSubscription` and `grokSubscription` build, with every
// optional field filled.
function realisticEnvelope(request: unknown): AuthorizeAttemptBody {
@@ -54,8 +53,18 @@ function requestOfBytes(bytes: number): { content: string } {
}
describe('ProviderAttemptAuthorizer', () => {
- it('T-R9-13a grants the envelope the same allowance as control-api', () => {
- expect(AUTHORIZE_ENVELOPE_ALLOWANCE_BYTES).toBe(CONTROL_API_ENVELOPE_ALLOWANCE_BYTES)
+ // R11 — control-api, both proxies and this authorizer import the allowance
+ // from the contracts. mcp-host has both contracts installed, so the parity
+ // check between them lives here. Each value is pinned first, so two missing
+ // exports cannot pass by comparing undefined with undefined.
+ it('T-R11-parity both contracts export the same 16 KiB envelope allowance', () => {
+ expect(CODEX_CONTRACT_ENVELOPE_ALLOWANCE_BYTES).toBe(16 * 1024)
+ expect(GROK_CONTRACT_ENVELOPE_ALLOWANCE_BYTES).toBe(16 * 1024)
+ expect(GROK_CONTRACT_ENVELOPE_ALLOWANCE_BYTES).toBe(CODEX_CONTRACT_ENVELOPE_ALLOWANCE_BYTES)
+ })
+
+ it('T-R9-13a grants the envelope the same allowance as control-api, from the contract', () => {
+ expect(AUTHORIZE_ENVELOPE_ALLOWANCE_BYTES).toBe(CODEX_CONTRACT_ENVELOPE_ALLOWANCE_BYTES)
})
it('T-R9-13b dispatches a request just under the cap in a realistic envelope', async () => {
@@ -83,7 +92,7 @@ describe('ProviderAttemptAuthorizer', () => {
readPlatformJwt: () => 'test-jwt',
fetchFn,
})
- const limit = LIMITS.maxRequestBodyBytes + CONTROL_API_ENVELOPE_ALLOWANCE_BYTES
+ const limit = LIMITS.maxRequestBodyBytes + CODEX_CONTRACT_ENVELOPE_ALLOWANCE_BYTES
const envelopeBytes = Buffer.byteLength(JSON.stringify(realisticEnvelope(requestOfBytes(100))))
const body = realisticEnvelope(requestOfBytes(limit + 1 - (envelopeBytes - 100)))
expect(Buffer.byteLength(JSON.stringify(body), 'utf8')).toBe(limit + 1)
diff --git a/packages/grok-provider-attempt-contract/index.test.cjs b/packages/grok-provider-attempt-contract/index.test.cjs
index 422e06c0d..dcf3c702c 100644
--- a/packages/grok-provider-attempt-contract/index.test.cjs
+++ b/packages/grok-provider-attempt-contract/index.test.cjs
@@ -40,6 +40,17 @@ test('declared LIMITS literals match the runtime values', () => {
assert.deepEqual(declared, { ...contract.LIMITS })
})
+// The proxy, control-api and mcp-host all import this allowance instead of
+// writing their own literal, so the declared literal type has to follow the
+// runtime value too.
+test('exports the 16 KiB envelope allowance with a matching declared literal', () => {
+ assert.equal(contract.ENVELOPE_ALLOWANCE_BYTES, 16 * 1024)
+ const declarations = fs.readFileSync(path.join(__dirname, 'index.d.ts'), 'utf8')
+ const declared = declarations.match(/export declare const ENVELOPE_ALLOWANCE_BYTES:\s*(\d+)\b/)
+ assert.ok(declared, 'index.d.ts must declare ENVELOPE_ALLOWANCE_BYTES as a numeric literal')
+ assert.equal(Number(declared[1]), contract.ENVELOPE_ALLOWANCE_BYTES)
+})
+
test('does not import Codex LIMITS or Codex provider id', () => {
const src = fs.readFileSync(path.join(__dirname, 'index.cjs'), 'utf8')
assert.equal(src.includes("require('../llm-provider-attempt-contract"), false)
diff --git a/packages/llm-provider-attempt-contract/index.test.cjs b/packages/llm-provider-attempt-contract/index.test.cjs
index 12b14b0fe..e232efccd 100644
--- a/packages/llm-provider-attempt-contract/index.test.cjs
+++ b/packages/llm-provider-attempt-contract/index.test.cjs
@@ -46,6 +46,17 @@ test('runtime exports stay aligned with the declaration file', () => {
assert.deepEqual(Object.keys(contract).sort(), declared)
})
+// The proxy, control-api and mcp-host all import this allowance instead of
+// writing their own literal, so the declared literal type has to follow the
+// runtime value too.
+test('exports the 16 KiB envelope allowance with a matching declared literal', () => {
+ assert.equal(contract.ENVELOPE_ALLOWANCE_BYTES, 16 * 1024)
+ const declarations = fs.readFileSync(path.join(__dirname, 'index.d.ts'), 'utf8')
+ const declared = declarations.match(/export declare const ENVELOPE_ALLOWANCE_BYTES:\s*(\d+)\b/)
+ assert.ok(declared, 'index.d.ts must declare ENVELOPE_ALLOWANCE_BYTES as a numeric literal')
+ assert.equal(Number(declared[1]), contract.ENVELOPE_ALLOWANCE_BYTES)
+})
+
test('parses the bounded V1 request and hashes with SHA-256', () => {
const parsed = contract.parseCodexCompletionRequestV1(BASE)
assert.equal(parsed.ok, true)