// Step 6 test — the harness is the test surface: it must PASS a clean extract, FAIL one with a // planted tracked state file, and use the glob test form (never a bare dir). Pattern: // plugins/voyage/tests/synthetic/*.test.mjs. import test from 'node:test'; import assert from 'node:assert/strict'; import { spawnSync } from 'node:child_process'; import { mkdtempSync, rmSync, cpSync, writeFileSync, readFileSync } from 'node:fs'; import os from 'node:os'; import path from 'node:path'; import { fileURLToPath } from 'node:url'; const here = path.dirname(fileURLToPath(import.meta.url)); const SCRIPT = path.join(here, '40-validate-standalone.sh'); const WORK = process.env.WORK || '/tmp/polyrepo-migration'; function harness(key, work) { // Strip the parent test-runner context so the harness's own `node --test` runs un-nested // (otherwise Node emits its IPC subtest format and the test-count label is suppressed). const env = { ...process.env, WORK: work }; delete env.NODE_TEST_CONTEXT; return spawnSync('bash', [SCRIPT, key], { encoding: 'utf8', env }); } const git = (dir, args) => spawnSync('git', ['-C', dir, ...args], { encoding: 'utf8' }); test('harness PASSes a clean standalone extract (graceful-handoff)', () => { const r = harness('graceful-handoff', WORK); assert.equal(r.status, 0, `expected PASS exit 0:\n${r.stdout}\n${r.stderr}`); assert.match(r.stdout, /graceful-handoff: PASS \(.*standalone-safe\)/); }); test('harness FAILs an extract with a planted tracked state file (SC7)', () => { const tmpWork = mkdtempSync(path.join(os.tmpdir(), 'validate-broken-')); try { const broken = path.join(tmpWork, 'graceful-handoff'); cpSync(path.join(WORK, 'graceful-handoff'), broken, { recursive: true }); writeFileSync(path.join(broken, 'STATE.md'), '# planted tracked state file\n'); assert.equal(git(broken, ['add', '-f', 'STATE.md']).status, 0); assert.equal(git(broken, ['commit', '-m', 'plant tracked STATE.md', '-q']).status, 0); const r = harness('graceful-handoff', tmpWork); assert.notEqual(r.status, 0, `expected FAIL (non-zero), got 0:\n${r.stdout}`); assert.match(r.stdout, /graceful-handoff: FAIL/); assert.match(r.stdout, /state-file leak/); } finally { rmSync(tmpWork, { recursive: true, force: true }); } }); test('harness uses the glob test form, never a bare dir (Node 25 gotcha)', () => { const src = readFileSync(SCRIPT, 'utf8'); assert.ok(src.includes('*.test.mjs'), 'harness must reference the glob test form *.test.mjs'); });