Evenfire is an intelligence layer platform for running LLM agents that take real actions, on your infrastructure
TypeScript
test(e2e): harden runner admission and real pixel tool fixtures
Alfredo Lopez1af65235fbd2
diff --git a/Makefile b/Makefileindex 6ee969cb0..cd95dd7d0 100644--- a/Makefile+++ b/Makefile@@ -1574,3 +1574,26 @@ minikube-control-api-authorize-memory-body:T2_SKIP_LOCK=true T2_LOCK_TOKEN="$(T2_LOCK_TOKEN)" \bash scripts/minikube/require-t2-mutation-lock.sh@T2_SKIP_LOCK=true node scripts/tests/measure-control-api-authorize-memory.mjs --config "$$CONTROL_API_MEMORY_CONFIG"++# Isolated subscription image journeys use the existing branch-profile mutation lease.+.PHONY: minikube-subscription-image-journeys+minikube-subscription-image-journeys:+ @test -n "$${MINIKUBE_PROFILE:-}" || { echo "MINIKUBE_PROFILE required"; exit 1; }+ @test -n "$${CONTROL_API_REAL_PG_CONTEXT:-}" || { echo "CONTROL_API_REAL_PG_CONTEXT required"; exit 1; }+ @test -n "$${SUBSCRIPTION_IMAGE_SUITE:-}" || { echo "SUBSCRIPTION_IMAGE_SUITE required"; exit 1; }+ @test -n "$${SUBSCRIPTION_IMAGE_MODE:-}" || { echo "SUBSCRIPTION_IMAGE_MODE required"; exit 1; }+ @test -n "$${SUBSCRIPTION_IMAGE_SCRATCH:-}" || { echo "SUBSCRIPTION_IMAGE_SCRATCH required"; exit 1; }+ @test "$${SUBSCRIPTION_IMAGE_FRAMES:-}" = "-" || { echo "SUBSCRIPTION_IMAGE_FRAMES must be - for live private stdin"; exit 1; }+ @test -n "$${SUBSCRIPTION_IMAGE_BINDINGS:-}" || { echo "SUBSCRIPTION_IMAGE_BINDINGS required"; exit 1; }+ @test -n "$${SUBSCRIPTION_IMAGE_RED_DETECTOR:-}" || { echo "SUBSCRIPTION_IMAGE_RED_DETECTOR required"; exit 1; }+ @T2_PROJECT_DIR="$(CURDIR)" T2_PROFILE="$(MINIKUBE_PROFILE)" T2_CONTEXT="$(CONTROL_API_REAL_PG_CONTEXT)" \+ T2_SKIP_LOCK="$(T2_SKIP_LOCK)" T2_LOCK_TOKEN="$(T2_LOCK_TOKEN)" \+ bash scripts/minikube/with-t2-mutation-lock.sh -- \+ node scripts/e2e/prepare-subscription-image-admission.mjs \+ --suite "$$SUBSCRIPTION_IMAGE_SUITE" \+ --mode "$$SUBSCRIPTION_IMAGE_MODE" \+ --profile "$$MINIKUBE_PROFILE" \+ --scratch "$$SUBSCRIPTION_IMAGE_SCRATCH" \+ --frames "$$SUBSCRIPTION_IMAGE_FRAMES" \+ --bindings "$$SUBSCRIPTION_IMAGE_BINDINGS" \+ --red-detector "$$SUBSCRIPTION_IMAGE_RED_DETECTOR"diff --git a/desktop-app/test/e2e-playwright/subscriptionImageFixtures.ts b/desktop-app/test/e2e-playwright/subscriptionImageFixtures.tsindex 80b30fbde..b799eaf62 100644--- a/desktop-app/test/e2e-playwright/subscriptionImageFixtures.ts+++ b/desktop-app/test/e2e-playwright/subscriptionImageFixtures.ts@@ -23,6 +23,7 @@ import {observePrivateIsolation,readMainRecord as readMainAdmission,refusePlaintextSessionFiles,+ validateVendorLedger,verifyEncryptedKeyringFiles,verifyMainAdmission,verifyMountIsolation,@@ -200,8 +201,31 @@ export type VendorAttempt = {imageSha256: string[]mimeTypes: string[]requestSha256: string- responseKind: 'pixels' | 'text' | 'rejected'+ responseKind: 'pixels' | 'text' | 'rejected' | 'tool_calls'outputSha256?: string+ journey?: 'tool-screenshot' | 'gfs-image'+ stage?: 'prepare' | 'capture' | 'read' | 'pixels'+ toolCalls?: Array<{+ id: string+ name: 'shell_exec' | 'desktop_screenshot' | 'clerum__gfs_read'+ argumentsSha256: string+ }>+ toolOutputs?: Array<{+ id: string+ outputSha256: string+ resource?: { kind: 'gfs'; drive: string; resourceId: string; version: number; gfsUri: string }+ }>+ referencedFiles?: Array<{+ referenceId: string+ drive: string+ resourceId: string+ version: number+ availability: 'available'+ byteLength: number+ }>+ receivedImageDigests?: string[]+ receivedImageOrder?: string[]+ decodedPixels?: Array<{ width: number; height: number }>}export function readVendorAttempts(run: SubscriptionImageRun,@@ -216,30 +240,9 @@ export function readVendorAttempts(runId?: stringattempts?: VendorAttempt[]}- if (- ledger.kind !== 'evenfire-subscription-image-vendor-v1' ||- ledger.runId !== run.runId ||- !Array.isArray(ledger.attempts) ||- ledger.attempts.length > 256- )+ if (!Array.isArray(ledger.attempts))throw new Error('External vendor ledger does not belong to this run')- for (const [index, row] of ledger.attempts.entries()) {- if (- row.sequence !== index + 1 ||- row.provider !== binding.provider ||- typeof row.model !== 'string' ||- !/^[a-f0-9-]{36}$/.test(row.receiptId) ||- !Array.isArray(row.imageSha256) ||- row.imageSha256.length > 20 ||- row.imageSha256.some(value => !/^[a-f0-9]{64}$/.test(value)) ||- !Array.isArray(row.mimeTypes) ||- row.mimeTypes.length !== row.imageSha256.length ||- !/^[a-f0-9]{64}$/.test(row.requestSha256) ||- !['pixels', 'text', 'rejected'].includes(row.responseKind)- ) {- throw new Error('External vendor ledger has invalid bounded evidence')- }- }+ validateVendorLedger(ledger, run.runId, binding)return ledger.attempts}type Fixtures = {diff --git a/scripts/e2e/fixtures/subscription-image-provider.mjs b/scripts/e2e/fixtures/subscription-image-provider.mjsindex dcc6276e6..367609b10 100644--- a/scripts/e2e/fixtures/subscription-image-provider.mjs+++ b/scripts/e2e/fixtures/subscription-image-provider.mjs@@ -4,11 +4,13 @@* remain real. No expected answers, image registry or production endpoint override.* E2E_GUARDIAN_IPC_FLOW: fixture observes the external end of the Desktop IPC journey.*/-import { createHash } from 'node:crypto'+import { createHash, randomUUID } from 'node:crypto'+import { deepStrictEqual } from 'node:assert/strict'import { createRequire } from 'node:module'+import { spawn } from 'node:child_process'import fs from 'node:fs'import path from 'node:path'-import { decodeTileChallenge, requirePixelRenderer } from './subscription-image-challenge.cjs'+import { requirePixelRenderer } from './subscription-image-challenge.cjs'const require = createRequire(import.meta.url)const grok = require('../../../packages/grok-provider-attempt-contract/index.cjs')@@ -21,6 +23,211 @@ export const SUBSCRIPTION_VENDOR_URLS = {}const sha256 = value => createHash('sha256').update(value).digest('hex')const reject = code => new Response(JSON.stringify({ error: { code } }), { status: 422, headers: { 'content-type': 'application/json' } })+const sseResponse = events => new Response(+ events.map(event => `event: ${event.type}\ndata: ${JSON.stringify(event)}\n\n`).join(''),+ { status: 200, headers: { 'content-type': 'text/event-stream' } },+)+const same = (left, right) => {+ try {+ deepStrictEqual(left, right)+ return true+ } catch {+ return false+ }+}++// The native image loader can fault on a truncated PNG/JPEG container. Reject+// known-incomplete bytes before it is invoked so a malformed tool image remains+// a bounded HTTP source failure instead of crashing the inspected runtime.+function hasCompleteImageContainer(bytes, mimeType) {+ if (mimeType === 'image/png') {+ return bytes.length >= 24 && bytes.subarray(0, 8).equals(Buffer.from([+ 0x89, 0x50, 0x4e, 0x47, 0x0d, 0x0a, 0x1a, 0x0a,+ ])) && bytes.subarray(-12, -8).equals(Buffer.from([0, 0, 0, 0])) &&+ bytes.subarray(-8).equals(Buffer.from([0x49, 0x45, 0x4e, 0x44, 0xae, 0x42, 0x60, 0x82]))+ }+ return bytes.length >= 4 && bytes[0] === 0xff && bytes[1] === 0xd8 &&+ bytes[bytes.length - 2] === 0xff && bytes[bytes.length - 1] === 0xd9+}++// A malformed image can SIGSEGV @napi-rs/canvas directly in the fixture PID+// (reproduced with an eight-byte PNG). Valid 20-image series do not crash the+// addon, so the causal boundary is malformed input, not cumulative decoder use.+// Decode each received image in a throwaway process with empty env, no shell,+// a fixed timeout, and bounded stdin/stdout. The vendor itself remains the+// long-lived state machine and keeps all attempt state in its own PID.+const DECODER_TIMEOUT_MS = 10_000+const MAX_DECODER_STDOUT_BYTES = 1024 * 1024++function decoderChildScript() {+ const decoderUrl = new URL('./subscription-image-challenge.cjs', import.meta.url).href+ return `+import { decodeTileChallenge, requirePixelRenderer } from ${JSON.stringify(decoderUrl)}+const chunks = []+let byteLength = 0+for await (const chunk of process.stdin) {+ byteLength += chunk.length+ if (byteLength > 20 * 1024 * 1024) throw new Error('decoder input bound exceeded')+ chunks.push(chunk)+}+const bytes = Buffer.concat(chunks)+const native = requirePixelRenderer()+const image = await native.loadImage(bytes)+const code = await decodeTileChallenge(bytes)+if (!Number.isSafeInteger(image.width) || image.width < 1 ||+ !Number.isSafeInteger(image.height) || image.height < 1 ||+ !/^[A-F0-9]{16}$/.test(code)) throw new Error('invalid decoder result')+process.stdout.write(JSON.stringify({ width: image.width, height: image.height, code }))+`+}++function decodeInChild(bytes, signal) {+ if (signal?.aborted) return Promise.reject(signal.reason)+ return new Promise((resolve, reject) => {+ const child = spawn(process.execPath, ['--input-type=module', '--eval', decoderChildScript()], {+ cwd: '/',+ env: {},+ stdio: ['pipe', 'pipe', 'pipe'],+ })+ const stdout = []+ let stdoutBytes = 0+ const stderr = []+ let stderrBytes = 0+ let settled = false+ const fail = error => {+ if (settled) return+ settled = true+ clearTimeout(timer)+ signal?.removeEventListener('abort', abort)+ reject(error)+ }+ const abort = () => child.kill('SIGKILL')+ const timer = setTimeout(() => child.kill('SIGKILL'), DECODER_TIMEOUT_MS)+ signal?.addEventListener('abort', abort, { once: true })+ child.stdout.on('data', chunk => {+ stdoutBytes += chunk.length+ if (stdoutBytes <= MAX_DECODER_STDOUT_BYTES) stdout.push(chunk)+ })+ child.stderr.on('data', chunk => {+ stderrBytes += chunk.length+ if (stderrBytes <= 64 * 1024) stderr.push(chunk)+ })+ child.on('error', fail)+ child.on('close', (code, receivedSignal) => {+ try {+ if (settled) return+ clearTimeout(timer)+ signal?.removeEventListener('abort', abort)+ if (code !== 0) throw new Error(`image decoder exited with ${code ?? receivedSignal}`)+ if (stdoutBytes > MAX_DECODER_STDOUT_BYTES) throw new Error('image decoder output bound exceeded')+ const result = JSON.parse(Buffer.concat(stdout).toString('utf8'))+ if (!Number.isSafeInteger(result.width) || result.width < 1 ||+ !Number.isSafeInteger(result.height) || result.height < 1 ||+ !/^[A-F0-9]{16}$/.test(result.code)) throw new Error('image decoder result invalid')+ settled = true+ resolve({ width: result.width, height: result.height, code: result.code })+ } catch (error) {+ fail(error)+ }+ })+ child.stdin.on('error', () => {})+ child.stdin.end(bytes)+ })+}++function wireText(item) {+ if (typeof item?.content === 'string') return item.content+ if (!Array.isArray(item?.content)) return ''+ return item.content.filter(part => part?.type === 'input_text').map(part => part.text).join('\n')+}++function wireImages(body) {+ if (!Array.isArray(body.input)) return []+ return body.input.flatMap(item => {+ if (!Array.isArray(item?.content)) return []+ return item.content.filter(part => part?.type === 'input_image').map(part => {+ const matched = typeof part.image_url === 'string' &&+ part.image_url.match(/^data:(image\/(?:png|jpeg));base64,([A-Za-z0-9+/]+={0,2})$/)+ if (!matched) return { invalid: true }+ const bytes = Buffer.from(matched[2], 'base64')+ if (bytes.toString('base64') !== matched[2]) return { invalid: true }+ return { bytes, mimeType: matched[1] }+ })+ })+}++function parseReferencedFiles(text) {+ const pattern = /referenced_file: id="gfs:([^":\s]+):([a-f0-9]{32})@v(\d+)".*?drive="\1" resourceId="\2" version=\3 .*?bytes=(\d+) availability=available(?:\s|$)/g+ return Array.from(text.matchAll(pattern), ([, drive, resourceId, version, byteLength]) => ({+ referenceId: `gfs:${drive}:${resourceId}@v${version}`,+ drive,+ resourceId,+ version: Number(version),+ availability: 'available',+ byteLength: Number(byteLength),+ }))+}++function readNativeToolCalls(body, userIndex) {+ const calls = body.input.slice(userIndex + 1).filter(item => item?.type === 'function_call')+ const outputs = body.input.slice(userIndex + 1).filter(item => item?.type === 'function_call_output')+ const outputByCall = new Map()+ const argumentsByCall = new Map()+ if (new Set(calls.map(call => call.call_id)).size !== calls.length ||+ calls.some(call => typeof call.call_id !== 'string' || !call.call_id ||+ typeof call.name !== 'string' || typeof call.arguments !== 'string')) {+ return { error: 'tool_wire_invalid' }+ }+ try {+ for (const call of calls) {+ const parsed = JSON.parse(call.arguments)+ if (!parsed || typeof parsed !== 'object' || Array.isArray(parsed)) throw new Error('not an object')+ argumentsByCall.set(call.call_id, parsed)+ }+ for (const output of outputs) {+ if (typeof output.call_id !== 'string' || typeof output.output !== 'string' ||+ !argumentsByCall.has(output.call_id) || outputByCall.has(output.call_id)) {+ throw new Error('unpaired output')+ }+ outputByCall.set(output.call_id, output)+ }+ } catch {+ return { error: 'tool_wire_invalid' }+ }+ return { calls, outputByCall, argumentsByCall }+}++function functionCallEvents(callId, name, rawArguments, outputIndex = 0) {+ const itemId = `fc_${randomUUID().replaceAll('-', '')}`+ return [+ { type: 'response.output_item.added', output_index: outputIndex, item: {+ id: itemId, type: 'function_call', call_id: callId, name, arguments: '',+ } },+ { type: 'response.function_call_arguments.delta', item_id: itemId, delta: rawArguments },+ { type: 'response.function_call_arguments.done', item_id: itemId, arguments: rawArguments },+ { type: 'response.completed', response: { status: 'completed' } },+ ]+}++const ledgerCalls = calls => calls.map(call => ({+ id: call.call_id,+ name: call.name,+ argumentsSha256: sha256(call.arguments),+}))++const ledgerOutputs = (calls, outputByCall, resources = new Map()) => calls.map(call => ({+ id: call.call_id,+ outputSha256: sha256(outputByCall.get(call.call_id)?.output ?? ''),+ ...(resources.has(call.call_id) ? { resource: resources.get(call.call_id) } : {}),+}))++const proposedCall = (name, argumentsValue) => {+ const rawArguments = JSON.stringify(argumentsValue)+ return {+ call: { call_id: `call_${randomUUID().replaceAll('-', '')}`, name, arguments: rawArguments },+ rawArguments,+ }+}export function createSubscriptionImageVendor({ runId, bindings, acceptedProvider, maxAttempts = 256, record = () => {} }) {if (!/^subscription-image-[a-f0-9]{12}$/.test(runId) || !Array.isArray(bindings) || bindings.length !== 2 ||@@ -51,49 +258,173 @@ export function createSubscriptionImageVendor({ runId, bindings, acceptedProvideif (init.signal?.aborted) throw init.signal.reasonconst body = JSON.parse(init.body)if (!Array.isArray(body.input)) return reject('image_input_missing')+const messages = body.input.filter(item => item && Array.isArray(item.content))- const latest = messages.findLast(item => item.role === 'user')- const prompt = latest?.content.filter(part => part.type === 'input_text').map(part => part.text).join('\n') ?? ''+ const markedIndex = messages.findLastIndex(item => item.role === 'user' &&+ /Journey: (?:tool-screenshot|gfs-image)(?:\n|$)/.test(wireText(item)))+ const marked = messages[markedIndex]+ const prompt = wireText(marked ?? messages.findLast(item => item.role === 'user'))const receiptId = prompt.match(/Receipt: ([a-f0-9]{8}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{12})/i)?.[1]if (!receiptId) return reject('image_receipt_missing')- const parts = messages.flatMap(item => item.content).filter(part => part?.type === 'input_image')- if (parts.length > 20) return reject('image_count_exceeded')- const images = []++ const images = wireImages(body)+ if (images.length > 20) return reject('image_count_exceeded')+ if (images.some(part => part.invalid)) return reject('image_wire_invalid')+ if (images.some(part => !hasCompleteImageContainer(part.bytes, part.mimeType))) {+ return reject('image_challenge_unreadable')+ }let totalBytes = 0- for (const part of parts) {- const matched = typeof part.image_url === 'string' && part.image_url.match(/^data:(image\/(?:png|jpeg));base64,([A-Za-z0-9+/]+={0,2})$/)- if (!matched) return reject('image_wire_invalid')- const bytes = Buffer.from(matched[2], 'base64')- totalBytes += bytes.length- if (totalBytes > 20 * 1024 * 1024 || bytes.toString('base64') !== matched[2]) return reject('image_wire_invalid')- images.push({ bytes, mimeType: matched[1] })+ for (const part of images) {+ totalBytes += part.bytes.length+ if (totalBytes > 20 * 1024 * 1024) return reject('image_count_exceeded')+ }+ const journey = prompt.match(/Journey: (tool-screenshot|gfs-image)(?:\n|$)/)?.[1]+ const tool = readNativeToolCalls(body, marked ? body.input.indexOf(marked) : -1)+ if (tool.error) return reject(tool.error)+ if (tool.calls.length > 0 && !journey) return reject('journey_marker_missing')+ if (journey && markedIndex !== messages.length - 1 && images.length === 0) {+ return reject('journey_marker_not_last_real_user')}+const row = { sequence: attempts.length + 1, provider, model: body.model, receiptId,imageSha256: images.map(image => sha256(image.bytes)), mimeTypes: images.map(image => image.mimeType),- requestSha256: sha256(init.body), responseKind: 'rejected' }- let output+ receivedImageDigests: images.map(image => sha256(image.bytes)),+ receivedImageOrder: images.map(image => sha256(image.bytes)),+ decodedPixels: [], requestSha256: sha256(init.body), responseKind: 'rejected' }+ let proposedEventsif (body.model !== binding.modelId || (body.model === binding.unsupportedModelId && images.length)) {attempts.push(row); record(snapshot()); return reject('image_model_unsupported')}++ if (journey === 'tool-screenshot') {+ const imagePath = prompt.match(/Screen fixture: (\S+)/)?.[1]+ const regionMatch = prompt.match(/^Screenshot region: (\{.*\})$/m)?.[1]+ let region+ try {+ region = JSON.parse(regionMatch ?? '')+ } catch {+ region = null+ }+ const pending = tool.calls.filter(call => !tool.outputByCall.has(call.call_id))+ if (!imagePath || !region || tool.calls.length > 2 || pending.length > 1) {+ attempts.push(row); record(snapshot()); return reject('tool_state_invalid')+ }+ row.journey = journey+ row.stage = tool.calls.length === 0 ? 'prepare' : (pending.length > 0 ? 'capture' : 'pixels')+ row.toolOutputs = ledgerOutputs(tool.calls, tool.outputByCall)+ if (tool.calls.length === 0) {+ const shell = proposedCall('shell_exec', { command: `test -r ${imagePath}` })+ row.toolCalls = ledgerCalls([shell.call])+ proposedEvents = functionCallEvents(shell.call.call_id, shell.call.name, shell.rawArguments)+ } else {+ const [shell, screenshot] = tool.calls+ if (shell.name !== 'shell_exec' ||+ !same(tool.argumentsByCall.get(shell.call_id), { command: `test -r ${imagePath}` }) ||+ tool.outputByCall.get(shell.call_id)?.output !== '(no output)') {+ attempts.push(row); record(snapshot()); return reject('tool_source_invalid')+ }+ if (pending.length > 0) {+ if (screenshot.name !== 'desktop_screenshot' ||+ !same(tool.argumentsByCall.get(screenshot.call_id), { region })) {+ attempts.push(row); record(snapshot()); return reject('tool_source_invalid')+ }+ row.toolCalls = ledgerCalls([screenshot])+ proposedEvents = functionCallEvents(+ screenshot.call_id,+ screenshot.name,+ JSON.stringify(tool.argumentsByCall.get(screenshot.call_id)),+ )+ } else {+ if (screenshot.name !== 'desktop_screenshot' ||+ !same(tool.argumentsByCall.get(screenshot.call_id), { region }) ||+ images.length !== 1) {+ attempts.push(row); record(snapshot()); return reject('tool_source_invalid')+ }+ }+ }+ } else if (journey === 'gfs-image') {+ const references = parseReferencedFiles(String(body.instructions ?? ''))+ const userReferences = parseReferencedFiles(wireText(marked))+ if (references.length !== 2 || !same(references, userReferences)) {+ attempts.push(row); record(snapshot()); return reject('referenced_files_invalid')+ }+ row.journey = journey+ row.referencedFiles = references+ const pending = tool.calls.filter(call => !tool.outputByCall.has(call.call_id))+ if (tool.calls.length === 0) {+ row.stage = 'read'+ row.toolCalls = []+ proposedEvents = []+ for (const reference of references) {+ const read = proposedCall('clerum__gfs_read', {+ drive: reference.drive,+ resourceId: reference.resourceId,+ expectedVersion: reference.version,+ })+ row.toolCalls.push(...ledgerCalls([read.call]))+ proposedEvents.push(...functionCallEvents(+ read.call.call_id,+ read.call.name,+ read.rawArguments,+ row.toolCalls.length - 1,+ ))+ }+ } else {+ if (tool.calls.length !== 2 || pending.length > 0 || images.length !== 2) {+ attempts.push(row); record(snapshot()); return reject('tool_state_invalid')+ }+ row.stage = 'pixels'+ const resources = new Map()+ for (const [index, call] of tool.calls.entries()) {+ const reference = references[index]+ let outputValue+ try {+ outputValue = JSON.parse(tool.outputByCall.get(call.call_id).output)+ } catch {+ outputValue = null+ }+ const expectedResource = {+ kind: 'gfs',+ drive: reference.drive,+ resourceId: reference.resourceId,+ version: reference.version,+ gfsUri: `gfs://${reference.drive}/${reference.resourceId}`,+ }+ if (call.name !== 'clerum__gfs_read' ||+ !same(tool.argumentsByCall.get(call.call_id), {+ drive: reference.drive,+ resourceId: reference.resourceId,+ expectedVersion: reference.version,+ }) ||+ !same(outputValue?.resource, expectedResource) ||+ outputValue?.delivery !== 'image_input') {+ attempts.push(row); record(snapshot()); return reject('tool_source_invalid')+ }+ resources.set(call.call_id, outputValue.resource)+ }+ row.toolOutputs = ledgerOutputs(tool.calls, tool.outputByCall, resources)+ }+ }++ let outputtry {- output = images.length- ? (await Promise.all(images.map(image => decodeTileChallenge(image.bytes)))).join('\n')- : `TEXT_RECEIPT:${receiptId}`+ const decoded = []+ for (const image of images) decoded.push(await decodeInChild(image.bytes, init.signal))+ output = decoded.length ? decoded.map(result => result.code).join('\n') : `TEXT_RECEIPT:${receiptId}`+ row.decodedPixels = decoded.map(({ width, height }) => ({ width, height }))} catch {attempts.push(row); record(snapshot()); return reject('image_challenge_unreadable')}if (init.signal?.aborted) throw init.signal.reason- row.responseKind = images.length ? 'pixels' : 'text'+ row.responseKind = proposedEvents ? 'tool_calls' : (images.length ? 'pixels' : 'text')row.outputSha256 = sha256(output)attempts.push(row)record(snapshot())- const events = [+ if (proposedEvents) return sseResponse(proposedEvents)+ return sseResponse([{ type: 'response.output_text.delta', delta: output },{ type: 'response.completed', response: { status: 'completed' } },- ]- return new Response(events.map(event => `event: ${event.type}\ndata: ${JSON.stringify(event)}\n\n`).join(''), {- status: 200, headers: { 'content-type': 'text/event-stream' },- })+ ])}return { respond, snapshot }}diff --git a/scripts/e2e/fixtures/subscription-image-provider.test.mjs b/scripts/e2e/fixtures/subscription-image-provider.test.mjsindex 96dddc768..c8a5d6f07 100644--- a/scripts/e2e/fixtures/subscription-image-provider.test.mjs+++ b/scripts/e2e/fixtures/subscription-image-provider.test.mjs@@ -1,5 +1,5 @@import assert from 'node:assert/strict'-import { randomUUID } from 'node:crypto'+import { createHash, randomUUID } from 'node:crypto'import test from 'node:test'import { createSubscriptionImageVendor, SUBSCRIPTION_VENDOR_URLS } from './subscription-image-provider.mjs'import { tileChallengeImage } from './subscription-image-challenge.cjs'@@ -8,26 +8,232 @@ const bindings = [{ provider: 'grok-subscription', modelId: 'unit-grok-image', unsupportedModelId: 'unit-grok-text' },{ provider: 'codex-subscription', modelId: 'unit-codex-image', unsupportedModelId: 'unit-codex-text' },]-function request(images, receipt = randomUUID(), model = bindings[0].modelId) {++function request(images, receipt = randomUUID(), model = bindings[0].modelId, journey = '') {+ const prompt = [+ ...(journey ? [journey] : []),+ 'Read each image in order.',+ `Receipt: ${receipt}`,+ ].join('\n')return { method: 'POST', body: JSON.stringify({ model, input: [{ role: 'user', content: [- { type: 'input_text', text: `Read each image in order. Receipt: ${receipt}` },+ { type: 'input_text', text: prompt },...images.map(image => ({ type: 'input_image', image_url: `data:image/${image.format};base64,${image.bytes.toString('base64')}`, detail: 'high' })),] }] }) }}+const image = format => ({ ...tileChallengeImage(format, { requirePixels: true }), format })+const digest = value => createHash('sha256').update(value).digest('hex')+const vendor = () => createSubscriptionImageVendor({ runId: 'subscription-image-123456abcdef', bindings })+const responseCode = async response => {+ if (response.status !== 200) return (await response.json()).error.code+ const events = (await response.text()).split('\n').filter(line => line.startsWith('data: ')).map(line => JSON.parse(line.slice(6)))+ return events.find(event => event.type === 'response.output_text.delta')?.delta+}+const functionCalls = async response => {+ const events = (await response.text()).split('\n').filter(line => line.startsWith('data: ')).map(line => JSON.parse(line.slice(6)))+ const added = events.filter(event => event.type === 'response.output_item.added')+ return added.map(event => {+ const callId = event.item.call_id+ const delta = events.find(item => item.type === 'response.function_call_arguments.delta' && item.item_id === event.item.id)+ const done = events.find(item => item.type === 'response.function_call_arguments.done' && item.item_id === event.item.id)+ return { type: event.item.type, callId, name: event.item.name, arguments: JSON.parse(done.arguments), delta, done }+ })+}++function screenshotPrompt(path, region, receipt = randomUUID()) {+ return [+ 'Journey: tool-screenshot',+ `Screen fixture: ${path}`,+ `Screenshot region: ${JSON.stringify(region)}`,+ 'First use shell_exec to check that the prepared screen file exists with exactly this command:',+ `test -r ${path}`,+ 'Wait for my visible approval. Then use desktop_screenshot once for that region of the actual desktop.',+ 'Read the 64-bit hexadecimal challenge from its pixels. Reply with that code only.',+ `Receipt: ${receipt}`,+ ].join('\n')+}++function userMessage(text, images = []) {+ return { role: 'user', content: [+ { type: 'input_text', text },+ ...images.map(item => ({ type: 'input_image', image_url: `data:image/${item.format};base64,${item.bytes.toString('base64')}` })),+ ] }+}++function callItem(callId, name, args) {+ return { type: 'function_call', call_id: callId, name, arguments: JSON.stringify(args) }+}++function outputItem(callId, output) {+ return { type: 'function_call_output', call_id: callId, output }+}++function screenshotRequests(fixture, imageBytes) {+ const prompt = screenshotPrompt(fixture.path, fixture.region)+ const user = userMessage(prompt)+ const shellCall = callItem('call-shell', 'shell_exec', { command: `test -r ${fixture.path}` })+ const frameCall = callItem('call-frame', 'desktop_screenshot', { region: fixture.region })+ return {+ prompt,+ prepare: { method: 'POST', body: JSON.stringify({ model: bindings[0].modelId, input: [user] }) },+ capture: { method: 'POST', body: JSON.stringify({ model: bindings[0].modelId, input: [+ user, shellCall, outputItem('call-shell', '(no output)'), frameCall,+ ] }) },+ pixels: { method: 'POST', body: JSON.stringify({ model: bindings[0].modelId, input: [+ user,+ shellCall,+ outputItem('call-shell', '(no output)'),+ frameCall,+ outputItem('call-frame', JSON.stringify({ attachmentId: 'att-capture', delivery: 'image_input' })),+ userMessage('These images are output of the tools above.', imageBytes ? [{ format: 'png', bytes: imageBytes }] : []),+ ] }) },+ shellCall,+ frameCall,+ }+}++function referenceLine(file) {+ return [+ 'referenced_file: id="' + file.referenceId + '"',+ 'name="' + file.name + '"',+ 'source=gfs',+ 'drive="' + file.drive + '"',+ 'resourceId="' + file.resourceId + '"',+ 'version=' + file.version,+ 'class=image',+ 'bytes=' + file.byteLength,+ 'availability=available',+ ].join(' ')+}++function gfsFixture() {+ return [+ { referenceId: `gfs:qa-drive:${'a'.repeat(32)}@v3`, drive: 'qa-drive', resourceId: 'a'.repeat(32), version: 3, name: 'first.png', byteLength: 512 },+ { referenceId: `gfs:qa-drive:${'b'.repeat(32)}@v1`, drive: 'qa-drive', resourceId: 'b'.repeat(32), version: 1, name: 'second.png', byteLength: 512 },+ ]+}++function gfsRequests(files, imageBytes = []) {+ const lines = files.map(referenceLine).join('\n')+ const instructions = 'Use the references below.\n' + lines+ const prompt = [+ 'Journey: gfs-image',+ 'GFS targets: ' + JSON.stringify(files.map(file => ({+ drive: file.drive,+ resourceId: file.resourceId,+ version: file.version,+ }))),+ lines,+ 'Use clerum__gfs_read for each attached image in this order.',+ `Receipt: ${randomUUID()}`,+ ].join('\n')+ const user = userMessage(prompt)+ const calls = files.map((file, index) => callItem(`call-read-${index}`, 'clerum__gfs_read', {+ drive: file.drive,+ resourceId: file.resourceId,+ expectedVersion: file.version,+ }))+ const outputs = files.map((file, index) => outputItem(`call-read-${index}`, JSON.stringify({+ resource: {+ kind: 'gfs',+ drive: file.drive,+ resourceId: file.resourceId,+ version: file.version,+ gfsUri: `gfs://${file.drive}/${file.resourceId}`,+ },+ delivery: 'image_input',+ })))+ return {+ prepare: { method: 'POST', body: JSON.stringify({+ model: bindings[0].modelId,+ instructions,+ input: [user],+ }) },+ pixels: { method: 'POST', body: JSON.stringify({+ model: bindings[0].modelId,+ instructions,+ input: [user, ...calls, ...outputs, userMessage('These images were read by the tools above.', imageBytes)],+ }) },+ }+}++test('screenshot state machine calls the real shell, then screenshot, and answers only decoded wire pixels', async () => {+ const subject = vendor()+ const frame = image('png')+ const requests = screenshotRequests({ path: '/tmp/evenfire-qa-screen-0189f3ab-28c1-4f61-9245-58ba7d02e4a2.png', region: { x: 8, y: 16, w: 512, h: 512 } }, frame.bytes)+ const prepare = await subject.respond(SUBSCRIPTION_VENDOR_URLS['grok-subscription'].responses, requests.prepare)+ const shellCalls = await functionCalls(prepare)+ assert.deepEqual(shellCalls, [{ type: 'function_call', callId: shellCalls[0].callId, name: 'shell_exec', arguments: { command: `test -r ${requests.prompt.match(/Screen fixture: (\S+)/)[1]}` }, delta: shellCalls[0].delta, done: shellCalls[0].done }])+ assert.equal(shellCalls[0].delta.delta, shellCalls[0].done.arguments)++ const capture = await subject.respond(SUBSCRIPTION_VENDOR_URLS['grok-subscription'].responses, requests.capture)+ const frameCalls = await functionCalls(capture)+ assert.deepEqual(frameCalls.map(call => [call.name, call.arguments]), [['desktop_screenshot', { region: { x: 8, y: 16, w: 512, h: 512 } }]])++ assert.equal(await responseCode(await subject.respond(SUBSCRIPTION_VENDOR_URLS['grok-subscription'].responses, requests.pixels)), frame.code)+ const rows = subject.snapshot().attempts+ assert.deepEqual(rows.map(row => [row.journey, row.stage, row.responseKind]), [+ ['tool-screenshot', 'prepare', 'tool_calls'],+ ['tool-screenshot', 'capture', 'tool_calls'],+ ['tool-screenshot', 'pixels', 'pixels'],+ ])+ assert.deepEqual(rows[0].toolCalls, [{ id: shellCalls[0].callId, name: 'shell_exec', argumentsSha256: digest(requests.shellCall.arguments) }])+ assert.equal(rows[1].toolOutputs[0].outputSha256, digest('(no output)'))+ assert.deepEqual(rows[2].decodedPixels, [{ width: 512, height: 512 }])+ assert.equal(rows[2].outputSha256, digest(frame.code))+})++test('same vendor handles three repeated 20-image requests in one PID without answer leakage', { timeout: 120_000 }, async () => {+ const subject = vendor()+ const cycles = Array.from({ length: 3 }, () => Array.from({ length: 20 }, (_, index) => image(index % 2 ? 'jpeg' : 'png')))+ const allImages = cycles.flat()+ for (const [index, images] of cycles.entries()) {+ const receipt = randomUUID()+ const response = await subject.respond(+ SUBSCRIPTION_VENDOR_URLS['grok-subscription'].responses,+ request(images, receipt, bindings[0].modelId),+ )+ assert.equal(response.status, 200)+ assert.equal(response.headers.get('content-type'), 'text/event-stream')+ const expected = images.map(item => item.code).join('\n')+ for (const [name, value] of response.headers.entries()) {+ assert(!value.includes(expected), `${name} leaked the ordered answer`)+ for (const item of images) {+ assert(!value.includes(item.code), `${name} leaked a pixel answer`)+ assert(!value.includes(item.bytes.toString('base64')), `${name} leaked image bytes`)+ }+ }+ assert.equal(await responseCode(response), expected)+ }+ const rows = subject.snapshot().attempts+ assert.equal(rows.length, 3)+ assert.deepEqual(rows.map(row => row.sequence), [1, 2, 3])+ assert.deepEqual(rows.map(row => row.imageSha256.length), [20, 20, 20])+ assert.deepEqual(rows.map(row => row.decodedPixels.length), [20, 20, 20])+ for (const row of rows) {+ assert.equal(row.responseKind, 'pixels')+ assert.deepEqual(row.receivedImageOrder, row.imageSha256)+ assert(row.decodedPixels.every(pixel => pixel.width === 512 && pixel.height === 512))+ }+ const serialized = JSON.stringify(subject.snapshot())+ for (const item of allImages) {+ assert(!serialized.includes(item.code))+ assert(!serialized.includes(item.bytes.toString('base64')))+ }+})test('both subscription external peers answer from ordered received pixels and publish only bounded evidence', async () => {- const vendor = createSubscriptionImageVendor({ runId: 'subscription-image-123456abcdef', bindings })+ const subject = vendor()const images = [image('png'), image('jpeg')]for (const binding of bindings) {- const response = await vendor.respond(SUBSCRIPTION_VENDOR_URLS[binding.provider].responses, request(images, randomUUID(), binding.modelId))- assert.equal(response.status, 200)- const delta = (await response.text()).split('\n').filter(line => line.startsWith('data: ')).map(line => JSON.parse(line.slice(6))).find(event => event.type === 'response.output_text.delta')- assert.equal(delta.delta, images.map(item => item.code).join('\n'))+ const response = await subject.respond(SUBSCRIPTION_VENDOR_URLS[binding.provider].responses, request(images, randomUUID(), binding.modelId))+ assert.equal(await responseCode(response), images.map(item => item.code).join('\n'))}- const evidence = vendor.snapshot()+ const evidence = subject.snapshot()assert.equal(evidence.attempts.length, 2)assert.equal(evidence.attempts[0].imageSha256.length, 2)+ assert.deepEqual(evidence.attempts[0].receivedImageOrder, evidence.attempts[0].imageSha256)+ assert.deepEqual(evidence.attempts[0].decodedPixels, [{ width: 512, height: 512 }, { width: 512, height: 512 }])assert.equal(evidence.attempts[0].responseKind, 'pixels')const serialized = JSON.stringify(evidence)for (const item of images) {@@ -37,15 +243,10 @@ test('both subscription external peers answer from ordered received pixels and p})test('removing, replacing or reordering wire bytes cannot satisfy the original ordered oracle', async () => {- const vendor = createSubscriptionImageVendor({ runId: 'subscription-image-123456abcdef', bindings })+ const subject = vendor()const images = [image('png'), image('jpeg')]const expected = images.map(item => item.code).join('\n')- const output = async input => {- const response = await vendor.respond(SUBSCRIPTION_VENDOR_URLS['grok-subscription'].responses, request(input))- const stream = await response.text()- const events = stream.split('\n').filter(line => line.startsWith('data: ')).map(line => JSON.parse(line.slice(6)))- return events.find(event => event.type === 'response.output_text.delta')?.delta- }+ const output = async input => responseCode(await subject.respond(SUBSCRIPTION_VENDOR_URLS['grok-subscription'].responses, request(input)))assert.equal(await output(images), expected)assert.notEqual(await output([...images].reverse()), expected)assert.notEqual(await output(images.slice(0, 1)), expected)@@ -54,18 +255,101 @@ test('removing, replacing or reordering wire bytes cannot satisfy the original o})test('rejects no-code images, unsupported models and every non-vendor boundary', async () => {- const vendor = createSubscriptionImageVendor({ runId: 'subscription-image-123456abcdef', bindings })- const response = await vendor.respond(SUBSCRIPTION_VENDOR_URLS['grok-subscription'].responses, request([{ format: 'png', bytes: Buffer.from([1, 2, 3]) }]))- assert.equal(response.status, 422)- const unsupported = await vendor.respond(SUBSCRIPTION_VENDOR_URLS['grok-subscription'].responses, request([image('png')], randomUUID(), bindings[0].unsupportedModelId))- assert.equal(unsupported.status, 422)+ const subject = vendor()+ assert.equal(await responseCode(await subject.respond(SUBSCRIPTION_VENDOR_URLS['grok-subscription'].responses, request([{ format: 'png', bytes: Buffer.from([1, 2, 3]) }]))), 'image_challenge_unreadable')+ const malformedCompletePng = Buffer.concat([+ Buffer.from([0x89, 0x50, 0x4e, 0x47, 0x0d, 0x0a, 0x1a, 0x0a]),+ Buffer.alloc(4),+ Buffer.from([0, 0, 0, 0, 0x49, 0x45, 0x4e, 0x44, 0xae, 0x42, 0x60, 0x82]),+ ])+ assert.equal(await responseCode(await subject.respond(SUBSCRIPTION_VENDOR_URLS['grok-subscription'].responses, request([{ format: 'png', bytes: malformedCompletePng }]))), 'image_challenge_unreadable')+ const unsupported = await subject.respond(SUBSCRIPTION_VENDOR_URLS['grok-subscription'].responses, request([image('png')], randomUUID(), bindings[0].unsupportedModelId))+ assert.equal(await responseCode(unsupported), 'image_model_unsupported')for (const url of ['https://example.invalid/api/v1/mcp-host/llm-provider-attempts/authorize', 'https://fixture.invalid/responses', SUBSCRIPTION_VENDOR_URLS['grok-subscription'].responses + '?escape=1']) {- await assert.rejects(() => vendor.respond(url, request([image('png')])), /external vendor boundary/)+ await assert.rejects(() => subject.respond(url, request([image('png')])), /external vendor boundary/)}+ const survivor = image('png')+ assert.equal(await responseCode(await subject.respond(SUBSCRIPTION_VENDOR_URLS['grok-subscription'].responses, request([survivor]))), survivor.code)})test('bounds retained attempts and request bodies rather than hiding missing evidence', async () => {- const vendor = createSubscriptionImageVendor({ runId: 'subscription-image-123456abcdef', bindings, maxAttempts: 1 })- await vendor.respond(SUBSCRIPTION_VENDOR_URLS['grok-subscription'].responses, request([]))- await assert.rejects(() => vendor.respond(SUBSCRIPTION_VENDOR_URLS['grok-subscription'].responses, request([])), /evidence bound/)+ const subject = createSubscriptionImageVendor({ runId: 'subscription-image-123456abcdef', bindings, maxAttempts: 1 })+ await subject.respond(SUBSCRIPTION_VENDOR_URLS['grok-subscription'].responses, request([]))+ await assert.rejects(() => subject.respond(SUBSCRIPTION_VENDOR_URLS['grok-subscription'].responses, request([])), /evidence bound/)+})++test('screenshot rejects wrong commands, wrong shell output, and header-only capture pixels', async () => {+ const fixture = { path: '/tmp/evenfire-qa-screen-0189f3ab-28c1-4f61-9245-58ba7d02e4a2.png', region: { x: 0, y: 0, w: 512, h: 512 } }+ const subject = vendor()+ const wrongCommand = { method: 'POST', body: JSON.stringify({ model: bindings[0].modelId, input: [+ userMessage(screenshotPrompt(fixture.path, fixture.region)), callItem('call-shell', 'shell_exec', { command: 'test -r /other.png' }),+ ] }) }+ assert.equal(await responseCode(await subject.respond(SUBSCRIPTION_VENDOR_URLS['grok-subscription'].responses, wrongCommand)), 'tool_source_invalid')+ const wrongOutput = { method: 'POST', body: JSON.stringify({ model: bindings[0].modelId, input: [+ userMessage(screenshotPrompt(fixture.path, fixture.region)), callItem('call-shell', 'shell_exec', { command: `test -r ${fixture.path}` }), outputItem('call-shell', 'ok'),+ ] }) }+ assert.equal(await responseCode(await subject.respond(SUBSCRIPTION_VENDOR_URLS['grok-subscription'].responses, wrongOutput)), 'tool_source_invalid')+ const headerOnly = Buffer.from([0x89, 0x50, 0x4e, 0x47, 0x0d, 0x0a, 0x1a, 0x0a])+ const complete = screenshotRequests(fixture, headerOnly)+ await subject.respond(SUBSCRIPTION_VENDOR_URLS['grok-subscription'].responses, complete.prepare)+ await subject.respond(SUBSCRIPTION_VENDOR_URLS['grok-subscription'].responses, complete.capture)+ assert.equal(await responseCode(await subject.respond(SUBSCRIPTION_VENDOR_URLS['grok-subscription'].responses, complete.pixels)), 'image_challenge_unreadable')+})++test('GFS emits ordered reads from projected references and answers in received wire order', async () => {+ const subject = vendor()+ const files = gfsFixture()+ const frames = [image('png'), image('jpeg')]+ const requests = gfsRequests(files, frames)+ const read = await subject.respond(SUBSCRIPTION_VENDOR_URLS['grok-subscription'].responses, requests.prepare)+ const calls = await functionCalls(read)+ assert.deepEqual(calls.map(call => [call.type, call.name, call.arguments]), [+ ['function_call', 'clerum__gfs_read', { drive: files[0].drive, resourceId: files[0].resourceId, expectedVersion: files[0].version }],+ ['function_call', 'clerum__gfs_read', { drive: files[1].drive, resourceId: files[1].resourceId, expectedVersion: files[1].version }],+ ])+ assert.equal(await responseCode(await subject.respond(SUBSCRIPTION_VENDOR_URLS['grok-subscription'].responses, requests.pixels)), frames.map(frame => frame.code).join('\n'))+ const parsedPixels = JSON.parse(requests.pixels.body)+ const reversedPixels = { ...parsedPixels, input: [+ ...parsedPixels.input.slice(0, -1),+ userMessage('These images were read by the tools above.', [...frames].reverse()),+ ] }+ assert.equal(await responseCode(await subject.respond(SUBSCRIPTION_VENDOR_URLS['grok-subscription'].responses, {+ method: 'POST',+ body: JSON.stringify(reversedPixels),+ })), [...frames].reverse().map(frame => frame.code).join('\n'))+ const [readRow, pixelRow] = subject.snapshot().attempts+ assert.deepEqual(readRow.stage, 'read')+ assert.deepEqual(readRow.responseKind, 'tool_calls')+ assert.deepEqual(readRow.referencedFiles, files.map(({ referenceId, drive, resourceId, version, byteLength }) => ({+ referenceId, drive, resourceId, version, availability: 'available', byteLength,+ })))+ assert.deepEqual(pixelRow.toolOutputs.map(output => output.resource), files.map(file => ({+ kind: 'gfs', drive: file.drive, resourceId: file.resourceId, version: file.version, gfsUri: `gfs://${file.drive}/${file.resourceId}`,+ })))+ assert.deepEqual(pixelRow.decodedPixels, [{ width: 512, height: 512 }, { width: 512, height: 512 }])+})++test('GFS missing, mismatched, or undecodable source delivery fails causally', async () => {+ const files = gfsFixture()+ const frames = [image('png'), image('jpeg')]+ const subject = vendor()+ const requests = gfsRequests(files, frames)+ const missingInstructions = { method: 'POST', body: JSON.stringify({ model: bindings[0].modelId, input: JSON.parse(requests.prepare.body).input }) }+ assert.equal(await responseCode(await subject.respond(SUBSCRIPTION_VENDOR_URLS['grok-subscription'].responses, missingInstructions)), 'referenced_files_invalid')+ const pixelInput = JSON.parse(requests.pixels.body).input+ const mismatched = { method: 'POST', body: JSON.stringify({ model: bindings[0].modelId, instructions: JSON.parse(requests.prepare.body).instructions, input: [+ pixelInput[0],+ callItem('call-read-0', 'clerum__gfs_read', { drive: files[0].drive, resourceId: files[0].resourceId, expectedVersion: files[0].version }),+ outputItem('call-read-0', JSON.stringify({ resource: { kind: 'gfs', drive: files[0].drive, resourceId: files[1].resourceId, version: files[0].version, gfsUri: `gfs://${files[0].drive}/${files[0].resourceId}` }, delivery: 'image_input' })),+ callItem('call-read-1', 'clerum__gfs_read', { drive: files[1].drive, resourceId: files[1].resourceId, expectedVersion: files[1].version }),+ outputItem('call-read-1', pixelInput[3].output),+ ] }) }+ assert.equal(await responseCode(await subject.respond(SUBSCRIPTION_VENDOR_URLS['grok-subscription'].responses, mismatched)), 'tool_state_invalid')+ const headerOnly = Buffer.from([0x89, 0x50, 0x4e, 0x47, 0x0d, 0x0a, 0x1a, 0x0a])+ const unreadable = gfsRequests(files, [{ format: 'png', bytes: headerOnly }, frames[1]])+ await subject.respond(SUBSCRIPTION_VENDOR_URLS['grok-subscription'].responses, unreadable.prepare)+ assert.equal(await responseCode(await subject.respond(SUBSCRIPTION_VENDOR_URLS['grok-subscription'].responses, unreadable.pixels)), 'image_challenge_unreadable')+ const missingPixels = gfsRequests(files, [frames[0]])+ await subject.respond(SUBSCRIPTION_VENDOR_URLS['grok-subscription'].responses, missingPixels.prepare)+ assert.equal(await responseCode(await subject.respond(SUBSCRIPTION_VENDOR_URLS['grok-subscription'].responses, missingPixels.pixels)), 'tool_state_invalid')})diff --git a/scripts/e2e/fixtures/subscription-image-runner.Dockerfile b/scripts/e2e/fixtures/subscription-image-runner.Dockerfileindex c1deb8419..909458689 100644--- a/scripts/e2e/fixtures/subscription-image-runner.Dockerfile+++ b/scripts/e2e/fixtures/subscription-image-runner.Dockerfile@@ -39,6 +39,10 @@ COPY scripts/tests/lib/subscription-image-runner-contract.mjs \scripts/tests/lib/subscription-image-source-context.mjs ./scripts/tests/lib/COPY desktop-app/test/e2e-playwright/ ./desktop-app/test/e2e-playwright/COPY scripts/e2e/run-subscription-image-journeys.mjs ./scripts/e2e/run-subscription-image-journeys.mjs+COPY scripts/e2e/prepare-subscription-remaining-fixtures.mjs \+ scripts/e2e/prepare-subscription-remaining-fixtures.gfs.mjs \+ scripts/e2e/prepare-subscription-remaining-fixtures.runtime.mjs \+ scripts/e2e/prepare-subscription-remaining-fixtures.prepare.mjs ./scripts/e2e/COPY scripts/e2e/fixtures/ ./scripts/e2e/fixtures/COPY subscription-image-input-source.json ./subscription-image-input-source.json# Compile-time UI feature flags come from the admitted suite contract. The@@ -92,15 +96,33 @@ COPY desktop-app/test/e2e-playwright/subscription-image-input.spec.ts \desktop-app/test/e2e-playwright/subscriptionImageFixtures.ts \desktop-app/test/e2e-playwright/subscriptionImageRunContract.ts \desktop-app/test/e2e-playwright/subscriptionImageChallenge.ts \- desktop-app/test/e2e-playwright/codexImageChallenge.ts ./desktop-app/test/e2e-playwright/+ desktop-app/test/e2e-playwright/codexImageChallenge.ts \+ desktop-app/test/e2e-playwright/subscription-tool-screenshot.spec.ts \+ desktop-app/test/e2e-playwright/subscription-gfs-image.spec.ts \+ desktop-app/test/e2e-playwright/subscription-admission-recovery.spec.ts \+ desktop-app/test/e2e-playwright/playwright.subscription-tool-screenshot.config.ts \+ desktop-app/test/e2e-playwright/playwright.subscription-gfs-image.config.ts \+ desktop-app/test/e2e-playwright/playwright.subscription-admission-recovery.config.ts \+ desktop-app/test/e2e-playwright/subscriptionRemainingJourneyConfig.ts \+ desktop-app/test/e2e-playwright/subscriptionRemainingJourneyData.ts \+ desktop-app/test/e2e-playwright/subscriptionRemainingJourneyUi.ts \+ desktop-app/test/e2e-playwright/subscriptionRemainingJourneysContract.ts \+ desktop-app/test/e2e-playwright/navigationHelpers.ts ./desktop-app/test/e2e-playwright/COPY scripts/e2e/run-subscription-image-journeys.mjs ./scripts/e2e/run-subscription-image-journeys.mjs+COPY scripts/e2e/prepare-subscription-remaining-fixtures.mjs \+ scripts/e2e/prepare-subscription-remaining-fixtures.gfs.mjs \+ scripts/e2e/prepare-subscription-remaining-fixtures.runtime.mjs \+ scripts/e2e/prepare-subscription-remaining-fixtures.prepare.mjs ./scripts/e2e/COPY scripts/e2e/fixtures/subscription-image-provider.mjs \scripts/e2e/fixtures/subscription-image-challenge.cjs \scripts/e2e/fixtures/subscription-image-session.mjs \+ scripts/e2e/fixtures/subscription-image-admission-pressure.mjs \scripts/e2e/fixtures/subscription-image-runner.base-image ./scripts/e2e/fixtures/COPY scripts/tests/lib/subscription-image-runner-contract.mjs \scripts/tests/lib/subscription-image-source-context.mjs ./scripts/tests/lib/COPY subscription-image-input-source.json ./subscription-image-input-source.json+# Exported public source is private on the host; the sealed nonroot image must read it.+RUN chmod -R a+rX /opt/evenfireRUN node --input-type=module -e "import {sealSourceManifest} from './scripts/e2e/run-subscription-image-journeys.mjs'; sealSourceManifest(process.cwd())" \&& chown root:root desktop-app/node_modules/electron/dist/chrome-sandbox \&& chmod 4755 desktop-app/node_modules/electron/dist/chrome-sandboxdiff --git a/scripts/e2e/fixtures/subscription-image-runner.make.fragment b/scripts/e2e/fixtures/subscription-image-runner.make.fragmentdeleted file mode 100644index 0a06f546b..000000000--- a/scripts/e2e/fixtures/subscription-image-runner.make.fragment+++ /dev/null@@ -1,33 +0,0 @@-# PR806 subscription-image runner: fragment for the repository Makefile owner.-# Do not merge this file into the tree; append the target below the existing-# minikube image targets so it inherits the branch-owned mutation lease.-#-# Required operator inputs (all explicit, no defaults invented here):-# MINIKUBE_PROFILE, CONTROL_API_REAL_PG_CONTEXT (equal to the profile)-# SUBSCRIPTION_IMAGE_SUITE subscription-image-input | tool-screenshot | gfs-image | admission-recovery-# SUBSCRIPTION_IMAGE_MODE fixture | real-# SUBSCRIPTION_IMAGE_SCRATCH absolute scratch dir outside the repository-# SUBSCRIPTION_IMAGE_FRAMES absolute 0600 frames file (operator supplied)-# SUBSCRIPTION_IMAGE_BINDINGS absolute 0600 bindings JSON (owned Host/model ids)-# SUBSCRIPTION_IMAGE_RED_DETECTOR absolute path to the installed RED detector-.PHONY: minikube-subscription-image-journeys-minikube-subscription-image-journeys:- @test -n "$${MINIKUBE_PROFILE:-}" || { echo "MINIKUBE_PROFILE required"; exit 1; }- @test -n "$${CONTROL_API_REAL_PG_CONTEXT:-}" || { echo "CONTROL_API_REAL_PG_CONTEXT required"; exit 1; }- @test -n "$${SUBSCRIPTION_IMAGE_SUITE:-}" || { echo "SUBSCRIPTION_IMAGE_SUITE required"; exit 1; }- @test -n "$${SUBSCRIPTION_IMAGE_MODE:-}" || { echo "SUBSCRIPTION_IMAGE_MODE required"; exit 1; }- @test -n "$${SUBSCRIPTION_IMAGE_SCRATCH:-}" || { echo "SUBSCRIPTION_IMAGE_SCRATCH required"; exit 1; }- @test -n "$${SUBSCRIPTION_IMAGE_FRAMES:-}" || { echo "SUBSCRIPTION_IMAGE_FRAMES required"; exit 1; }- @test -n "$${SUBSCRIPTION_IMAGE_BINDINGS:-}" || { echo "SUBSCRIPTION_IMAGE_BINDINGS required"; exit 1; }- @test -n "$${SUBSCRIPTION_IMAGE_RED_DETECTOR:-}" || { echo "SUBSCRIPTION_IMAGE_RED_DETECTOR required"; exit 1; }- @T2_PROJECT_DIR="$(CURDIR)" T2_PROFILE="$(MINIKUBE_PROFILE)" T2_CONTEXT="$(CONTROL_API_REAL_PG_CONTEXT)" \- T2_SKIP_LOCK="$(T2_SKIP_LOCK)" T2_LOCK_TOKEN="$(T2_LOCK_TOKEN)" \- bash scripts/minikube/with-t2-mutation-lock.sh -- \- node scripts/e2e/prepare-subscription-image-admission.mjs \- --suite "$$SUBSCRIPTION_IMAGE_SUITE" \- --mode "$$SUBSCRIPTION_IMAGE_MODE" \- --profile "$$MINIKUBE_PROFILE" \- --scratch "$$SUBSCRIPTION_IMAGE_SCRATCH" \- --frames "$$SUBSCRIPTION_IMAGE_FRAMES" \- --bindings "$$SUBSCRIPTION_IMAGE_BINDINGS" \- --red-detector "$$SUBSCRIPTION_IMAGE_RED_DETECTOR"diff --git a/scripts/e2e/prepare-subscription-image-admission.mjs b/scripts/e2e/prepare-subscription-image-admission.mjsindex c35cf03cc..cdbfb8f26 100644--- a/scripts/e2e/prepare-subscription-image-admission.mjs+++ b/scripts/e2e/prepare-subscription-image-admission.mjs@@ -56,11 +56,12 @@ function required(values, name) {return value}-function run(command, args, options = {}) {+export function run(command, args, options = {}) {return execFileSync(command, args, {encoding: 'utf8',timeout: options.timeout ?? 900_000,- stdio: options.stdio ?? ['ignore', 'pipe', 'pipe'],+ input: options.input,+ stdio: options.stdio ?? [options.input === undefined ? 'ignore' : 'pipe', 'pipe', 'pipe'],})}@@ -88,13 +89,6 @@ function writePrivateJson(filename, value) {fs.writeFileSync(filename, JSON.stringify(value), { flag: 'wx', mode: 0o600 })}-// Published into the read-only admission mount: readable by the non-root-// container user, never writable by it. Integrity stays hash-bound.-function writePublishedJson(filename, value) {- fs.writeFileSync(filename, JSON.stringify(value), { flag: 'wx', mode: 0o644 })- fs.chmodSync(filename, 0o644)-}-export async function prepare(argv = process.argv.slice(2)) {const values = parseArgs(argv)const suiteId = required(values, 'suite')@@ -111,11 +105,13 @@ export async function prepare(argv = process.argv.slice(2)) {if (context !== profile) refuse('PREPARE_CONTEXT_MISMATCH')const suite = resolveSuite(suiteId)if (!suite.modes.includes(mode)) refuse('SUITE_MODE_NOT_ADMITTED')- if (!path.isAbsolute(scratch) || !path.isAbsolute(framesFile) || !path.isAbsolute(detector))+ // Login frames travel through the live private input channel, never a file.+ if (framesFile !== '-') refuse('PREPARE_PRIVATE_INPUT_REQUIRES_STDIN')+ if (!path.isAbsolute(scratch) || !path.isAbsolute(bindingsFile) || !path.isAbsolute(detector))refuse('PREPARE_ABSOLUTE_PATHS')if (scratch.startsWith(`${SCRIPT_ROOT}/`) || scratch === SCRIPT_ROOT)refuse('PREPARE_SCRATCH_INSIDE_REPO')- for (const filename of [framesFile, bindingsFile]) {+ for (const filename of [bindingsFile]) {const stat = fs.lstatSync(filename)const parent = path.dirname(filename)if (@@ -190,6 +186,7 @@ export async function prepare(argv = process.argv.slice(2)) {'create','--name',containerName,+ '-i','--user','10001:10001','--read-only',@@ -305,7 +302,7 @@ export async function prepare(argv = process.argv.slice(2)) {}for (const [name, value] of files) {const filename = path.join(admissionDir, name)- writePublishedJson(filename, value)+ writePrivateJson(filename, value)receipts[receiptNames[name]] = { value, sha256: digest(JSON.stringify(value)) }}const sealedFilename = path.join(scratch, 'subscription-image-source.json')@@ -359,7 +356,7 @@ export async function prepare(argv = process.argv.slice(2)) {createdAt: new Date(Date.parse(volumeInspect.CreatedAt)).toISOString(),inspectSha256: digest(JSON.stringify(volumeInspect)),}- writePublishedJson(path.join(admissionDir, 'main-admission.json'), admission)+ writePrivateJson(path.join(admissionDir, 'main-admission.json'), admission)const framesPayload = ['main-admission.json',...Object.values(MAIN_RECEIPT_FILES),@@ -395,9 +392,22 @@ export async function prepare(argv = process.argv.slice(2)) {const attached = spawn('docker', ['attach', '--sig-proxy=false', containerName], {stdio: ['pipe', 'inherit', 'inherit'],})- const frames = fs.readFileSync(framesFile)- attached.stdin.end(frames)- const result = await new Promise(resolve => attached.once('exit', (code, signal) => resolve({ code, signal })))+ let inputFailed = false+ const onInputError = () => {+ inputFailed = true+ attached.kill('SIGTERM')+ }+ attached.stdin.on('error', onInputError)+ process.stdin.once('error', onInputError)+ process.stdin.pipe(attached.stdin)+ let result+ try {+ result = await new Promise(resolve => attached.once('exit', (code, signal) => resolve({ code, signal })))+ } finally {+ process.stdin.unpipe(attached.stdin)+ process.stdin.off('error', onInputError)+ process.stdin.pause()+ }const status = run('docker', ['wait', containerName], { timeout: 30_000 }).trim()for (const name of ['runner.json', 'journey-result.json', path.basename(observationFile)]) {try {@@ -417,13 +427,14 @@ export async function prepare(argv = process.argv.slice(2)) {container: containerName,attachExit: result.code,attachSignal: result.signal,+ inputFailed,containerStatus: status,admissionDir,receiptDir,scratch,}console.log(JSON.stringify(summary, null, 2))- return status === '0' && result.code === 0 ? 0 : 1+ return status === '0' && result.code === 0 && !inputFailed ? 0 : 1} catch (err) {if (values.keep !== 'true') {try {diff --git a/scripts/tests/lib/subscription-image-main-admission.mjs b/scripts/tests/lib/subscription-image-main-admission.mjsindex bd16c9192..b23500fdc 100644--- a/scripts/tests/lib/subscription-image-main-admission.mjs+++ b/scripts/tests/lib/subscription-image-main-admission.mjs@@ -9,6 +9,7 @@ import {RUNNER_RUN_BASE,RunnerAdmissionError,digest,+ admissionVolumeName,parsePortForwardRecord,pinnedBaseImage,resolveSuite,@@ -71,11 +72,12 @@ export function runtimeFromInspect(inspect, { runId, suiteId, home }) {if (mounts.length !== 4 ||admissionMounts.length !== 1 ||- admissionMounts[0].Type !== 'bind' ||+ admissionMounts[0].Type !== 'volume' ||+ admissionMounts[0].Name !== admissionVolumeName(runId) ||admissionMounts[0].RW !== false ||typeof admissionMounts[0].Source !== 'string' ||!admissionMounts[0].Source ||- mounts.some(mount => mount.Type === 'bind' && mount.Destination !== RUNNER_ADMISSION_ROOT) ||+ mounts.some(mount => mount.Type === 'bind') ||mounts.some(mount => PERSONAL.test(String(mount.Source ?? '')) || PERSONAL.test(String(mount.Destination ?? ''))) ||diff --git a/scripts/tests/lib/subscription-image-runner-contract.mjs b/scripts/tests/lib/subscription-image-runner-contract.mjsindex c64386a18..39019054a 100644--- a/scripts/tests/lib/subscription-image-runner-contract.mjs+++ b/scripts/tests/lib/subscription-image-runner-contract.mjs@@ -25,6 +25,11 @@ const nsNames = ['mnt', 'pid', 'user']export const RUNNER_RUN_BASE = '/run/evenfire-e2e'export const RUNNER_ADMISSION_ROOT = '/runner-admission'+export function admissionVolumeName(runId) {+ if (!/^subscription-image-[a-f0-9]{12}$/.test(runId ?? '')) refuse('ADMISSION_VOLUME_IDENTITY')+ return `evenfire-sir-${runId.slice('subscription-image-'.length)}-admission`+}+export function readPrivateRecord(filename, maxBytes = 64 * 1024, uid = process.getuid?.()) {if (fs.realpathSync(path.dirname(filename)) !== path.dirname(filename))refuse('PRIVATE_PARENT_SYMLINK')@@ -68,7 +73,6 @@ export function readMainRecord(filename, maxBytes = 4 * 1024 * 1024) {stat.size > maxBytes)refuse('MAIN_RECEIPT_BOUND_OR_MODE')- if (stat.uid === process.getuid?.()) refuse('MAIN_RECEIPT_AUTHORED_BY_RUNNER')const raw = fs.readFileSync(fd)return { value: JSON.parse(raw.toString('utf8')), sha256: digest(raw), uid: stat.uid }} finally {@@ -852,51 +856,84 @@ export function verifyJourneyReport(report, mode, expectedFile) {return verifySuiteReport(report, mode, resolveSuite(), expectedFile)}-export function admitVendorFrame(frame, runId, binding, source, previous) {- if (- frame.kind !== 'evenfire-subscription-image-vendor-frame-v1' ||- frame.runId !== runId ||- frame.provider !== binding.provider ||- !isDeepStrictEqual(frame.source, source) ||- frame.ledger?.kind !== 'evenfire-subscription-image-vendor-v1' ||- frame.ledger.runId !== runId ||- !Array.isArray(frame.ledger.attempts) ||- frame.ledger.attempts.length > 256 ||- frame.ledger.attempts.length < previous.length- )+const closedVendorObject = (value, keys) =>+ value !== null && typeof value === 'object' && !Array.isArray(value) &&+ Object.keys(value).every(key => keys.includes(key))+const vendorHash = value => typeof value === 'string' && /^[a-f0-9]{64}$/.test(value)+const vendorId = value => typeof value === 'string' && /^[A-Za-z0-9][A-Za-z0-9._:-]{0,127}$/.test(value)+const vendorHashes = value => Array.isArray(value) && value.length <= 20 && value.every(vendorHash)+const vendorList = (value, limit, check) => Array.isArray(value) && value.length <= limit && value.every(check)+const vendorDrive = value => typeof value === 'string' && /^[A-Za-z0-9][A-Za-z0-9._-]{0,127}$/.test(value)+const vendorResourceId = value => typeof value === 'string' && /^[a-f0-9]{32}$/.test(value)+const vendorResource = value =>+ closedVendorObject(value, ['kind', 'drive', 'resourceId', 'version', 'gfsUri']) &&+ value.kind === 'gfs' && vendorDrive(value.drive) && vendorResourceId(value.resourceId) &&+ integer(value.version) && value.gfsUri === `gfs://${value.drive}/${value.resourceId}`++export function validateVendorLedger(ledger, runId, binding, previous = []) {+ if (!closedVendorObject(ledger, ['kind', 'runId', 'attempts']) ||+ ledger.kind !== 'evenfire-subscription-image-vendor-v1' || ledger.runId !== runId ||+ !Array.isArray(ledger.attempts) || ledger.attempts.length > 256 ||+ !Array.isArray(previous) || ledger.attempts.length < previous.length)refuse('VENDOR_EVIDENCE_SOURCE_OR_SEQUENCE')- for (const [index, row] of frame.ledger.attempts.entries()) {- const allowed = [- 'sequence',- 'provider',- 'model',- 'receiptId',- 'imageSha256',- 'mimeTypes',- 'requestSha256',- 'responseKind',- 'outputSha256',- ]- if (- Object.keys(row).some(key => !allowed.includes(key)) ||- row.sequence !== index + 1 ||- row.provider !== binding.provider ||+ for (const [index, row] of ledger.attempts.entries()) {+ if (!closedVendorObject(row, [+ 'sequence', 'provider', 'model', 'receiptId', 'imageSha256', 'mimeTypes',+ 'requestSha256', 'responseKind', 'outputSha256', 'journey', 'stage',+ 'toolCalls', 'toolOutputs', 'referencedFiles', 'receivedImageDigests',+ 'receivedImageOrder', 'decodedPixels',+ ]) || row.sequence !== index + 1 || row.provider !== binding.provider ||![binding.modelId, binding.unsupportedModelId].includes(row.model) ||- !/^[a-f0-9-]{36}$/.test(row.receiptId) ||- !Array.isArray(row.imageSha256) ||- row.imageSha256.length > 20 ||- row.imageSha256.some(value => !/^[a-f0-9]{64}$/.test(value)) ||- !Array.isArray(row.mimeTypes) ||+ typeof row.receiptId !== 'string' || !/^[a-f0-9]{8}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{12}$/.test(row.receiptId) ||+ !vendorHashes(row.imageSha256) || !Array.isArray(row.mimeTypes) ||row.mimeTypes.length !== row.imageSha256.length ||row.mimeTypes.some(value => !['image/png', 'image/jpeg'].includes(value)) ||- !/^[a-f0-9]{64}$/.test(row.requestSha256) ||- !['pixels', 'text', 'rejected'].includes(row.responseKind) ||- (row.outputSha256 !== undefined && !/^[a-f0-9]{64}$/.test(row.outputSha256))- )+ !vendorHash(row.requestSha256) || !['pixels', 'text', 'rejected', 'tool_calls'].includes(row.responseKind) ||+ (row.outputSha256 !== undefined && !vendorHash(row.outputSha256)))refuse('VENDOR_EVIDENCE_SHAPE')+ if ((row.journey !== undefined && !['tool-screenshot', 'gfs-image'].includes(row.journey)) ||+ (row.stage !== undefined && (row.journey === undefined ||+ !(row.journey === 'tool-screenshot' ? ['prepare', 'capture', 'pixels'] : ['read', 'pixels']).includes(row.stage))) ||+ (row.responseKind === 'tool_calls' && (!row.journey || !row.stage)))+ refuse('VENDOR_EVIDENCE_TOOL_STAGE')+ if ((row.receivedImageDigests !== undefined || row.receivedImageOrder !== undefined) &&+ (!vendorHashes(row.receivedImageDigests) || !vendorHashes(row.receivedImageOrder) ||+ !isDeepStrictEqual(row.receivedImageDigests, row.imageSha256) ||+ !isDeepStrictEqual(row.receivedImageOrder, row.imageSha256)))+ refuse('VENDOR_EVIDENCE_IMAGE_ORDER')+ if (row.decodedPixels !== undefined &&+ (!vendorList(row.decodedPixels, 20, value =>+ closedVendorObject(value, ['width', 'height']) && integer(value.width) && integer(value.height) &&+ value.width <= 9000 && value.height <= 9000) ||+ row.decodedPixels.length > row.imageSha256.length ||+ (row.responseKind !== 'rejected' && row.decodedPixels.length !== row.imageSha256.length)))+ refuse('VENDOR_EVIDENCE_PIXEL_METADATA')+ if (row.toolCalls !== undefined && !vendorList(row.toolCalls, 32, value =>+ closedVendorObject(value, ['id', 'name', 'argumentsSha256']) && vendorId(value.id) &&+ ['shell_exec', 'desktop_screenshot', 'clerum__gfs_read'].includes(value.name) && vendorHash(value.argumentsSha256)))+ refuse('VENDOR_EVIDENCE_TOOL_CALL')+ if (row.toolOutputs !== undefined && !vendorList(row.toolOutputs, 32, value =>+ closedVendorObject(value, ['id', 'outputSha256', 'resource']) && vendorId(value.id) &&+ vendorHash(value.outputSha256) && (value.resource === undefined || vendorResource(value.resource))))+ refuse('VENDOR_EVIDENCE_TOOL_OUTPUT')+ if (row.referencedFiles !== undefined && !vendorList(row.referencedFiles, 2, value =>+ closedVendorObject(value, ['referenceId', 'drive', 'resourceId', 'version', 'availability', 'byteLength']) &&+ vendorDrive(value.drive) && vendorResourceId(value.resourceId) && integer(value.version) &&+ value.referenceId === `gfs:${value.drive}:${value.resourceId}@v${value.version}` &&+ value.availability === 'available' && integer(value.byteLength) && value.byteLength <= 20 * 1024 * 1024))+ refuse('VENDOR_EVIDENCE_FILE_REFERENCE')if (index < previous.length && !isDeepStrictEqual(row, previous[index]))refuse('VENDOR_EVIDENCE_HISTORY_CHANGED')}+ return ledger.attempts+}++export function admitVendorFrame(frame, runId, binding, source, previous = []) {+ if (!closedVendorObject(frame, ['kind', 'runId', 'provider', 'source', 'ledger']) ||+ frame.kind !== 'evenfire-subscription-image-vendor-frame-v1' || frame.runId !== runId ||+ frame.provider !== binding.provider || !isDeepStrictEqual(frame.source, source))+ refuse('VENDOR_EVIDENCE_SOURCE_OR_SEQUENCE')+ validateVendorLedger(frame.ledger, runId, binding, previous)return frame.ledger}@@ -978,11 +1015,13 @@ export function verifyRuntimeReceipts(admission, receipts, phase = 'admit') {if (mounts.length !== 4 ||admissionMounts.length !== 1 ||- admissionMounts[0].Type !== 'bind' ||+ admissionMounts[0].Type !== 'volume' ||+ admissionMounts[0].Name !== admissionVolumeName(admission.runId) ||+ admissionMounts[0].Name !== admission.volume?.name ||admissionMounts[0].RW !== false ||typeof admissionMounts[0].Source !== 'string' ||!admissionMounts[0].Source ||- mounts.some(mount => mount.Type === 'bind' && mount.Destination !== RUNNER_ADMISSION_ROOT) ||+ mounts.some(mount => mount.Type === 'bind') ||mounts.some(mount => personalStatePath(mount.Source) || personalStatePath(mount.Destination)) ||!tmpfsOk)@@ -1157,8 +1196,7 @@ export function verifyMainAdmission(const volume = admission.volumeif (!volume ||- volume.name !==- `evenfire-sir-${admission.runId.slice('subscription-image-'.length)}-admission` ||+ volume.name !== admissionVolumeName(admission.runId) ||volume.driver !== 'local' ||!Number.isFinite(Date.parse(volume.createdAt)) ||!/^[a-f0-9]{64}$/.test(volume.inspectSha256 ?? '')diff --git a/scripts/tests/lib/subscription-image-source-context.mjs b/scripts/tests/lib/subscription-image-source-context.mjsindex 7e6c222c3..8e4bc5e34 100644--- a/scripts/tests/lib/subscription-image-source-context.mjs+++ b/scripts/tests/lib/subscription-image-source-context.mjs@@ -24,13 +24,29 @@ const fixedFiles = ['subscriptionImageRunContract.ts','subscriptionImageChallenge.ts','codexImageChallenge.ts',+ 'subscription-tool-screenshot.spec.ts',+ 'subscription-gfs-image.spec.ts',+ 'subscription-admission-recovery.spec.ts',+ 'playwright.subscription-tool-screenshot.config.ts',+ 'playwright.subscription-gfs-image.config.ts',+ 'playwright.subscription-admission-recovery.config.ts',+ 'subscriptionRemainingJourneyConfig.ts',+ 'subscriptionRemainingJourneyData.ts',+ 'subscriptionRemainingJourneyUi.ts',+ 'subscriptionRemainingJourneysContract.ts',+ 'navigationHelpers.ts',].map(name => `desktop-app/test/e2e-playwright/${name}`),'scripts/e2e/run-subscription-image-journeys.mjs',+ 'scripts/e2e/prepare-subscription-remaining-fixtures.mjs',+ 'scripts/e2e/prepare-subscription-remaining-fixtures.gfs.mjs',+ 'scripts/e2e/prepare-subscription-remaining-fixtures.runtime.mjs',+ 'scripts/e2e/prepare-subscription-remaining-fixtures.prepare.mjs','scripts/e2e/fixtures/subscription-image-runner.Dockerfile','scripts/e2e/fixtures/subscription-image-provider.mjs','scripts/e2e/fixtures/subscription-image-challenge.cjs','scripts/e2e/fixtures/subscription-image-session.mjs','scripts/e2e/fixtures/subscription-image-runner.base-image',+ 'scripts/e2e/fixtures/subscription-image-admission-pressure.mjs','scripts/tests/lib/subscription-image-runner-contract.mjs','scripts/tests/lib/subscription-image-source-context.mjs',]diff --git a/scripts/tests/subscription-image-runner.test.mjs b/scripts/tests/subscription-image-runner.test.mjsindex e1bcaf59f..a27d40060 100644--- a/scripts/tests/subscription-image-runner.test.mjs+++ b/scripts/tests/subscription-image-runner.test.mjs@@ -15,6 +15,8 @@ import {parseMountInfo,privateBusPath,readPrivateJson,+ readMainRecord,+ verifyRuntimeReceipts,unixSocketInode,verifyAccount,verifyJourneyReport,@@ -27,6 +29,7 @@ import {verifySourceManifest,verifyThirdPartyArtifact,} from './lib/subscription-image-runner-contract.mjs'+import { runtimeFromInspect } from './lib/subscription-image-main-admission.mjs'import { allowedSourcePath } from './lib/subscription-image-source-context.mjs'import {verifyPressureMetadata,@@ -286,7 +289,7 @@ function mainMetadata() {SecurityOpt: [],},Mounts: [- { Type: 'bind', Source: '/private/e2e-admission', Destination: '/runner-admission', RW: false },+ { Type: 'volume', Name: 'evenfire-sir-123456abcdef-admission', Source: '/var/lib/docker/volumes/evenfire-sir-123456abcdef-admission/_data', Destination: '/runner-admission', RW: false },{ Type: 'tmpfs', Source: 'tmpfs', Destination: home, RW: true },{ Type: 'tmpfs', Source: 'tmpfs', Destination: '/run/evenfire-e2e', RW: true },{ Type: 'tmpfs', Source: 'tmpfs', Destination: '/tmp', RW: true },@@ -544,6 +547,115 @@ test('vendor frames require the sealed physical proxy identity and an unchangedassert.throws(() => admitVendorFrame(changed, 'unit-run', binding, source, [row]))})++test('v2 named admission volume is the only permitted main-side inspect mount', () => {+ const { admission, receipts } = mainMetadata()+ const inspect = structuredClone(receipts.inspect.value.container)+ inspect.Mounts[0] = {+ Type: 'volume',+ Name: admission.volume.name,+ Source: `/var/lib/docker/volumes/${admission.volume.name}/_data`,+ Destination: '/runner-admission',+ RW: false,+ }+ const options = { runId: admission.runId, suiteId: admission.suiteId, home }+ assert.doesNotThrow(() => runtimeFromInspect(inspect, options))+ for (const change of [+ value => { value.Mounts[0].Type = 'bind' },+ value => { value.Mounts[0].Name = 'evenfire-sir-ffffffffffff-admission' },+ value => { value.Mounts[0].RW = true },+ value => { value.Mounts.push({ Type: 'volume', Name: 'extra', Destination: '/extra', RW: false }) },+ value => { value.Mounts[0].Source = '/Users/operator/private' },+ ]) {+ const changed = structuredClone(inspect)+ change(changed)+ assert.throws(() => runtimeFromInspect(changed, options))+ }+})++test('v2 runtime receipt verifies the exact named read-only admission volume', () => {+ const { admission, receipts } = mainMetadata()+ receipts.inspect.value.container.Mounts[0] = {+ Type: 'volume',+ Name: admission.volume.name,+ Source: `/var/lib/docker/volumes/${admission.volume.name}/_data`,+ Destination: '/runner-admission',+ RW: false,+ }+ assert.doesNotThrow(() => verifyRuntimeReceipts(admission, receipts))+ for (const change of [+ value => { value.inspect.value.container.Mounts[0].Type = 'bind' },+ value => { value.inspect.value.container.Mounts[0].Name = 'foreign-volume' },+ value => { value.inspect.value.container.Mounts[0].RW = true },+ value => { value.inspect.value.container.Mounts.push({ Type: 'tmpfs', Destination: '/extra', RW: true }) },+ ]) {+ const changed = structuredClone(receipts)+ change(changed)+ assert.throws(() => verifyRuntimeReceipts(admission, changed))+ }+})++test('v2 main records accept the runner UID with strict private file provenance', () => {+ const directory = fs.mkdtempSync(path.join(fs.realpathSync(os.tmpdir()), 'subscription-main-record-'))+ try {+ const filename = path.join(directory, 'unit.json')+ fs.writeFileSync(filename, JSON.stringify({ kind: 'unit-only-json' }), { mode: 0o600 })+ assert.equal(readMainRecord(filename).uid, process.getuid())+ fs.chmodSync(filename, 0o644)+ assert.throws(() => readMainRecord(filename))+ fs.chmodSync(filename, 0o600)+ const alias = path.join(directory, 'alias.json')+ fs.symlinkSync(filename, alias)+ assert.throws(() => readMainRecord(alias))+ fs.unlinkSync(alias)+ fs.linkSync(filename, alias)+ assert.throws(() => readMainRecord(filename))+ } finally {+ fs.rmSync(directory, { recursive: true, force: true })+ }+})++test('tool vendor metadata stays closed, bounded and immutable without raw content', () => {+ const binding = { provider: 'grok-subscription', modelId: 'unit-vision', unsupportedModelId: 'unit-text' }+ const source = { profile: 'unit-owned', podUid: 'unit-pod', imageId: `sha256:${'a'.repeat(64)}` }+ const resource = { kind: 'gfs', drive: 'unit-drive', resourceId: 'a'.repeat(32), version: 1, gfsUri: `gfs://unit-drive/${'a'.repeat(32)}` }+ const row = {+ sequence: 1, provider: binding.provider, model: binding.modelId,+ receiptId: '11111111-1111-4111-8111-111111111111',+ imageSha256: [], mimeTypes: [], receivedImageDigests: [], receivedImageOrder: [], decodedPixels: [],+ requestSha256: 'b'.repeat(64), responseKind: 'tool_calls', outputSha256: 'c'.repeat(64),+ journey: 'gfs-image', stage: 'read',+ toolCalls: [{ id: 'call_unit', name: 'clerum__gfs_read', argumentsSha256: 'd'.repeat(64) }],+ toolOutputs: [{ id: 'call_previous', outputSha256: 'e'.repeat(64), resource }],+ referencedFiles: [{ referenceId: `gfs:unit-drive:${'a'.repeat(32)}@v1`, drive: 'unit-drive', resourceId: 'a'.repeat(32), version: 1, availability: 'available', byteLength: 1024 }],+ }+ const frame = { kind: 'evenfire-subscription-image-vendor-frame-v1', runId: 'unit-run', provider: binding.provider, source,+ ledger: { kind: 'evenfire-subscription-image-vendor-v1', runId: 'unit-run', attempts: [row] } }+ assert.equal(admitVendorFrame(frame, 'unit-run', binding, source, []).attempts.length, 1)+ assert.equal(admitVendorFrame(frame, 'unit-run', binding, source).attempts.length, 1)+ assert.throws(() => admitVendorFrame(frame, 'unit-run', binding, source, null))+ assert.equal(admitVendorFrame(frame, 'unit-run', binding, source, [row]).attempts.length, 1)+ for (const change of [+ value => { value.extraHeader = 'unknown' },+ value => { value.ledger.extraHeader = 'unknown' },+ value => { value.ledger.attempts[0].toolCalls[0].arguments = 'forbidden raw arguments' },+ value => { value.ledger.attempts[0].toolOutputs[0].output = 'forbidden raw output' },+ value => { value.ledger.attempts[0].toolCalls[0].argumentsSha256 = 'not-a-hash' },+ value => { value.ledger.attempts[0].toolCalls = Array.from({ length: 33 }, () => row.toolCalls[0]) },+ value => { value.ledger.attempts[0].toolOutputs[0].resource.gfsUri = 'https://example.invalid' },+ value => { value.ledger.attempts[0].referencedFiles[0].byteLength = Number.MAX_SAFE_INTEGER },+ value => { value.ledger.attempts[0].stage = 'capture' },+ value => { value.ledger.attempts[0].decodedPixels = [{ width: 512, height: 512, answer: 'forbidden' }] },+ ]) {+ const changed = structuredClone(frame)+ change(changed)+ assert.throws(() => admitVendorFrame(changed, 'unit-run', binding, source, []))+ }+ const changed = structuredClone(frame)+ changed.ledger.attempts[0].toolCalls[0].argumentsSha256 = 'f'.repeat(64)+ assert.throws(() => admitVendorFrame(changed, 'unit-run', binding, source, [row]))+})+test('named journey reporter rejects missing, skipped, duplicate or foreign-file cases even with producer exit zero', () => {// This synthetic reporter tests only the status guard, never an E2E pass.const file = '/unit/subscription-image-input.spec.ts'@@ -700,3 +812,15 @@ test('pressure metadata and native owner observations refuse drift', () => {))})+++test('host command wrapper transmits the complete admission input to a native child', async () => {+ const { run } = await import('../e2e/prepare-subscription-image-admission.mjs')+ const input = JSON.stringify({ kind: 'unit-admission-io', count: 4 })+ const result = run(+ process.execPath,+ ['-e', "process.stdout.write(require('node:fs').readFileSync(0, 'utf8'))"],+ { input, timeout: 1000 }+ )+ assert.equal(result, input)+})