Evenfire is an intelligence layer platform for running LLM agents that take real actions, on your infrastructure
TypeScript
fix(test): r4-m4 reject vacuous upload transport contracts
Josué3004e1ba3883
diff --git a/control-api/package-lock.json b/control-api/package-lock.jsonindex e0697b7ef..86fb0fcd1 100644--- a/control-api/package-lock.json+++ b/control-api/package-lock.json@@ -1,12 +1,12 @@{"name": "clerum-control-api",- "version": "0.1.489",+ "version": "0.1.490","lockfileVersion": 3,"requires": true,"packages": {"": {"name": "clerum-control-api",- "version": "0.1.489",+ "version": "0.1.490","dependencies": {"@clerum/display-field": "file:../packages/display-field","@clerum/image-policy": "file:../packages/image-policy",diff --git a/control-api/package.json b/control-api/package.jsonindex ed0cabcc0..9b05f4639 100644--- a/control-api/package.json+++ b/control-api/package.json@@ -1,6 +1,6 @@{"name": "clerum-control-api",- "version": "0.1.489",+ "version": "0.1.490","description": "Internal Clerum control plane REST API + UI for managing CRDs and secrets","main": "dist/main.js","engines": {diff --git a/control-api/test/helpers/uploadV2TransportBounds.ts b/control-api/test/helpers/uploadV2TransportBounds.tsnew file mode 100644index 000000000..415988efa--- /dev/null+++ b/control-api/test/helpers/uploadV2TransportBounds.ts@@ -0,0 +1,36 @@+import type { BoundedEnvBytes } from './staticSourceAuthority.js'++export function assertUploadV2TransportBounds(input: {+ writerProtocol: number+ writerPart: number+ protocolMirrors: number[]+ partMirrors: number[]+ relayBounds: BoundedEnvBytes[]+ gatewayBytes: number+}): void {+ if (input.protocolMirrors.length === 0)+ throw new Error('protocol mirrors must contain at least one producer')+ if (input.partMirrors.length === 0)+ throw new Error('part mirrors must contain at least one producer')+ if (input.relayBounds.length === 0)+ throw new Error('relay bounds must contain at least one producer')+ if (input.writerProtocol !== 1024 * 1024 * 1024)+ throw new Error('writer protocol maximum must remain 1 GiB')+ if (input.writerPart !== 16 * 1024 * 1024)+ throw new Error('writer part maximum must remain 16 MiB')+ if (input.writerPart >= input.writerProtocol)+ throw new Error('writer part maximum must be below the protocol maximum')+ if (input.protocolMirrors.some(value => value !== input.writerProtocol))+ throw new Error('client protocol maximum diverges from the writer')+ if (input.partMirrors.some(value => value !== input.writerPart))+ throw new Error('client part maximum diverges from the writer')+ if (+ input.relayBounds.some(+ bounds => bounds.fallback !== input.writerPart || bounds.ceiling !== input.writerPart+ )+ ) {+ throw new Error('relay part maximum diverges from the writer')+ }+ if (input.writerPart >= input.gatewayBytes)+ throw new Error('gateway request cap cannot safely carry an Upload v2 part')+}diff --git a/control-api/test/network.gateway.intent.test.ts b/control-api/test/network.gateway.intent.test.tsindex a204b430a..4538e2369 100644--- a/control-api/test/network.gateway.intent.test.ts+++ b/control-api/test/network.gateway.intent.test.ts@@ -1,6 +1,10 @@import { describe, expect, it } from 'vitest'import { existsSync, readFileSync, readdirSync, statSync } from 'node:fs'-import ts from 'typescript'+import {+ boundedEnvBytesFromSource,+ staticExportedBytesFromSource,+} from './helpers/staticSourceAuthority.js'+import { assertUploadV2TransportBounds } from './helpers/uploadV2TransportBounds.js'/** Paths are relative to this file: control-api/test/ → repo root is ../.. */const BASE = '../../deploy/base'@@ -84,100 +88,8 @@ function escapeRegExp(value: string): string {return value.replace(/[.*+?^${}()|[\]\\]/g, '\\$&')}-function parseTypeScript(source: string, label: string): ts.SourceFile {- const file = ts.createSourceFile(label, source, ts.ScriptTarget.Latest, true, ts.ScriptKind.TS)- const diagnostics = (file as ts.SourceFile & { parseDiagnostics: readonly ts.Diagnostic[] })- .parseDiagnostics- if (diagnostics.length > 0) throw new Error(`${label} contains malformed TypeScript`)- return file-}--function evaluateStaticByteExpression(- expression: ts.Expression,- sourceFile: ts.SourceFile,- label: string-): number {- if (ts.isNumericLiteral(expression)) {- const literal = expression.getText(sourceFile)- if (!/^(?:0|[1-9][0-9]*(?:_[0-9]+)*)$/.test(literal))- throw new Error(`${label} must use a decimal integer literal`)- const value = Number(literal.replaceAll('_', ''))- if (!Number.isSafeInteger(value)) throw new Error(`${label} must be a safe integer`)- return value- }- if (- ts.isBinaryExpression(expression) &&- expression.operatorToken.kind === ts.SyntaxKind.AsteriskToken- ) {- const left = evaluateStaticByteExpression(expression.left, sourceFile, label)- const right = evaluateStaticByteExpression(expression.right, sourceFile, label)- const value = left * right- if (!Number.isSafeInteger(value)) throw new Error(`${label} must be a safe integer`)- return value- }- throw new Error(`${label} must use only decimal integers and multiplication`)-}--function staticBytesFromSource(source: string, symbol: string, label = symbol): number {- const sourceFile = parseTypeScript(source, label)- const matches: ts.VariableDeclaration[] = []- const visit = (node: ts.Node): void => {- if (- ts.isVariableDeclaration(node) &&- ts.isIdentifier(node.name) &&- node.name.text === symbol &&- ts.isVariableDeclarationList(node.parent) &&- (node.parent.flags & ts.NodeFlags.Const) !== 0- ) {- matches.push(node)- }- ts.forEachChild(node, visit)- }- visit(sourceFile)- if (matches.length !== 1 || !matches[0].initializer)- throw new Error(`${symbol} must have exactly one active const initializer in ${label}`)- return evaluateStaticByteExpression(matches[0].initializer, sourceFile, `${label}:${symbol}`)-}-function staticBytes(relPath: string, symbol: string): number {- return staticBytesFromSource(read(relPath), symbol, relPath)-}--function boundedEnvBytesFromSource(- source: string,- property: string,- envName: string,- label = envName-): { fallback: number; ceiling: number } {- const sourceFile = parseTypeScript(source, label)- const properties: ts.PropertyAssignment[] = []- const visit = (node: ts.Node): void => {- if (ts.isPropertyAssignment(node)) {- const propertyName =- ts.isIdentifier(node.name) || ts.isStringLiteral(node.name) ? node.name.text : null- if (propertyName === property) properties.push(node)- }- ts.forEachChild(node, visit)- }- visit(sourceFile)- if (properties.length !== 1)- throw new Error(`${envName} must have exactly one active bounded config in ${label}`)- const initializer = properties[0].initializer- if (- !ts.isCallExpression(initializer) ||- !ts.isIdentifier(initializer.expression) ||- initializer.expression.text !== 'boundedIntegerFromEnv' ||- initializer.arguments.length !== 3 ||- !ts.isStringLiteral(initializer.arguments[0]) ||- initializer.arguments[0].text !== envName- ) {- throw new Error(`${envName} must use the expected boundedIntegerFromEnv call in ${label}`)- }- const [, fallback, ceiling] = initializer.arguments- return {- fallback: evaluateStaticByteExpression(fallback, sourceFile, `${label}:${envName}:fallback`),- ceiling: evaluateStaticByteExpression(ceiling, sourceFile, `${label}:${envName}:ceiling`),- }+ return staticExportedBytesFromSource(read(relPath), symbol, relPath)}function boundedEnvBytes(@@ -185,35 +97,7 @@ function boundedEnvBytes(property: string,envName: string): { fallback: number; ceiling: number } {- return boundedEnvBytesFromSource(read(relPath), property, envName, relPath)-}--function assertUploadV2TransportBounds(input: {- writerProtocol: number- writerPart: number- protocolMirrors: number[]- partMirrors: number[]- relayBounds: Array<{ fallback: number; ceiling: number }>- gatewayBytes: number-}): void {- if (input.writerProtocol !== 1024 * 1024 * 1024)- throw new Error('writer protocol maximum must remain 1 GiB')- if (input.writerPart !== 16 * 1024 * 1024)- throw new Error('writer part maximum must remain 16 MiB')- if (input.writerPart >= input.writerProtocol)- throw new Error('writer part maximum must be below the protocol maximum')- if (input.protocolMirrors.some(value => value !== input.writerProtocol))- throw new Error('client protocol maximum diverges from the writer')- if (input.partMirrors.some(value => value !== input.writerPart))- throw new Error('client part maximum diverges from the writer')- if (- input.relayBounds.some(- bounds => bounds.fallback !== input.writerPart || bounds.ceiling !== input.writerPart- )- )- throw new Error('relay part maximum diverges from the writer')- if (input.writerPart >= input.gatewayBytes)- throw new Error('gateway request cap cannot safely carry an Upload v2 part')+ return boundedEnvBytesFromSource(read(relPath), 'config', property, envName, relPath)}function expectCanonicalPublicEgressExceptions(): void {@@ -379,123 +263,6 @@ function routeIsAllowlisted(route: RouteRef, locations: NginxLocation[]): boolea// invariants in deploy/base/{rpc-proxy,control-plane,mcp-host}/ keep the gateway// topology locked down (rpc-proxy egress only via control-api-rpc-gateway, HCC// ingress only via host-context-controller-api-gateway, and nginx allowlist routes).-describe('GFS static byte contract extraction', () => {- const SYMBOL = 'GFS_UPLOAD_V2_MAX_PART_BYTES'-- it.each([- ['exported multiplication', `export const ${SYMBOL} = 16 * 1024 * 1024`],- ['non-exported multiplication', `const ${SYMBOL} = 16 * 1024 * 1024`],- ['numeric separators', `export const ${SYMBOL} = 16 * 1_024 * 1_024`],- ])('accepts %s', (_label, source) => {- expect(staticBytesFromSource(source, SYMBOL)).toBe(16 * 1024 * 1024)- })-- it.each([- ['addition', `export const ${SYMBOL} = 16 * 1024 * 1024 + 1`],- ['division', `export const ${SYMBOL} = 16 * 1024 * 1024 / 2`],- ['identifier', `export const ${SYMBOL} = 16 * 1024 * SOME_IDENTIFIER`],- ['malformed trailing expression', `export const ${SYMBOL} = 16 * 1024 * 1024 nonsense`],- ['line-comment only', `// export const ${SYMBOL} = 16 * 1024 * 1024`],- ['block-comment only', `/* export const ${SYMBOL} = 16 * 1024 * 1024 */`],- ])('rejects %s', (_label, source) => {- expect(() => staticBytesFromSource(source, SYMBOL)).toThrow()- })-- it('ignores a commented safe declaration before a live unsafe declaration', () => {- const source = [- `// export const ${SYMBOL} = 16 * 1024 * 1024`,- `export const ${SYMBOL} = 17 * 1024 * 1024`,- ].join('\n')- expect(staticBytesFromSource(source, SYMBOL)).toBe(17 * 1024 * 1024)- })-- it('rejects a commented relay bound without a live producer', () => {- const source = [- '// gfsUploadMaxPartBytes: boundedIntegerFromEnv(',- "// 'CONTROL_API_GFS_UPLOAD_MAX_PART_BYTES',",- '// 16 * 1024 * 1024,',- '// 16 * 1024 * 1024',- '// ),',- ].join('\n')- expect(() =>- boundedEnvBytesFromSource(- source,- 'gfsUploadMaxPartBytes',- 'CONTROL_API_GFS_UPLOAD_MAX_PART_BYTES'- )- ).toThrow()- })-- it.each([- ['different env', `gfsUploadMaxPartBytes: boundedIntegerFromEnv('OTHER_MAX_BYTES', 1, 1),`],- [- 'different bounds',- `gfsUploadMaxPartBytes: boundedIntegerFromEnv('CONTROL_API_GFS_UPLOAD_MAX_PART_BYTES', 1, 1),`,- ],- ])('rejects duplicate active relay properties with %s', (_label, duplicate) => {- const source = `const config = {- gfsUploadMaxPartBytes: boundedIntegerFromEnv('CONTROL_API_GFS_UPLOAD_MAX_PART_BYTES', 16 * 1024 * 1024, 16 * 1024 * 1024),- ${duplicate}- }`- expect(() =>- boundedEnvBytesFromSource(- source,- 'gfsUploadMaxPartBytes',- 'CONTROL_API_GFS_UPLOAD_MAX_PART_BYTES'- )- ).toThrow()- })-- it('ignores commented duplicates and similarly named unrelated properties', () => {- const source = `const config = {- // gfsUploadMaxPartBytes: boundedIntegerFromEnv('OTHER_MAX_BYTES', 1, 1),- gfsUploadMaxPartBytesExtra: boundedIntegerFromEnv('OTHER_MAX_BYTES', 1, 1),- gfsUploadMaxPartBytes: boundedIntegerFromEnv('CONTROL_API_GFS_UPLOAD_MAX_PART_BYTES', 16 * 1024 * 1024, 16 * 1024 * 1024),- }`- expect(- boundedEnvBytesFromSource(- source,- 'gfsUploadMaxPartBytes',- 'CONTROL_API_GFS_UPLOAD_MAX_PART_BYTES'- )- ).toEqual({ fallback: 16 * 1024 * 1024, ceiling: 16 * 1024 * 1024 })- })-- it.each([- 'gfsUploadMaxPartBytes: 16 * 1024 * 1024,',- "gfsUploadMaxPartBytes: boundedIntegerFromEnv('CONTROL_API_GFS_UPLOAD_MAX_PART_BYTES', 16 * 1024 * 1024),",- ])('rejects malformed or unsupported relay property %s', propertySource => {- expect(() =>- boundedEnvBytesFromSource(- `const config = { ${propertySource} }`,- 'gfsUploadMaxPartBytes',- 'CONTROL_API_GFS_UPLOAD_MAX_PART_BYTES'- )- ).toThrow()- })-- it('turns red when the effective writer part maximum exceeds a relay ceiling', () => {- expect(() =>- assertUploadV2TransportBounds(- (() => {- const unsafeWriterPart = staticBytesFromSource(- `export const ${SYMBOL} = 17 * 1024 * 1024`,- SYMBOL- )- return {- writerProtocol: 1024 * 1024 * 1024,- writerPart: unsafeWriterPart,- protocolMirrors: [1024 * 1024 * 1024],- partMirrors: [unsafeWriterPart],- relayBounds: [{ fallback: 16 * 1024 * 1024, ceiling: 16 * 1024 * 1024 }],- gatewayBytes: 24 * 1024 * 1024,- }- })()- )- ).toThrow(/writer part maximum|relay part maximum/)- })-})-describe('network/gateway intent (manifest-level)', () => {it('ships a GFS namespace default-deny policy while HCC owns gfsc allowlists', () => {const gfsKustomization = read(`${BASE}/gfs/kustomization.yaml`)diff --git a/control-api/test/uploadV2TransportBounds.test.ts b/control-api/test/uploadV2TransportBounds.test.tsnew file mode 100644index 000000000..70713ad02--- /dev/null+++ b/control-api/test/uploadV2TransportBounds.test.ts@@ -0,0 +1,35 @@+import { describe, expect, it } from 'vitest'+import { assertUploadV2TransportBounds } from './helpers/uploadV2TransportBounds.js'++describe('Upload v2 transport-bound non-vacuity', () => {+ const valid = {+ writerProtocol: 1024 * 1024 * 1024,+ writerPart: 16 * 1024 * 1024,+ protocolMirrors: [1024 * 1024 * 1024],+ partMirrors: [16 * 1024 * 1024],+ relayBounds: [{ fallback: 16 * 1024 * 1024, ceiling: 16 * 1024 * 1024 }],+ gatewayBytes: 24 * 1024 * 1024,+ }++ it('accepts a complete aligned producer chain', () => {+ expect(() => assertUploadV2TransportBounds(valid)).not.toThrow()+ })++ it.each(['protocolMirrors', 'partMirrors', 'relayBounds'] as const)(+ 'rejects an empty %s producer list',+ field => {+ expect(() => assertUploadV2TransportBounds({ ...valid, [field]: [] })).toThrow(+ /at least one producer/+ )+ }+ )++ it.each([+ ['writer part above its relay', { writerPart: 17 * 1024 * 1024 }],+ ['client part above its relay', { partMirrors: [17 * 1024 * 1024] }],+ ['undersized relay', { relayBounds: [{ fallback: 15, ceiling: 15 }] }],+ ['undersized gateway', { gatewayBytes: 16 * 1024 * 1024 }],+ ])('rejects %s', (_label, mutation) => {+ expect(() => assertUploadV2TransportBounds({ ...valid, ...mutation })).toThrow()+ })+})diff --git a/control-ui/app/control-api/[...path]/route.ts b/control-ui/app/control-api/[...path]/route.tsindex 52b647a5a..d1069e480 100644--- a/control-ui/app/control-api/[...path]/route.ts+++ b/control-ui/app/control-api/[...path]/route.ts@@ -45,7 +45,7 @@ function resolveGfsUploadProxyTimeoutMs(): number {// default. Set CONTROL_UI_PROXY_MAX_BODY_BYTES on the deployment to change it.const DEFAULT_MAX_BODY_BYTES = 24 * 1024 * 1024const MAX_BODY_BYTES_CEILING = 512 * 1024 * 1024-const GFS_UPLOAD_MAX_PART_BYTES = 16 * 1024 * 1024+export const GFS_UPLOAD_MAX_PART_BYTES = 16 * 1024 * 1024function resolveMaxBodyBytes(): number {const raw = process.env.CONTROL_UI_PROXY_MAX_BODY_BYTESconst parsed = raw ? Number(raw) : Number.NaNdiff --git a/control-ui/package-lock.json b/control-ui/package-lock.jsonindex c6b258943..cb12f538b 100644--- a/control-ui/package-lock.json+++ b/control-ui/package-lock.json@@ -1,12 +1,12 @@{"name": "clerum-control-ui",- "version": "0.1.446",+ "version": "0.1.447","lockfileVersion": 3,"requires": true,"packages": {"": {"name": "clerum-control-ui",- "version": "0.1.446",+ "version": "0.1.447","dependencies": {"@clerum/display-field": "file:../packages/display-field","@clerum/llm-providers": "file:../packages/llm-providers",diff --git a/control-ui/package.json b/control-ui/package.jsonindex 73e7bf984..a389c6693 100644--- a/control-ui/package.json+++ b/control-ui/package.json@@ -1,6 +1,6 @@{"name": "clerum-control-ui",- "version": "0.1.446",+ "version": "0.1.447","private": true,"scripts": {"dev": "NEXT_IGNORE_INCORRECT_LOCKFILE=1 next dev",diff --git a/external-rest-api/package-lock.json b/external-rest-api/package-lock.jsonindex e7adc5bb0..4ee9bf8fc 100644--- a/external-rest-api/package-lock.json+++ b/external-rest-api/package-lock.json@@ -1,12 +1,12 @@{"name": "clerum-external-rest-api",- "version": "0.1.80",+ "version": "0.1.81","lockfileVersion": 3,"requires": true,"packages": {"": {"name": "clerum-external-rest-api",- "version": "0.1.80",+ "version": "0.1.81","dependencies": {"cors": "^2.8.5","express": "^4.21.2",diff --git a/external-rest-api/package.json b/external-rest-api/package.jsonindex b3dc59f36..e2320af8d 100644--- a/external-rest-api/package.json+++ b/external-rest-api/package.json@@ -1,6 +1,6 @@{"name": "clerum-external-rest-api",- "version": "0.1.80",+ "version": "0.1.81","description": "External REST API for profile, team management, and RPC token brokerage","main": "dist/main.js","engines": {diff --git a/external-rest-api/src/config.ts b/external-rest-api/src/config.tsindex c0004d9df..4c24d431e 100644--- a/external-rest-api/src/config.ts+++ b/external-rest-api/src/config.ts@@ -198,7 +198,10 @@ export const config: Config = {// Coherent GFS-only tiers: token IP <= client IP < process aggregate. The// Control API's distributed 10/min token and 30/min session/actor budgets// remain authoritative.- ...externalGfsEdgeRateLimits,+ externalGfsEdgeAggregateRlPerMin: externalGfsEdgeRateLimits.externalGfsEdgeAggregateRlPerMin,+ externalGfsEdgeAuthenticatedIpRlPerMin:+ externalGfsEdgeRateLimits.externalGfsEdgeAuthenticatedIpRlPerMin,+ externalGfsEdgeTokenIpRlPerMin: externalGfsEdgeRateLimits.externalGfsEdgeTokenIpRlPerMin,}if (process.env.NODE_ENV === 'production' && config.corsOrigin === '*') {diff --git a/external-rest-api/src/releaseManifest.ts b/external-rest-api/src/releaseManifest.tsindex 0ae6125bb..127cbd36a 100644--- a/external-rest-api/src/releaseManifest.ts+++ b/external-rest-api/src/releaseManifest.ts@@ -8,7 +8,7 @@ export type ReleaseManifest = {export const releaseManifest: ReleaseManifest = {releaseId: 'v0.7.0',- externalRestApiVersion: '0.1.80',+ externalRestApiVersion: '0.1.81',rpcProxyVersion: '0.1.65',desktopVersion: '0.7.0',minimumDesktopVersion: '0.1.252',