test: add PI release proof harness
This commit is contained in:
@@ -6,7 +6,24 @@ import { join, resolve } from 'node:path';
|
||||
import { bundlePiRuntime } from './bundle-pi-runtime.mjs';
|
||||
import { defaultPiBundleTarget } from './lib/pi-runtime-bundle.mjs';
|
||||
|
||||
function runVitest(runtimeRoot) {
|
||||
function parseArgs(argv) {
|
||||
const options = { runtimeRoot: undefined, electronExecutable: undefined };
|
||||
for (let index = 0; index < argv.length; index += 1) {
|
||||
const argument = argv[index];
|
||||
const value = argv[index + 1];
|
||||
if (!value || value.startsWith('--')) throw new Error(`${argument} requires a value`);
|
||||
if (argument === '--runtime-root') options.runtimeRoot = resolve(value);
|
||||
else if (argument === '--electron-executable') options.electronExecutable = resolve(value);
|
||||
else throw new Error(`Unknown argument: ${argument}`);
|
||||
index += 1;
|
||||
}
|
||||
if (Boolean(options.runtimeRoot) !== Boolean(options.electronExecutable)) {
|
||||
throw new Error('--runtime-root and --electron-executable must be provided together');
|
||||
}
|
||||
return options;
|
||||
}
|
||||
|
||||
function runVitest(runtimeRoot, electronExecutable) {
|
||||
return new Promise((resolvePromise, reject) => {
|
||||
const child = spawn(process.execPath, [
|
||||
resolve('node_modules/vitest/vitest.mjs'),
|
||||
@@ -14,7 +31,11 @@ function runVitest(runtimeRoot) {
|
||||
'tests/unit/pi-worker-process-real.test.ts',
|
||||
], {
|
||||
cwd: process.cwd(),
|
||||
env: { ...process.env, MAKELORE_PI_STAGED_RUNTIME_ROOT: runtimeRoot },
|
||||
env: {
|
||||
...process.env,
|
||||
MAKELORE_PI_STAGED_RUNTIME_ROOT: runtimeRoot,
|
||||
...(electronExecutable ? { MAKELORE_PI_ELECTRON_EXECUTABLE: electronExecutable } : {}),
|
||||
},
|
||||
stdio: 'inherit',
|
||||
windowsHide: true,
|
||||
});
|
||||
@@ -30,13 +51,20 @@ function runVitest(runtimeRoot) {
|
||||
});
|
||||
}
|
||||
|
||||
function runElectronProductTools() {
|
||||
function runElectronProductTools(electronExecutable) {
|
||||
return new Promise((resolvePromise, reject) => {
|
||||
const child = spawn(process.execPath, [
|
||||
resolve('scripts/run-electron-vitest.mjs'),
|
||||
'tests/unit/pi-extension-bundle.test.ts',
|
||||
], {
|
||||
cwd: process.cwd(),
|
||||
env: {
|
||||
...process.env,
|
||||
...(electronExecutable ? {
|
||||
MAKELORE_ELECTRON_EXECUTABLE: electronExecutable,
|
||||
MAKELORE_PI_ELECTRON_EXECUTABLE: electronExecutable,
|
||||
} : {}),
|
||||
},
|
||||
stdio: 'inherit',
|
||||
windowsHide: true,
|
||||
});
|
||||
@@ -52,15 +80,24 @@ function runElectronProductTools() {
|
||||
});
|
||||
}
|
||||
|
||||
const outputRoot = await mkdtemp(join(tmpdir(), 'makelore-pi-subagent-package-'));
|
||||
const options = parseArgs(process.argv.slice(2));
|
||||
const outputRoot = options.runtimeRoot
|
||||
? null
|
||||
: await mkdtemp(join(tmpdir(), 'makelore-pi-subagent-package-'));
|
||||
try {
|
||||
const [bundle] = await bundlePiRuntime({
|
||||
outputRoot,
|
||||
targets: [defaultPiBundleTarget()],
|
||||
});
|
||||
if (!bundle) throw new Error('Pi runtime bundler returned no staged runtime');
|
||||
await runVitest(bundle.destination);
|
||||
await runElectronProductTools();
|
||||
let runtimeRoot = options.runtimeRoot;
|
||||
if (!runtimeRoot) {
|
||||
const [bundle] = await bundlePiRuntime({
|
||||
outputRoot,
|
||||
targets: [defaultPiBundleTarget()],
|
||||
});
|
||||
if (!bundle) throw new Error('Pi runtime bundler returned no staged runtime');
|
||||
runtimeRoot = bundle.destination;
|
||||
}
|
||||
await runVitest(runtimeRoot, options.electronExecutable);
|
||||
await runElectronProductTools(options.electronExecutable);
|
||||
} finally {
|
||||
await rm(outputRoot, { recursive: true, force: true, maxRetries: 5, retryDelay: 200 });
|
||||
if (outputRoot) {
|
||||
await rm(outputRoot, { recursive: true, force: true, maxRetries: 5, retryDelay: 200 });
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user