Evenfire is an intelligence layer platform for running LLM agents that take real actions, on your infrastructure
TypeScript
fix(test): r3-l4 restore absent gfs product-limit env
Josuéc9d008b45308
diff --git a/tests/e2e/gfsUploadV2Runtime.read.test.ts b/tests/e2e/gfsUploadV2Runtime.read.test.tsnew file mode 100644index 000000000..1e73bfae6--- /dev/null+++ b/tests/e2e/gfsUploadV2Runtime.read.test.ts@@ -0,0 +1,47 @@+import { beforeEach, describe, expect, it, vi } from 'vitest'+import { readGfsUploadProductMaxBytes } from './gfsUploadV2Runtime'++const { execFileMock, execFileSyncMock, kubectlContextMock } = vi.hoisted(() => ({+ execFileMock: vi.fn(),+ execFileSyncMock: vi.fn(),+ kubectlContextMock: vi.fn(() => 'clerum-test'),+}))++vi.mock('node:child_process', () => ({+ execFile: execFileMock,+ execFileSync: execFileSyncMock,+}))++vi.mock('./gfsFixtureCore', async importOriginal => ({+ ...(await importOriginal<typeof import('./gfsFixtureCore')>()),+ kubectlContext: kubectlContextMock,+}))++describe('readGfsUploadProductMaxBytes', () => {+ beforeEach(() => {+ execFileMock.mockReset()+ execFileSyncMock.mockReset()+ kubectlContextMock.mockClear()+ execFileMock.mockImplementation(+ (_file: unknown, args: unknown[], _options: unknown, callback: Function) => {+ const isJson = args.includes('-o') && args[args.indexOf('-o') + 1] === 'json'+ callback(null, {+ stdout: isJson+ ? JSON.stringify({ spec: { template: { spec: { containers: [{ env: [] }] } } } })+ : '',+ stderr: '',+ })+ }+ )+ })++ it('represents an absent rendered writer env without treating it as malformed', async () => {+ await expect(readGfsUploadProductMaxBytes()).resolves.toEqual({ kind: 'absent' })+ expect(execFileMock).toHaveBeenCalledWith(+ 'kubectl',+ expect.arrayContaining(['-o', 'json']),+ expect.anything(),+ expect.any(Function)+ )+ })+})diff --git a/tests/e2e/gfsUploadV2Runtime.test.ts b/tests/e2e/gfsUploadV2Runtime.test.tsnew file mode 100644index 000000000..ae51dd237--- /dev/null+++ b/tests/e2e/gfsUploadV2Runtime.test.ts@@ -0,0 +1,71 @@+import { describe, expect, it } from 'vitest'+import {+ buildGfsUploadProductMaxEnvArgs,+ parseGfsUploadProductMaxState,+ parseRenderedGfsUploadProductMax,+} from './gfsUploadV2Runtime'++function renderedDeployment(env: unknown[]): string {+ return JSON.stringify({+ spec: { template: { spec: { containers: [{ env }] } } },+ })+}++describe('GFS Upload v2 runtime product-limit helper', () => {+ it('round-trips an explicit baseline through set and restore command construction', () => {+ const baseline = parseGfsUploadProductMaxState(+ renderedDeployment([{ name: 'GFS_UPLOAD_PRODUCT_MAX_FILE_BYTES', value: '104857600' }])+ )++ expect(baseline).toEqual({ kind: 'explicit', value: 104857600 })+ expect(buildGfsUploadProductMaxEnvArgs(300 * 1024 * 1024)).toEqual([+ 'CONTEXT_MAPPER_GFSC_UPLOAD_PRODUCT_MAX_FILE_BYTES=314572800',+ 'CONTEXT_MAPPER_GFSC_UPLOAD_MAX_FILE_BYTES=314572800',+ ])+ expect(buildGfsUploadProductMaxEnvArgs(baseline)).toEqual([+ 'CONTEXT_MAPPER_GFSC_UPLOAD_PRODUCT_MAX_FILE_BYTES=104857600',+ 'CONTEXT_MAPPER_GFSC_UPLOAD_MAX_FILE_BYTES=104857600',+ ])+ })++ it('represents an absent baseline and constructs an explicit unset operation', () => {+ const baseline = parseGfsUploadProductMaxState(renderedDeployment([]))++ expect(baseline).toEqual({ kind: 'absent' })+ expect(buildGfsUploadProductMaxEnvArgs(300 * 1024 * 1024)).toEqual([+ 'CONTEXT_MAPPER_GFSC_UPLOAD_PRODUCT_MAX_FILE_BYTES=314572800',+ 'CONTEXT_MAPPER_GFSC_UPLOAD_MAX_FILE_BYTES=314572800',+ ])+ expect(buildGfsUploadProductMaxEnvArgs(baseline)).toEqual([+ 'CONTEXT_MAPPER_GFSC_UPLOAD_PRODUCT_MAX_FILE_BYTES-',+ 'CONTEXT_MAPPER_GFSC_UPLOAD_MAX_FILE_BYTES-',+ ])+ })++ it('fails closed for malformed present values instead of treating them as absent', () => {+ expect(() =>+ parseGfsUploadProductMaxState(+ renderedDeployment([{ name: 'GFS_UPLOAD_PRODUCT_MAX_FILE_BYTES', value: '' }])+ )+ ).toThrow('GFS writer rendered an invalid')+ expect(() =>+ parseGfsUploadProductMaxState(+ renderedDeployment([{ name: 'GFS_UPLOAD_PRODUCT_MAX_FILE_BYTES', value: '300MiB' }])+ )+ ).toThrow('GFS writer rendered an invalid')+ })++ it('rejects duplicate authoritative env entries and malformed deployment data', () => {+ expect(() =>+ parseRenderedGfsUploadProductMax(+ renderedDeployment([+ { name: 'GFS_UPLOAD_PRODUCT_MAX_FILE_BYTES', value: '100' },+ { name: 'GFS_UPLOAD_PRODUCT_MAX_FILE_BYTES', value: '300' },+ ])+ )+ ).toThrow('invalid rendered GFS_UPLOAD_PRODUCT_MAX_FILE_BYTES value')+ expect(() => parseRenderedGfsUploadProductMax('{"spec":{}}')).toThrow(+ 'invalid rendered GFS_UPLOAD_PRODUCT_MAX_FILE_BYTES deployment shape'+ )+ })+})diff --git a/tests/e2e/gfsUploadV2Runtime.ts b/tests/e2e/gfsUploadV2Runtime.tsindex 3228fde23..819a28b3f 100644--- a/tests/e2e/gfsUploadV2Runtime.ts+++ b/tests/e2e/gfsUploadV2Runtime.ts@@ -36,6 +36,8 @@ export interface ExpectedGfsRuntimeImageMarker {imagesGeneratedAt?: string}+export type GfsUploadProductMaxState = { kind: 'absent' } | { kind: 'explicit'; value: number }+/*** Local Minikube image mode intentionally has no registry tag. GHCR mode must* carry one because it is the immutable image coordinate that proves which@@ -234,17 +236,77 @@ async function renderedWriterFlag(): Promise<string> {).trim()}-async function renderedWriterProductMax(): Promise<string> {- return (- await kubectl([- '-n',- GFS_NAMESPACE,- 'get',- `deployment/${GFS_WRITER_DEPLOYMENT}`,- '-o',- `jsonpath={range .spec.template.spec.containers[*]}{range .env[?(@.name=="${GFS_PRODUCT_MAX_WRITER_ENV}")]}{.value}{end}{end}`,- ])- ).trim()+interface RenderedWriterEnv {+ name?: unknown+ value?: unknown+}++interface RenderedWriterDeployment {+ spec?: {+ template?: {+ spec?: {+ containers?: Array<{ env?: RenderedWriterEnv[] }>+ }+ }+ }+}++/**+ * Reads the complete deployment object so an absent env can be distinguished+ * from a present-but-malformed value. A malformed deployment or duplicate+ * authoritative env fails closed instead of being treated as the default.+ */+export function parseRenderedGfsUploadProductMax(raw: string): string | undefined {+ let deployment: RenderedWriterDeployment+ try {+ deployment = JSON.parse(raw) as RenderedWriterDeployment+ } catch {+ throw new Error(`invalid rendered ${GFS_PRODUCT_MAX_WRITER_ENV} deployment JSON`)+ }++ const containers = deployment.spec?.template?.spec?.containers+ if (!Array.isArray(containers)) {+ throw new Error(`invalid rendered ${GFS_PRODUCT_MAX_WRITER_ENV} deployment shape`)+ }+ const matches = containers.flatMap(container => {+ if (container === null || typeof container !== 'object') {+ throw new Error(`invalid rendered ${GFS_PRODUCT_MAX_WRITER_ENV} container shape`)+ }+ if (container.env === undefined) return []+ if (!Array.isArray(container.env)) {+ throw new Error(`invalid rendered ${GFS_PRODUCT_MAX_WRITER_ENV} env shape`)+ }+ return container.env.filter(env => env?.name === GFS_PRODUCT_MAX_WRITER_ENV)+ })+ if (matches.length === 0) return undefined+ if (matches.length !== 1 || typeof matches[0]?.value !== 'string') {+ throw new Error(`invalid rendered ${GFS_PRODUCT_MAX_WRITER_ENV} value`)+ }+ return matches[0].value+}++export function parseGfsUploadProductMaxState(raw: string): GfsUploadProductMaxState {+ const value = parseRenderedGfsUploadProductMax(raw)+ if (value === undefined) return { kind: 'absent' }+ return {+ kind: 'explicit',+ value: validateGfsUploadProductMaxBytes(parseCanonicalProductMax(value)),+ }+}++function parseCanonicalProductMax(value: string): number {+ if (!/^[1-9]\d*$/.test(value)) {+ throw new Error(+ `GFS writer rendered an invalid ${GFS_PRODUCT_MAX_WRITER_ENV} value: ${value || '<empty>'}`+ )+ }+ return Number(value)+}++async function renderedWriterProductMax(): Promise<string | undefined> {+ return parseRenderedGfsUploadProductMax(+ await kubectl(['-n', GFS_NAMESPACE, 'get', `deployment/${GFS_WRITER_DEPLOYMENT}`, '-o', 'json'])+ )}async function waitForRenderedWriterFlag(expected: boolean): Promise<void> {@@ -261,17 +323,17 @@ async function waitForRenderedWriterFlag(expected: boolean): Promise<void> {)}-async function waitForRenderedWriterProductMax(expected: number): Promise<void> {- const expectedValue = String(expected)+async function waitForRenderedWriterProductMax(expected: number | undefined): Promise<void> {+ const expectedValue = expected === undefined ? '<absent>' : String(expected)const deadline = Date.now() + 240_000- let lastValue = ''+ let lastValue: string | undefinedwhile (Date.now() < deadline) {lastValue = await renderedWriterProductMax()- if (lastValue === expectedValue) return+ if (lastValue === (expected === undefined ? undefined : expectedValue)) returnawait new Promise(resolve => setTimeout(resolve, 1_000))}throw new Error(- `GFS Upload v2 product maximum did not converge to ${expectedValue}; observed ${lastValue || '<empty>'}`+ `GFS Upload v2 product maximum did not converge to ${expectedValue}; observed ${lastValue || '<absent>'}`)}@@ -341,18 +403,37 @@ export async function readGfsUploadV2Enabled(): Promise<boolean> {* reader to converge. The caller must restore the original value in a finally* block. This changes policy only; the compiled protocol geometry is untouched.*/-export async function setGfsUploadProductMaxBytes(productMaxBytes: number): Promise<void> {- const validated = validateGfsUploadProductMaxBytes(productMaxBytes)+export function buildGfsUploadProductMaxEnvArgs(+ state: GfsUploadProductMaxState | number+): string[] {+ if (typeof state === 'number') {+ const validated = validateGfsUploadProductMaxBytes(state)+ return [+ `${GFS_PRODUCT_MAX_HCC_ENV}=${String(validated)}`,+ `${GFS_PRODUCT_MAX_HCC_ALIAS_ENV}=${String(validated)}`,+ ]+ }+ if (state.kind === 'absent') {+ return [`${GFS_PRODUCT_MAX_HCC_ENV}-`, `${GFS_PRODUCT_MAX_HCC_ALIAS_ENV}-`]+ }+ if (state.kind === 'explicit') {+ const validated = validateGfsUploadProductMaxBytes(state.value)+ return [+ `${GFS_PRODUCT_MAX_HCC_ENV}=${String(validated)}`,+ `${GFS_PRODUCT_MAX_HCC_ALIAS_ENV}=${String(validated)}`,+ ]+ }+ throw new Error('invalid GFS Upload v2 product maximum restoration state')+}++export async function setGfsUploadProductMaxBytes(+ state: GfsUploadProductMaxState | number+): Promise<void> {+ const envArgs = buildGfsUploadProductMaxEnvArgs(state)+ const expected =+ typeof state === 'number' ? state : state.kind === 'explicit' ? state.value : undefinedawait assertOwnedRuntimeContext()- await kubectl([- '-n',- HCC_NAMESPACE,- 'set',- 'env',- `deployment/${HCC_DEPLOYMENT}`,- `${GFS_PRODUCT_MAX_HCC_ENV}=${String(validated)}`,- `${GFS_PRODUCT_MAX_HCC_ALIAS_ENV}=${String(validated)}`,- ])+ await kubectl(['-n', HCC_NAMESPACE, 'set', 'env', `deployment/${HCC_DEPLOYMENT}`, ...envArgs])await kubectl(['-n',HCC_NAMESPACE,@@ -361,19 +442,18 @@ export async function setGfsUploadProductMaxBytes(productMaxBytes: number): Prom`deployment/${HCC_DEPLOYMENT}`,'--timeout=240s',])- await waitForRenderedWriterProductMax(validated)+ await waitForRenderedWriterProductMax(expected)await waitForDeployment(GFS_WRITER_DEPLOYMENT)await waitForDeployment(GFS_READER_DEPLOYMENT)}-export async function readGfsUploadProductMaxBytes(): Promise<number> {+export async function readGfsUploadProductMaxBytes(): Promise<GfsUploadProductMaxState> {const value = await renderedWriterProductMax()- if (!/^[1-9]\d*$/.test(value)) {- throw new Error(- `GFS writer rendered an invalid ${GFS_PRODUCT_MAX_WRITER_ENV} value: ${value || '<empty>'}`- )+ if (value === undefined) return { kind: 'absent' }+ return {+ kind: 'explicit',+ value: validateGfsUploadProductMaxBytes(parseCanonicalProductMax(value)),}- return validateGfsUploadProductMaxBytes(Number(value))}export async function restartGfsWriter(): Promise<void> {diff --git a/tests/e2e/package-lock.json b/tests/e2e/package-lock.jsonindex 5ace9758b..8b6c35470 100644--- a/tests/e2e/package-lock.json+++ b/tests/e2e/package-lock.json@@ -1,12 +1,12 @@{"name": "clerum-e2e-tests",- "version": "0.1.67",+ "version": "0.1.68","lockfileVersion": 3,"requires": true,"packages": {"": {"name": "clerum-e2e-tests",- "version": "0.1.67",+ "version": "0.1.68","devDependencies": {"@types/jsonwebtoken": "^9.0.10","@types/node": "^22.0.0",diff --git a/tests/e2e/package.json b/tests/e2e/package.jsonindex 6770e4a49..b2262ef2a 100644--- a/tests/e2e/package.json+++ b/tests/e2e/package.json@@ -1,6 +1,6 @@{"name": "clerum-e2e-tests",- "version": "0.1.67",+ "version": "0.1.68","private": true,"type": "module","scripts": {