fast ci: task graph runner, sharded tests balanced by recorded durations, ci:quick (typecheck + related tests + scrub), Rust only when src-tauri / sidecar build changed, event waits instead of sleeps
This commit is contained in:
parent
cde9424ce3
commit
c71e690aae
13 changed files with 472 additions and 45 deletions
|
|
@ -79,7 +79,9 @@ const server = Bun.serve({
|
|||
});
|
||||
afterAll(() => server.stop(true));
|
||||
|
||||
const canLaunch = spawnSync('bun', ['-e', `const { launch } = await import(${JSON.stringify(join(import.meta.dir, '..', 'cli', 'shots', 'browser.ts'))}); await (await launch(${JSON.stringify(join(import.meta.dir, '..'))}, { headless: true })).close();`], { timeout: 60_000 }).status === 0;
|
||||
// launch only: exiting closes the browser's pipe and it quits on its own (a graceful close of Google Chrome, the
|
||||
// fallback without playwright's Chromium, can take 30 s)
|
||||
const canLaunch = spawnSync('bun', ['-e', `const { launch } = await import(${JSON.stringify(join(import.meta.dir, '..', 'cli', 'shots', 'browser.ts'))}); await launch(${JSON.stringify(join(import.meta.dir, '..'))}, { headless: true }); process.exit(0);`], { timeout: 60_000 }).status === 0;
|
||||
if (!canLaunch) console.warn('capture-web browser tests skipped: no Chromium could launch (bunx playwright install chromium)');
|
||||
|
||||
/** A temp project with this config; cli() runs `storebound shots capture <args>` in it. */
|
||||
|
|
|
|||
62
tests/ci-plan.test.ts
Normal file
62
tests/ci-plan.test.ts
Normal file
|
|
@ -0,0 +1,62 @@
|
|||
import { describe, expect, test } from 'bun:test';
|
||||
import { balance, depsOf, GLOBAL, HEAVY, junitTimes, listTests, relatedTests, rustNeeded, shardCount } from '../tools/ci-plan';
|
||||
|
||||
describe('tools/ci-plan: test shards', () => {
|
||||
test('shard count: cores - 1, between 1 and 8, env override', () => {
|
||||
expect(shardCount({}, 10)).toBe(8);
|
||||
expect(shardCount({}, 4)).toBe(3);
|
||||
expect(shardCount({}, 1)).toBe(1);
|
||||
expect(shardCount({ STOREBOUND_CI_SHARDS: '3' }, 10)).toBe(3);
|
||||
expect(shardCount({ STOREBOUND_CI_SHARDS: 'x' }, 10)).toBe(8);
|
||||
});
|
||||
test('balance: every file once, longest first, heavy suites never share a shard', () => {
|
||||
const cost: Record<string, number> = { h1: 10, h2: 9, a: 5, b: 4, c: 3, d: 2, e: 1 };
|
||||
const shards = balance(Object.keys(cost), 3, f => cost[f]!, ['h1', 'h2']);
|
||||
expect(shards.flat().sort()).toEqual(Object.keys(cost).sort());
|
||||
for (const s of shards) expect(s.filter(f => f.startsWith('h')).length).toBeLessThanOrEqual(1);
|
||||
const loads = shards.map(s => s.reduce((n, f) => n + cost[f]!, 0));
|
||||
expect(Math.max(...loads) - Math.min(...loads)).toBeLessThanOrEqual(cost.a!);
|
||||
});
|
||||
test('balance: more heavy suites than shards still places each once; empty shards dropped', () => {
|
||||
expect(balance(['h1', 'h2', 'h3'], 2, () => 1, ['h1', 'h2', 'h3']).flat().sort()).toEqual(['h1', 'h2', 'h3']);
|
||||
expect(balance(['a'], 8, () => 1)).toEqual([['a']]);
|
||||
});
|
||||
test('JUnit report: per-file seconds from the top-level suites only', () => {
|
||||
const xml = `<testsuites><testsuite name="tests/a.test.ts" file="tests/a.test.ts" tests="2" time="1.5" hostname="h">
|
||||
<testsuite name="group" file="tests/a.test.ts" time="0.2"></testsuite></testsuite>
|
||||
<testsuite name="tests/b.test.ts" file="tests/b.test.ts" time="0.25"></testsuite></testsuites>`;
|
||||
expect(junitTimes(xml)).toEqual({ 'tests/a.test.ts': 1.5, 'tests/b.test.ts': 0.25 });
|
||||
});
|
||||
test('every heavy suite exists and every test file is found', () => {
|
||||
const all = listTests();
|
||||
for (const h of HEAVY) expect(all).toContain(h);
|
||||
expect(all).toContain('tests/ci-plan.test.ts');
|
||||
expect(all).toContain('apps/desktop/tests/webview.test.ts');
|
||||
expect(all.some(f => f.includes('node_modules') || f.includes('/fixtures/'))).toBe(false);
|
||||
});
|
||||
});
|
||||
|
||||
describe('tools/ci-plan: related tests (ci:quick)', () => {
|
||||
const all = listTests();
|
||||
test('imports, transitive imports and spawned CLI paths', () => {
|
||||
expect(depsOf('tests/ci-plan.test.ts')).toEqual(['tools/ci-plan.ts']);
|
||||
expect(relatedTests(['tools/ci-plan.ts'], all)).toEqual(['tests/ci-plan.test.ts']);
|
||||
// a CLI library change reaches the tests that import it directly and through other modules
|
||||
const upsert = relatedTests(['cli/lib/upsert.ts'], all);
|
||||
expect(upsert).toContain('tests/idempotency.test.ts');
|
||||
expect(upsert.length).toBeGreaterThan(3);
|
||||
});
|
||||
test('a changed test runs itself; a global file runs everything; docs run nothing', () => {
|
||||
expect(relatedTests(['tests/pure.test.ts'], all)).toEqual(['tests/pure.test.ts']);
|
||||
expect(relatedTests(['package.json'], all)).toEqual(all);
|
||||
expect(GLOBAL.test('bunfig.toml')).toBe(true);
|
||||
expect(relatedTests([['docs/nobody', 'reads.md'].join('-')], all)).toEqual([]);
|
||||
});
|
||||
test('Rust steps only for the Tauri crate or the sidecar build, or with CI=full / unknown diff', () => {
|
||||
expect(rustNeeded(['cli/index.ts'], {})).toBe(false);
|
||||
expect(rustNeeded(['apps/desktop/src-tauri/src/main.rs'], {})).toBe(true);
|
||||
expect(rustNeeded(['tools/build-sidecars.ts'], {})).toBe(true);
|
||||
expect(rustNeeded([], { CI: 'full' })).toBe(true);
|
||||
expect(rustNeeded(null, {})).toBe(true);
|
||||
});
|
||||
});
|
||||
|
|
@ -34,6 +34,12 @@ function fakeRunner(reply: (argv: string[]) => { code?: number; out?: string; da
|
|||
return { calls, run };
|
||||
}
|
||||
|
||||
/** Resolves once `cond` holds (the child was started), instead of a fixed sleep. */
|
||||
async function until(cond: () => boolean, ms = 5000) {
|
||||
const end = Date.now() + ms;
|
||||
while (!cond()) { if (Date.now() > end) throw new Error('until: timed out'); await new Promise(r => setImmediate(r)); }
|
||||
}
|
||||
|
||||
async function session(reply?: Parameters<typeof fakeRunner>[0], clock: () => number = Date.now) {
|
||||
const sent: J[] = [];
|
||||
const f = fakeRunner(reply);
|
||||
|
|
@ -195,10 +201,10 @@ describe('serve --stdio: session', () => {
|
|||
} finally { rmSync(dir, { recursive: true, force: true }); }
|
||||
});
|
||||
test('cancellation answers -32800 and kills the child', async () => {
|
||||
const { s, call, nextId } = await session(() => ({ wait: new Promise(() => {}) }));
|
||||
const { s, call, calls, nextId } = await session(() => ({ wait: new Promise(() => {}) }));
|
||||
const id = nextId();
|
||||
const pending = call('validate', { project: DEMO });
|
||||
await Bun.sleep(5);
|
||||
await until(() => calls.length > 0);
|
||||
await s.handle({ jsonrpc: '2.0', method: '$/cancelRequest', params: { id } });
|
||||
expect(errOf(await pending).code).toBe(ERR.cancelled);
|
||||
});
|
||||
|
|
@ -223,7 +229,7 @@ describe('serve --stdio: session', () => {
|
|||
// real run: waits for the owner (no timeout), the token answers the command's own question, a cancel stops it
|
||||
const id = nextId();
|
||||
const pending = call('console.fill', { ...p, dryRun: false, confirmToken: mint(SECRET, 'console.fill', p, { now }) });
|
||||
await Bun.sleep(5);
|
||||
await until(() => calls.length > n);
|
||||
expect(calls.length).toBe(n + 1);
|
||||
expect(calls.at(-1)!.argv).toEqual(['console', 'fill', 'apple-age-rating', '--json']);
|
||||
expect(calls.at(-1)!.o.env?.STOREBOUND_OWNER_CONFIRMED).toBe('1');
|
||||
|
|
|
|||
|
|
@ -16,7 +16,8 @@ try {
|
|||
} catch (e) { skipWhy = (e as Error).message.split('\n')[0]!; }
|
||||
if (!browser) console.warn(`site overflow test skipped: no Chromium could launch (${skipWhy}). Run \`bunx playwright install chromium\`.`);
|
||||
|
||||
afterAll(async () => { await browser?.close(); });
|
||||
// Google Chrome (the fallback when playwright's own Chromium is missing) can take 30 s to shut down
|
||||
afterAll(async () => { await browser?.close(); }, 60_000);
|
||||
|
||||
describe.skipIf(!browser)('site: no horizontal overflow', () => {
|
||||
for (const scheme of ['light', 'dark'] as const) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue