Skip to content

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

TypeScript

fix(e2e): journal and clean only owned fixture resources

Alfredo Lopezb3c48b45fb7d
diff --git a/.github/workflows/ci-public.yml b/.github/workflows/ci-public.yml
index 12a1076cf..4ed466520 100644
--- a/.github/workflows/ci-public.yml
+++ b/.github/workflows/ci-public.yml
@@ -139,6 +139,7 @@ jobs:
scripts/e2e/desktop-login-seed.test.mjs \
scripts/e2e/approved-tools-image-proof.test.mjs \
scripts/e2e/approved-tools-restoration.test.mjs \
+ scripts/e2e/approved-tools-resource-cleanup.test.mjs \
tests/e2e/fixtures/codex-subscription/approved-tools-workflow/index.test.mjs
# Typecheck against the base tsconfig (covers src + test dirs).
diff --git a/docs/architecture/codex-subscription-transport-contract.md b/docs/architecture/codex-subscription-transport-contract.md
index 1a352056f..75a03a947 100644
--- a/docs/architecture/codex-subscription-transport-contract.md
+++ b/docs/architecture/codex-subscription-transport-contract.md
@@ -49,17 +49,17 @@ OAuth scopes: `openid`, `profile`, `email`, `offline_access`.
All values are finite and greater than zero. `maxRetriesPerAttempt` is `1`:
one physical execution per ticket. A retry or fallback must mint a new attempt.
-| Limit | Value |
-| --- | --- |
-| maxRequestBodyBytes | 1048576 |
-| maxMessages | 128 |
-| maxToolCalls | 32 |
-| maxOutputTokens | 16384 |
-| maxStreamDurationMs | 300000 |
-| maxDeadlineMs | 300000 |
-| maxConcurrentStreams | 8 |
-| maxQueuedRequests | 16 |
-| maxRetriesPerAttempt | 1 |
+| Limit | Value |
+| -------------------- | ------- |
+| maxRequestBodyBytes | 1048576 |
+| maxMessages | 128 |
+| maxToolCalls | 32 |
+| maxOutputTokens | 16384 |
+| maxStreamDurationMs | 300000 |
+| maxDeadlineMs | 300000 |
+| maxConcurrentStreams | 8 |
+| maxQueuedRequests | 16 |
+| maxRetriesPerAttempt | 1 |
Tool definitions have no independent count ceiling in the Evenfire request
contract. The entire serialized request, including all definitions, remains
@@ -84,12 +84,14 @@ included in the hash. Tickets and receipts keep their existing binding.
This is a validator relaxation, not a new wire format. No version negotiation
or fallback to a truncated catalog is introduced.
-| Sender | Validator | Result within all other limits |
-| --- | --- | --- |
-| Old (at most 32 definitions) | New | Accepted; unchanged hash |
-| New (at most 32 definitions) | Old | Accepted; unchanged hash |
-| New (more than 32 definitions) | Old | Explicit count-limit rejection |
-| New (more than 32 definitions) | New | Accepted locally; upstream capability is tested separately |
+| Sender | Authorizer | Proxy | Result within all other limits |
+| ------------------------------ | -------------- | --------------------- | ----------------------------------------------------------------------------- |
+| Old (at most 32 definitions) | New | New | Accepted; unchanged hash |
+| New (at most 32 definitions) | Old | Old | Accepted; unchanged hash |
+| New (more than 32 definitions) | Old | Any | Rejected before issuing the execution ticket |
+| New (more than 32 definitions) | New | Old | Authorization can succeed, then the proxy rejects the request |
+| New (more than 32 definitions) | New | New | Accepted locally; upstream capability is tested separately |
+| New (more than 32 definitions) | Mixed replicas | Mixed or new replicas | Results can vary by serving replica; readiness of one replica is insufficient |
Deploy updated Control API and proxy consumers before the updated MCP Host
sender. Verify that both consumers use the updated shared package; rebuilding
diff --git a/scripts/e2e/approved-tools-resource-cleanup.mjs b/scripts/e2e/approved-tools-resource-cleanup.mjs
new file mode 100644
index 000000000..742db0da0
--- /dev/null
+++ b/scripts/e2e/approved-tools-resource-cleanup.mjs
@@ -0,0 +1,176 @@
+const suiteKey = 'evenfire.ai/e2e-suite'
+const runKey = 'evenfire.ai/e2e-run'
+const suite = 'codex-approved-tools'
+const kinds = {
+ WorkflowRecipe: ['clerum.io/v1alpha1', 'workflowrecipes', 'sandbox-recipes', 'recipe', 0],
+ Host: ['clerum.io/v1alpha1', 'hosts', 'mcp-host', 'agent', 1],
+ McpServer: ['clerum.io/v1alpha1', 'mcpservers', 'mcp-server', 'mcp', 2],
+ Context: ['clerum.io/v1alpha1', 'contexts', 'mcp-server', 'context', 3],
+ NetworkPolicy: ['networking.k8s.io/v1', 'networkpolicies', null, null, 4],
+}
+
+// This protocol deliberately has no shell/network implementation. Its adapter
+// must send the exact DeleteOptions body, honor finite deadlines, and represent
+// only an API NotFound as null. A transport error is never evidence of absence.
+export function fixtureResourceIdentity(resource, run) {
+ if (!/^approved-tools-[a-f0-9]{12}$/.test(run ?? '')) throw new Error('Invalid fixture run')
+ const rule = kinds[resource?.kind]
+ const metadata = resource?.metadata
+ if (!rule || resource.apiVersion !== rule[0] || !metadata)
+ throw new Error('Unsupported fixture resource')
+ const labels = metadata.labels
+ const scenario = labels?.[runKey]?.slice(run.length + 1)
+ if (
+ labels?.[suiteKey] !== suite ||
+ !['83', '150', '250', 'workflow'].includes(scenario) ||
+ labels[runKey] !== `${run}-${scenario}`
+ )
+ throw new Error('Invalid fixture labels')
+ if (resource.kind === 'NetworkPolicy') {
+ if (
+ scenario !== 'workflow' ||
+ ![
+ ['sandbox-recipes', `${run}-recipe-receipt-egress`],
+ ['mcp-server', `${run}-recipe-receipt-ingress`],
+ ].some(([namespace, name]) => metadata.namespace === namespace && metadata.name === name)
+ )
+ throw new Error('Invalid fixture policy binding')
+ } else if (
+ metadata.namespace !== rule[2] ||
+ metadata.name !==
+ (resource.kind === 'WorkflowRecipe' ? `${run}-recipe` : `${run}-${rule[3]}-${scenario}`) ||
+ (resource.kind === 'WorkflowRecipe' && scenario !== 'workflow')
+ )
+ throw new Error('Invalid fixture resource binding')
+ return {
+ apiVersion: resource.apiVersion,
+ kind: resource.kind,
+ metadata: {
+ name: metadata.name,
+ namespace: metadata.namespace,
+ labels: { [suiteKey]: suite, [runKey]: labels[runKey] },
+ },
+ }
+}
+
+function serverIdentity(metadata) {
+ if (
+ !/^[a-zA-Z0-9-]{1,128}$/.test(metadata?.uid ?? '') ||
+ !/^[0-9]{1,32}$/.test(metadata?.resourceVersion ?? '')
+ )
+ throw new Error('Missing server resource identity')
+ return { uid: metadata.uid, resourceVersion: metadata.resourceVersion }
+}
+
+function sameIdentity(expected, observed, run) {
+ if (
+ JSON.stringify(fixtureResourceIdentity(expected, run)) !==
+ JSON.stringify(fixtureResourceIdentity(observed, run))
+ )
+ throw new Error('Fixture resource ownership changed')
+}
+
+export async function createJournaledFixtureResources({
+ resources,
+ run,
+ journal,
+ save,
+ create,
+ validateCreated,
+}) {
+ if (!Array.isArray(journal) || journal.length)
+ throw new Error('Expected an empty resource journal')
+ // Validate the entire proposal before its first mutation.
+ const identities = resources.map(resource => fixtureResourceIdentity(resource, run))
+ if (new Set(identities.map(identity => JSON.stringify(identity))).size !== identities.length)
+ throw new Error('Duplicate fixture resource')
+ for (const [index, resource] of resources.entries()) {
+ const entry = { ...identities[index], status: 'creation-pending' }
+ journal.push(entry)
+ await save()
+ // A lost create response is unresolved, even if a later same-name object
+ // bears our labels. Never infer the original UID from a subsequent read.
+ const created = await create(resource)
+ sameIdentity(entry, created, run)
+ Object.assign(entry.metadata, serverIdentity(created.metadata))
+ entry.status = 'created'
+ await save()
+ if (validateCreated) await validateCreated(resource, created)
+ }
+ return journal
+}
+
+export function fixtureResourceGetArgs(entry, run) {
+ fixtureResourceIdentity(entry, run)
+ serverIdentity(entry.metadata)
+ return [
+ '-n',
+ entry.metadata.namespace,
+ 'get',
+ `${kinds[entry.kind][1]}.${entry.apiVersion.split('/')[0]}/${entry.metadata.name}`,
+ '--ignore-not-found=true',
+ '-o',
+ 'json',
+ ]
+}
+
+export function fixtureDeleteRequest(entry, live, run) {
+ sameIdentity(entry, live, run)
+ const original = serverIdentity(entry.metadata)
+ const current = serverIdentity(live.metadata)
+ if (current.uid !== original.uid) throw new Error('Fixture resource UID changed')
+ // Controllers may legitimately update resourceVersion since creation. Bind
+ // deletion to the version just checked; an intervening update must conflict.
+ return {
+ method: 'DELETE',
+ path: `/apis/${entry.apiVersion}/namespaces/${entry.metadata.namespace}/${kinds[entry.kind][1]}/${entry.metadata.name}`,
+ body: {
+ apiVersion: 'v1',
+ kind: 'DeleteOptions',
+ propagationPolicy: 'Foreground',
+ preconditions: current,
+ },
+ }
+}
+
+export function validateFixtureDeleteRequest(request, entry, live, run) {
+ if (JSON.stringify(request) !== JSON.stringify(fixtureDeleteRequest(entry, live, run)))
+ throw new Error('Invalid fixture deletion request')
+ return request
+}
+
+export async function cleanupJournaledFixtureResources({
+ journal,
+ run,
+ save,
+ get,
+ remove,
+ waitForDeletion = get,
+}) {
+ if (!Array.isArray(journal)) throw new Error('Missing resource journal')
+ for (const entry of journal) {
+ fixtureResourceIdentity(entry, run)
+ if (!['creation-pending', 'created', 'deleted'].includes(entry.status))
+ throw new Error('Invalid resource journal status')
+ if (entry.status !== 'creation-pending') serverIdentity(entry.metadata)
+ }
+ // An ambiguous create might have left a dependent alive. Fail closed before
+ // removing any dependency, and retain the journal for explicit recovery.
+ if (journal.some(entry => entry.status === 'creation-pending'))
+ throw new Error('Unresolved fixture creation; cleanup requires server identity')
+ for (const entry of [...journal].sort((a, b) => kinds[a.kind][4] - kinds[b.kind][4])) {
+ if (entry.status === 'deleted') continue
+ const live = await get(entry)
+ if (live !== null) {
+ await remove(fixtureDeleteRequest(entry, live, run), entry, live)
+ // Foreground deletion is asynchronous: do not remove dependencies until
+ // the adapter confirms this exact resource is absent. Retry is bounded
+ // by the caller; conflicts/terminating objects remain in the journal.
+ if ((await waitForDeletion(entry)) !== null)
+ throw new Error('Fixture resource deletion is not complete')
+ }
+ entry.status = 'deleted'
+ await save()
+ }
+ return journal
+}
diff --git a/scripts/e2e/approved-tools-resource-cleanup.test.mjs b/scripts/e2e/approved-tools-resource-cleanup.test.mjs
new file mode 100644
index 000000000..71bcfa1af
--- /dev/null
+++ b/scripts/e2e/approved-tools-resource-cleanup.test.mjs
@@ -0,0 +1,282 @@
+import assert from 'node:assert/strict'
+import { test } from 'node:test'
+import {
+ cleanupJournaledFixtureResources,
+ createJournaledFixtureResources,
+ fixtureDeleteRequest,
+ fixtureResourceGetArgs,
+ fixtureResourceIdentity,
+} from './approved-tools-resource-cleanup.mjs'
+import {
+ assertResourceRoundTrip,
+ makeResources,
+ makeScenarios,
+ makeWorkflowResources,
+ makeWorkflowScenario,
+ restoreOwnedFixture,
+ validateKubectlArgs,
+} from './prepare-codex-approved-tools.mjs'
+
+const run = 'approved-tools-123456789abc'
+const profile = 'clerum-fixture-12345678'
+const prefix = [`--context=${profile}`, '--request-timeout=30s']
+function proposal() {
+ const workflow = makeWorkflowScenario(run, 43105, 43104)
+ return [
+ ...makeResources([...makeScenarios(run, [43101, 43102, 43103], 43104), workflow]),
+ ...makeWorkflowResources(workflow),
+ ]
+}
+function returned(resource, index = 1) {
+ return {
+ ...structuredClone(resource),
+ metadata: {
+ ...structuredClone(resource.metadata),
+ uid: `server-${index}`,
+ resourceVersion: String(index),
+ },
+ }
+}
+async function journalFor(resources = proposal()) {
+ const journal = []
+ await createJournaledFixtureResources({
+ resources,
+ run,
+ journal,
+ save() {},
+ create: resource => returned(resource, journal.length),
+ })
+ return journal
+}
+
+test('real proposal kinds, namespaces, names and exact run labels are accepted and each server identity is saved', async () => {
+ const journal = []
+ const saves = []
+ await createJournaledFixtureResources({
+ resources: proposal(),
+ run,
+ journal,
+ save: () => saves.push(structuredClone(journal)),
+ create: resource => returned(resource, journal.length),
+ validateCreated: assertResourceRoundTrip,
+ })
+ assert.equal(journal.length, 15)
+ assert.equal(saves.length, 30)
+ assert.equal(saves[0][0].status, 'creation-pending')
+ assert.equal(saves[1][0].metadata.uid, 'server-1')
+ assert.equal(saves[1][0].metadata.resourceVersion, '1')
+ for (const entry of journal) assert.doesNotThrow(() => fixtureResourceIdentity(entry, run))
+})
+
+test('partial create failure retains actual earlier identities and ambiguous intent without name-only cleanup', async () => {
+ const journal = []
+ await assert.rejects(
+ createJournaledFixtureResources({
+ resources: proposal(),
+ run,
+ journal,
+ save() {},
+ create: resource => {
+ if (journal.length === 2) throw new Error('lost response')
+ return returned(resource)
+ },
+ }),
+ /lost response/
+ )
+ assert.equal(journal.length, 2)
+ assert.equal(journal[0].metadata.uid, 'server-1')
+ assert.equal(journal[1].status, 'creation-pending')
+ await assert.rejects(
+ cleanupJournaledFixtureResources({
+ journal,
+ run,
+ save() {},
+ get: () => assert.fail('ambiguous ownership read'),
+ remove: () => assert.fail('name-only delete'),
+ }),
+ /Unresolved/
+ )
+})
+
+test('creation field validation fails after identity persistence, permitting ownership cleanup', async () => {
+ const journal = []
+ await assert.rejects(
+ createJournaledFixtureResources({
+ resources: proposal(),
+ run,
+ journal,
+ save() {},
+ create: resource => returned(resource),
+ validateCreated() {
+ throw new Error('pruned field')
+ },
+ }),
+ /pruned field/
+ )
+ assert.equal(journal[0].status, 'created')
+ assert.equal(journal[0].metadata.uid, 'server-1')
+})
+
+test('deletes dependents first, uses fresh resourceVersion, saves completion and permits absent resources', async () => {
+ const journal = await journalFor()
+ const removed = new Set()
+ const order = []
+ await cleanupJournaledFixtureResources({
+ journal,
+ run,
+ save() {},
+ get: entry =>
+ removed.has(entry.metadata.uid) || entry.metadata.uid === 'server-1'
+ ? null
+ : { ...entry, metadata: { ...entry.metadata, resourceVersion: '999' } },
+ remove: request => {
+ assert.equal(request.body.preconditions.resourceVersion, '999')
+ assert.equal(request.body.propagationPolicy, 'Foreground')
+ const entry = journal.find(item => item.metadata.uid === request.body.preconditions.uid)
+ order.push(entry.kind)
+ removed.add(entry.metadata.uid)
+ },
+ })
+ assert.equal(order[0], 'WorkflowRecipe')
+ assert(order.lastIndexOf('Host') < order.indexOf('McpServer'))
+ assert(order.lastIndexOf('McpServer') < order.indexOf('Context'))
+ assert(order.lastIndexOf('Context') < order.indexOf('NetworkPolicy'))
+ assert(journal.every(entry => entry.status === 'deleted'))
+})
+
+for (const mutation of ['uid', 'run', 'suite', 'namespace', 'name', 'kind', 'apiVersion']) {
+ test(`changed ${mutation} prevents deletion`, async () => {
+ const journal = await journalFor(proposal().slice(0, 1))
+ const live = structuredClone(journal[0])
+ if (mutation === 'run')
+ live.metadata.labels['evenfire.ai/e2e-run'] = 'approved-tools-aaaaaaaaaaaa-83'
+ else if (mutation === 'suite') live.metadata.labels['evenfire.ai/e2e-suite'] = 'foreign'
+ else if (['kind', 'apiVersion'].includes(mutation)) live[mutation] = 'foreign'
+ else live.metadata[mutation] = 'foreign'
+ await assert.rejects(
+ cleanupJournaledFixtureResources({
+ journal,
+ run,
+ save() {},
+ get: () => live,
+ remove: () => assert.fail('foreign delete'),
+ })
+ )
+ assert.equal(journal[0].status, 'created')
+ })
+}
+
+test('delete conflict and replacement while waiting preserve journal and stop dependency deletion', async () => {
+ for (const conflict of [true, false]) {
+ const journal = await journalFor()
+ let deletes = 0
+ await assert.rejects(
+ cleanupJournaledFixtureResources({
+ journal,
+ run,
+ save() {},
+ get: entry => entry,
+ remove() {
+ deletes++
+ if (conflict) throw new Error('Conflict')
+ },
+ waitForDeletion: entry => returned(entry, 999),
+ })
+ )
+ assert.equal(deletes, 1)
+ assert(journal.every(entry => entry.status === 'created'))
+ }
+})
+
+test('read errors and legacy name-only journals fail closed', async () => {
+ for (const journal of [
+ await journalFor(),
+ [{ kind: 'Host', name: `${run}-agent-83`, namespace: 'mcp-host' }],
+ ]) {
+ await assert.rejects(
+ cleanupJournaledFixtureResources({
+ journal,
+ run,
+ save() {},
+ get() {
+ throw new Error('transport')
+ },
+ remove: () => assert.fail('delete'),
+ })
+ )
+ }
+})
+
+test('allowlist binds exact namespace, kind, generated name and both preconditions to checked resource', async () => {
+ const [entry] = await journalFor()
+ const live = { ...entry, metadata: { ...entry.metadata, resourceVersion: '200' } }
+ const request = fixtureDeleteRequest(entry, live, run)
+ const args = [...prefix, 'delete', '--raw', request.path, '-f', '-']
+ const options = { resourceCleanup: { entry, live, run }, input: JSON.stringify(request.body) }
+ assert.doesNotThrow(() => validateKubectlArgs(args, profile, options))
+ assert.doesNotThrow(() =>
+ validateKubectlArgs([...prefix, ...fixtureResourceGetArgs(entry, run)], profile, {
+ resourceCleanup: { entry, run },
+ })
+ )
+ assert.throws(() => validateKubectlArgs(args, profile))
+ for (const field of ['uid', 'resourceVersion']) {
+ const body = structuredClone(request.body)
+ delete body.preconditions[field]
+ assert.throws(() =>
+ validateKubectlArgs(args, profile, { ...options, input: JSON.stringify(body) })
+ )
+ }
+ for (const uri of [
+ '/api/v1/namespaces/default',
+ request.path.replace('/mcp-server/', '/mcp-host/'),
+ request.path.replace('/contexts/', '/hosts/'),
+ request.path.replace(run, 'approved-tools-aaaaaaaaaaaa'),
+ ])
+ assert.throws(() =>
+ validateKubectlArgs([...prefix, 'delete', '--raw', uri, '-f', '-'], profile, options)
+ )
+ assert.throws(() =>
+ validateKubectlArgs([...prefix, 'delete', '--all', 'hosts'], profile, options)
+ )
+})
+
+test('resource cleanup failure leaves restored false after proxy and forward cleanup', async () => {
+ const events = []
+ const state = {
+ profile,
+ worktree: 'owned',
+ head: 'head',
+ run,
+ proxyUid: 'proxy',
+ originalProxyImage: 'original',
+ forwards: [1],
+ resources: await journalFor(),
+ }
+ await assert.rejects(
+ restoreOwnedFixture({
+ state,
+ profile,
+ worktree: 'owned',
+ head: 'head',
+ getDeployment: () => ({
+ metadata: { uid: 'proxy' },
+ spec: {
+ template: { spec: { containers: [{ name: 'codex-llm-proxy', image: 'original' }] } },
+ },
+ }),
+ patchProxy() {
+ assert.fail('patch')
+ },
+ waitProxyRollout: () => events.push('proxy'),
+ cleanupForward: () => events.push('forward'),
+ cleanupResources() {
+ events.push('resources')
+ throw new Error('resource conflict')
+ },
+ }),
+ /resource conflict/
+ )
+ assert.deepEqual(events, ['proxy', 'forward', 'resources'])
+ assert.equal(state.restored, false)
+})
diff --git a/scripts/e2e/prepare-codex-approved-tools.mjs b/scripts/e2e/prepare-codex-approved-tools.mjs
index ef4e5a64e..aca04c270 100644
--- a/scripts/e2e/prepare-codex-approved-tools.mjs
+++ b/scripts/e2e/prepare-codex-approved-tools.mjs
@@ -5,6 +5,13 @@ import net from 'node:net'
import path from 'node:path'
import { fileURLToPath, pathToFileURL } from 'node:url'
import { buildApprovedToolsImageProof } from './approved-tools-image-proof.mjs'
+import {
+ cleanupJournaledFixtureResources,
+ createJournaledFixtureResources,
+ fixtureDeleteRequest,
+ fixtureResourceGetArgs,
+ validateFixtureDeleteRequest,
+} from './approved-tools-resource-cleanup.mjs'
const repo = path.resolve(path.dirname(fileURLToPath(import.meta.url)), '../..')
const sizes = [83, 150, 250]
@@ -392,11 +399,21 @@ export function validateOwnerArgs(args, recording, profile, pidDirectory) {
return args
}
-export function validateKubectlArgs(args, profile) {
+export function validateKubectlArgs(args, profile, { input, resourceCleanup } = {}) {
if (args[0] !== `--context=${validateProfile(profile)}` || args[1] !== '--request-timeout=30s')
throw new Error('Invalid kubectl context or timeout')
const operation = args.slice(2)
const exact = allowed => JSON.stringify(operation) === JSON.stringify(allowed)
+ if (resourceCleanup) {
+ const { entry, live, run } = resourceCleanup
+ if (exact(fixtureResourceGetArgs(entry, run)) && input === undefined) return args
+ const request = fixtureDeleteRequest(entry, live, run)
+ if (exact(['delete', '--raw', request.path, '-f', '-'])) {
+ validateFixtureDeleteRequest({ ...request, body: JSON.parse(input) }, entry, live, run)
+ return args
+ }
+ throw new Error('Invalid owned resource cleanup operation')
+ }
if (
exact(['create', '--dry-run=server', '-f', '-', '-o', 'json']) ||
exact(['create', '-f', '-', '-o', 'json'])
@@ -547,7 +564,11 @@ export function validateKubectlArgs(args, profile) {
throw new Error('Unsupported kubectl operation')
}
-function command(operation, args, { input, timeout = 60_000, inherit = false } = {}) {
+function command(
+ operation,
+ args,
+ { input, timeout = 60_000, inherit = false, resourceCleanup } = {}
+) {
const env = { ...process.env }
for (const key of Object.keys(env))
if (
@@ -591,7 +612,7 @@ function command(operation, args, { input, timeout = 60_000, inherit = false } =
case 'kubectl':
result = spawnSync(
'kubectl',
- validateKubectlArgs(args, required('MINIKUBE_PROFILE')),
+ validateKubectlArgs(args, required('MINIKUBE_PROFILE'), { input, resourceCleanup }),
options
)
break
@@ -693,6 +714,7 @@ export async function restoreOwnedFixture({
patchProxy,
waitProxyRollout,
cleanupForward,
+ cleanupResources,
}) {
if (!state || state.profile !== profile || state.worktree !== worktree)
throw new Error('Fixture ownership mismatch')
@@ -742,6 +764,13 @@ export async function restoreOwnedFixture({
cleanupErrors.push(error)
}
}
+ try {
+ if (state.resources?.length && !cleanupResources)
+ throw new Error('Resource cleanup adapter is required')
+ if (cleanupResources) await cleanupResources()
+ } catch (error) {
+ cleanupErrors.push(error)
+ }
if (proxyError || cleanupErrors.length > 0) {
throw proxyError ?? cleanupErrors[0]
}
@@ -821,6 +850,12 @@ async function main() {
fs.writeSync(stateFile.fd, data, 0, data.length, 0)
fs.fsyncSync(stateFile.fd)
}
+ const getOwnedResource = entry => {
+ const output = kubectl(fixtureResourceGetArgs(entry, state.run), {
+ resourceCleanup: { entry, run: state.run },
+ }).trim()
+ return output === '' ? null : JSON.parse(output)
+ }
async function restore() {
try {
await restoreOwnedFixture({
@@ -875,6 +910,30 @@ async function main() {
String(binding.localPort),
String(binding.remotePort),
]),
+ cleanupResources: () =>
+ cleanupJournaledFixtureResources({
+ journal: state.resources,
+ run: state.run,
+ save,
+ get: getOwnedResource,
+ waitForDeletion: async entry => {
+ const deadline = Date.now() + 30_000
+ do {
+ const live = getOwnedResource(entry)
+ if (live === null) return null
+ // Stop immediately on replacement or lost labels; otherwise
+ // poll foreground deletion within a finite cleanup deadline.
+ fixtureDeleteRequest(entry, live, state.run)
+ await new Promise(resolve => setTimeout(resolve, 200))
+ } while (Date.now() < deadline)
+ throw new Error('Fixture foreground deletion deadline exceeded')
+ },
+ remove: (request, entry, live) =>
+ kubectl(['delete', '--raw', request.path, '-f', '-'], {
+ input: JSON.stringify(request.body),
+ resourceCleanup: { entry, live, run: state.run },
+ }),
+ }),
})
save()
} catch (error) {
@@ -1026,11 +1085,7 @@ async function main() {
scenarios,
workflowScenario,
forwards: [],
- resources: resources.map(r => ({
- kind: r.kind,
- name: r.metadata.name,
- namespace: r.metadata.namespace,
- })),
+ resources: [],
originalProxyImage: container.image,
originalImagePullPolicy: container.imagePullPolicy,
originalNodeEnv,
@@ -1090,10 +1145,19 @@ async function main() {
validateForward(binding)
}
try {
- const created = JSON.parse(
- kubectl(['create', '-f', '-', '-o', 'json'], { input: JSON.stringify(proposed) })
- )
- assertResourceRoundTrip(resources, created.items)
+ await createJournaledFixtureResources({
+ resources,
+ run,
+ journal: state.resources,
+ save,
+ create: resource =>
+ JSON.parse(
+ kubectl(['create', '-f', '-', '-o', 'json'], {
+ input: JSON.stringify(resource),
+ })
+ ),
+ validateCreated: assertResourceRoundTrip,
+ })
kubectl([
'-n',
'control-plane',
diff --git a/scripts/tests/test-codex-subscription-t0.sh b/scripts/tests/test-codex-subscription-t0.sh
index 9ef3a42cd..c151b9b07 100755
--- a/scripts/tests/test-codex-subscription-t0.sh
+++ b/scripts/tests/test-codex-subscription-t0.sh
@@ -203,6 +203,7 @@ run_node_group "approved-tools-fixtures-and-runner" \
"scripts/e2e/desktop-login-seed.test.mjs" \
"scripts/e2e/approved-tools-image-proof.test.mjs" \
"scripts/e2e/approved-tools-restoration.test.mjs" \
+ "scripts/e2e/approved-tools-resource-cleanup.test.mjs" \
"tests/e2e/fixtures/codex-subscription/approved-tools-workflow/index.test.mjs"
diff --git a/tests/e2e/fixtures/codex-subscription/approved-tools-setup/README.md b/tests/e2e/fixtures/codex-subscription/approved-tools-setup/README.md
index d57f70efb..795b30532 100644
--- a/tests/e2e/fixtures/codex-subscription/approved-tools-setup/README.md
+++ b/tests/e2e/fixtures/codex-subscription/approved-tools-setup/README.md
@@ -64,8 +64,12 @@ restore still attempts owned-forward cleanup and never reports restored=true.
Scenario metadata is written to `scenarios.json` and passed directly to the runner
in `run` mode. It contains no credentials. State records retain only fixture
identity, ports, original image/pull policy and the non-sensitive NODE_ENV value.
-Created CRDs and synthetic database fixtures remain available for diagnosis;
-cleanup must explicitly target the listed run-owned resources and seed rows.
+Created Kubernetes resources are journaled individually with their server UID
+and version. Restoration deletes them in dependency order after checking the
+current run labels and UID, using UID/version preconditions. Ambiguous creation
+and legacy journals fail closed and require explicit recovery; they are never
+deleted by name alone. Database fixture cleanup remains pending with the absent
+seed implementation, so this does not certify a complete E2E cleanup.
Real subscription tests do not use this synthetic prepare path. They require the
separately approved account/preconditions and production proxy image. Refusing
diff --git a/tests/e2e/fixtures/codex-subscription/approved-tools/README.md b/tests/e2e/fixtures/codex-subscription/approved-tools/README.md
index 329e582cf..4d23f41a0 100644
--- a/tests/e2e/fixtures/codex-subscription/approved-tools/README.md
+++ b/tests/e2e/fixtures/codex-subscription/approved-tools/README.md
@@ -13,7 +13,8 @@ tests use ephemeral loopback ports and require host execution if the sandbox
forbids listening. No subscription is consumed.
Start the service with `node tests/e2e/fixtures/codex-subscription/approved-tools/server.mjs`.
-Configure CATALOG_SIZE to exactly 83, 150 or 250, RUN_ID to a unique safe run
+CATALOG_SIZE defaults to 83; set it explicitly to 83, 150 or 250 for each
+measured scenario. Configure RUN_ID to a unique safe run
identifier, and PORT to the assigned port. The default bind address is loopback.
For the isolated Minikube instance set BIND_ADDRESS to all interfaces. The
Node 24 test container needs only server.mjs mounted read-only.
diff --git a/tests/e2e/fixtures/package-lock.json b/tests/e2e/fixtures/package-lock.json
index 5c765e049..a9b0869ae 100644
--- a/tests/e2e/fixtures/package-lock.json
+++ b/tests/e2e/fixtures/package-lock.json
@@ -1,12 +1,12 @@
{
"name": "@clerum/e2e-test-fixtures",
- "version": "1.0.76",
+ "version": "1.0.77",
"lockfileVersion": 3,
"requires": true,
"packages": {
"": {
"name": "@clerum/e2e-test-fixtures",
- "version": "1.0.76",
+ "version": "1.0.77",
"dependencies": {
"@kubernetes/client-node": "^1.0.0"
},
diff --git a/tests/e2e/fixtures/package.json b/tests/e2e/fixtures/package.json
index 188471d1d..890f18cee 100644
--- a/tests/e2e/fixtures/package.json
+++ b/tests/e2e/fixtures/package.json
@@ -1,6 +1,6 @@
{
"name": "@clerum/e2e-test-fixtures",
- "version": "1.0.76",
+ "version": "1.0.77",
"description": "E2E test fixtures and utilities for Clerum testing",
"type": "module",
"main": "index.ts",