67 lines
2.0 KiB
JavaScript
67 lines
2.0 KiB
JavaScript
import { spawn } from 'node:child_process';
|
|
import { mkdtemp, rm } from 'node:fs/promises';
|
|
import { tmpdir } from 'node:os';
|
|
import { join, resolve } from 'node:path';
|
|
|
|
import { bundlePiRuntime } from './bundle-pi-runtime.mjs';
|
|
import { defaultPiBundleTarget } from './lib/pi-runtime-bundle.mjs';
|
|
|
|
function runVitest(runtimeRoot) {
|
|
return new Promise((resolvePromise, reject) => {
|
|
const child = spawn(process.execPath, [
|
|
resolve('node_modules/vitest/vitest.mjs'),
|
|
'run',
|
|
'tests/unit/pi-worker-process-real.test.ts',
|
|
], {
|
|
cwd: process.cwd(),
|
|
env: { ...process.env, MAKELORE_PI_STAGED_RUNTIME_ROOT: runtimeRoot },
|
|
stdio: 'inherit',
|
|
windowsHide: true,
|
|
});
|
|
child.once('error', reject);
|
|
child.once('exit', (code, signal) => {
|
|
if (code === 0) resolvePromise();
|
|
else {
|
|
reject(new Error(
|
|
`Packaged subagent smoke failed with code ${code ?? 'null'} signal ${signal ?? 'none'}`,
|
|
));
|
|
}
|
|
});
|
|
});
|
|
}
|
|
|
|
function runElectronProductTools() {
|
|
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(),
|
|
stdio: 'inherit',
|
|
windowsHide: true,
|
|
});
|
|
child.once('error', reject);
|
|
child.once('exit', (code, signal) => {
|
|
if (code === 0) resolvePromise();
|
|
else {
|
|
reject(new Error(
|
|
`Packaged product-tools Electron smoke failed with code ${code ?? 'null'} signal ${signal ?? 'none'}`,
|
|
));
|
|
}
|
|
});
|
|
});
|
|
}
|
|
|
|
const outputRoot = 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();
|
|
} finally {
|
|
await rm(outputRoot, { recursive: true, force: true, maxRetries: 5, retryDelay: 200 });
|
|
}
|