Evenfire is an intelligence layer platform for running LLM agents that take real actions, on your infrastructure
TypeScript
test(e2e): register chat-body parity in the node-unit gate
Alfredo Lopez2b569d72de87
diff --git a/scripts/e2e/run-vitest-e2e.sh b/scripts/e2e/run-vitest-e2e.shindex ba1530fc5..263a05783 100755--- a/scripts/e2e/run-vitest-e2e.sh+++ b/scripts/e2e/run-vitest-e2e.sh@@ -16,6 +16,9 @@ DEFAULT_NODE_UNIT_VITEST_SUITES=(# Codex subscription contract freeze: reads only repository files, so it# belongs in the node-unit group and not behind a cluster.integration/codex-subscription-contract-freeze.test.ts+ # Chat body budget parity (#678): compares rpc-proxy, mcp-host and composer+ # sources, so it needs no cluster either.+ integration/chat-body-budget-parity.test.ts)DEFAULT_CLUSTER_VITEST_SUITES=(gfsUploadProductMutation.test.tsdiff --git a/scripts/tests/test-e2e-vitest-node-unit-gate.sh b/scripts/tests/test-e2e-vitest-node-unit-gate.shindex bb0c30a62..8d52ad07e 100755--- a/scripts/tests/test-e2e-vitest-node-unit-gate.sh+++ b/scripts/tests/test-e2e-vitest-node-unit-gate.sh@@ -142,6 +142,8 @@ require_contains "${RUNNER}" "gfsUploadV2Fixtures.test.ts" \"descriptor fixture suite registration"require_node_unit_suite "integration/codex-subscription-contract-freeze.test.ts" \"Codex subscription contract freeze node-unit registration"+require_node_unit_suite "integration/chat-body-budget-parity.test.ts" \+ "chat body budget parity node-unit registration"require_contains "${RUNNER}" "E2E_VITEST_SUITE_GROUP" \"suite-group selector"require_contains "${RUNNER}" "if [[ \"\${VITEST_SUITE_GROUP}\" == \"node-unit\" ]]" \diff --git a/tests/e2e/integration/chat-body-budget-parity.test.ts b/tests/e2e/integration/chat-body-budget-parity.test.tsindex 07686e836..50d62f0da 100644--- a/tests/e2e/integration/chat-body-budget-parity.test.ts+++ b/tests/e2e/integration/chat-body-budget-parity.test.ts@@ -26,6 +26,11 @@ const sources = {mcpHost: readFileSync(join(repoRoot, 'mcp-host/src/server.ts'), 'utf8'),composer: readFileSync(join(repoRoot, 'desktop-app/ui/src/constants/attachments.ts'), 'utf8'),hostConfig: readFileSync(join(repoRoot, 'mcp-host/src/config.ts'), 'utf8'),+ hostAdmission: readFileSync(join(repoRoot, 'mcp-host/src/agent/incomingAttachments.ts'), 'utf8'),+ rpcProxyForwardingTest: readFileSync(+ join(repoRoot, 'rpc-proxy/src/__tests__/wake-and-hold-route.test.ts'),+ 'utf8'+ ),}function soleMatch(source: string, pattern: RegExp, label: string): RegExpMatchArray {@@ -68,7 +73,21 @@ const SERVER_LIMITS: ReadonlyArray<readonly [string, number]> = [['MAX_FILE_BASE64_BYTES_TOTAL', 16 * MIB],]+/** Declarations both parsers must spell identically, with the value they must have. */+const SERVER_DECLARATIONS: ReadonlyArray<readonly [string, string]> = [+ ['BASE64_RE', '/^[A-Za-z0-9+/]+={0,2}$/'],+ ['PNG_SIGNATURE', 'Buffer.from([0x89, 0x50, 0x4e, 0x47, 0x0d, 0x0a, 0x1a, 0x0a])'],+ ['JPEG_SIGNATURE', 'Buffer.from([0xff, 0xd8, 0xff])'],+]++/** One trimmed source line of `functionText` that starts with `prefix`. */+function soleLine(functionText: string, prefix: string, label: string): string {+ const escaped = prefix.replace(/[.*+?^${}()|[\]\\]/g, '\\$&')+ return soleMatch(functionText, new RegExp(`^ *${escaped}.*$`, 'm'), label)[0].trim()+}+const BUDGET_FUNCTIONS = [+ 'base64SextetValue','decodedBase64Bytes','inspectChatImageBudget','inspectChatFileBudget',@@ -89,6 +108,14 @@ describe('chat body budget parity across rpc-proxy, mcp-host and the composer (#expect(mcpHost).toBe(rpcProxy)})+ it.each(SERVER_DECLARATIONS)('both parsers declare %s as the same value', (name, expected) => {+ const pattern = new RegExp(`^const ${name} = (.+)$`, 'm')+ const rpcProxy = soleMatch(sources.rpcProxy, pattern, `rpc-proxy ${name}`)[1]+ const mcpHost = soleMatch(sources.mcpHost, pattern, `mcp-host ${name}`)[1]+ expect(rpcProxy).toBe(expected)+ expect(mcpHost).toBe(rpcProxy)+ })+it.each(BUDGET_FUNCTIONS)('both parsers implement %s identically', name => {const rpcProxy = functionSource(sources.rpcProxy, name, 'rpc-proxy')const mcpHost = functionSource(sources.mcpHost, name, 'mcp-host')@@ -99,13 +126,18 @@ describe('chat body budget parity across rpc-proxy, mcp-host and the composer (#it('credits a file by its decoded size, bounded by the per-file and total quotas', () => {const inspect = functionSource(sources.rpcProxy, 'inspectChatFileBudget', 'rpc-proxy')- expect(inspect).toContain('decoded > MAX_FILE_DECODED_BYTES')- expect(inspect).toContain('credited + dataBase64.length > MAX_FILE_BASE64_BYTES_TOTAL')- expect(inspect).toContain('counted >= MAX_CHAT_FILES')- expect(inspect).toContain('SHA256_HEX_RE.test(digest.hex)')+ expect(soleLine(inspect, 'if (decoded === null', 'per-file credit condition')).toBe(+ 'if (decoded === null || decoded <= 0 || decoded > MAX_FILE_DECODED_BYTES) continue'+ )+ expect(soleLine(inspect, 'if (counted >=', 'file quota condition')).toBe(+ 'if (counted >= MAX_CHAT_FILES || credited + dataBase64.length > MAX_FILE_BASE64_BYTES_TOTAL) {'+ )+ expect(soleLine(inspect, '!SHA256_HEX_RE.test(', 'digest condition')).toBe(+ '!SHA256_HEX_RE.test(digest.hex)'+ )const exceeds = functionSource(sources.rpcProxy, 'chatBodyExceedsNonImageBudget', 'rpc-proxy')- expect(exceeds).toContain(- 'rawBodyBytes - images.creditedBase64 - files.creditedBase64 > MAX_NON_IMAGE_BODY_BYTES'+ expect(soleLine(exceeds, 'return rawBodyBytes', 'non-image share condition')).toBe(+ 'return rawBodyBytes - images.creditedBase64 - files.creditedBase64 > MAX_NON_IMAGE_BODY_BYTES')})@@ -127,13 +159,28 @@ describe('chat body budget parity across rpc-proxy, mcp-host and the composer (#'COMPOSER_MAX_TOTAL_FILE_BASE64_BYTES',constantValue(sources.rpcProxy, 'MAX_FILE_BASE64_BYTES_TOTAL', 'rpc-proxy'),],- ['COMPOSER_MAX_ATTACHMENTS', constantValue(sources.rpcProxy, 'MAX_CHAT_FILES', 'rpc-proxy')],+ // The composer counts images and files together, as the Host admission does;+ // MAX_CHAT_FILES bounds only the credited files.+ [+ 'COMPOSER_MAX_ATTACHMENTS',+ constantValue(sources.hostAdmission, 'INCOMING_ATTACHMENT_MAX_COUNT', 'mcp-host admission'),+ ],]for (const [name, serverValue] of composer) {expect(constantValue(sources.composer, name, 'composer'), name).toBe(serverValue)}})+ it('the composer reserves the headroom rpc-proxy is tested to add when forwarding', () => {+ expect(constantValue(sources.composer, 'COMPOSER_FORWARDED_FIELDS_BYTES', 'composer')).toBe(+ constantValue(+ sources.rpcProxyForwardingTest,+ 'DESKTOP_FORWARDED_FIELDS_HEADROOM_BYTES',+ 'rpc-proxy forwarding test'+ )+ )+ })+it('the Host admission default equals the per-file credit ceiling', () => {const [, literal] = soleMatch(sources.hostConfig,diff --git a/tests/e2e/package-lock.json b/tests/e2e/package-lock.jsonindex c4e9efb72..5111bfe43 100644--- a/tests/e2e/package-lock.json+++ b/tests/e2e/package-lock.json@@ -1,12 +1,12 @@{"name": "clerum-e2e-tests",- "version": "0.1.97",+ "version": "0.1.98","lockfileVersion": 3,"requires": true,"packages": {"": {"name": "clerum-e2e-tests",- "version": "0.1.97",+ "version": "0.1.98","devDependencies": {"@clerum/llm-provider-attempt-contract": "file:../../packages/llm-provider-attempt-contract","@types/jsonwebtoken": "^9.0.10",diff --git a/tests/e2e/package.json b/tests/e2e/package.jsonindex e3c2c5a98..c27e783d6 100644--- a/tests/e2e/package.json+++ b/tests/e2e/package.json@@ -1,6 +1,6 @@{"name": "clerum-e2e-tests",- "version": "0.1.97",+ "version": "0.1.98","private": true,"type": "module","scripts": {diff --git a/tests/e2e/tsconfig.node-unit.json b/tests/e2e/tsconfig.node-unit.jsonindex bec9f95d6..e36908249 100644--- a/tests/e2e/tsconfig.node-unit.json+++ b/tests/e2e/tsconfig.node-unit.json@@ -4,5 +4,9 @@"noEmit": true},"include": [],- "files": ["gfsUploadV2Fixtures.test.ts", "integration/codex-subscription-contract-freeze.test.ts"]+ "files": [+ "gfsUploadV2Fixtures.test.ts",+ "integration/codex-subscription-contract-freeze.test.ts",+ "integration/chat-body-budget-parity.test.ts"+ ]}