import fs from 'node:fs'; import assert from 'node:assert/strict'; import { createHash } from 'node:crypto'; import { spawn } from 'node:child_process'; const read = file => JSON.parse(fs.readFileSync(file, 'utf8')); const prior = read('.qa/task-control-j-formal-resume-pipeline.json'); assert.equal(prior.success, false); assert.deepEqual(prior.completed.map(row => row.phase), ['formal-stage-resume', 'formal-upgrade', 'formal-activate', 'formal-verify', 'formal-ui']); for (const row of prior.completed) { const receipt = read(row.receipt); assert.equal(receipt.success, true); assert.equal(receipt.unchangedInputs, true); assert.equal(createHash('sha256').update(fs.readFileSync(receipt.logPath)).digest('hex'), receipt.logSha256); } const output = '.qa/task-control-j-formal-completed.json'; assert.equal(fs.existsSync(output), false); const startedAt = new Date().toISOString(), completed = prior.completed.slice(); let success = false, error; try { for (const phase of ['formal-native-visible', 'formal-artifacts']) { console.log('START ' + phase + ' ' + new Date().toISOString()); const child = spawn(process.execPath, [phase === 'formal-native-visible' ? '.qa/run-task-control-j-native-visible-phase.mjs' : '.qa/run-task-control-j-phase.mjs', phase], { windowsHide: true, stdio: 'inherit' }); const code = await new Promise((resolve, reject) => { child.once('error', reject); child.once('close', resolve); }); const receipt = '.qa/task-control-j-' + phase + '-result.json'; assert.equal(code, 0, phase); assert.equal(read(receipt).success, true); completed.push({ phase, receipt, finishedAt: new Date().toISOString() }); console.log('PASS ' + phase); } success = true; } catch (failure) { error = failure.stack; process.exitCode = 1; } fs.writeFileSync(output, JSON.stringify({ success, startedAt, finishedAt: new Date().toISOString(), completed, retainedPrior: '.qa/task-control-j-formal-resume-pipeline.json', failedNative: '.qa/task-control-j-formal-native-validation.json', ...(error ? { error } : {}), scope: 'Original successful stage/upgrade/activation/verify/UI receipts and exact logs retained; repeat only the failed native capture as a complete visible two-viewport run, then all artifacts. No formal model request or replayed upgrade.' }, null, 2) + '\n', { flag: 'wx' }); console.log(JSON.stringify({ success, output, error }));