mirror of
https://github.com/garrytan/gstack.git
synced 2026-11-23 08:31:44 +01:00
Deleted tests still check the files that list them, and Playwright fixture specs run under Playwright (#4702)
Deleting or renaming a test now runs the tests of files that still list it even when another test already covers it, and Playwright specs that take `test` from a local fixtures file run under `playwright test`. Why: a deleted test could pass the local checks while a stale curation list failed after merge (#3536), and fixture-based Playwright specs went to the unit runner and failed (#4347). Nothing to do. A repo whose specs import `@playwright/test` directly sees no change. Co-authored-by: Yuan S. <3579304+szsunyuan@users.noreply.github.com> Co-authored-by: marcode <244097767+vilano93@users.noreply.github.com> Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com> Review-Finding: review-p1/specialist-batched#1 reader=specialist-batched Review-Finding: review-p1/specialist-batched#2 reader=specialist-batched Review-Finding: review-p1/red-team#1 reader=red-team Review-Finding: review-v1/outside-voice#1 reader=outside-voice Review-Finding: review-v1/outside-voice#2 reader=outside-voice Review-Finding: review-v1/outside-voice#3 reader=outside-voice Review-Finding: review-v1/outside-voice#4 reader=outside-voice Review-Finding: review-p2/specialist-batched#1 reader=specialist-batched Review-Finding: review-p2/red-team#1 reader=red-team
This commit is contained in:
6 files changed
+173
-16
No files matched your search
@@ -0,0 +1,2 @@
|
||||
- **Deleting or renaming a test now checks the files that still list it, even when another test covers it.** Before, if a `dependencies` entry or another test already pointed at the removed test, `/verify` and `/ship` ran only that test and passed, while a curation list that still named the deleted file was never checked (#3536). Those files' tests now run, and a file that names it with no test of its own fails closed.
|
||||
- **Playwright specs that use a local fixtures file run under `playwright test`.** A spec that takes `test` from a repo module built on `@playwright/test` (Playwright's fixtures pattern, `export const test = base.extend(…)`) was sent to the unit runner, which found no tests and failed (#4347). It now runs through `playwright test` like a spec that imports `@playwright/test` directly.
|
||||
+7
-2
@@ -91,7 +91,7 @@ the byte-pinned `/ship` renders in `test/fixtures/golden/`).
|
||||
|
||||
| Key | Meaning |
|
||||
|---|---|
|
||||
| `runner` | the local test command with `{files}` (gstack: `bun test --timeout=30000 {files}`, the 30 s per-test timeout CI uses); set, the local lane gives it only the selected files its tool runs, judged by extension (JS/TS files for `bun test`, `node --test`, `deno test`, vitest, jest, mocha, ava or playwright; `.py` files for pytest; each matched as a whole word, so `npx vitest run` counts and `tests/node/run.sh` does not; every file for any other command, such as a `node scripts/run-tests.js` dispatcher, or one naming both), and the lanes detail names each file it cannot run as not run and not counted as covered, so a `*_test.py` never reaches a local `bun test` (no Python lane runs beside a declared runner; the remote gate and `test_backend` commands still receive the whole selection, a declared test tree's tests included, since that exclusion is local-only); unset, it is detected (bun, vitest or jest for JS/TS files, pytest when python3 can import it (else `pytest` or `python3` is named missing), `node --test`, and `flutter test`/`dart test` per Dart package root, through fvm when that package or an ancestor pins it with `.fvmrc` or `.fvm/fvm_config.json` and fvm is on PATH; `cargo test -p <name>` per Rust crate, run from the root of the workspace the crate is a member of (Cargo's `members` globs, `exclude` and `package.workspace`), else the crate directory; a JS/TS test whose nearest package.json is a nested package declaring vitest or jest (a dependency or its `test` script) runs from that package, with package-relative paths, through the package manager its `packageManager` field or the nearest lockfile up to the repo root names: `pnpm exec`, `yarn`, `bun x`, else `npx`; a JS/TS test file that imports `@playwright/test` at the start of a line runs as `playwright test --reporter=list` from its nearest package through that same package manager, whatever the unit runner is, a type-only import (`import type …`, or one whose every specifier is `type X`) does not count, file arguments are passed as escaped regexes anchored to the path (Playwright reads them as regexes), and a run where every test fails and Playwright says its browser is not installed is `PREGATE_ENVIRONMENT` (a partial install, where some tests pass, stays the diff's failure); a `.js`, `.mjs` or `.cjs` test that loads `node:test` in a statement starting a line, and loads neither vitest nor `@jest/globals`, runs through `node --test` from the repo root even when the repo or its package declares vitest or jest (which find no suite in such a file), while a bun repo keeps `bun test` for it; every other test keeps the root detection, split by language when no one runner fits them all, so `.mjs` and `.py` root tests each get their own runner); nothing detected, a Dart SDK, cargo or package manager missing from PATH, a `.dart` file with no `pubspec.yaml` above it, a `.rs` file outside any crate, or one in a crate whose name Cargo would reject (anything but letters, digits, `_` and `-`), is `incomplete` (the runnable groups still run, so a real failure still fails) |
|
||||
| `runner` | the local test command with `{files}` (gstack: `bun test --timeout=30000 {files}`, the 30 s per-test timeout CI uses); set, the local lane gives it only the selected files its tool runs, judged by extension (JS/TS files for `bun test`, `node --test`, `deno test`, vitest, jest, mocha, ava or playwright; `.py` files for pytest; each matched as a whole word, so `npx vitest run` counts and `tests/node/run.sh` does not; every file for any other command, such as a `node scripts/run-tests.js` dispatcher, or one naming both), and the lanes detail names each file it cannot run as not run and not counted as covered, so a `*_test.py` never reaches a local `bun test` (no Python lane runs beside a declared runner; the remote gate and `test_backend` commands still receive the whole selection, a declared test tree's tests included, since that exclusion is local-only); unset, it is detected (bun, vitest or jest for JS/TS files, pytest when python3 can import it (else `pytest` or `python3` is named missing), `node --test`, and `flutter test`/`dart test` per Dart package root, through fvm when that package or an ancestor pins it with `.fvmrc` or `.fvm/fvm_config.json` and fvm is on PATH; `cargo test -p <name>` per Rust crate, run from the root of the workspace the crate is a member of (Cargo's `members` globs, `exclude` and `package.workspace`), else the crate directory; a JS/TS test whose nearest package.json is a nested package declaring vitest or jest (a dependency or its `test` script) runs from that package, with package-relative paths, through the package manager its `packageManager` field or the nearest lockfile up to the repo root names: `pnpm exec`, `yarn`, `bun x`, else `npx`; a JS/TS test file that imports `@playwright/test` at the start of a line, or takes `test` from a repo module that takes `test` from it (Playwright's fixtures pattern, followed through named and `export *` re-exports and `index` modules up to 8 deep, never outside the repo; only the module `test` comes from), runs as `playwright test --reporter=list` from its nearest package through that same package manager, whatever the unit runner is, a type-only import (`import type …`, or one whose every specifier is `type X`) does not count, file arguments are passed as escaped regexes anchored to the path (Playwright reads them as regexes), and a run where every test fails and Playwright says its browser is not installed is `PREGATE_ENVIRONMENT` (a partial install, where some tests pass, stays the diff's failure); a `.js`, `.mjs` or `.cjs` test that loads `node:test` in a statement starting a line, and loads neither vitest nor `@jest/globals`, runs through `node --test` from the repo root even when the repo or its package declares vitest or jest (which find no suite in such a file), while a bun repo keeps `bun test` for it; every other test keeps the root detection, split by language when no one runner fits them all, so `.mjs` and `.py` root tests each get their own runner); nothing detected, a Dart SDK, cargo or package manager missing from PATH, a `.dart` file with no `pubspec.yaml` above it, a `.rs` file outside any crate, or one in a crate whose name Cargo would reject (anything but letters, digits, `_` and `-`), is `incomplete` (the runnable groups still run, so a real failure still fails) |
|
||||
| `dependencies` | glob → test files for subprocess targets, runtime reads and generated inputs the import graph cannot see; `[]` declares "no lane needed" (docs, licences). A `[]` on a folder inside a test directory (`test/`, `tests/`, `spec/` or `__tests__/`, as in `"tests/live/**": []`; never the whole directory, so `"test/**": []` changes nothing) is the repo's statement that the tests under it run in their own tier, not in /ship's local lane: pregate keeps every selected test under that glob out of the local lane, whether touched or picked through an import (a test `.gstack/always-run.json` names still runs; the remote side is unchanged: the remote gate, `test_backend` and any remote platform lane that selects the test still owe it; and only a base-branch or user-owned policy's `[]` counts, never a bootstrap head file read under `--policy-from` head when neither exists), and prints `declared test tree <glob>: N test file(s) not run in the local lane` in the `lanes` lines it records; tests outside the glob still run, and a `[]` on any other glob never skips a test. A `[]` that matches a deleted test does not skip it: the deleted test still runs its owning suite, and a file naming it that `[]` covers (a durations list) counts as covered. With this key present, even empty, the policy [declares lanes](#lane-requirements) |
|
||||
| `empty_lanes` | extra globs for the docs/no-tests empty lane. Any Markdown file already qualifies with no pin file when no test depends on it (the same import graph as other files: a quoted path, a `join()` of path segments, an import, or a `dependencies` entry). reStructuredText and AsciiDoc count as Markdown here. README, CHANGELOG, CONTRIBUTING, LICENSE, AGENTS and CLAUDE qualify even without `.md`, and so does licence text under any vendored name (`roboto-LICENSE.txt`, `LICENSE-MIT`, `licenses/*.txt`). Source code and files under a test directory never qualify. A test that reads the file still selects that test |
|
||||
| `selection` | `workflow.yml/job` → a command printing the lane's file list, for matrices a planner computes (gstack: `scripts/test-free-shards.ts --list`) |
|
||||
@@ -350,7 +350,12 @@ Two stages with separate clocks, both printed:
|
||||
the tests of each remaining non-Markdown file that mentions its name
|
||||
without the final extension anywhere (`alpha.test`, `test_alpha`:
|
||||
a path with or without the extension, or a dotted module), such as a curation list (`files naming it run: …`), and fails closed when
|
||||
such a file has no test (`still named by …, which no test covers`). A test
|
||||
such a file has no test (`still named by …, which no test covers`). A removed
|
||||
test that a remaining test already selects (through a `dependencies` entry, or a
|
||||
test that names its path) runs those files' tests too and fails closed the
|
||||
same way. A `dependencies` key in `.gstack/pregate.json`, or a listed test
|
||||
beside another test that still exists, is not a file naming it, and neither is
|
||||
a mention under another directory's path (#3536). A test
|
||||
renamed to another test path then defers to its new name (`old name of
|
||||
<new>`). A deleted test, or one renamed to a non-test path, also runs its
|
||||
owning suite, the remaining tests that directly exercise the files its
|
||||
|
||||
@@ -197,6 +197,36 @@ function importsPlaywright(text: string): boolean {
|
||||
}
|
||||
return false;
|
||||
}
|
||||
/** Where a file takes the value `test` from: a relative module or `@playwright/test`, by `import { test } from …` (aliased or not), `export { test } from …` or `export * from …`. */
|
||||
function testSources(text: string): string[] {
|
||||
const code = text.replace(/\/\*[\s\S]*?\*\/|\/\/[^\n]*/g, '');
|
||||
return [...code.matchAll(/^[\t ]*(?:(?:import|export)[\t ]*\{([^}]*)\}|export[\t ]*\*)[\t ]*from[\t ]*['"](\.{1,2}\/[^'"]+|@playwright\/test)['"]/gm)].filter(m => m[1] === undefined || m[1].split(',').some(s => /^test(?:\s+as\s+[\w$]+)?$/.test(s.trim()))).map(m => m[2]!);
|
||||
}
|
||||
/**
|
||||
* Whether a JS/TS test is a Playwright spec: it imports a value from `@playwright/test`, or takes `test` from a repo module that does and doesn't take
|
||||
* `test` from a unit runner, directly or through further such modules, up to 8 deep (Playwright's fixtures pattern: `base.extend(…)`, `mergeTests(…)`).
|
||||
* Only the modules `test` comes from are followed, so a unit test whose helper or vitest fixture uses other Playwright APIs keeps its runner (#4347).
|
||||
*/
|
||||
function playwrightSpec(repoRoot: string, file: string): boolean {
|
||||
const exts = ['.ts', '.tsx', '.mts', '.cts', '.js', '.jsx', '.mjs', '.cjs'];
|
||||
const seen = new Set<string>();
|
||||
let level = [file];
|
||||
for (let depth = 0; level.length && depth <= 8; depth++) {
|
||||
const next: string[] = [];
|
||||
for (const mod of level.filter(m => !seen.has(m))) {
|
||||
seen.add(mod);
|
||||
const text = readRepoFile(repoRoot, mod) ?? '', sources = testSources(text);
|
||||
if (depth === 0 ? importsPlaywright(text) : sources.includes('@playwright/test') || (importsPlaywright(text) && !/^[\t ]*import\b[^;]*\btest\b[^;]*\bfrom[\t ]*['"](?:vitest|@jest\/globals|bun:test|node:test)['"]/m.test(text))) return true;
|
||||
for (const base of sources.filter(s => s.startsWith('.')).map(spec => path.posix.normalize(path.posix.join(path.posix.dirname(mod), spec))).filter(b => b !== '..' && !b.startsWith('../'))) {
|
||||
const stem = base.replace(/\.[cm]?jsx?$/, '');
|
||||
const hit = [base, ...exts.map(e => stem + e), ...exts.map(e => `${base}/index${e}`)].find(c => readRepoFile(repoRoot, c) !== null);
|
||||
if (hit) next.push(hit);
|
||||
}
|
||||
}
|
||||
level = next;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
/** Whether a JS test is a node:test file: it loads `node:test` in a statement that starts a line (`import … from 'node:test'`, a bare import, or `require`) and loads neither vitest nor `@jest/globals`, whose runner owns it. Text that mentions a module mid-line, in a comment or in a template literal does not count. */
|
||||
function importsNodeTest(text: string): boolean {
|
||||
const code = text.replace(/\/\*[\s\S]*?\*\/|\/\/[^\n]*|`(?:\\[\s\S]|[^\\`])*`/g, '');
|
||||
@@ -222,7 +252,7 @@ function declaredRunnerFiles(runner: string): RegExp | null {
|
||||
* against its own pubspec); Rust tests run per crate as `cargo test -p <name>`
|
||||
* from the crate's workspace root; JS/TS tests owned by a nested package that
|
||||
* declares vitest or jest run from that package; a JS/TS test that imports
|
||||
* `@playwright/test` runs through `playwright test` from its nearest package;
|
||||
* `@playwright/test`, or takes `test` from a local fixtures module built on it, runs through `playwright test` from its nearest package;
|
||||
* a `.js`, `.mjs` or `.cjs` test that loads `node:test` runs from the repo root with the runner `detectRunner` gives node:test files;
|
||||
* the rest go to the detected runner from the repo root, split by language
|
||||
* when no one runner fits them all (`.mjs` + `.py` runs both), and pytest only
|
||||
@@ -265,7 +295,7 @@ export function planRuns(ctx: PregateContext, files: readonly string[]): RunPlan
|
||||
continue;
|
||||
}
|
||||
const pkg = /\.[cm]?[jt]sx?$/.test(f) ? nearestRoot(ctx.repoRoot, f, 'package.json', seenPackage) : null;
|
||||
if (pkg !== null && importsPlaywright(readRepoFile(ctx.repoRoot, f) ?? '')) { add(playwright, pkg, under(pkg, f)); continue; }
|
||||
if (pkg !== null && playwrightSpec(ctx.repoRoot, f)) { add(playwright, pkg, under(pkg, f)); continue; }
|
||||
if (/\.[cm]?js$/.test(f) && importsNodeTest(readRepoFile(ctx.repoRoot, f) ?? '')) { nodeTests.push(f); continue; }
|
||||
if (pkg) {
|
||||
if (!pkgRunners.has(pkg)) pkgRunners.set(pkg, packageRunner(ctx.repoRoot, pkg, ctx.env));
|
||||
|
||||
@@ -149,14 +149,36 @@ function outputsOf(all: readonly string[], globs: readonly string[]): string[] {
|
||||
/**
|
||||
* Tracked files outside Markdown that mention `file`'s name without its final extension anywhere, where the import graph cannot
|
||||
* see: a curation list, a durations manifest, a script, a workflow, an extensionless path (`node test/alpha.test`), a dotted
|
||||
* module (`tests.test_alpha`), or an escaped or encoded path (`\talpha.test.js`, `test%2Falpha.test.js`).
|
||||
* module (`tests.test_alpha`), or an escaped or encoded path (`\talpha.test.js`, `test%2Falpha.test.js`). A file whose every mention sits under
|
||||
* another directory's path (`packages/b/alpha.test`) does not count, nor does `.gstack/pregate.json` when its only mentions are `dependencies` keys,
|
||||
* listed tests beside another test that still exists, or another directory's listed test.
|
||||
*/
|
||||
function namedBy(ctx: PregateContext, file: string): string[] {
|
||||
const base = path.posix.basename(file);
|
||||
const stem = base.includes('.') ? base.slice(0, base.lastIndexOf('.')) : base;
|
||||
const r = spawnSync('git', ['grep', '--untracked', '-l', '-F', '-e', stem, '--', '.', ':(exclude)*.md', ':(exclude)*.mdx'], { cwd: ctx.repoRoot, encoding: 'utf8', timeout: 60_000, maxBuffer: 16 * 1024 * 1024, env: ctx.env });
|
||||
if (r.status === 1) return [];
|
||||
return r.status === 0 ? (r.stdout ?? '').split('\n').filter(Boolean) : ['(git grep failed)'];
|
||||
if (r.status !== 0) return ['(git grep failed)'];
|
||||
const dir = path.posix.dirname(file);
|
||||
return (r.stdout ?? '').split('\n').filter(Boolean).filter(n => {
|
||||
let text: string;
|
||||
try { text = fs.readFileSync(path.join(ctx.repoRoot, n), 'utf8'); } catch { return true; }
|
||||
if (n === PREGATE_CONFIG_PATH) {
|
||||
try {
|
||||
const { dependencies: deps, ...rest } = JSON.parse(text);
|
||||
if (deps && typeof deps === 'object' && !Array.isArray(deps) && !JSON.stringify(rest).includes(stem)) {
|
||||
const own = (t: unknown) => typeof t === 'string' ? t.includes(stem) && (!t.includes('/') || path.posix.normalize(path.posix.dirname(t)) === dir) : JSON.stringify(t ?? null).includes(stem);
|
||||
const sibling = (t: unknown) => typeof t === 'string' && !t.includes(stem) && !!fs.statSync(path.join(ctx.repoRoot, t), { throwIfNoEntry: false })?.isFile();
|
||||
return Object.values(deps).some(list => Array.isArray(list) ? list.some(own) && !list.some(sibling) : own(list));
|
||||
}
|
||||
} catch { return true; }
|
||||
}
|
||||
return text.split(stem).slice(0, -1).some(before => {
|
||||
if (before.endsWith(`${dir}/`)) return true;
|
||||
const q = /(?:^|[\s'"`=,(\[])((?:[\w.@-]+\/)+)$/.exec(before)?.[1];
|
||||
return !q || q.startsWith('./') || q.startsWith('../') || `/${dir}/`.endsWith(`/${q}`) || `/${q}`.endsWith(`/${dir}/`);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
/** Test languages whose importers the graph resolves file by file; a Go or Ruby test may define helpers its package still uses. */
|
||||
@@ -164,6 +186,17 @@ const RESOLVED_IMPORTS = /\.(?:[cm]?[jt]sx?|py|dart)$/;
|
||||
|
||||
const shown = (files: readonly string[]) => `${files.slice(0, 8).join(' ')}${files.length > 8 ? ` … +${files.length - 8} more` : ''}`;
|
||||
|
||||
/** The tests of the remaining non-Markdown files that name a removed test (a curation list, a durations manifest), and why it is refused when one of them has no test. */
|
||||
function namerCoverage(ctx: PregateContext, graph: Graph, gone: ReadonlySet<string>, file: string): { suite: string[]; refused?: string } {
|
||||
const suite = new Set<string>();
|
||||
const uncovered = namedBy(ctx, file).filter(f => !gone.has(f)).filter(n => {
|
||||
const m = testsFor(graph, n, ctx.config.dependencies);
|
||||
for (const t of m.tests) suite.add(t);
|
||||
return !m.tests.length && !m.declaredNone;
|
||||
});
|
||||
return { suite: [...suite].sort(), ...(uncovered.length ? { refused: `removed, but still named by ${shown(uncovered)}, which no test covers` } : {}) };
|
||||
}
|
||||
|
||||
/**
|
||||
* Why a removed test no remaining test selects owes no lane, and the tests it selects, or `refused` when it must fail closed as
|
||||
* no lane. Only a removed JS, TS, Python, Dart or bats test is waived; any other removed path, a renamed source's old name
|
||||
@@ -179,19 +212,14 @@ function removedPath(ctx: PregateContext, graph: Graph, gone: ReadonlySet<string
|
||||
const edges = [...graph.reverse].filter(([k]) => k === file || (k.endsWith('/**') && file.startsWith(k.slice(0, -2)))).flatMap(([, list]) => list);
|
||||
const importers = [...new Set(edges.map(e => e.from))].filter(f => !gone.has(f)).sort();
|
||||
if (importers.length) return { refused: `removed, but still imported by ${shown(importers)}` };
|
||||
const namerSuite = new Set<string>();
|
||||
const uncovered = namedBy(ctx, file).filter(f => !gone.has(f)).filter(n => {
|
||||
const m = testsFor(graph, n, ctx.config.dependencies);
|
||||
for (const t of m.tests) namerSuite.add(t);
|
||||
return !m.tests.length && !m.declaredNone;
|
||||
});
|
||||
if (uncovered.length) return { refused: `removed, but still named by ${shown(uncovered)}, which no test covers` };
|
||||
const namerNote = namerSuite.size ? `files naming it run: ${shown([...namerSuite].sort())}` : '';
|
||||
const { suite: namerSuite, refused } = namerCoverage(ctx, graph, gone, file);
|
||||
if (refused) return { refused };
|
||||
const namerNote = namerSuite.length ? `files naming it run: ${shown(namerSuite)}` : '';
|
||||
const renamedTo = ctx.touched.find(t => t.renamedFrom === file)?.path;
|
||||
if (renamedTo && isTestFile(renamedTo)) return { removed: { file, note: [`old name of ${renamedTo}`, namerNote].filter(Boolean).join('; '), lostCoverage: [] }, suite: [...namerSuite] };
|
||||
if (renamedTo && isTestFile(renamedTo)) return { removed: { file, note: [`old name of ${renamedTo}`, namerNote].filter(Boolean).join('; '), lostCoverage: [] }, suite: namerSuite };
|
||||
const subjects = graph.goneSubjects?.get(file);
|
||||
if (!subjects) return { refused: 'removed test whose merge-base text could not be read (not a regular file there, invalid UTF-8 or over 1 MiB)' };
|
||||
if (!subjects.length) return { removed: { file, note: ['it exercised no file still in the tree', namerNote].filter(Boolean).join('; '), lostCoverage: [] }, suite: [...namerSuite] };
|
||||
if (!subjects.length) return { removed: { file, note: ['it exercised no file still in the tree', namerNote].filter(Boolean).join('; '), lostCoverage: [] }, suite: namerSuite };
|
||||
const suite = new Set<string>();
|
||||
const lostCoverage: string[] = [];
|
||||
for (const subject of subjects) {
|
||||
@@ -243,6 +271,12 @@ export function selectLanes(ctx: PregateContext): Selection {
|
||||
const m = testsFor(graph, file, ctx.config.dependencies);
|
||||
for (const t of m.tests) tests.add(t);
|
||||
provenance.push(...m.provenance.map(p => `${p} [${why}]`));
|
||||
if (m.tests.length && goneSet.has(file) && isTestFile(file)) {
|
||||
const namers = namerCoverage(ctx, graph, goneSet, file);
|
||||
for (const t of namers.suite) tests.add(t);
|
||||
if (namers.refused) { noLane.push(file); provenance.push(`${file}: ${namers.refused}; no lane until declared`); }
|
||||
else if (namers.suite.length) provenance.push(`${file}: files naming it run: ${shown(namers.suite)}`);
|
||||
}
|
||||
if (m.tests.length || why.startsWith('generated')) continue;
|
||||
// An explicit `[]` already cleared the file. A removed test still runs its owning suite; label the rest docs/no-tests only when it is that class.
|
||||
if (m.declaredNone) {
|
||||
|
||||
@@ -229,6 +229,58 @@ describe('removed paths in lanes (#3529)', () => {
|
||||
expect(r.removed[0]).toContain('files naming it run: test/curation.test.js');
|
||||
});
|
||||
|
||||
const RETRY_TEST = "const test = require('node:test');\nconst assert = require('node:assert');\ntest('retry', () => assert.ok(true));\n";
|
||||
const withDeps = (deps: Record<string, string[]>) => ({ ...BASE_PREGATE, dependencies: { ...BASE_PREGATE.dependencies, ...deps } });
|
||||
// Value: protects=a removed test that already maps to another test (a dependencies entry or a remaining test that names its path) still
|
||||
// runs the tests of the files that name it, so a stale curation entry fails loudly instead of passing; fails_when=the mapped-test early
|
||||
// return skips the files-naming-it check again (#3536: pregate exited 0 running only the mapped test); why_new=#3534 covered only
|
||||
// unmapped removals; seam=none; no_claim=Markdown namers (excluded as before)
|
||||
test.each([
|
||||
['deleted test mapped by a dependencies entry', { 'test/util.test.js': ['test/retry.test.js'] }, {}, (repo: FixtureRepo) => commit(repo, { 'test/util.test.js': null })],
|
||||
['deleted test named by a remaining test', {}, { 'test/retry.test.js': RETRY_TEST + "const OLD = 'test/util.test.js';\n" }, (repo: FixtureRepo) => commit(repo, { 'test/util.test.js': null })],
|
||||
['test renamed to a test whose old name a dependencies entry maps', { 'test/util.test.js': ['test/retry.test.js'] }, {}, (repo: FixtureRepo) => move(repo, 'test/util.test.js', 'test/util2.test.js')],
|
||||
])('a %s still runs the tests of the files that name it (#3536)', (_how, deps, files, change) => {
|
||||
const repo = fixture({ pregate: withDeps(deps), baseFiles: { 'scripts/curation.js': CURATION, 'test/curation.test.js': CURATION_TEST, 'test/retry.test.js': RETRY_TEST, ...files } });
|
||||
change(repo);
|
||||
const r = lanes(repo);
|
||||
expect(r.ran).toContain('test/curation.test.js');
|
||||
expect(r.ran).toContain('test/retry.test.js');
|
||||
expect(r.check.status).toBe('fail');
|
||||
});
|
||||
|
||||
test('a mapped removed test that an untested file still names fails closed; its dependencies key alone is not a namer (#3536)', () => {
|
||||
const repo = fixture({ pregate: withDeps({ 'test/util.test.js': ['test/retry.test.js'] }), baseFiles: { 'test/retry.test.js': RETRY_TEST, 'ci/skip-list.txt': 'test/util.test.js\n' } });
|
||||
commit(repo, { 'test/util.test.js': null });
|
||||
const r = lanes(repo);
|
||||
expect(r.check.code).toBe('PREGATE_NO_LANE');
|
||||
expect(r.check.detail).toContain('test/util.test.js');
|
||||
const control = fixture({ pregate: withDeps({ 'test/util.test.js': ['test/retry.test.js'] }), baseFiles: { 'test/retry.test.js': RETRY_TEST } });
|
||||
commit(control, { 'test/util.test.js': null });
|
||||
const c = lanes(control);
|
||||
expect(c.check.status).toBe('pass');
|
||||
expect(c.ran).toContain('test/retry.test.js');
|
||||
});
|
||||
|
||||
// Value: protects=.gstack/pregate.json still counts as naming a removed test it lists as the only test of a dependencies entry, while a
|
||||
// listed test beside a surviving one, or a list naming another directory's same-named test, does not refuse the deletion;
|
||||
// fails_when=the dependencies map is dropped wholesale from the namer check, or any same-basename path counts as a mention;
|
||||
// why_new=only the key-only case was covered; seam=none; no_claim=other policy keys
|
||||
test.each([
|
||||
['the only listed test of a dependencies entry', { 'scripts/build.js': ['test/util.test.js'] }, {}, 'fail', 'test/util.test.js'],
|
||||
['a listed test beside one that still exists', { 'scripts/build.js': ['test/util.test.js', 'test/retry.test.js'] }, {}, 'pass', 'test/util.test.js'],
|
||||
['a same-named test in another directory', {}, { 'ci/skip-list.txt': 'packages/b/util.test.js\n' }, 'pass', 'test/util.test.js'],
|
||||
['the only listed test of an entry, under another directory', { 'scripts/build.js': ['packages/b/util.test.js'] }, {}, 'pass', 'test/util.test.js'],
|
||||
['its own path in a directory with a space', {}, { 'ci/skip-list.txt': 'test/e2e suite/util.test.js\n' }, 'fail', 'test/e2e suite/util.test.js'],
|
||||
['its own path in a $-named directory', {}, { 'ci/skip-list.txt': 'test/$id/util.test.js\n' }, 'fail', 'test/$id/util.test.js'],
|
||||
] as [string, Record<string, string[]>, Record<string, string>, string, string][])('a mapped removed test named as %s', (_how, deps, files, status, gone) => {
|
||||
const repo = fixture({ pregate: withDeps({ [gone]: ['test/retry.test.js'], ...deps }), baseFiles: { 'test/retry.test.js': RETRY_TEST, [gone]: RETRY_TEST, ...files } });
|
||||
commit(repo, { [gone]: null });
|
||||
const r = lanes(repo);
|
||||
expect(r.check.status).toBe(status);
|
||||
if (status === 'fail') expect(r.check.code).toBe('PREGATE_NO_LANE');
|
||||
else expect(r.ran).toContain('test/retry.test.js');
|
||||
});
|
||||
|
||||
test.each([
|
||||
['an extensionless path in package.json', 'test/util.test.js', { 'package.json': '{ "name": "fixture", "scripts": { "smoke": "node --test test/util.test" } }\n' }],
|
||||
['a dotted module name in a Makefile', 'tests/test_alpha.py', { 'tests/__init__.py': '', 'tests/test_alpha.py': 'import unittest\nclass T(unittest.TestCase):\n def test_a(self):\n pass\n', 'Makefile': 'smoke:\n\tpython3 -m unittest tests.test_alpha\n' }],
|
||||
|
||||
@@ -1078,6 +1078,40 @@ describe('nested JS packages run their own runner from their own directory', ()
|
||||
expect(planRuns(ctxFor(repo, { PATH: path.join(repo.root, 'empty-path') }), ['app/e2e/app.spec.ts'])).toEqual({ groups: [], unclaimed: ['app/e2e/app.spec.ts'], missing: ['pnpm'], noPubspec: [] });
|
||||
});
|
||||
|
||||
|
||||
// Value: protects=a spec that takes `test` from a local fixtures module built on @playwright/test (Playwright's documented fixtures pattern),
|
||||
// directly, aliased, through a re-export or an index module, or through a .js specifier naming a .ts source, runs through `playwright test`,
|
||||
// an `export *` barrel or a mergeTests module, while a unit test that imports some other Playwright-based helper, or takes `test` from a vitest fixture that
|
||||
// uses Playwright's request API, keeps its runner and a module outside the repo (`../../x` or `../..`) is never followed;
|
||||
// fails_when=only a direct @playwright/test import marks a spec again (#4347: the spec went to vitest, which found no test files);
|
||||
// why_new=no case covered fixtures modules; seam=none; no_claim=a real Playwright run (plan only)
|
||||
test('a spec taking test from a local Playwright fixtures module runs through playwright test; other helpers keep the unit runner (#4347)', () => {
|
||||
const repo = fixture({ pregate: null, baseFiles: APP });
|
||||
const ctx = ctxFor(repo, pmShim(repo));
|
||||
write(repo.work, 'package.json', JSON.stringify({ name: 'fixture', devDependencies: { vitest: '^3.2.0', '@playwright/test': '^1.48.0' } }) + '\n');
|
||||
write(repo.work, 'e2e/base.ts', "import { test as base } from '@playwright/test';\nexport const test = base.extend({});\nexport { expect } from '@playwright/test';\n");
|
||||
write(repo.work, 'e2e/fixtures/index.ts', "export { test, expect } from '../base';\n");
|
||||
write(repo.work, 'e2e/direct.spec.ts', "import { expect, test } from './base';\ntest('direct', async ({ page }) => expect(page).toBeTruthy());\n");
|
||||
write(repo.work, 'e2e/aliased.spec.ts', "import {\n test as it,\n expect,\n} from './fixtures';\nit('aliased', () => {});\n");
|
||||
write(repo.work, 'e2e/js-specifier.spec.ts', "import { test } from './base.js';\ntest('js', () => {});\n");
|
||||
write(repo.work, 'test/helper.ts', "import { chromium } from '@playwright/test';\nexport const launch = () => chromium;\nexport const test = 1;\n");
|
||||
write(repo.work, 'test/unit.test.ts', "import { expect, test } from 'vitest';\nimport { launch } from './helper';\ntest('unit', () => expect(launch).toBeTruthy());\n");
|
||||
write(repo.work, 'test/outside.test.ts', "import { test } from '../../outside/base';\ntest('outside', () => {});\n");
|
||||
write(repo.work, 'e2e/barrel/index.ts', "export * from '../base';\n");
|
||||
write(repo.work, 'e2e/star.spec.ts', "import { test } from './barrel';\ntest('star', () => {});\n");
|
||||
write(repo.work, 'test/api-fixture.ts', "import { test as base } from 'vitest';\nimport { request } from '@playwright/test';\nexport const test = base.extend({ api: async ({}, use) => use(await request.newContext()) });\n");
|
||||
write(repo.work, 'test/api.test.ts', "import { test } from './api-fixture';\ntest('api', () => {});\n");
|
||||
write(repo.work, 'e2e/merged.ts', "import { mergeTests } from '@playwright/test';\nimport { test as dbTest } from 'database-test-utils';\nexport const test = mergeTests(dbTest);\n");
|
||||
write(repo.work, 'e2e/merged.spec.ts', "import { test } from './merged';\ntest('m', () => {});\n");
|
||||
write(repo.work, '../index.ts', "import { test as base } from '@playwright/test';\nexport const test = base;\n");
|
||||
write(repo.work, 'test/up.test.ts', "import { test } from '../..';\ntest('up', () => {});\n");
|
||||
const plan = planRuns(ctx, ['e2e/direct.spec.ts', 'e2e/aliased.spec.ts', 'e2e/js-specifier.spec.ts', 'e2e/star.spec.ts', 'e2e/merged.spec.ts', 'test/unit.test.ts', 'test/outside.test.ts', 'test/api.test.ts', 'test/up.test.ts']);
|
||||
expect(plan.groups).toEqual([
|
||||
{ runner: 'npx vitest run {files}', cwd: '', files: ['test/unit.test.ts', 'test/outside.test.ts', 'test/api.test.ts', 'test/up.test.ts'] },
|
||||
{ runner: 'npx playwright test --reporter=list {files}', cwd: '', files: ['e2e/direct.spec.ts', 'e2e/aliased.spec.ts', 'e2e/js-specifier.spec.ts', 'e2e/star.spec.ts', 'e2e/merged.spec.ts'] },
|
||||
]);
|
||||
});
|
||||
|
||||
// Value: protects=a JS test that loads node:test runs through `node --test`, never the repo's vitest (which finds no suite in it and fails
|
||||
// the lane, stopping /ship's finish on every PR that selects one); fails_when=the repo-wide runner takes node:test files again (#4586);
|
||||
// why_new=no detection looked at node:test imports; seam=none; no_claim=a real node or vitest run (plan only)
|
||||
|
||||
Reference in new issue
Block a user