import fs from 'node:fs'; import path from 'node:path'; import assert from 'node:assert/strict'; import { createHash } from 'node:crypto'; import { observeWindowsProcess } from '../src/core/desktop/process-identity.mjs'; const read = file => JSON.parse(fs.readFileSync(file, 'utf8')); const hash = bytes => createHash('sha256').update(bytes).digest('hex'); const failure = read('.qa/engineering-evals-all-ui-validation.json'); assert.equal(failure.success, false); assert.equal(failure.script, 'verify-change-sets-ui.mjs'); const directory = '.qa/evals-all-ui-version-allowlist-failure'; assert.equal(fs.existsSync(directory), false); fs.mkdirSync(directory); const files = new Map(); for (const file of ['.qa/engineering-evals-all-ui-validation.json', '.qa/evaluation-f-development-all-ui-fixed.log', '.qa/evaluation-f-development-all-ui-fixed-result.json', failure.log, ...failure.results.flatMap(row => [row.log, row.evidence]), 'scripts/verify-change-sets-ui.mjs', 'scripts/verify-context-ui.mjs']) files.set(path.resolve(file), file); const archived = []; for (const [original] of files) { const bytes = fs.readFileSync(original), file = directory + '/' + String(archived.length + 1).padStart(3, '0') + '-' + path.basename(original).replace(/\.log$/, '-log.txt'); fs.writeFileSync(file, bytes, { flag: 'wx' }); archived.push({ original, file, bytes: bytes.length, sha256: hash(bytes) }); } fs.writeFileSync(directory + '/manifest.json', JSON.stringify({ success: true, scope: 'Original failed full UI run stopped at obsolete hardcoded version allowlist. Passed groups remain partial evidence only; package guard rejected it.', files: archived }, null, 2) + '\n', { flag: 'wx' }); const root = path.resolve('.qa/batch-ui-e24e0b01-17c7-443c-b031-7df97af1e6e2/data'), info = read(path.join(root, 'service-info.json')); assert.equal(info.dataRoot, root); assert.equal(info.appRoot, process.cwd()); assert.notEqual(info.pid, 36552); const owned = observeWindowsProcess(info.pid); assert.ok(owned); assert.equal(owned.createdAt, info.createdAt); const url = 'http://127.0.0.1:' + info.port, bootstrap = await (await fetch(url + '/api/bootstrap')).json(); assert.equal(bootstrap.processId, info.pid); assert.equal(bootstrap.runtimeRoot, process.cwd()); assert.equal(bootstrap.config.hasKey, false); assert.equal(bootstrap.config.mode, 'demo'); const response = await fetch(url + '/api/shutdown', { method: 'POST', headers: { 'Content-Type': 'application/json', 'X-Workbench-Token': bootstrap.token, Connection: 'close' }, body: '{}' }); assert.ok(response.ok); const deadline = Date.now() + 15000; while (observeWindowsProcess(info.pid) && Date.now() < deadline) await new Promise(resolve => setTimeout(resolve, 100)); assert.equal(observeWindowsProcess(info.pid), null); fs.writeFileSync(directory + '/owned-host-cleanup.json', JSON.stringify({ success: true, pid: info.pid, createdAt: info.createdAt, dataRoot: root, port: info.port, gracefulShutdown: true, modelRequests: 0, formalServiceTouched: false }, null, 2) + '\n', { flag: 'wx' }); const changed = []; for (const file of ['scripts/verify-change-sets-ui.mjs', 'scripts/verify-context-ui.mjs']) { const code = fs.readFileSync(file, 'utf8'), pattern = /assert\.ok\(\[[^\r\n]+\]\.includes\(bootstrap\.version\)\);/g; const matches = [...code.matchAll(pattern)]; assert.equal(matches.length, 1, file); fs.writeFileSync(file, code.replace(pattern, "assert.equal(bootstrap.version, JSON.parse(fs.readFileSync(new URL('../package.json', import.meta.url), 'utf8')).version, 'The UI host must match this package version.');")); changed.push(file); } for (const [old, next] of [['docs/engineering-evals-release-code-baseline.json', 'docs/engineering-evals-second-candidate-code-baseline.json'], ['.qa/engineering-evals-release-code-baseline.json', '.qa/engineering-evals-second-candidate-code-baseline.json'], ['.qa/evals-f-code-git-audit.json', '.qa/evals-f-second-candidate-code-git-audit.json']]) { assert.equal(fs.existsSync(next), false); fs.renameSync(old, next); } console.log(JSON.stringify({ success: true, changed, archived: archived.length, ownedHostStopped: info.pid, next: 'Commit QA identity checks, freeze the new candidate and rerun the full UI suite.' }));