ci:quick: browser suites only for nearby imports (full ci runs them always)
This commit is contained in:
parent
c71e690aae
commit
95a0bdba0a
3 changed files with 26 additions and 17 deletions
|
|
@ -52,6 +52,12 @@ describe('tools/ci-plan: related tests (ci:quick)', () => {
|
|||
expect(GLOBAL.test('bunfig.toml')).toBe(true);
|
||||
expect(relatedTests([['docs/nobody', 'reads.md'].join('-')], all)).toEqual([]);
|
||||
});
|
||||
test('a browser suite runs for its own module and its near imports, not for every shared core module', () => {
|
||||
expect(relatedTests(['cli/lib/upsert.ts'], all, undefined, HEAVY)).not.toContain('tests/console-fill.test.ts');
|
||||
expect(relatedTests(['cli/lib/upsert.ts'], all)).toContain('tests/console-fill.test.ts');
|
||||
expect(relatedTests(['cli/console/fill.ts'], all, undefined, HEAVY)).toContain('tests/console-fill.test.ts');
|
||||
expect(relatedTests(['tests/capture-web.test.ts'], all, undefined, HEAVY)).toEqual(['tests/capture-web.test.ts']);
|
||||
});
|
||||
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);
|
||||
|
|
|
|||
|
|
@ -123,30 +123,30 @@ export function depsOf(file: string, root = ROOT, src = readFileSync(join(root,
|
|||
/**
|
||||
* Tests related to the changed files: a changed test itself, every test that imports a changed file (transitively),
|
||||
* and every test that names a changed non-code file (fixture, page, skill) by its file name or its fixture folder.
|
||||
* A change to a GLOBAL file returns every test.
|
||||
* A change to a GLOBAL file returns every test. Files in `near` (the browser suites, by default none) count as
|
||||
* related only through imports at most NEAR_DEPTH steps away: nearly every module reaches cli/lib/config.ts and the
|
||||
* store clients, and ci:quick should not start a browser for every change there (the full ci runs them).
|
||||
*/
|
||||
export function relatedTests(changed: string[], tests: string[], root = ROOT): string[] {
|
||||
export const NEAR_DEPTH = 2;
|
||||
export function relatedTests(changed: string[], tests: string[], root = ROOT, near: string[] = []): string[] {
|
||||
if (changed.some(f => GLOBAL.test(f))) return tests;
|
||||
const changedSet = new Set(changed);
|
||||
const memo = new Map<string, Set<string>>();
|
||||
const direct = new Map<string, string[]>();
|
||||
const depsCached = (f: string) => {
|
||||
let d = direct.get(f);
|
||||
if (!d) { try { d = depsOf(f, root); } catch { d = []; } direct.set(f, d); }
|
||||
return d;
|
||||
};
|
||||
const closure = (f: string): Set<string> => {
|
||||
const hit = memo.get(f);
|
||||
if (hit) return hit;
|
||||
const seen = new Set<string>([f]);
|
||||
memo.set(f, seen);
|
||||
const stack = [f];
|
||||
while (stack.length) {
|
||||
const cur = stack.pop()!;
|
||||
/** Every file a test reaches, with its import distance. */
|
||||
const closure = (f: string): Map<string, number> => {
|
||||
const depth = new Map<string, number>([[f, 0]]);
|
||||
const queue = [f];
|
||||
while (queue.length) {
|
||||
const cur = queue.shift()!;
|
||||
if (!/\.(ts|tsx)$/.test(cur)) continue;
|
||||
for (const d of depsCached(cur)) if (!seen.has(d)) { seen.add(d); stack.push(d); }
|
||||
for (const d of depsCached(cur)) if (!depth.has(d)) { depth.set(d, depth.get(cur)! + 1); queue.push(d); }
|
||||
}
|
||||
return seen;
|
||||
return depth;
|
||||
};
|
||||
const names = changed.filter(f => !/\.(ts|tsx)$/.test(f) || f.includes('/fixtures/')).flatMap(f => {
|
||||
const base = f.split('/').pop()!;
|
||||
|
|
@ -155,10 +155,11 @@ export function relatedTests(changed: string[], tests: string[], root = ROOT): s
|
|||
});
|
||||
return tests.filter(t => {
|
||||
if (changedSet.has(t)) return true;
|
||||
const deps = closure(t);
|
||||
if (changed.some(c => deps.has(c))) return true;
|
||||
const all = closure(t);
|
||||
const max = near.includes(t) ? NEAR_DEPTH : Infinity;
|
||||
if (changed.some(c => all.has(c) && all.get(c)! <= max)) return true;
|
||||
if (!names.length) return false;
|
||||
const srcs = [...deps].filter(d => d.startsWith('tests/') || d.startsWith('apps/desktop/tests/')).map(d => {
|
||||
const srcs = [...all.keys()].filter(d => d.startsWith('tests/') || d.startsWith('apps/desktop/tests/')).map(d => {
|
||||
try { return readFileSync(join(root, d), 'utf8'); } catch { return ''; }
|
||||
}).join('\n');
|
||||
return names.some(n => srcs.includes(n));
|
||||
|
|
|
|||
|
|
@ -46,8 +46,10 @@ function addTests(files: string[]) {
|
|||
}
|
||||
|
||||
if (quick) {
|
||||
const related = changed === null ? tests : relatedTests(changed, tests);
|
||||
const related = changed === null ? tests : relatedTests(changed, tests, ROOT, HEAVY);
|
||||
const far = changed === null ? [] : relatedTests(changed, tests).filter(t => !related.includes(t));
|
||||
console.log(`ci:quick: ${changed === null ? 'no origin/main to diff against: every test' : `${changed.length} changed file(s), ${related.length} related test file(s)`}`);
|
||||
if (far.length) console.log(`ci:quick: left out ${far.length} browser suite(s) reached only through shared modules (bun run ci runs them): ${far.join(' ')}`);
|
||||
add({ name: 'adapters', cmd: ['bun', 'tools/gen-adapters.ts', '--check'] });
|
||||
tsc('typecheck', '.');
|
||||
if (touches(/^apps\/desktop\//)) tsc('desktop typecheck', 'apps/desktop');
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue