Skip to content

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

TypeScript

test(codex): bound workflow artifacts to validated receipts

Alfredo Lopez7493d4cf7bcd
diff --git a/tests/e2e/fixtures/codex-subscription/approved-tools-workflow/index.js b/tests/e2e/fixtures/codex-subscription/approved-tools-workflow/index.js
index e9c3dd76e..824830fef 100644
--- a/tests/e2e/fixtures/codex-subscription/approved-tools-workflow/index.js
+++ b/tests/e2e/fixtures/codex-subscription/approved-tools-workflow/index.js
@@ -5,6 +5,30 @@ const { randomUUID } = require('node:crypto')
const ARTIFACT_NAME = 'approved-tools-workflow-result.json'
const ARTIFACT_PATH = `/output/${ARTIFACT_NAME}`
+function validatedReceipt(value, selected) {
+ const uuid = /^[a-f0-9]{8}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{12}$/
+ if (
+ !value ||
+ value.tool !== selected ||
+ typeof value.tool !== 'string' ||
+ !/^[a-zA-Z0-9_]{1,128}$/.test(value.tool) ||
+ typeof value.businessId !== 'string' ||
+ !uuid.test(value.businessId) ||
+ typeof value.callId !== 'string' ||
+ !uuid.test(value.callId) ||
+ typeof value.runId !== 'string' ||
+ !/^[a-zA-Z0-9_-]{1,128}$/.test(value.runId)
+ )
+ throw new Error('receipt_binding_missing')
+ // Persist only the bounded receipt contract, never arbitrary remote fields.
+ return {
+ runId: value.runId,
+ tool: value.tool,
+ callId: value.callId,
+ businessId: value.businessId,
+ }
+}
+
function receiptEndpoint(spec) {
if (!Array.isArray(spec.mcpServers) || spec.mcpServers.length !== 1) {
throw new Error('exactly_one_declared_receipt_service_required')
@@ -76,15 +100,7 @@ async function readReceipt(endpoint, fetchImpl = fetch) {
result.content[0].type !== 'text'
)
throw new Error('invalid_receipt_result')
- const receipt = JSON.parse(result.content[0].text)
- if (
- receipt.tool !== selected ||
- typeof receipt.businessId !== 'string' ||
- typeof receipt.runId !== 'string' ||
- typeof receipt.callId !== 'string'
- )
- throw new Error('receipt_binding_missing')
- return receipt
+ return validatedReceipt(JSON.parse(result.content[0].text), selected)
}
async function main() {
@@ -104,10 +120,18 @@ async function main() {
executor: 'custom',
startedAt: new Date().toISOString(),
})
- const receipt = await readReceipt(endpoint)
await fs.mkdir('/output', { recursive: true })
- await fs.writeFile(ARTIFACT_PATH, JSON.stringify(receipt), { flag: 'wx' })
- const { size } = await fs.stat(ARTIFACT_PATH)
+ // Reserve the fixed artifact before the business call. An existing output
+ // stops a duplicate run before execution; the same handle owns write/stat.
+ const artifact = await fs.open(ARTIFACT_PATH, 'wx', 0o600)
+ let size
+ try {
+ const receipt = await readReceipt(endpoint)
+ await artifact.writeFile(JSON.stringify(receipt))
+ size = (await artifact.stat()).size
+ } finally {
+ await artifact.close()
+ }
const output = {
artifacts: [
{
@@ -139,7 +163,7 @@ async function main() {
}
}
-module.exports = { receiptEndpoint, readReceipt }
+module.exports = { receiptEndpoint, readReceipt, validatedReceipt }
if (require.main === module)
main().catch(() => {
process.exitCode = 1
diff --git a/tests/e2e/fixtures/codex-subscription/approved-tools-workflow/index.test.mjs b/tests/e2e/fixtures/codex-subscription/approved-tools-workflow/index.test.mjs
index 4f28457a9..b1dcc64fe 100644
--- a/tests/e2e/fixtures/codex-subscription/approved-tools-workflow/index.test.mjs
+++ b/tests/e2e/fixtures/codex-subscription/approved-tools-workflow/index.test.mjs
@@ -6,6 +6,28 @@ import { fileURLToPath } from 'node:url'
import { createApprovedToolsFixture } from '../approved-tools/server.mjs'
import coordinator from './index.js'
+test('receipt artifacts contain only bounded validated business fields', () => {
+ const receipt = {
+ runId: 'workflow-fixture',
+ tool: 'workitem_read_receipt',
+ callId: '12345678-1234-4234-8234-123456789abc',
+ businessId: 'abcdef12-1234-4234-8234-123456789abc',
+ }
+ assert.deepEqual(
+ coordinator.validatedReceipt({ ...receipt, remoteExtra: 'must not persist' }, receipt.tool),
+ receipt
+ )
+ for (const invalid of [
+ { ...receipt, tool: 'other_tool' },
+ { ...receipt, businessId: 'not-a-business-id' },
+ { ...receipt, callId: '' },
+ { ...receipt, runId: '../other-artifact' },
+ { ...receipt, runId: 'x'.repeat(129) },
+ ]) {
+ assert.throws(() => coordinator.validatedReceipt(invalid, receipt.tool))
+ }
+})
+
test('coordinator refuses eager execution without a triggered workflow run', () => {
const result = spawnSync(
process.execPath,
diff --git a/tests/e2e/fixtures/package-lock.json b/tests/e2e/fixtures/package-lock.json
index 334f53d1e..0b8ebdbeb 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.73",
+ "version": "1.0.74",
"lockfileVersion": 3,
"requires": true,
"packages": {
"": {
"name": "@clerum/e2e-test-fixtures",
- "version": "1.0.73",
+ "version": "1.0.74",
"dependencies": {
"@kubernetes/client-node": "^1.0.0"
},
diff --git a/tests/e2e/fixtures/package.json b/tests/e2e/fixtures/package.json
index 65ca97022..b5787e4f2 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.73",
+ "version": "1.0.74",
"description": "E2E test fixtures and utilities for Clerum testing",
"type": "module",
"main": "index.ts",