Evenfire is an intelligence layer platform for running LLM agents that take real actions, on your infrastructure
TypeScript
test(codex): reject empty node test files in CI and T0
Alfredo Lopez438763b89d31
diff --git a/.github/workflows/ci-public.yml b/.github/workflows/ci-public.ymlindex 4ed466520..4482c76ba 100644--- a/.github/workflows/ci-public.yml+++ b/.github/workflows/ci-public.yml@@ -132,7 +132,8 @@ jobs:- name: Test Codex approved-tools fixtures and runnerif: matrix.service == 'mcp-host'run: |- node --test --test-reporter=tap \+ node scripts/tests/run-node-test-files.mjs \+ scripts/tests/run-node-test-files.test.mjs \tests/e2e/fixtures/codex-subscription/approved-tools/server.test.mjs \scripts/e2e/prepare-codex-approved-tools.test.mjs \scripts/e2e/run-codex-approved-tools.test.mjs \diff --git a/scripts/tests/node-registration-reporter.mjs b/scripts/tests/node-registration-reporter.mjsnew file mode 100644index 000000000..4ae668ad1--- /dev/null+++ b/scripts/tests/node-registration-reporter.mjs@@ -0,0 +1,27 @@+import { realpathSync } from 'node:fs'++// Companion reporter: a successful file-process placeholder is not a test.+// Keep normal TAP output as the primary reporter and fail on missing coverage.+export default async function* registrationReporter(source) {+ const requested = JSON.parse(process.env.NODE_TEST_EXPECTED_FILES || '[]')+ if (!Array.isArray(requested) || requested.length === 0)+ throw new Error('Expected explicit node test files')+ const counts = new Map(requested.map(file => [realpathSync(file), 0]))+ for await (const event of source) {+ if (event.type !== 'test:pass') continue+ const data = event.data+ if (!data?.file || data.skip || data.todo || data.details?.type !== 'test') continue+ const file = realpathSync(data.file)+ if (!counts.has(file)) continue+ // Empty files generate a synthetic case named after the input path.+ let filePlaceholder = false+ try {+ filePlaceholder = realpathSync(data.name) === file+ } catch {+ /* Ordinary test name. */+ }+ if (!filePlaceholder) counts.set(file, counts.get(file) + 1)+ }+ const missing = [...counts].filter(([, count]) => count === 0).map(([file]) => file)+ if (missing.length) throw new Error(`No executed test cases in: ${missing.join(', ')}`)+}diff --git a/scripts/tests/run-node-test-files.mjs b/scripts/tests/run-node-test-files.mjsnew file mode 100644index 000000000..d9e206416--- /dev/null+++ b/scripts/tests/run-node-test-files.mjs@@ -0,0 +1,26 @@+import { spawnSync } from 'node:child_process'+import { realpathSync } from 'node:fs'+import { fileURLToPath } from 'node:url'++const files = process.argv.slice(2).map(file => realpathSync(file))+if (files.length === 0) throw new Error('Expected explicit node test files')+const reporter = fileURLToPath(new URL('./node-registration-reporter.mjs', import.meta.url))+const env = { ...process.env, NODE_TEST_EXPECTED_FILES: JSON.stringify(files) }+// An explicit runner invocation must not inherit a parent test worker's IPC mode.+delete env.NODE_TEST_CONTEXT+const result = spawnSync(+ process.execPath,+ [+ '--test',+ '--test-reporter=tap',+ '--test-reporter-destination=stdout',+ `--test-reporter=${reporter}`,+ '--test-reporter-destination=stderr',+ ...files,+ ],+ {+ stdio: 'inherit',+ env,+ }+)+process.exit(result.status ?? 1)diff --git a/scripts/tests/run-node-test-files.test.mjs b/scripts/tests/run-node-test-files.test.mjsnew file mode 100644index 000000000..002c997ca--- /dev/null+++ b/scripts/tests/run-node-test-files.test.mjs@@ -0,0 +1,35 @@+import assert from 'node:assert/strict'+import { spawnSync } from 'node:child_process'+import { mkdtempSync, rmSync, writeFileSync } from 'node:fs'+import { tmpdir } from 'node:os'+import path from 'node:path'+import test from 'node:test'+import { fileURLToPath } from 'node:url'++const runner = fileURLToPath(new URL('./run-node-test-files.mjs', import.meta.url))+for (const scenario of ['valid', 'empty', 'mixed', 'skipped']) {+ test(`registration gate checks each file: ${scenario}`, () => {+ const directory = mkdtempSync(path.join(tmpdir(), 'evenfire-registration-'))+ try {+ const valid = path.join(directory, 'valid.test.mjs')+ const other = path.join(directory, 'other.test.mjs')+ writeFileSync(valid, "import test from 'node:test'; test('registered case', () => {});")+ writeFileSync(+ other,+ scenario === 'skipped'+ ? "import test from 'node:test'; test.skip('omitted case', () => {});"+ : ''+ )+ const files = scenario === 'valid' ? [valid] : scenario === 'mixed' ? [valid, other] : [other]+ const result = spawnSync(process.execPath, [runner, ...files], {+ encoding: 'utf8',+ timeout: 10_000,+ })+ assert.equal(result.error, undefined)+ assert.equal(result.status, scenario === 'valid' ? 0 : 1)+ if (scenario !== 'valid') assert.match(result.stderr, /No executed test cases in:/)+ } finally {+ rmSync(directory, { recursive: true, force: true })+ }+ })+}diff --git a/scripts/tests/test-codex-subscription-t0.sh b/scripts/tests/test-codex-subscription-t0.shindex c151b9b07..abeee53cc 100755--- a/scripts/tests/test-codex-subscription-t0.sh+++ b/scripts/tests/test-codex-subscription-t0.sh@@ -144,7 +144,7 @@ run_node_group() {[[ ${#files[@]} -gt 0 ]] || { fail "$name: group listed no suite files"; return 1; }log="$(mktemp)"echo "── ${name} ──"- if ! node --test --test-reporter=tap "${files[@]}" >"$log" 2>&1; then+ if ! node "$ROOT/scripts/tests/run-node-test-files.mjs" "${files[@]}" >"$log" 2>&1; thenfail "$name: command failed"cat "$log"rm -f "$log"@@ -197,6 +197,7 @@ run_group "shared-contract" "packages/llm-provider-attempt-contract" "index.testrun_group "codex-catalog-projection" "packages/codex-catalog-projection" "index.test.cjs"run_node_group "approved-tools-fixtures-and-runner" \+ "scripts/tests/run-node-test-files.test.mjs" \"tests/e2e/fixtures/codex-subscription/approved-tools/server.test.mjs" \"scripts/e2e/prepare-codex-approved-tools.test.mjs" \"scripts/e2e/run-codex-approved-tools.test.mjs" \