48 lines
4.3 KiB
JavaScript
48 lines
4.3 KiB
JavaScript
import fs from 'node:fs';
|
|
import path from 'node:path';
|
|
import { randomUUID, createHash } from 'node:crypto';
|
|
import { spawnSync, execFileSync } from 'node:child_process';
|
|
import { build } from 'esbuild';
|
|
|
|
const withTerminal = process.argv.includes('--with-terminal');
|
|
const tests = ['tests/python-selection.test.mjs', ...(withTerminal ? ['tests/terminal-delivery.test.mjs'] : []),
|
|
...(process.argv.includes('--with-runtime') ? ['tests/runtime.test.mjs'] : [])];
|
|
const label = withTerminal ? 'engineering' : 'python';
|
|
const output = path.resolve('.qa/engineering-repairs-' + (withTerminal ? 'ai-' : 'ah-') + randomUUID()); fs.mkdirSync(output);
|
|
const appRoot = path.join(output, 'app'); fs.mkdirSync(path.join(appRoot, 'dist-server'), { recursive: true });
|
|
fs.mkdirSync(path.join(appRoot, 'scripts'));
|
|
fs.copyFileSync('scripts/python-check-runner.py', path.join(appRoot, 'scripts/python-check-runner.py'));
|
|
fs.writeFileSync(path.join(appRoot, 'package.json'), execFileSync('git', ['show', 'HEAD:package.json']), { flag: 'wx' });
|
|
const installedRoot = JSON.parse(fs.readFileSync('.qa/live-purge-ag/current.json')).host.identity.runtimeRoot;
|
|
// Reuse immutable installed client bytes only to satisfy host identity registration.
|
|
// This does not build or copy the parallel source UI, and no browser is opened here.
|
|
fs.cpSync(path.join(installedRoot, 'dist-client'), path.join(appRoot, 'dist-client'), { recursive: true });
|
|
const sha = b => createHash('sha256').update(b).digest('hex'), inputs = [];
|
|
function walk(directory) {
|
|
for (const entry of fs.readdirSync(directory, { withFileTypes: true })) {
|
|
const name = path.join(directory, entry.name); if (entry.isDirectory()) walk(name);
|
|
else if (entry.isFile()) inputs.push({ path: name, sha256: sha(fs.readFileSync(name)) });
|
|
}
|
|
}
|
|
for (const directory of ['src/server', 'src/core', 'src/shared']) walk(directory);
|
|
inputs.push(...['scripts/python-check-runner.py', 'tests/helpers.mjs', 'tests/fixtures/delivery-project.mjs', ...tests].map(name => ({ path: name, sha256: sha(fs.readFileSync(name)) })));
|
|
fs.writeFileSync(path.join(output, 'inputs.json'), JSON.stringify(inputs, null, 2));
|
|
console.log(JSON.stringify({ output, building: 'isolated backend only', sharedBuildsModified: false }));
|
|
await build({ entryPoints: ['src/server/index.mjs'], outfile: path.join(appRoot, 'dist-server/server.mjs'), bundle: true, platform: 'node', target: 'node24', format: 'esm',
|
|
sourcemap: false, legalComments: 'eof', banner: { js: "import { createRequire as __awbCreateRequire } from 'node:module'; const require = __awbCreateRequire(import.meta.url);" } });
|
|
for (const [entry, name] of [['src/server/hot-upgrade.mjs', 'hot-upgrade'], ['src/desktop/host-cli.mjs', 'host-launcher']]) {
|
|
await build({ entryPoints: [entry], outfile: path.join(appRoot, 'dist-server/' + name + '.mjs'), bundle: true, platform: 'node', target: 'node24', format: 'esm',
|
|
sourcemap: false, legalComments: 'eof', banner: { js: "import { createRequire as __awbCreateRequire } from 'node:module'; const require = __awbCreateRequire(import.meta.url);" } });
|
|
}
|
|
const args = ['--test', '--test-concurrency=1', ...tests];
|
|
const result = spawnSync(process.execPath, args, { encoding: 'utf8', windowsHide: true, timeout: withTerminal ? 240000 : 120000, maxBuffer: 32 * 1024 * 1024,
|
|
env: { ...process.env, AGENT_WORKBENCH_TEST_APP_ROOT: appRoot, AGENT_WORKBENCH_TEST_PYTHON: process.env.AGENT_WORKBENCH_TEST_PYTHON ?? path.resolve('.qa/reliability-1.25.2/python-env/Scripts/python.exe') } });
|
|
fs.writeFileSync(path.join(output, label + '.stdout.txt'), result.stdout ?? ''); fs.writeFileSync(path.join(output, label + '.stderr.txt'), result.stderr ?? '');
|
|
const sourceUnchanged = inputs.every(row => sha(fs.readFileSync(row.path)) === row.sha256);
|
|
const receipt = { success: result.status === 0 && sourceUnchanged, status: result.status, signal: result.signal, error: result.error?.message ?? null,
|
|
args, sourceUnchanged, serverSha256: sha(fs.readFileSync(path.join(appRoot, 'dist-server/server.mjs'))),
|
|
sharedBuildsModified: false, unchangedInstalledClientSource: installedRoot, realModelRequests: 0 };
|
|
fs.writeFileSync(path.join(output, 'result.json'), JSON.stringify(receipt, null, 2));
|
|
console.log(result.stdout); if (result.stderr) console.error(result.stderr); console.log(JSON.stringify({ output, ...receipt }));
|
|
if (!receipt.success) process.exitCode = 1;
|