Files
Agent-Workbench/docs/embedded-browser-release-evidence/verifiers/prepare-installer.mjs
T

41 lines
4.6 KiB
JavaScript

import fs from 'node:fs';
import path from 'node:path';
import assert from 'node:assert/strict';
import { randomUUID, createHash } from 'node:crypto';
import { buildWindowsInstaller } from '../scripts/build-installer.mjs';
const release = JSON.parse(fs.readFileSync('releases/latest.json', 'utf8')); assert.equal(release.installer.version, '1.22.0');
const appId = randomUUID(), destination = '.qa/embedded-browser-d-qa-installer.json'; assert.equal(fs.existsSync(destination), false);
const installer = buildWindowsInstaller({ root: process.cwd(), portableRoot: release.portableRoot, outputRoot: path.resolve('.qa'),
name: 'embedded-browser-installer-qa-' + appId, qaFixture: { appId, fault: 'none' } });
const source = fs.readFileSync(installer.source, 'utf8'), product = fs.readFileSync(release.installer.source, 'utf8');
const body = value => value.split('\n').filter(line => !line.startsWith('#define OutputRoot ') && !line.startsWith('#define OutputName ')).join('\n');
assert.equal(body(source).replaceAll(appId, 'E914E883-46F9-4B82-B27F-BDB2B40DCC90')
.replace('DefaultGroupName=Agent Workbench QA E914E883-46F9-4B82-B27F-BDB2B40DCC90', 'DefaultGroupName=Agent Workbench'), body(product));
fs.writeFileSync(destination, JSON.stringify({ ...installer, productSetup: release.installer,
samePayloadManifestSha256: createHash('sha256').update(fs.readFileSync(path.join(release.portableRoot, 'MANIFEST.json'))).digest('hex'),
sourceComparison: 'Only isolated QA AppId/group and output destination/name differ; entire product payload and installation behavior are exact. Product setup will separately stage the existing formal installation.' }, null, 2) + '\n', { flag: 'wx' });
let code = fs.readFileSync('.qa/verify-desktop-f-canonical-storage-guard-install.mjs', 'utf8');
for (const [before, after] of [['desktop-host-f-canonical-storage-guard-qa-installer.json', 'embedded-browser-d-qa-installer.json'],
['desktop-host-f-canonical-storage-install-location.json', 'embedded-browser-d-install-location.json'],
['ff4e7d22-f233-4021-829a-6f5c71933c46', appId], ['1.15.0', '1.22.0'], ['AWQA15', 'AWQA22DI'], ['timeout = 300000', 'timeout = 900000']]) {
assert.ok(code.includes(before), before); code = code.replaceAll(before, after);
}
const nativeSpawn = " const chunks = [], child = spawn(binary, args, { cwd: path.dirname(binary), env, windowsHide: true, stdio: bootstrap ? 'ignore' : ['ignore', 'pipe', 'pipe'] });";
assert.ok(code.includes(nativeSpawn));
code = code.replace(nativeSpawn, " const nativeOutput = bootstrap ? fs.openSync(path.join(root, label + '-native-output.txt'), 'wx') : null;\n const chunks = [], child = spawn(binary, args, { cwd: path.dirname(binary), env, windowsHide: true, stdio: bootstrap ? ['ignore', nativeOutput, nativeOutput] : ['ignore', 'pipe', 'pipe'] });\n if (nativeOutput !== null) fs.closeSync(nativeOutput);");
const checkAnchor=" record(stage, { sessionId: session.id, originalApprovalId: approval.id, checkId, actualTests: checked.results[0].tests, originalLogArtifactId: checked.results[0].logArtifactId });";
assert.ok(code.includes(checkAnchor));
const installedCheck=String.raw`
const browserLog=path.join(root,'installed-browser.log'),browserStream=fs.createWriteStream(browserLog,{flags:'wx'});
const browserChild=spawn(process.execPath,['scripts/verify-embedded-browser.mjs','--app-root',candidate],{cwd:process.cwd(),env,windowsHide:true,stdio:['ignore','pipe','pipe']});
browserChild.stdout.pipe(browserStream,{end:false});browserChild.stderr.pipe(browserStream,{end:false});
const browserExit=await new Promise((resolve,reject)=>{browserChild.once('error',reject);browserChild.once('close',resolve);});await new Promise(resolve=>browserStream.end(resolve));
assert.equal(browserExit,0,'Actual installed browser verifier failed: '+browserLog);
const browserProof=JSON.parse(fs.readFileSync('.qa/embedded-browser-latest.json'));assert.equal(browserProof.success,true);assert.equal(browserProof.appRoot,candidate);assert.equal(browserProof.checks.length,17);assert.equal(browserProof.realModelRequests,0);
`;
code=code.replace(checkAnchor,installedCheck+checkAnchor.replace('actualTests: checked.results[0].tests,','actualTests: checked.results[0].tests, embeddedBrowser: {groups:browserProof.checks.length,directory:browserProof.root,resultSha256:hash(fs.readFileSync(path.join(browserProof.root,\'result.json\'))),log:browserLog,logSha256:hash(fs.readFileSync(browserLog))},'));
fs.writeFileSync('.qa/verify-embedded-browser-d-install.mjs', code, { flag: 'wx' });
console.log(JSON.stringify({ success: true, appId, installerSha256: installer.sha256, productSetupSha256: release.installer.sha256, samePayload: true }));