mirror of
https://github.com/hanzoai/extension.git
synced 2026-10-31 21:57:06 +00:00
ci.yml has failed on every push since 2026-08-05 — twenty runs — and the cause was two test files each running src/build.js into the same dist/, gated on DIFFERENT sentinels: output-root.test.ts checked for the directory, webextension-polyfill.test.ts checked for a file inside it. vitest runs files in parallel, the directory appears the instant the slower build starts, so the faster suite skipped its own build and asserted against a tree still being written. It failed 'chrome: expected false to be true' in 12ms — too fast to have built anything, which is the tell. The build is a fixture the suite needs, not something a test conjures, so it now happens once in globalSetup before parallelism starts and the assertions go back to being assertions. Requiring EVERY artifact, not just one, means an interrupted run rebuilds instead of being mistaken for a finished one — the same confusion between started and done that caused the race. Verified from a deleted dist/: 24 files, 302/302. Locally this suite had been reporting 22 files/292 tests off a stale dist — the two build-driving files never ran — which is why it looked green here while CI was red. Co-authored-by: Hanzo Dev <[email protected]>
46 lines
2.0 KiB
TypeScript
46 lines
2.0 KiB
TypeScript
import { execFileSync } from 'child_process';
|
|
import * as fs from 'fs';
|
|
import * as path from 'path';
|
|
|
|
/**
|
|
* Build the extension ONCE, before any test file runs.
|
|
*
|
|
* Two suites assert against `dist/<engine>/` and each used to run `src/build.js`
|
|
* itself, guarded by a different sentinel — output-root.test.ts checked for the
|
|
* DIRECTORY, webextension-polyfill.test.ts checked for a FILE inside it. Vitest
|
|
* runs files in parallel, and the directory appears the moment the slower
|
|
* suite's build starts, so the faster one saw `dist/chrome/` already there,
|
|
* skipped its own build, and asserted against a tree that was still being
|
|
* written. It failed on `chrome: expected false to be true` in 12ms — too fast
|
|
* to have built anything, which is the tell.
|
|
*
|
|
* That is a race between two copies of one step, so the fix is to stop having
|
|
* two: the build is a fixture the suite needs, not something a test conjures.
|
|
* Here it happens once, before parallelism starts, and the assertions become
|
|
* assertions again.
|
|
*/
|
|
const BROWSER = path.resolve(__dirname, '..');
|
|
const DIST = path.resolve(BROWSER, '..', '..', 'dist');
|
|
|
|
/** Every artifact a suite reads. Present ⇒ a real build has completed. */
|
|
const artifacts = [
|
|
path.join(DIST, 'chrome', 'manifest.json'),
|
|
path.join(DIST, 'firefox', 'manifest.json'),
|
|
path.join(DIST, 'chrome', 'background.js'),
|
|
];
|
|
|
|
export function setup() {
|
|
// A half-written tree is NOT a build. Requiring every artifact means an
|
|
// interrupted run rebuilds rather than being mistaken for a finished one —
|
|
// the same confusion between "started" and "done" that caused the race.
|
|
if (artifacts.every((f) => fs.existsSync(f))) return;
|
|
execFileSync('node', ['src/build.js'], { cwd: BROWSER, stdio: 'inherit' });
|
|
const missing = artifacts.filter((f) => !fs.existsSync(f));
|
|
if (missing.length) {
|
|
throw new Error(
|
|
`src/build.js exited 0 but did not write:\n ${missing.join('\n ')}\n` +
|
|
'A suite that asserts about the bundle must have the bundle.',
|
|
);
|
|
}
|
|
}
|