Evenfire is an intelligence layer platform for running LLM agents that take real actions, on your infrastructure
TypeScript
fix(e2e): mount a writable /tmp on the approved-tools fixture Control API
Alfredo Lopez093a88f02f6b
diff --git a/scripts/e2e/approved-tools-control-api-lifecycle.mjs b/scripts/e2e/approved-tools-control-api-lifecycle.mjsindex 5d3226d00..c5ca33c4f 100644--- a/scripts/e2e/approved-tools-control-api-lifecycle.mjs+++ b/scripts/e2e/approved-tools-control-api-lifecycle.mjs@@ -7,6 +7,11 @@ export const controlApiFlags = ['MINIKUBE_PROFILE','CONTROL_API_REAL_PG_CONTEXT',]+// The fixture entrypoint writes its activation marker to /tmp before starting the+// API, and the Control API Deployment runs with readOnlyRootFilesystem. The+// fixture patch mounts a run-scoped emptyDir there; the restore patch deletes it.+export const controlApiFixtureVolume = 'approved-tools-oauth-tmp'+export const controlApiFixtureMountPath = '/tmp'const runPattern = /^approved-tools-[a-f0-9]{12}$/function validateImage(image, policy) {@@ -47,16 +52,54 @@ function validateEnv(env, profile) {}}export function controlApiPatch({ metadata, image, imagePullPolicy, env, run }) {+ const fixture = image === controlApiFixtureImagereturn {metadata: { uid: metadata.uid, resourceVersion: metadata.resourceVersion },spec: {template: {metadata: { annotations: { [controlApiRunAnnotation]: run } },- spec: { containers: [{ name: 'control-api', image, imagePullPolicy, env }] },+ spec: {+ volumes: [+ fixture+ ? { name: controlApiFixtureVolume, emptyDir: {} }+ : { name: controlApiFixtureVolume, $patch: 'delete' },+ ],+ containers: [+ {+ name: 'control-api',+ image,+ imagePullPolicy,+ env,+ volumeMounts: [+ fixture+ ? { name: controlApiFixtureVolume, mountPath: controlApiFixtureMountPath }+ : { mountPath: controlApiFixtureMountPath, $patch: 'delete' },+ ],+ },+ ],+ },},},}}+function hasFixtureStorage(template, container) {+ return (+ (template?.spec?.volumes ?? []).some(v => v.name === controlApiFixtureVolume) ||+ (container?.volumeMounts ?? []).some(m => m.mountPath === controlApiFixtureMountPath)+ )+}+function hasExactFixtureStorage(template, container) {+ const volumes = (template?.spec?.volumes ?? []).filter(v => v.name === controlApiFixtureVolume)+ const mounts = (container?.volumeMounts ?? []).filter(+ m => m.mountPath === controlApiFixtureMountPath+ )+ return (+ volumes.length === 1 &&+ JSON.stringify(volumes[0].emptyDir) === '{}' &&+ mounts.length === 1 &&+ mounts[0].name === controlApiFixtureVolume+ )+}export function validateControlApiPatch(patch, profile) {if (!/^[a-zA-Z0-9-]{1,128}$/.test(patch?.metadata?.uid ?? '') ||@@ -102,6 +145,7 @@ export function captureControlApi(deployment, profile) {!c ||c.image === controlApiFixtureImage ||deployment.spec.template.metadata?.annotations?.[controlApiRunAnnotation] !== undefined ||+ hasFixtureStorage(deployment.spec.template, c) ||(c.env ?? []).some(e =>['EVENFIRE_APPROVED_TOOLS_OAUTH_FIXTURE', 'APPROVED_TOOLS_RUN_ID'].includes(e.name))@@ -140,7 +184,8 @@ export async function restoreControlApi({ state, profile, get, patch, wait }) {if (c.image !== original.image ||c.imagePullPolicy !== original.imagePullPolicy ||- run !== undefined+ run !== undefined ||+ hasFixtureStorage(live.spec.template, c))throw new Error('Control API original deployment does not match')const env = controlApiFlags.map(@@ -186,7 +231,8 @@ export async function recoverControlApiForCleanup({ state, profile, get, patch,if (affected.length !== controlApiFlags.length ||JSON.stringify(ordered) !== JSON.stringify(controlApiFixtureEnv(state.run, profile)) ||- c.imagePullPolicy !== 'Never'+ c.imagePullPolicy !== 'Never' ||+ !hasExactFixtureStorage(live.spec.template, c))throw new Error('Control API fixture environment changed')} else {diff --git a/scripts/e2e/approved-tools-control-api-lifecycle.test.mjs b/scripts/e2e/approved-tools-control-api-lifecycle.test.mjsindex b342eb697..f5115d72d 100644--- a/scripts/e2e/approved-tools-control-api-lifecycle.test.mjs+++ b/scripts/e2e/approved-tools-control-api-lifecycle.test.mjs@@ -4,6 +4,8 @@ import {captureControlApi,controlApiFixtureEnv,controlApiFixtureImage,+ controlApiFixtureMountPath,+ controlApiFixtureVolume,controlApiPatch,controlApiRunAnnotation,recoverControlApiForCleanup,@@ -45,8 +47,85 @@ function fixture() {d.spec.template.metadata = { annotations: { [controlApiRunAnnotation]: run } }d.spec.template.spec.containers[0].image = controlApiFixtureImaged.spec.template.spec.containers[0].env = controlApiFixtureEnv(run, profile)+ d.spec.template.spec.volumes = [{ name: controlApiFixtureVolume, emptyDir: {} }]+ d.spec.template.spec.containers[0].volumeMounts = [+ { name: controlApiFixtureVolume, mountPath: controlApiFixtureMountPath },+ ]return d}+test('fixture patch mounts a writable /tmp for the activation marker and restore deletes it', () => {+ const install = controlApiPatch({+ metadata: deployment().metadata,+ image: controlApiFixtureImage,+ imagePullPolicy: 'Never',+ env: controlApiFixtureEnv(run, profile),+ run,+ })+ assert.doesNotThrow(() => validateControlApiPatch(install, profile))+ assert.deepEqual(install.spec.template.spec.volumes, [+ { name: controlApiFixtureVolume, emptyDir: {} },+ ])+ assert.deepEqual(install.spec.template.spec.containers[0].volumeMounts, [+ { name: controlApiFixtureVolume, mountPath: '/tmp' },+ ])+ const original = captureControlApi(deployment(), profile)+ const restore = controlApiPatch({ ...original, run: null })+ assert.doesNotThrow(() => validateControlApiPatch(restore, profile))+ assert.deepEqual(restore.spec.template.spec.volumes, [+ { name: controlApiFixtureVolume, $patch: 'delete' },+ ])+ assert.deepEqual(restore.spec.template.spec.containers[0].volumeMounts, [+ { mountPath: '/tmp', $patch: 'delete' },+ ])+ for (const mutate of [+ p => {+ p.spec.template.spec.volumes = []+ },+ p => {+ p.spec.template.spec.volumes[0] = { name: controlApiFixtureVolume, hostPath: { path: '/' } }+ },+ p => {+ p.spec.template.spec.containers[0].volumeMounts[0].mountPath = '/app'+ },+ p => {+ delete p.spec.template.spec.containers[0].volumeMounts+ },+ ]) {+ const p = structuredClone(install)+ mutate(p)+ assert.throws(() => validateControlApiPatch(p, profile), /Unexpected Control API patch fields/)+ }+})+test('an original deployment that already uses the fixture volume or /tmp is refused', async () => {+ for (const mutate of [+ d => {+ d.spec.template.spec.volumes = [{ name: controlApiFixtureVolume, emptyDir: {} }]+ },+ d => {+ d.spec.template.spec.containers[0].volumeMounts = [{ name: 'scratch', mountPath: '/tmp' }]+ },+ ]) {+ const d = deployment()+ mutate(d)+ assert.throws(() => captureControlApi(d, profile), /test ownership/)+ const original = captureControlApi(deployment(), profile)+ const calls = []+ await assert.rejects(+ restoreControlApi({+ state: { run, controlApi: original },+ profile,+ get: () => {+ calls.push('get')+ return d+ },+ patch: () => assert.fail(),+ wait: () => assert.fail(),+ }),+ /original deployment does not match/+ )+ assert.deepEqual(calls, ['get'])+ }+})test('snapshot captures only restorable affected bindings and refuses unsafe originals', () => {const original = captureControlApi(deployment(), profile)assert.equal(JSON.stringify(original).includes('UNRELATED'), false)@@ -278,6 +357,10 @@ test('identity cleanup retry reinstalls the guarded API and restores it after bo}const c = live.spec.template.spec.containers[0]c.env = c.env.filter(e => e.$patch !== 'delete')+ c.volumeMounts = c.volumeMounts.filter(m => m.$patch !== 'delete')+ live.spec.template.spec.volumes = live.spec.template.spec.volumes.filter(+ v => v.$patch !== 'delete'+ )if (live.spec.template.metadata.annotations[controlApiRunAnnotation] === null)delete live.spec.template.metadata.annotations[controlApiRunAnnotation]},