opencode-model-router 2.7.0 → 2.8.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +219 -0
- package/package.json +1 -1
- package/src/commands/approvals.ts +354 -0
- package/src/commands/output.ts +12 -1
- package/src/compat/v2-hooks.ts +255 -53
- package/src/index.ts +328 -37
- package/src/router/config.ts +48 -2
- package/src/router/dispatch-header.ts +95 -2
- package/src/router/git-tools.ts +165 -9
- package/src/router/protocol.ts +5 -1
- package/src/router/role-agents.ts +110 -3
- package/src/router/roles-config.ts +83 -0
- package/src/router/roles.ts +1 -1
- package/src/router/sessions.ts +11 -0
- package/src/routing/classify/route-line.ts +96 -5
- package/src/routing/classify/types.ts +26 -0
- package/src/routing/outcomes/signals.ts +17 -0
- package/src/routing/roles/admission.ts +1028 -0
- package/src/routing/roles/approvals.ts +876 -0
- package/src/routing/roles/binding.ts +17 -4
- package/src/routing/roles/check-placement.ts +112 -0
- package/src/routing/roles/git-root.ts +500 -0
- package/src/routing/roles/policy.ts +9 -0
- package/src/routing/roles/read-set.ts +325 -0
- package/src/routing/roles/work-root.ts +9 -1
- package/src/routing/wire/dispatch.ts +611 -18
- package/src/routing/wire/working-set.ts +58 -0
- package/src/util/linear-trim.ts +32 -0
- package/src/verify/batch.ts +7 -2
- package/src/verify/branch.ts +135 -0
- package/src/verify/deterministic.ts +232 -10
- package/src/verify/dispatch.ts +284 -9
- package/src/verify/dod.ts +46 -0
- package/src/verify/edges.ts +817 -0
- package/src/verify/gate.ts +349 -16
- package/src/verify/git-top.ts +43 -0
- package/src/verify/head.ts +107 -0
- package/src/verify/pending.ts +155 -8
- package/src/verify/perimeter.ts +1180 -0
- package/src/verify/pin.ts +109 -0
- package/src/verify/reference.ts +82 -6
- package/src/verify/risk.ts +16 -3
- package/src/verify/runner.ts +706 -32
- package/src/verify/tree.ts +347 -8
- package/src/verify/types.ts +57 -0
- package/src/verify/wiring.ts +1324 -35
package/src/verify/runner.ts
CHANGED
|
@@ -466,6 +466,29 @@
|
|
|
466
466
|
// "packages/a/../b/x.ts" is inside -> kept as packages/b/x.ts (see O.9).
|
|
467
467
|
// win32 P.relative compares case-insensitively, so "c:\repo\a.ts" is inside a gitRoot of
|
|
468
468
|
// "C:\repo".
|
|
469
|
+
// 4b. Cross-link inputs (cross-repo P3a, planScopedRun and planStaticScoping only; lint ignores
|
|
470
|
+
// them). With input.crossLinkRoot (W's git top, SD-P3a-5), a candidate inside
|
|
471
|
+
// realOf(crossLinkRoot) is kept as an external file (FileRef.external); W is tried first and
|
|
472
|
+
// the deeper root wins (B1: a W nested in gitRoot, a submodule or a nested clone, keeps its
|
|
473
|
+
// files; inside both, the shorter relative path wins, the consumer on a tie). A candidate
|
|
474
|
+
// outside both is dropped as in 4. Every request with a crossLinkRoot needs vitest -> S6
|
|
475
|
+
// cross-link-unsupported otherwise (jest, pytest), and the resolved vitest's major must be
|
|
476
|
+
// CROSS_LINK_VITEST_MAJOR (checked after the entry, F) -> S6 cross-link-unsupported, with or
|
|
477
|
+
// without external files. For external files that are not non-inputs (8; a W declaration
|
|
478
|
+
// file, .d.ts/.d.mts/.d.cts, is one too: vite never loads it): a W package.json, lockfile,
|
|
479
|
+
// tsconfig*.json or vitest/vite config -> S6 config-changed, never for an ignored module
|
|
480
|
+
// (status `!!`, D23: an ignored dist/esm/package.json is no config change; the in-repo trigger
|
|
481
|
+
// names of 7 skip `!!` entries too); a W test file (JS_TEST_RE, __tests__) is dropped with a
|
|
482
|
+
// note; a gone one (deleted, rename source) -> S6 cross-link-gone; one every spelling of which
|
|
483
|
+
// contains the text node_modules -> S6 cross-link-unreachable; a W file the consumer's config
|
|
484
|
+
// names as a setup file (setupFiles, globalSetup, ..., matched in every spelling, M3) -> S6
|
|
485
|
+
// config-changed. G.7a reads only the in-repo files' dirs, never W. Each existing one is an
|
|
486
|
+
// input in every spelling of SD-P3a-2: its real path, then crossLinkRoot + rel and each
|
|
487
|
+
// crossLinkAliases entry + rel, deduplicated by exact string (vitest matches related ids
|
|
488
|
+
// exactly, so case-only variants are kept), never a spelling that contains node_modules
|
|
489
|
+
// (vitest skips every id whose path contains that text, case-sensitive, X4). Every spec
|
|
490
|
+
// planned with a crossLinkRoot has crossLink: true and crossLinkRoot (B1, Y2).
|
|
491
|
+
// Without crossLinkRoot nothing here applies.
|
|
469
492
|
// 5. canonical = P.join(gitRoot, rel), so drive-letter case and separators follow gitRoot.
|
|
470
493
|
// Deduplicate by key and sort by key. Spaces and unicode need nothing special: each path is
|
|
471
494
|
// one argv element.
|
|
@@ -760,6 +783,16 @@
|
|
|
760
783
|
// non-empty inputs, becomes complete = false when
|
|
761
784
|
// - mode is "rerun" (every input is an existing test file), note `rerun ran no tests
|
|
762
785
|
// although every input is a test file`;
|
|
786
|
+
// - the spec has crossLink (Y2: a link vitest does not follow selects 0 tests), note `vitest
|
|
787
|
+
// selected no test in <cwd> for the change in <crossLinkRoot>; the link may not be followed
|
|
788
|
+
// (resolve.preserveSymlinks, a built entry, or no test imports the changed files): use
|
|
789
|
+
// scope=full`. QA-1 M2 (completeness check, after this guard, on every result path, the
|
|
790
|
+
// text fallback included): a still complete result of a spec with crossLinkExpected
|
|
791
|
+
// becomes complete = false when an expected file is not a testsByFile key (cwd-relative,
|
|
792
|
+
// ctx.key), note `vitest did not run <n> consumer test file(s) that import the linked
|
|
793
|
+
// repository (<first 3 rel paths>[, …]); the link may not be followed: use scope=full`,
|
|
794
|
+
// or, without testsByFile, note `vitest gave no per-file results, so the consumer test
|
|
795
|
+
// files that import the linked repository cannot be checked: use scope=full`;
|
|
763
796
|
// - the inputs are test files (inputsAreTests: pytest), or related was given a JS test file
|
|
764
797
|
// (G.8 rule; a test file passed to related runs itself), note `<runner> ran no tests
|
|
765
798
|
// although a test file was passed`;
|
|
@@ -927,6 +960,7 @@
|
|
|
927
960
|
// yarn-pnp yarn Plug'n'Play has no node_modules to resolve <pkg> from
|
|
928
961
|
// bad-bin invalid bin for <pkg>: <detail>
|
|
929
962
|
// config-changed config file changed: <rel>
|
|
963
|
+
// config file changed in the linked repository: <rel> (G.4b)
|
|
930
964
|
// deleted-no-tests deleted source <rel>: no test file references "<stem>"
|
|
931
965
|
// stem-too-common deleted source <rel>: "<stem>" appears in <n> test files (limit 20)
|
|
932
966
|
// search-failed test search failed for <rel>
|
|
@@ -947,6 +981,33 @@
|
|
|
947
981
|
// its fixtures reach cannot be mapped
|
|
948
982
|
// package structure changed: <rel> deleted; pytest import paths
|
|
949
983
|
// may shift (G.8, QA-G-22; <rel> ends in __init__.py)
|
|
984
|
+
// cross-link-unsupported a change in a linked repository needs vitest 5 to scope: this
|
|
985
|
+
// check runs <jest|pytest>
|
|
986
|
+
// ... the resolved vitest is <version|of an unknown version>
|
|
987
|
+
// (G.4b, cross-repo P3a; any request with a cross-link root)
|
|
988
|
+
// cross-link-unreachable the path of <rel> in the linked repository contains node_modules,
|
|
989
|
+
// which vitest never follows (G.4b, X4; every spelling of it
|
|
990
|
+
// contains the text node_modules, case-sensitive)
|
|
991
|
+
// cross-link-gone changed file gone in the linked repository (deleted or renamed
|
|
992
|
+
// away): <rel> (G.4b; <rel> is relative to the linked repository)
|
|
993
|
+
// cross-link-ignored-over-bounds
|
|
994
|
+
// too many ignored modules in the linked repository to pass as
|
|
995
|
+
// inputs: <root> (the testsPass hook, D23; over tree.ts
|
|
996
|
+
// MAX_IGNORED_MODULES files, MAX_IGNORED_MODULE_PATH_BYTES path bytes
|
|
997
|
+
// or MAX_IGNORED_WALK_ENTRIES walked entries)
|
|
998
|
+
// cross-link-ignored-unavailable
|
|
999
|
+
// the ignored modules of the linked repository could not be listed:
|
|
1000
|
+
// <root> (the testsPass hook, D23; not a repository, git failed)
|
|
1001
|
+
// cross-link-build-stale the build output in <W>/<dir> is older than <rel> changed in the linked repository; rebuild it (e.g. a buildPasses check in the linked repository before this one) or use scope=full (the testsPass hook, D23 QA round 2 M-A)
|
|
1002
|
+
// cross-link-unchecked cannot check which consumer tests import the linked repository
|
|
1003
|
+
// <root>: <why>; use scope=full (G.4b, QA-1 M2 completeness check;
|
|
1004
|
+
// <why>: it has no package.json | its package.json cannot be read |
|
|
1005
|
+
// its workspace list cannot be read | a workspace pattern cannot be
|
|
1006
|
+
// expanded | more than 256 workspace directories | <rel>/package.json
|
|
1007
|
+
// cannot be read | more than 64 package names | it names no package
|
|
1008
|
+
// (the eight above also from planStaticScoping) | the test search for
|
|
1009
|
+
// "<name>" failed | more than 200 consumer test files contain its
|
|
1010
|
+
// package names | cannot read <rel>)
|
|
950
1011
|
// M.2 NoAffected notes:
|
|
951
1012
|
// "no changed files, no affected tests" (section 1.5-6, exactly)
|
|
952
1013
|
// "no affected tests: no changed file is a test input" (docs only, dropped paths,
|
|
@@ -1188,7 +1249,14 @@ export type S6Code =
|
|
|
1188
1249
|
| "node-not-found"
|
|
1189
1250
|
| "too-many-searches"
|
|
1190
1251
|
| "config-too-large"
|
|
1191
|
-
| "unmapped-module"
|
|
1252
|
+
| "unmapped-module"
|
|
1253
|
+
| "cross-link-unsupported"
|
|
1254
|
+
| "cross-link-unreachable"
|
|
1255
|
+
| "cross-link-gone"
|
|
1256
|
+
| "cross-link-ignored-over-bounds"
|
|
1257
|
+
| "cross-link-ignored-unavailable"
|
|
1258
|
+
| "cross-link-build-stale"
|
|
1259
|
+
| "cross-link-unchecked";
|
|
1192
1260
|
|
|
1193
1261
|
/** S6: scoping is impossible. The reason names the construct (section M.1) and never triggers a full suite. */
|
|
1194
1262
|
export interface Unverifiable {
|
|
@@ -1457,6 +1525,25 @@ export interface ScopedSpec {
|
|
|
1457
1525
|
* reporting 0 tests as incomplete (I step 2a).
|
|
1458
1526
|
*/
|
|
1459
1527
|
readonly lexicalPaths?: true;
|
|
1528
|
+
/**
|
|
1529
|
+
* Cross-repo P3a (G.4b): the spec was planned with a crossLinkRoot, another repository the
|
|
1530
|
+
* consumer reaches through a link; some inputs may be its files. B1: set on every such spec, with
|
|
1531
|
+
* or without linked inputs (a W file taken for the consumer's own still reaches the Y2 guard).
|
|
1532
|
+
* Always a vitest `related` spec.
|
|
1533
|
+
*/
|
|
1534
|
+
readonly crossLink?: true;
|
|
1535
|
+
/**
|
|
1536
|
+
* Cross-repo P3a (Y2): with crossLink, the cross-link root as given (StaticScopingInput.crossLinkRoot),
|
|
1537
|
+
* for the zero-tests note.
|
|
1538
|
+
*/
|
|
1539
|
+
readonly crossLinkRoot?: string;
|
|
1540
|
+
/**
|
|
1541
|
+
* Cross-repo QA-1 M2 (completeness check): with crossLink, the consumer's test files (absolute, as the
|
|
1542
|
+
* search returned them, sorted) whose content names a package of the linked repository in an import or
|
|
1543
|
+
* require specifier (`"<name>"`, `'<name>/…'`). readResult requires each of them in the run's per-file
|
|
1544
|
+
* results; a missing one makes the run incomplete (the link may not be followed for it).
|
|
1545
|
+
*/
|
|
1546
|
+
readonly crossLinkExpected?: readonly string[];
|
|
1460
1547
|
}
|
|
1461
1548
|
|
|
1462
1549
|
/** An executable scoped eslint run (section K). Pass or fail comes from the exit code. */
|
|
@@ -1502,6 +1589,19 @@ export interface PlanScopedRunInput {
|
|
|
1502
1589
|
readonly fs: PlannerFs;
|
|
1503
1590
|
readonly search: TestSearchSeam;
|
|
1504
1591
|
readonly host?: Partial<RunnerHost>;
|
|
1592
|
+
/**
|
|
1593
|
+
* Cross-repo P3a (G.4b): the git top of the repository W whose change this consumer check in `cwd`
|
|
1594
|
+
* covers (SD-P3a-5). With it, a changed path inside W becomes a vitest `related` input, in every
|
|
1595
|
+
* spelling of SD-P3a-2, instead of being dropped as outside the git root. planScopedLint ignores
|
|
1596
|
+
* it (a foreign lint stays full-only). Unset by every caller today.
|
|
1597
|
+
*/
|
|
1598
|
+
readonly crossLinkRoot?: string;
|
|
1599
|
+
/**
|
|
1600
|
+
* Other spellings of crossLinkRoot's directory, such as the JS fs.realpathSync of a consumer link
|
|
1601
|
+
* into W (it keeps the link's stored target text, which vite uses). Each one + the relative path
|
|
1602
|
+
* is an input too (SD-P3a-2). Used only with crossLinkRoot.
|
|
1603
|
+
*/
|
|
1604
|
+
readonly crossLinkAliases?: readonly string[];
|
|
1505
1605
|
}
|
|
1506
1606
|
|
|
1507
1607
|
/** planScopedRun's input without the process-backed search. */
|
|
@@ -1696,6 +1796,17 @@ function s6(code: S6Code, reason: string): Unverifiable {
|
|
|
1696
1796
|
return { unverifiable: true, code, reason };
|
|
1697
1797
|
}
|
|
1698
1798
|
|
|
1799
|
+
/**
|
|
1800
|
+
* Cross-repo P3a (D23, OD-P3a-2 b): the S6 of a cross-link request whose linked repository's ignored modules (tree.ts
|
|
1801
|
+
* listIgnoredModules) are over the bounds or could not be listed (M.1). `root` is the cross-link root as given. The testsPass
|
|
1802
|
+
* hook returns it before planning: the related run would otherwise miss a consumer that loads W's build output.
|
|
1803
|
+
*/
|
|
1804
|
+
export function crossLinkIgnoredS6(kind: "over-bounds" | "unavailable", root: string): Unverifiable {
|
|
1805
|
+
return kind === "over-bounds"
|
|
1806
|
+
? s6("cross-link-ignored-over-bounds", `too many ignored modules in the linked repository to pass as inputs: ${root}`)
|
|
1807
|
+
: s6("cross-link-ignored-unavailable", `the ignored modules of the linked repository could not be listed: ${root}`);
|
|
1808
|
+
}
|
|
1809
|
+
|
|
1699
1810
|
function noAffected(note: string): NoAffected {
|
|
1700
1811
|
return { noAffected: true, note };
|
|
1701
1812
|
}
|
|
@@ -3853,12 +3964,27 @@ const SETUP_FILE_RE = new RegExp(
|
|
|
3853
3964
|
const SETUP_BARE_RE = new RegExp(String.raw`^(?:setup|teardown)${JS_EXT}`, "i");
|
|
3854
3965
|
const SETUP_DIR_RE = /^(?:tests?|specs?|testing|jest|vitest|__tests__)$/i;
|
|
3855
3966
|
|
|
3967
|
+
/**
|
|
3968
|
+
* G.7 (QA-1.3-29): `f` is a setup file by name (`names`, its namesOf, [] for an ignored module):
|
|
3969
|
+
* not a test file, and SETUP_FILE_RE, or SETUP_BARE_RE below a test directory (SETUP_DIR_RE).
|
|
3970
|
+
* QA-2 M-B (a): the same rule for a W file, on its path relative to W.
|
|
3971
|
+
*/
|
|
3972
|
+
function isSetupByName(f: FileRef, names: readonly string[]): boolean {
|
|
3973
|
+
if (isJsTestPath(f.rel)) return false;
|
|
3974
|
+
const segs = f.rel.split("/");
|
|
3975
|
+
return names.some((b) => SETUP_FILE_RE.test(b)) || (names.some((b) => SETUP_BARE_RE.test(b)) && segs.slice(0, -1).some((s) => SETUP_DIR_RE.test(s)));
|
|
3976
|
+
}
|
|
3977
|
+
|
|
3856
3978
|
/** The JS runner config files scanned for static references (G.7a), per directory from runnerCwd up to gitRoot. */
|
|
3857
3979
|
const JS_CONFIG_EXTS = ["js", "ts", "mjs", "cjs", "mts", "cts"];
|
|
3858
3980
|
const JS_CONFIG_NAMES: Readonly<Record<"vitest" | "jest", readonly string[]>> = {
|
|
3859
3981
|
vitest: ["vitest.config", "vite.config"].flatMap((b) => JS_CONFIG_EXTS.map((x) => `${b}.${x}`)),
|
|
3860
3982
|
jest: [...JS_CONFIG_EXTS.map((x) => `jest.config.${x}`), "jest.config.json", "package.json"],
|
|
3861
3983
|
};
|
|
3984
|
+
/** QA-2 M-B (c): vitest's workspace files (projects defined outside the config). */
|
|
3985
|
+
const VITEST_WORKSPACE_NAMES = [...JS_CONFIG_EXTS, "json"].map((x) => `vitest.workspace.${x}`);
|
|
3986
|
+
/** QA-2 M-B (c): a vitest config that sets `projects` or `workspace` (a key, quoted or not; a comment that names one only adds S6). */
|
|
3987
|
+
const VITEST_PROJECTS_KEY_RE = /(?<![\w$])["'`]?(?:projects|workspace)["'`]?[ \t]*:/;
|
|
3862
3988
|
/** Config keys whose values name setup files (vitest and jest share them). */
|
|
3863
3989
|
const SETUP_KEYS = ["setupFiles", "setupFilesAfterEnv", "globalSetup", "globalTeardown"] as const;
|
|
3864
3990
|
const CONFIG_KEY_RE = /(?<![\w$])["']?(setupFiles|setupFilesAfterEnv|globalSetup|globalTeardown|rootDir|root)["']?[ \t]*:[ \t\r\n]*/g;
|
|
@@ -4008,6 +4134,13 @@ interface JsConfigFacts {
|
|
|
4008
4134
|
readonly setupStems: ReadonlySet<string>;
|
|
4009
4135
|
/** QA-1.3-50: path tails ("testing/boot.js") of references built on an argument the scan cannot resolve; any file ending with one counts. */
|
|
4010
4136
|
readonly setupTails: ReadonlySet<string>;
|
|
4137
|
+
/**
|
|
4138
|
+
* QA-2 M-B (cross-link): every setup reference string as the configs spell it, unresolved and
|
|
4139
|
+
* unfiltered (a bare specifier such as `@acme/testkit/global-setup` names a package, not a path).
|
|
4140
|
+
*/
|
|
4141
|
+
readonly setupRaw: readonly string[] | "too-many";
|
|
4142
|
+
/** QA-2 M-B (cross-link): a read vitest config that sets `projects`/`workspace`, or a vitest.workspace.* file, when there is one. */
|
|
4143
|
+
readonly projectsIn?: string;
|
|
4011
4144
|
}
|
|
4012
4145
|
|
|
4013
4146
|
/**
|
|
@@ -4049,15 +4182,28 @@ async function jsConfigFacts(
|
|
|
4049
4182
|
// QA-1.3-51: one listing per directory where the seam can list (hasEntry). The listings are
|
|
4050
4183
|
// started together; the configs are still taken in directory order.
|
|
4051
4184
|
await Promise.all([...dirs.values()].map((d) => dirListing(ctx, fs, d)));
|
|
4185
|
+
let workspaceFile: string | undefined;
|
|
4052
4186
|
for (const d of dirs.values()) {
|
|
4053
4187
|
for (const n of JS_CONFIG_NAMES[kind]) {
|
|
4054
4188
|
if (await hasEntry(ctx, fs, d, n)) files.add(P.join(d, n));
|
|
4055
4189
|
}
|
|
4190
|
+
// QA-2 M-B (c): a vitest.workspace.* file defines projects whose configs are never read here.
|
|
4191
|
+
if (kind === "vitest" && workspaceFile === undefined) {
|
|
4192
|
+
for (const n of VITEST_WORKSPACE_NAMES) {
|
|
4193
|
+
if (await hasEntry(ctx, fs, d, n)) {
|
|
4194
|
+
workspaceFile = P.join(d, n);
|
|
4195
|
+
break;
|
|
4196
|
+
}
|
|
4197
|
+
}
|
|
4198
|
+
}
|
|
4056
4199
|
}
|
|
4057
4200
|
const cliRoot = kind === "jest" ? jestCliRootDir(det) : undefined;
|
|
4058
4201
|
const setupKeys = new Set<string>();
|
|
4059
4202
|
const setupStems = new Set<string>();
|
|
4060
4203
|
const setupTails = new Set<string>();
|
|
4204
|
+
// QA-2 M-B: the setup strings as spelled (a bare specifier is a package, not a path), bounded by budget.
|
|
4205
|
+
const setupRaw = new Set<string>();
|
|
4206
|
+
let projectsIn: string | undefined = workspaceFile;
|
|
4061
4207
|
const trailing = ctx.win ? /[\\/]+$/ : /\/+$/;
|
|
4062
4208
|
// The last segment of a reference; "", ".", "..", "<rootDir>" or a drive only resolve to know.
|
|
4063
4209
|
const wanted = (v: string): boolean => {
|
|
@@ -4072,13 +4218,21 @@ async function jsConfigFacts(
|
|
|
4072
4218
|
const addRefs = (lits: ReadonlyMap<string, readonly string[]>, dir: string, where: string, floating?: ReadonlyMap<string, readonly string[]>): Unverifiable | undefined => {
|
|
4073
4219
|
const refs = new Set<string>();
|
|
4074
4220
|
const tails = new Set<string>();
|
|
4221
|
+
const raw = new Set<string>();
|
|
4075
4222
|
for (const key of SETUP_KEYS) {
|
|
4076
|
-
for (const v of lits.get(key) ?? [])
|
|
4223
|
+
for (const v of lits.get(key) ?? []) {
|
|
4224
|
+
raw.add(v);
|
|
4225
|
+
if (usable(v)) refs.add(v);
|
|
4226
|
+
}
|
|
4077
4227
|
for (const v of floating?.get(key) ?? []) {
|
|
4228
|
+
raw.add(v);
|
|
4078
4229
|
const t = pathTail(v);
|
|
4079
4230
|
if (t !== undefined && usable(t)) tails.add(ctx.key(t));
|
|
4080
4231
|
}
|
|
4081
4232
|
}
|
|
4233
|
+
// QA-2 M-B: kept apart from the resolution budget (no plan without a cross link changes); past
|
|
4234
|
+
// SETUP_REF_LIMIT distinct strings a cross-link plan fails closed (crossSetupCheck).
|
|
4235
|
+
for (const v of raw) if (setupRaw.size <= SETUP_REF_LIMIT) setupRaw.add(v);
|
|
4082
4236
|
// QA-1.3-50: a tail costs one set entry, and a suffix check per changed file.
|
|
4083
4237
|
budget -= tails.size;
|
|
4084
4238
|
if (budget < 0) return s6("config-too-large", `too many setup references in ${where} (limit ${SETUP_REF_LIMIT})`);
|
|
@@ -4105,6 +4259,7 @@ async function jsConfigFacts(
|
|
|
4105
4259
|
if (t === "too-large") return tooLarge(file);
|
|
4106
4260
|
if (t === "unreadable") continue;
|
|
4107
4261
|
const { lits, floating } = configLiterals(t.text);
|
|
4262
|
+
if (kind === "vitest" && projectsIn === undefined && VITEST_PROJECTS_KEY_RE.test(t.text)) projectsIn = file;
|
|
4108
4263
|
if (P.extname(file) === ".json") {
|
|
4109
4264
|
// QA-1.3-46: jest-config reads a JSON config as parseJson(stripJsonComments(text)). One that
|
|
4110
4265
|
// still does not parse fails the user's run; package.json is the exception, because jest's
|
|
@@ -4122,7 +4277,7 @@ async function jsConfigFacts(
|
|
|
4122
4277
|
const bad = addRefs(jsonLiterals(parseJson(c)), det.runnerCwd, "the inline jest --config");
|
|
4123
4278
|
if (bad) return bad;
|
|
4124
4279
|
}
|
|
4125
|
-
return { setupKeys, setupStems, setupTails };
|
|
4280
|
+
return { setupKeys, setupStems, setupTails, setupRaw: setupRaw.size > SETUP_REF_LIMIT ? "too-many" : [...setupRaw], projectsIn };
|
|
4126
4281
|
}
|
|
4127
4282
|
|
|
4128
4283
|
/** QA-1.3-45: the last jest `--rootDir` in the kept arguments; jest-config's setFromArgv puts it over every config's rootDir. */
|
|
@@ -4187,10 +4342,18 @@ const NOTE_NO_LINT = "no changed lintable files";
|
|
|
4187
4342
|
const NOTE_NO_RERUN = "no rerun: none of the test files exist in this tree";
|
|
4188
4343
|
|
|
4189
4344
|
interface FileRef {
|
|
4345
|
+
/** G.4b: a file of the cross-link repository W; abs is its real path and rel is relative to W's real top. */
|
|
4346
|
+
readonly external?: true;
|
|
4190
4347
|
readonly abs: string;
|
|
4191
4348
|
readonly rel: string;
|
|
4192
4349
|
/** The basename as the producer spelled it, before realpath (a trigger reached through a symlink). */
|
|
4193
4350
|
readonly lexBase?: string;
|
|
4351
|
+
/**
|
|
4352
|
+
* M4 (D23): every entry naming this file had git status `!!` (an ignored module the testsPass hook
|
|
4353
|
+
* appended): it is never matched against the config trigger names (an ignored dist/esm/package.json
|
|
4354
|
+
* or vite.config.ts.timestamp-*.mjs is not a config change).
|
|
4355
|
+
*/
|
|
4356
|
+
readonly ignored?: true;
|
|
4194
4357
|
}
|
|
4195
4358
|
|
|
4196
4359
|
function stemOf(ctx: Ctx, abs: string): string {
|
|
@@ -4280,6 +4443,403 @@ async function readBounded(fs: PlannerFs, abs: string): Promise<string | undefin
|
|
|
4280
4443
|
}
|
|
4281
4444
|
}
|
|
4282
4445
|
|
|
4446
|
+
/** G.4b (cross-repo P3a): the cross-link repository W as the planner sees it. */
|
|
4447
|
+
interface CrossLink {
|
|
4448
|
+
/** realOf(crossLinkRoot): external FileRefs lie below it and are relative to it. */
|
|
4449
|
+
readonly real: string;
|
|
4450
|
+
/** W's top as given (crossLinkRoot), then each crossLinkAliases entry, absolute and in order. */
|
|
4451
|
+
readonly spellings: readonly string[];
|
|
4452
|
+
}
|
|
4453
|
+
|
|
4454
|
+
/** SD-P3a-4: the vitest major whose `related` run across a link is pinned (the Y5 integration test). */
|
|
4455
|
+
const CROSS_LINK_VITEST_MAJOR = 5;
|
|
4456
|
+
|
|
4457
|
+
/** G.4b: W from the input, or undefined without a usable crossLinkRoot (then nothing of G.4b applies). */
|
|
4458
|
+
async function crossLinkOf(ctx: Ctx, fs: PlannerFs, cwd: string, input: StaticScopingInput): Promise<CrossLink | undefined> {
|
|
4459
|
+
const usable = (p: string | undefined): p is string => p !== undefined && p !== "" && !p.includes("\0");
|
|
4460
|
+
if (!usable(input.crossLinkRoot)) return undefined;
|
|
4461
|
+
const abs = (p: string) => ctx.P.resolve(cwd, stripWinPrefix(ctx, p));
|
|
4462
|
+
const given = abs(input.crossLinkRoot);
|
|
4463
|
+
return { real: await realOf(ctx, fs, given), spellings: [given, ...(input.crossLinkAliases ?? []).filter(usable).map(abs)] };
|
|
4464
|
+
}
|
|
4465
|
+
|
|
4466
|
+
/**
|
|
4467
|
+
* X4, M.1: vitest's related graph skips every module id whose path CONTAINS the text node_modules
|
|
4468
|
+
* (vitest's `fsPath.includes("node_modules")`: a case-sensitive substring, not only a segment).
|
|
4469
|
+
*/
|
|
4470
|
+
function vitestSkipsId(p: string): boolean {
|
|
4471
|
+
return p.includes("node_modules");
|
|
4472
|
+
}
|
|
4473
|
+
|
|
4474
|
+
/**
|
|
4475
|
+
* SD-P3a-2: every spelling of the external file `f` vitest may hold as a module id: its real path
|
|
4476
|
+
* (as realOf produced it), then each of W's spellings + its relative path. Deduplicated by exact
|
|
4477
|
+
* string (a case-only variant is another id to vitest); a spelling that contains node_modules
|
|
4478
|
+
* (vitestSkipsId) is never passed.
|
|
4479
|
+
*/
|
|
4480
|
+
function crossSpellings(ctx: Ctx, cross: CrossLink, f: FileRef): string[] {
|
|
4481
|
+
return allCrossSpellings(ctx, cross, f).filter((s) => !vitestSkipsId(s));
|
|
4482
|
+
}
|
|
4483
|
+
|
|
4484
|
+
/** Every spelling of the external file `f` (crossSpellings without the node_modules filter). */
|
|
4485
|
+
function allCrossSpellings(ctx: Ctx, cross: CrossLink, f: FileRef): string[] {
|
|
4486
|
+
const parts = f.rel.split("/");
|
|
4487
|
+
return [...new Set([f.abs, ...cross.spellings.map((d) => ctx.P.join(d, ...parts))])];
|
|
4488
|
+
}
|
|
4489
|
+
|
|
4490
|
+
/** G.4b: a W test file (classify's JS rule). The consumer's related run never runs W's own tests. */
|
|
4491
|
+
function isCrossTest(ctx: Ctx, f: FileRef): boolean {
|
|
4492
|
+
return JS_TEST_RE.test(ctx.P.basename(f.abs)) || f.rel.split("/").includes("__tests__");
|
|
4493
|
+
}
|
|
4494
|
+
|
|
4495
|
+
/** M4: a declaration file (.d.ts, .d.mts, .d.cts); vite never loads one, so a W one is never an input. */
|
|
4496
|
+
const DECLARATION_RE = /\.d\.[cm]?ts$/;
|
|
4497
|
+
|
|
4498
|
+
/** G.8 plus M4: a non-input, or a W declaration file (both are skipped, never inputs). */
|
|
4499
|
+
function isCrossNonInput(ctx: Ctx, f: FileRef): boolean {
|
|
4500
|
+
return isNonInput(ctx, f) || (f.external === true && DECLARATION_RE.test(ctx.P.basename(f.abs)));
|
|
4501
|
+
}
|
|
4502
|
+
|
|
4503
|
+
/**
|
|
4504
|
+
* G.4b (SD-P3a-4, SD-P3a-7): the S6s the external files reach without a config read or a search,
|
|
4505
|
+
* so planScopedRun and planStaticScoping agree. Non-input external files (G.8, and W declaration
|
|
4506
|
+
* files, M4) are never looked at here; classify skips them. B1: the runner check applies to every
|
|
4507
|
+
* request with a cross-link root, with or without external files. M4: an ignored module (`!!`) is
|
|
4508
|
+
* never matched against the trigger names. QA-2 M-B (a): nor against the setup name rule
|
|
4509
|
+
* (isSetupByName), which W's files meet as in-repo ones do. The vitest major is checked after the entry is resolved
|
|
4510
|
+
* (classify), for every request with a cross-link root too.
|
|
4511
|
+
*/
|
|
4512
|
+
async function crossLinkChecks(
|
|
4513
|
+
ctx: Ctx,
|
|
4514
|
+
fs: PlannerFs,
|
|
4515
|
+
det: Detected<RunnerKind>,
|
|
4516
|
+
sorted: readonly FileRef[],
|
|
4517
|
+
cross: CrossLink,
|
|
4518
|
+
): Promise<Unverifiable | undefined> {
|
|
4519
|
+
if (det.kind !== "vitest") {
|
|
4520
|
+
return s6("cross-link-unsupported", `a change in a linked repository needs vitest ${CROSS_LINK_VITEST_MAJOR} to scope: this check runs ${det.kind}`);
|
|
4521
|
+
}
|
|
4522
|
+
const ext = crossInputFiles(ctx, sorted);
|
|
4523
|
+
for (const f of ext) {
|
|
4524
|
+
// QA-2 M-B (a): W's setup files by name too (vitest reruns nothing for a globalSetup or a
|
|
4525
|
+
// non-root setupFiles entry, so a related run cannot scope one).
|
|
4526
|
+
const names = f.ignored === true ? [] : namesOf(ctx, f);
|
|
4527
|
+
if (names.some((b) => TRIGGERS.vitest.test(b)) || isSetupByName(f, names)) {
|
|
4528
|
+
return s6("config-changed", `config file changed in the linked repository: ${f.rel}`);
|
|
4529
|
+
}
|
|
4530
|
+
}
|
|
4531
|
+
for (const f of ext) {
|
|
4532
|
+
if (isCrossTest(ctx, f)) continue;
|
|
4533
|
+
if (!(await existsCached(ctx, fs, f.abs))) {
|
|
4534
|
+
return s6("cross-link-gone", `changed file gone in the linked repository (deleted or renamed away): ${f.rel}`);
|
|
4535
|
+
}
|
|
4536
|
+
if (crossSpellings(ctx, cross, f).length === 0) {
|
|
4537
|
+
return s6("cross-link-unreachable", `the path of ${f.rel} in the linked repository contains node_modules, which vitest never follows`);
|
|
4538
|
+
}
|
|
4539
|
+
}
|
|
4540
|
+
return undefined;
|
|
4541
|
+
}
|
|
4542
|
+
|
|
4543
|
+
/** G.4b: the external files that are not non-inputs (isCrossNonInput), in order. */
|
|
4544
|
+
function crossInputFiles(ctx: Ctx, sorted: readonly FileRef[]): FileRef[] {
|
|
4545
|
+
return sorted.filter((f) => f.external === true && !isCrossNonInput(ctx, f));
|
|
4546
|
+
}
|
|
4547
|
+
|
|
4548
|
+
/**
|
|
4549
|
+
* M3 (G.7a for W): a W file the consumer's config names as a setup file (setupFiles, globalSetup,
|
|
4550
|
+
* ...): vitest reruns everything for a setupFiles entry only on an exact spelling match and never
|
|
4551
|
+
* for globalSetup, so a related run cannot scope it -> S6 config-changed. Every spelling of each W
|
|
4552
|
+
* file is checked. The facts come from the consumer's configs only; nothing under W is read but
|
|
4553
|
+
* its manifests (crossLinkNames).
|
|
4554
|
+
* QA-2 M-B: vitest adds only the root config's setupFiles to forceRerunTriggers and never
|
|
4555
|
+
* globalSetup, and a path resolution misses a W file named through a package or a consumer link
|
|
4556
|
+
* (production never passes a node_modules alias). So, when any W input changed: (b) a setup string
|
|
4557
|
+
* that contains node_modules/ (either separator), or a bare specifier naming a W package (`name` or
|
|
4558
|
+
* `name/...`, crossLinkNames) -> S6 config-changed; (c) a consumer config that sets `projects` or
|
|
4559
|
+
* `workspace`, or a vitest.workspace.* file, whose project configs this scan never reads -> S6
|
|
4560
|
+
* cross-link-unchecked.
|
|
4561
|
+
*/
|
|
4562
|
+
async function crossSetupCheck(ctx: Ctx, fs: PlannerFs, facts: JsConfigFacts, cross: CrossLink, ext: readonly FileRef[]): Promise<Unverifiable | undefined> {
|
|
4563
|
+
if (ext.length === 0) return undefined;
|
|
4564
|
+
for (const f of ext) {
|
|
4565
|
+
if (allCrossSpellings(ctx, cross, f).some((s) => isReferencedSetup(ctx, facts, s))) {
|
|
4566
|
+
return s6("config-changed", `config file changed in the linked repository: ${f.rel}`);
|
|
4567
|
+
}
|
|
4568
|
+
}
|
|
4569
|
+
const R = facts.setupRaw;
|
|
4570
|
+
if (R === "too-many") return s6("config-too-large", `too many setup references in the consumer's configs (limit ${SETUP_REF_LIMIT})`);
|
|
4571
|
+
const changedOne = ext[0].rel;
|
|
4572
|
+
const viaLink = R.find((v) => v.replace(/\\/g, "/").includes("node_modules/"));
|
|
4573
|
+
if (viaLink !== undefined) return s6("config-changed", crossSetupReason(viaLink, changedOne));
|
|
4574
|
+
const bare = R.filter((v) => isBareSpecifier(ctx, v));
|
|
4575
|
+
if (bare.length > 0) {
|
|
4576
|
+
const names = await crossLinkNames(ctx, fs, cross);
|
|
4577
|
+
if (isS6(names)) return names;
|
|
4578
|
+
const hit = bare.find((v) => names.some((n) => v === n || v.startsWith(`${n}/`)));
|
|
4579
|
+
if (hit !== undefined) return s6("config-changed", crossSetupReason(hit, changedOne));
|
|
4580
|
+
}
|
|
4581
|
+
if (facts.projectsIn !== undefined) return s6("cross-link-unchecked", "the consumer's vitest projects are not read; use scope=full");
|
|
4582
|
+
return undefined;
|
|
4583
|
+
}
|
|
4584
|
+
|
|
4585
|
+
/** QA-2 M-B (b): the reason of a consumer setup string that may name a file of W. */
|
|
4586
|
+
function crossSetupReason(v: string, rel: string): string {
|
|
4587
|
+
return `the consumer's setup file "${v}" may come from the linked repository: ${rel} changed`;
|
|
4588
|
+
}
|
|
4589
|
+
|
|
4590
|
+
/** QA-2 M-B (b): `v` may be a package specifier: not relative, not absolute, not a drive or `<rootDir>` path. */
|
|
4591
|
+
function isBareSpecifier(ctx: Ctx, v: string): boolean {
|
|
4592
|
+
const t = v.trim();
|
|
4593
|
+
return t !== "" && !t.startsWith(".") && !/^[\\/]/.test(t) && !/^[A-Za-z]:/.test(t) && !t.includes("<") && !ctx.P.isAbsolute(t);
|
|
4594
|
+
}
|
|
4595
|
+
|
|
4596
|
+
/** M3: the external files as one FileRef per spelling, so changedNames covers every spelling's names. */
|
|
4597
|
+
function crossSpellingRefs(ctx: Ctx, cross: CrossLink, ext: readonly FileRef[]): FileRef[] {
|
|
4598
|
+
return ext.flatMap((f) => allCrossSpellings(ctx, cross, f).map((abs) => ({ ...f, abs })));
|
|
4599
|
+
}
|
|
4600
|
+
|
|
4601
|
+
/** SD-P3a-4: the resolved vitest's major must be CROSS_LINK_VITEST_MAJOR. */
|
|
4602
|
+
function crossLinkVersion(entry: ResolvedEntry): Unverifiable | undefined {
|
|
4603
|
+
if (Number.parseInt(entry.version ?? "", 10) === CROSS_LINK_VITEST_MAJOR) return undefined;
|
|
4604
|
+
const found = entry.version === undefined ? "of an unknown version" : entry.version;
|
|
4605
|
+
return s6("cross-link-unsupported", `a change in a linked repository needs vitest ${CROSS_LINK_VITEST_MAJOR} to scope: the resolved vitest is ${found}`);
|
|
4606
|
+
}
|
|
4607
|
+
|
|
4608
|
+
// QA-1 M2 (completeness check). The zero-selection guard (Y2) catches a related run that selects no
|
|
4609
|
+
// test; a run that selects one consumer test and misses another (an uncovered link spelling, a vite
|
|
4610
|
+
// alias, a require(), a per-project preserveSymlinks) passed. So, at plan time, the consumer's test
|
|
4611
|
+
// files that name a package of W in an import or require specifier (`"<name>"`, `'<name>/...'`) are
|
|
4612
|
+
// the expected files (ScopedSpec.crossLinkExpected), and readResult requires each of them in the
|
|
4613
|
+
// run's per-file results. W's names: `name` in W's top package.json plus each workspace package's
|
|
4614
|
+
// (package.json `workspaces`, an array or { packages }, and pnpm-workspace.yaml `packages`; a pattern
|
|
4615
|
+
// is literal directories with at most a final `*` segment, negations are ignored). Only manifests are
|
|
4616
|
+
// read, with the config size limit; nothing is executed. Fail closed (S6 cross-link-unchecked) when W
|
|
4617
|
+
// has no package.json, a manifest or workspace list cannot be read or expanded, W names no package or
|
|
4618
|
+
// more than CROSS_LINK_NAME_LIMIT, a search fails, or more than CROSS_LINK_CANDIDATE_LIMIT consumer
|
|
4619
|
+
// test files name W's packages: the run could not be checked, so it would be unverifiable anyway.
|
|
4620
|
+
// planStaticScoping reads the names too (fs only), so it reaches the same S6 for them; the searches
|
|
4621
|
+
// are planScopedRun's. Not covered: a consumer test that reaches W only through a relative specifier
|
|
4622
|
+
// (`../w/src/x`), which has no literal needle; the zero-selection guard still covers a run that
|
|
4623
|
+
// selects none. An expected file the consumer's vitest config does not include (a narrowed
|
|
4624
|
+
// `include`, a project) is reported as not run: the check fails closed to scope=full.
|
|
4625
|
+
|
|
4626
|
+
/** QA-1 M2: the most package names (W's top plus its workspace packages) the completeness check searches for. */
|
|
4627
|
+
export const CROSS_LINK_NAME_LIMIT = 64;
|
|
4628
|
+
/** QA-1 M2: the most workspace directories the completeness check looks into. */
|
|
4629
|
+
const CROSS_LINK_DIR_LIMIT = 256;
|
|
4630
|
+
/** QA-1 M2: the most consumer test files, over every name's search, the completeness check reads. */
|
|
4631
|
+
export const CROSS_LINK_CANDIDATE_LIMIT = 200;
|
|
4632
|
+
|
|
4633
|
+
/** QA-1 M2: vitest's default test-file include (`**\/*.{test,spec}.?(c|m)[jt]s?(x)`), on the basename. */
|
|
4634
|
+
const VITEST_TEST_RE = /\.(?:test|spec)\.[cm]?[jt]sx?$/;
|
|
4635
|
+
/**
|
|
4636
|
+
* QA-1 M2: path segments vitest's default exclude skips. QA-2 minor 1: vitest 5 (the pinned major,
|
|
4637
|
+
* CROSS_LINK_VITEST_MAJOR) excludes only `**\/node_modules/**` and `**\/.git/**` by default, so a
|
|
4638
|
+
* consumer test under dist/, cypress/, .cache/ and the like runs and is expected.
|
|
4639
|
+
*/
|
|
4640
|
+
const VITEST_EXCLUDED_SEGMENTS = new Set(["node_modules", ".git"]);
|
|
4641
|
+
/** QA-1 M2: an npm package name, optionally scoped. */
|
|
4642
|
+
const PACKAGE_NAME_RE = /^(?:@[A-Za-z0-9._~-]+\/)?[A-Za-z0-9._~-]+$/;
|
|
4643
|
+
|
|
4644
|
+
/** QA-1 M2: the S6 of a cross-link request whose completeness check cannot be prepared. */
|
|
4645
|
+
function crossUnchecked(root: string, why: string): Unverifiable {
|
|
4646
|
+
return s6("cross-link-unchecked", `cannot check which consumer tests import the linked repository ${root}: ${why}; use scope=full`);
|
|
4647
|
+
}
|
|
4648
|
+
|
|
4649
|
+
/** QA-1 M2: a manifest (package.json) as a record, or undefined when it cannot be read, is over the size limit or is not an object. */
|
|
4650
|
+
async function readManifest(ctx: Ctx, fs: PlannerFs, p: string): Promise<Record<string, unknown> | undefined> {
|
|
4651
|
+
const read = await readConfigText(ctx, fs, p);
|
|
4652
|
+
if (typeof read !== "object") return undefined;
|
|
4653
|
+
try {
|
|
4654
|
+
const value: unknown = JSON.parse(read.text.replace(/^\uFEFF/, ""));
|
|
4655
|
+
return isRecord(value) ? value : undefined;
|
|
4656
|
+
} catch {
|
|
4657
|
+
return undefined;
|
|
4658
|
+
}
|
|
4659
|
+
}
|
|
4660
|
+
|
|
4661
|
+
/** QA-1 M2: one YAML block-sequence scalar (plain, or single/double quoted without escapes), or undefined. */
|
|
4662
|
+
function yamlScalar(v: string): string | undefined {
|
|
4663
|
+
const s = v.trim();
|
|
4664
|
+
const q = s[0];
|
|
4665
|
+
if (q === "'" || q === '"') {
|
|
4666
|
+
const end = s.indexOf(q, 1);
|
|
4667
|
+
if (end < 0) return undefined;
|
|
4668
|
+
const rest = s.slice(end + 1).trim();
|
|
4669
|
+
if (rest !== "" && !rest.startsWith("#")) return undefined;
|
|
4670
|
+
const inner = s.slice(1, end);
|
|
4671
|
+
return q === '"' && inner.includes("\\") ? undefined : inner;
|
|
4672
|
+
}
|
|
4673
|
+
const plain = s.replace(/\s+#.*$/, "").trim();
|
|
4674
|
+
return plain === "" || /^[[\]{}&*!|>%@`#]/.test(plain) ? undefined : plain;
|
|
4675
|
+
}
|
|
4676
|
+
|
|
4677
|
+
/**
|
|
4678
|
+
* QA-1 M2: the `packages` list of a pnpm-workspace.yaml, block style only (`packages:` then `- item` lines,
|
|
4679
|
+
* indented or not). Undefined when it cannot be read that way (a flow list, an anchor, a second key).
|
|
4680
|
+
*/
|
|
4681
|
+
function pnpmWorkspacePackages(text: string): string[] | undefined {
|
|
4682
|
+
const out: string[] = [];
|
|
4683
|
+
let inList = false;
|
|
4684
|
+
let seen = false;
|
|
4685
|
+
for (const raw of text.replace(/^\uFEFF/, "").split(/\r?\n/)) {
|
|
4686
|
+
if (/^\s*(?:#.*)?$/.test(raw)) continue;
|
|
4687
|
+
const item = /^\s*-(?:\s+(.*))?$/.exec(raw);
|
|
4688
|
+
if (inList && item) {
|
|
4689
|
+
const v = yamlScalar(item[1] ?? "");
|
|
4690
|
+
if (v === undefined) return undefined;
|
|
4691
|
+
out.push(v);
|
|
4692
|
+
continue;
|
|
4693
|
+
}
|
|
4694
|
+
if (/^\s/.test(raw)) {
|
|
4695
|
+
if (inList) return undefined;
|
|
4696
|
+
continue;
|
|
4697
|
+
}
|
|
4698
|
+
inList = false;
|
|
4699
|
+
const key = /^packages\s*:(.*)$/.exec(raw);
|
|
4700
|
+
if (!key) continue;
|
|
4701
|
+
if (seen) return undefined;
|
|
4702
|
+
seen = true;
|
|
4703
|
+
const rest = key[1].replace(/\s+#.*$/, "").trim();
|
|
4704
|
+
if (rest === "[]") continue;
|
|
4705
|
+
if (rest !== "") return undefined;
|
|
4706
|
+
inList = true;
|
|
4707
|
+
}
|
|
4708
|
+
return out;
|
|
4709
|
+
}
|
|
4710
|
+
|
|
4711
|
+
/** QA-1 M2: W's workspace patterns (package.json `workspaces` and pnpm-workspace.yaml), or undefined when one cannot be read. */
|
|
4712
|
+
async function workspacePatterns(ctx: Ctx, fs: PlannerFs, real: string, manifest: Record<string, unknown>): Promise<string[] | undefined> {
|
|
4713
|
+
const out: string[] = [];
|
|
4714
|
+
const ws = manifest.workspaces;
|
|
4715
|
+
const list = isRecord(ws) ? ws.packages : ws;
|
|
4716
|
+
if (list !== undefined) {
|
|
4717
|
+
if (!Array.isArray(list) || !list.every((x): x is string => typeof x === "string")) return undefined;
|
|
4718
|
+
out.push(...list);
|
|
4719
|
+
}
|
|
4720
|
+
const pnpm = ctx.P.join(real, "pnpm-workspace.yaml");
|
|
4721
|
+
if (await existsCached(ctx, fs, pnpm)) {
|
|
4722
|
+
const read = await readConfigText(ctx, fs, pnpm);
|
|
4723
|
+
if (typeof read !== "object") return undefined;
|
|
4724
|
+
const packages = pnpmWorkspacePackages(read.text);
|
|
4725
|
+
if (packages === undefined) return undefined;
|
|
4726
|
+
out.push(...packages);
|
|
4727
|
+
}
|
|
4728
|
+
return out;
|
|
4729
|
+
}
|
|
4730
|
+
|
|
4731
|
+
/**
|
|
4732
|
+
* QA-1 M2: the directories W's workspace patterns name, below `real`. A pattern is literal segments
|
|
4733
|
+
* with at most a final `*` (one level, no dot entries, no node_modules); a negation is ignored. Undefined
|
|
4734
|
+
* when a pattern is any other glob, leaves W, or needs a directory listing the fs seam cannot give.
|
|
4735
|
+
* "over" when more than CROSS_LINK_DIR_LIMIT directories.
|
|
4736
|
+
*/
|
|
4737
|
+
async function workspaceDirs(ctx: Ctx, fs: PlannerFs, real: string, patterns: readonly string[]): Promise<string[] | "over" | undefined> {
|
|
4738
|
+
const P = ctx.P;
|
|
4739
|
+
const dirs = new Map<string, string>();
|
|
4740
|
+
const add = (d: string) => dirs.set(ctx.key(d), d);
|
|
4741
|
+
for (const pattern of patterns) {
|
|
4742
|
+
if (pattern.startsWith("!")) continue;
|
|
4743
|
+
const segs = pattern.replace(/\\/g, "/").split("/").filter((s) => s !== "" && s !== ".");
|
|
4744
|
+
if (segs.length === 0) continue;
|
|
4745
|
+
const last = segs[segs.length - 1];
|
|
4746
|
+
const fixed = last === "*" ? segs.slice(0, -1) : segs;
|
|
4747
|
+
if (fixed.some((s) => s === ".." || /[*?[\]{}!]/.test(s)) || P.isAbsolute(pattern) || /^[A-Za-z]:/.test(pattern)) return undefined;
|
|
4748
|
+
const base = P.join(real, ...fixed);
|
|
4749
|
+
if (last !== "*") add(base);
|
|
4750
|
+
else if (await existsCached(ctx, fs, base)) {
|
|
4751
|
+
if (!fs.readdir) return undefined;
|
|
4752
|
+
let entries: readonly string[];
|
|
4753
|
+
try {
|
|
4754
|
+
entries = await fs.readdir(base);
|
|
4755
|
+
} catch {
|
|
4756
|
+
return undefined;
|
|
4757
|
+
}
|
|
4758
|
+
for (const e of entries) if (!e.startsWith(".") && e !== "node_modules") add(P.join(base, e));
|
|
4759
|
+
}
|
|
4760
|
+
if (dirs.size > CROSS_LINK_DIR_LIMIT) return "over";
|
|
4761
|
+
}
|
|
4762
|
+
return [...dirs.entries()].sort(byKey).map(([, v]) => v);
|
|
4763
|
+
}
|
|
4764
|
+
|
|
4765
|
+
/**
|
|
4766
|
+
* QA-1 M2: the package names of W (its top package.json `name` plus each workspace package's), sorted,
|
|
4767
|
+
* or S6 cross-link-unchecked. fs only, so planScopedRun and planStaticScoping agree.
|
|
4768
|
+
*/
|
|
4769
|
+
async function crossLinkNames(ctx: Ctx, fs: PlannerFs, cross: CrossLink): Promise<readonly string[] | Unverifiable> {
|
|
4770
|
+
const root = cross.spellings[0];
|
|
4771
|
+
const P = ctx.P;
|
|
4772
|
+
const top = P.join(cross.real, "package.json");
|
|
4773
|
+
if (!(await existsCached(ctx, fs, top))) return crossUnchecked(root, "it has no package.json");
|
|
4774
|
+
const manifest = await readManifest(ctx, fs, top);
|
|
4775
|
+
if (manifest === undefined) return crossUnchecked(root, "its package.json cannot be read");
|
|
4776
|
+
const names = new Set<string>();
|
|
4777
|
+
const addName = (m: Record<string, unknown>) => {
|
|
4778
|
+
if (typeof m.name === "string" && m.name.length <= 214 && PACKAGE_NAME_RE.test(m.name)) names.add(m.name);
|
|
4779
|
+
};
|
|
4780
|
+
addName(manifest);
|
|
4781
|
+
const patterns = await workspacePatterns(ctx, fs, cross.real, manifest);
|
|
4782
|
+
if (patterns === undefined) return crossUnchecked(root, "its workspace list cannot be read");
|
|
4783
|
+
const dirs = await workspaceDirs(ctx, fs, cross.real, patterns);
|
|
4784
|
+
if (dirs === undefined) return crossUnchecked(root, "a workspace pattern cannot be expanded");
|
|
4785
|
+
if (dirs === "over") return crossUnchecked(root, `more than ${CROSS_LINK_DIR_LIMIT} workspace directories`);
|
|
4786
|
+
for (const d of dirs) {
|
|
4787
|
+
const pj = P.join(d, "package.json");
|
|
4788
|
+
if (!(await existsCached(ctx, fs, pj))) continue;
|
|
4789
|
+
const m = await readManifest(ctx, fs, pj);
|
|
4790
|
+
if (m === undefined) return crossUnchecked(root, `${toSlash(ctx, P.relative(cross.real, pj))} cannot be read`);
|
|
4791
|
+
addName(m);
|
|
4792
|
+
if (names.size > CROSS_LINK_NAME_LIMIT) return crossUnchecked(root, `more than ${CROSS_LINK_NAME_LIMIT} package names`);
|
|
4793
|
+
}
|
|
4794
|
+
if (names.size === 0) return crossUnchecked(root, "it names no package");
|
|
4795
|
+
return [...names].sort();
|
|
4796
|
+
}
|
|
4797
|
+
|
|
4798
|
+
/** QA-1 M2: an import or require specifier naming the package `name` (`"<name>"`, `'<name>/...'`, any quote). */
|
|
4799
|
+
function specifierRe(name: string): RegExp {
|
|
4800
|
+
return new RegExp(`(["'\`])${name.replace(/[.*+?^${}()|[\]\\/]/g, "\\$&")}(?:\\1|/)`);
|
|
4801
|
+
}
|
|
4802
|
+
|
|
4803
|
+
/**
|
|
4804
|
+
* QA-1 M2: the consumer's test files (vitest's default include and exclude, below the runner's cwd)
|
|
4805
|
+
* whose content names one of `names` in a specifier, absolute and sorted by key; or S6 cross-link-unchecked
|
|
4806
|
+
* when a search fails or more than CROSS_LINK_CANDIDATE_LIMIT test files contain a name.
|
|
4807
|
+
*/
|
|
4808
|
+
async function crossLinkExpected(
|
|
4809
|
+
ctx: Ctx,
|
|
4810
|
+
fs: PlannerFs,
|
|
4811
|
+
search: TestSearchSeam,
|
|
4812
|
+
gitRoot: string,
|
|
4813
|
+
runnerCwd: string,
|
|
4814
|
+
names: readonly string[],
|
|
4815
|
+
root: string,
|
|
4816
|
+
): Promise<readonly string[] | Unverifiable> {
|
|
4817
|
+
const P = ctx.P;
|
|
4818
|
+
const candidates = new Map<string, string>();
|
|
4819
|
+
for (const name of names) {
|
|
4820
|
+
const hits = await search.findByContent(gitRoot, name, JS_TEST_GLOBS);
|
|
4821
|
+
if (hits === undefined) return crossUnchecked(root, `the test search for "${name}" failed`);
|
|
4822
|
+
for (const h of hits) {
|
|
4823
|
+
const ref = canonicalize(ctx, gitRoot, gitRoot, h);
|
|
4824
|
+
if (!ref || !isInside(ctx, runnerCwd, ref.abs) || !VITEST_TEST_RE.test(P.basename(ref.abs))) continue;
|
|
4825
|
+
if (ref.rel.split("/").some((s) => VITEST_EXCLUDED_SEGMENTS.has(s))) continue;
|
|
4826
|
+
candidates.set(ctx.key(ref.abs), ref.abs);
|
|
4827
|
+
if (candidates.size > CROSS_LINK_CANDIDATE_LIMIT) {
|
|
4828
|
+
return crossUnchecked(root, `more than ${CROSS_LINK_CANDIDATE_LIMIT} consumer test files contain its package names`);
|
|
4829
|
+
}
|
|
4830
|
+
}
|
|
4831
|
+
}
|
|
4832
|
+
const res = names.map(specifierRe);
|
|
4833
|
+
const expected: string[] = [];
|
|
4834
|
+
for (const [, abs] of [...candidates.entries()].sort(byKey)) {
|
|
4835
|
+
if (!(await fs.fileExists(abs))) continue;
|
|
4836
|
+
const text = await readBounded(fs, abs);
|
|
4837
|
+
if (text === undefined) return crossUnchecked(root, `cannot read ${toSlash(ctx, P.relative(gitRoot, abs))}`);
|
|
4838
|
+
if (res.some((re) => re.test(text))) expected.push(abs);
|
|
4839
|
+
}
|
|
4840
|
+
return expected;
|
|
4841
|
+
}
|
|
4842
|
+
|
|
4283
4843
|
/** G.3-G.5 for one path: canonical absolute path inside gitRoot, or undefined. */
|
|
4284
4844
|
function canonicalize(ctx: Ctx, cwd: string, gitRoot: string, p: string): FileRef | undefined {
|
|
4285
4845
|
const abs = ctx.P.resolve(cwd, p);
|
|
@@ -4302,34 +4862,49 @@ async function plan(input: StaticScopingInput, search: TestSearchSeam | undefine
|
|
|
4302
4862
|
const gitRoot = det.gitRoot;
|
|
4303
4863
|
const cwd = await canonicalCwd(ctx, fs, input.cwd);
|
|
4304
4864
|
const notes: string[] = [...det.notes];
|
|
4305
|
-
const
|
|
4865
|
+
const cross = await crossLinkOf(ctx, fs, cwd, input);
|
|
4866
|
+
const sorted = await collectChanged(ctx, fs, cwd, gitRoot, input.changedFiles, notes, cross);
|
|
4306
4867
|
if (sorted.length === 0) return s6("attribution-unavailable", NO_PATH_KEPT);
|
|
4868
|
+
if (cross) {
|
|
4869
|
+
const bad = await crossLinkChecks(ctx, fs, det, sorted, cross);
|
|
4870
|
+
if (bad) return bad;
|
|
4871
|
+
}
|
|
4872
|
+
// G.4b: G.7 and G.7a read configs from the in-repo files' directories only, so no config read
|
|
4873
|
+
// walks into W. M3: the setup references those configs hold are matched against every changed
|
|
4874
|
+
// file, W's (non-input ones aside, isCrossNonInput) in every spelling. QA-2 M-B: and, as spelled,
|
|
4875
|
+
// against W's package names and node_modules/ paths; consumer projects fail closed (crossSetupCheck).
|
|
4876
|
+
const local = cross ? sorted.filter((f) => f.external !== true) : sorted;
|
|
4877
|
+
const ext = cross ? crossInputFiles(ctx, sorted) : [];
|
|
4307
4878
|
|
|
4308
4879
|
// G.7: config triggers.
|
|
4309
4880
|
const sourcePj = det.source.type === "script" ? ctx.key(det.source.packageJson) : undefined;
|
|
4310
4881
|
const configKeys = new Set((det.configFiles ?? []).map((p) => ctx.key(p)));
|
|
4311
4882
|
const js = det.kind === "vitest" || det.kind === "jest";
|
|
4312
4883
|
if (js) {
|
|
4313
|
-
const early = await jsCheapChecks(ctx, fs, sorted);
|
|
4884
|
+
const early = await jsCheapChecks(ctx, fs, cross ? sorted.filter((f) => !(f.external === true && (isCrossTest(ctx, f) || isCrossNonInput(ctx, f)))) : sorted);
|
|
4314
4885
|
if (early) return early;
|
|
4315
4886
|
}
|
|
4316
|
-
const
|
|
4887
|
+
const refNames = changedNames(ctx, cross ? [...local, ...crossSpellingRefs(ctx, cross, ext)] : local);
|
|
4888
|
+
const facts = js ? await jsConfigFacts(ctx, fs, det, refNames, local) : undefined;
|
|
4317
4889
|
if (facts && isS6(facts)) return facts;
|
|
4318
|
-
for (const f of
|
|
4319
|
-
|
|
4890
|
+
for (const f of local) {
|
|
4891
|
+
// M4: an ignored module (`!!`) is never matched by name (triggers, setup names, requirements/).
|
|
4892
|
+
const names = f.ignored === true ? [] : namesOf(ctx, f);
|
|
4320
4893
|
const segs = f.rel.split("/");
|
|
4321
4894
|
// QA-1.3-29: a setup file by name (not a test file), a bare setup.* in a test directory, or a
|
|
4322
4895
|
// file the vitest/jest config names as a setup file.
|
|
4323
|
-
const setup =
|
|
4324
|
-
|
|
4325
|
-
|
|
4326
|
-
(facts !== undefined && isReferencedSetup(ctx, facts, f.abs)));
|
|
4327
|
-
const reqDir = det.kind === "pytest" && PY_REQ_DIR_FILE_RE.test(segs[segs.length - 1]) && segs.slice(0, -1).some((s) => ctx.key(s) === "requirements");
|
|
4896
|
+
const setup = js && (isSetupByName(f, names) || (facts !== undefined && isReferencedSetup(ctx, facts, f.abs)));
|
|
4897
|
+
const reqDir =
|
|
4898
|
+
det.kind === "pytest" && f.ignored !== true && PY_REQ_DIR_FILE_RE.test(segs[segs.length - 1]) && segs.slice(0, -1).some((s) => ctx.key(s) === "requirements");
|
|
4328
4899
|
if (setup || reqDir || names.some((b) => TRIGGERS[det.kind].test(b)) || ctx.key(f.abs) === sourcePj || configKeys.has(ctx.key(f.abs))) {
|
|
4329
4900
|
return s6("config-changed", `config file changed: ${f.rel}`);
|
|
4330
4901
|
}
|
|
4331
4902
|
}
|
|
4332
|
-
|
|
4903
|
+
if (cross && facts) {
|
|
4904
|
+
const bad = await crossSetupCheck(ctx, fs, facts, cross, ext);
|
|
4905
|
+
if (bad) return bad;
|
|
4906
|
+
}
|
|
4907
|
+
return classify(ctx, input, det, sorted, notes, search, cross);
|
|
4333
4908
|
}
|
|
4334
4909
|
|
|
4335
4910
|
/** G.8: docs, licences and .github files are never inputs. */
|
|
@@ -4399,6 +4974,7 @@ async function collectChanged(
|
|
|
4399
4974
|
gitRoot: string,
|
|
4400
4975
|
changed: readonly ChangedPath[],
|
|
4401
4976
|
notes: string[],
|
|
4977
|
+
cross?: CrossLink,
|
|
4402
4978
|
): Promise<FileRef[]> {
|
|
4403
4979
|
const files = new Map<string, FileRef>();
|
|
4404
4980
|
for (const c of changed) {
|
|
@@ -4409,7 +4985,15 @@ async function collectChanged(
|
|
|
4409
4985
|
continue;
|
|
4410
4986
|
}
|
|
4411
4987
|
const lexical = ctx.P.resolve(cwd, lexicalSpelling(ctx, cand));
|
|
4412
|
-
const
|
|
4988
|
+
const real = await realOf(ctx, fs, lexical);
|
|
4989
|
+
const inRepo = canonicalize(ctx, gitRoot, gitRoot, real);
|
|
4990
|
+
// G.4b: inside the cross-link repository W -> an external file. B1: W is classified first and
|
|
4991
|
+
// the deeper root wins, so a W nested in the consumer's root (a submodule, a nested clone) keeps
|
|
4992
|
+
// its files; inside both, the shorter relative path is the deeper root (equal: the consumer's).
|
|
4993
|
+
const inW = cross ? canonicalize(ctx, cross.real, cross.real, real) : undefined;
|
|
4994
|
+
const wDeeper = inW !== undefined && (inRepo === undefined || inW.rel.length < inRepo.rel.length);
|
|
4995
|
+
const located: FileRef | undefined = wDeeper ? { ...inW, external: true } : inRepo;
|
|
4996
|
+
const ref: FileRef | undefined = located && c.status === "!!" ? { ...located, ignored: true } : located;
|
|
4413
4997
|
if (!ref) {
|
|
4414
4998
|
notes.push(`dropped outside the git root: ${cand}`);
|
|
4415
4999
|
continue;
|
|
@@ -4420,7 +5004,10 @@ async function collectChanged(
|
|
|
4420
5004
|
}
|
|
4421
5005
|
const lexBase = ctx.P.basename(lexical);
|
|
4422
5006
|
const full = lexBase === ctx.P.basename(ref.abs) ? ref : { ...ref, lexBase };
|
|
4423
|
-
|
|
5007
|
+
// M4: a file also named by an entry that is not `!!` is a tracked change, not an ignored module.
|
|
5008
|
+
const prev = files.get(ctx.key(ref.abs));
|
|
5009
|
+
if (!prev) files.set(ctx.key(ref.abs), full);
|
|
5010
|
+
else if (prev.ignored === true && full.ignored !== true) files.set(ctx.key(ref.abs), full);
|
|
4424
5011
|
}
|
|
4425
5012
|
}
|
|
4426
5013
|
return [...files.entries()].sort(byKey).map(([, v]) => v);
|
|
@@ -4437,6 +5024,7 @@ async function classify(
|
|
|
4437
5024
|
sorted: readonly FileRef[],
|
|
4438
5025
|
notes: string[],
|
|
4439
5026
|
search: TestSearchSeam | undefined,
|
|
5027
|
+
cross?: CrossLink,
|
|
4440
5028
|
): Promise<ScopingPlan | StaticScoping> {
|
|
4441
5029
|
const P = ctx.P;
|
|
4442
5030
|
const fs = input.fs;
|
|
@@ -4444,6 +5032,8 @@ async function classify(
|
|
|
4444
5032
|
// G.8: classification. A test file the runner's config excludes stays an input (G.8a, QA-1.3-38).
|
|
4445
5033
|
const inputs = new Map<string, string>();
|
|
4446
5034
|
const addInput = (abs: string) => inputs.set(ctx.key(abs), abs);
|
|
5035
|
+
// G.4b: the external inputs, every spelling (SD-P3a-2), deduplicated by exact string, not by key.
|
|
5036
|
+
const crossInputs = new Set<string>();
|
|
4447
5037
|
const goneSources: FileRef[] = [];
|
|
4448
5038
|
const modules: FileRef[] = [];
|
|
4449
5039
|
const goneModules: FileRef[] = [];
|
|
@@ -4457,10 +5047,16 @@ async function classify(
|
|
|
4457
5047
|
|
|
4458
5048
|
for (const f of sorted) {
|
|
4459
5049
|
const base = P.basename(f.abs);
|
|
4460
|
-
if (
|
|
5050
|
+
if (isCrossNonInput(ctx, f) || (det.kind === "pytest" && !base.endsWith(".py"))) {
|
|
4461
5051
|
skipped++;
|
|
4462
5052
|
continue;
|
|
4463
5053
|
}
|
|
5054
|
+
if (f.external === true && cross) {
|
|
5055
|
+
// G.4b: crossLinkChecks already returned S6 for a gone or unreachable one, and for any runner but vitest.
|
|
5056
|
+
if (isCrossTest(ctx, f)) notes.push(`linked repository test file not run: ${f.rel}`);
|
|
5057
|
+
else for (const s of crossSpellings(ctx, cross, f)) crossInputs.add(s);
|
|
5058
|
+
continue;
|
|
5059
|
+
}
|
|
4464
5060
|
const exists = await existsCached(ctx, fs, f.abs);
|
|
4465
5061
|
if (det.kind === "pytest") {
|
|
4466
5062
|
const isTest = isPyTestFile(ctx, pyFiles, f.abs);
|
|
@@ -4496,9 +5092,17 @@ async function classify(
|
|
|
4496
5092
|
}
|
|
4497
5093
|
|
|
4498
5094
|
if (!search) {
|
|
4499
|
-
if (inputs.size === 0 && pending === 0) return noAffected(NOTE_NO_INPUT);
|
|
5095
|
+
if (inputs.size === 0 && pending === 0 && crossInputs.size === 0) return noAffected(NOTE_NO_INPUT);
|
|
4500
5096
|
const pre = await preflight(ctx, det, fs);
|
|
4501
5097
|
if (isS6(pre)) return pre;
|
|
5098
|
+
// B1: the vitest major is checked for every request with a cross-link root.
|
|
5099
|
+
const old = cross ? crossLinkVersion(pre.entry) : undefined;
|
|
5100
|
+
if (old) return old;
|
|
5101
|
+
// QA-1 M2: W's package names are read here too (fs only), so a name S6 is the same as planScopedRun's.
|
|
5102
|
+
if (cross) {
|
|
5103
|
+
const names = await crossLinkNames(ctx, fs, cross);
|
|
5104
|
+
if (isS6(names)) return names;
|
|
5105
|
+
}
|
|
4502
5106
|
const staticNotes = [...notes, ...pre.notes];
|
|
4503
5107
|
// QA-1.3-27: the spec-time pytest config lookup needs only the fs. Run it over the test inputs
|
|
4504
5108
|
// known without a search, so 1.6 sees the S6 planScopedRun would return for them.
|
|
@@ -4642,16 +5246,44 @@ async function classify(
|
|
|
4642
5246
|
// Every pytest module and gone module above added an input or returned S6, so an empty set here
|
|
4643
5247
|
// means no changed file was a test input or a module (docs, dropped paths, deleted test files
|
|
4644
5248
|
// nothing imports).
|
|
4645
|
-
if (inputs.size === 0) return noAffected(NOTE_NO_INPUT);
|
|
5249
|
+
if (inputs.size === 0 && crossInputs.size === 0) return noAffected(NOTE_NO_INPUT);
|
|
4646
5250
|
const pre = await preflight(ctx, det, fs);
|
|
4647
5251
|
if (isS6(pre)) return pre;
|
|
4648
|
-
|
|
5252
|
+
// B1: the vitest major is checked for every request with a cross-link root.
|
|
5253
|
+
const old = cross ? crossLinkVersion(pre.entry) : undefined;
|
|
5254
|
+
if (old) return old;
|
|
5255
|
+
// QA-1 M2 (completeness check): the consumer test files that name a package of W must all run.
|
|
5256
|
+
let expected: readonly string[] | undefined;
|
|
5257
|
+
if (cross) {
|
|
5258
|
+
const names = await crossLinkNames(ctx, fs, cross);
|
|
5259
|
+
if (isS6(names)) return names;
|
|
5260
|
+
const found = await crossLinkExpected(ctx, fs, search, gitRoot, det.runnerCwd, names, cross.spellings[0]);
|
|
5261
|
+
if (isS6(found)) return found;
|
|
5262
|
+
expected = found;
|
|
5263
|
+
}
|
|
5264
|
+
const F = crossInputs.size === 0 ? [...inputs.entries()].sort(byKey).map(([, v]) => v) : withCrossInputs(ctx, inputs, crossInputs);
|
|
4649
5265
|
const allNotes = [...notes, ...pre.notes];
|
|
4650
5266
|
const long = pytestArgvFloor(ctx, det, pre.entry, F);
|
|
4651
5267
|
if (long) return long;
|
|
4652
5268
|
const py = await pytestAtInputs(ctx, fs, det, F, det.runnerCwd, allNotes);
|
|
4653
5269
|
if (py !== undefined && isS6(py)) return py;
|
|
4654
|
-
|
|
5270
|
+
// B1 (Y2): every spec planned with a cross-link root is a cross-link spec, linked inputs or not,
|
|
5271
|
+
// so a related run that selects no test is never taken as "no affected tests".
|
|
5272
|
+
const crossRoot = cross?.spellings[0];
|
|
5273
|
+
return buildSpec(ctx, det, pre.entry, F, input.budget, input.cores, allNotes, "related", det.runnerCwd, gitRoot, !fs.realpath, py, crossRoot, expected);
|
|
5274
|
+
}
|
|
5275
|
+
|
|
5276
|
+
/**
|
|
5277
|
+
* G.4b: the in-repo inputs (deduplicated by key) and the external spellings (deduplicated by exact
|
|
5278
|
+
* string, SD-P3a-2) as one sorted list: by key, then by the exact string, so case-only variants of
|
|
5279
|
+
* one path stay distinct and the order is deterministic.
|
|
5280
|
+
*/
|
|
5281
|
+
function withCrossInputs(ctx: Ctx, inputs: ReadonlyMap<string, string>, crossInputs: ReadonlySet<string>): string[] {
|
|
5282
|
+
const all = [...new Set([...inputs.values(), ...crossInputs])];
|
|
5283
|
+
return all
|
|
5284
|
+
.map((v) => [ctx.key(v), v] as const)
|
|
5285
|
+
.sort((a, b) => byKey(a, b) || (a[1] < b[1] ? -1 : a[1] > b[1] ? 1 : 0))
|
|
5286
|
+
.map(([, v]) => v);
|
|
4655
5287
|
}
|
|
4656
5288
|
|
|
4657
5289
|
/** H, N.4 (QA-1.3-11): the tmpdir must be absolute and must not be inside gitRoot, lexically or after realpath. */
|
|
@@ -4707,6 +5339,8 @@ function buildSpec(
|
|
|
4707
5339
|
gitRoot: string,
|
|
4708
5340
|
lexical: boolean,
|
|
4709
5341
|
py: PytestEvidence | undefined,
|
|
5342
|
+
crossLinkRoot?: string,
|
|
5343
|
+
crossLinkExpected?: readonly string[],
|
|
4710
5344
|
): ScopedSpec | Unverifiable {
|
|
4711
5345
|
const C = inputCores ?? ctx.host.cores;
|
|
4712
5346
|
const xdist = py ? py.xdist : det.xdist;
|
|
@@ -4751,6 +5385,8 @@ function buildSpec(
|
|
|
4751
5385
|
workers,
|
|
4752
5386
|
notes,
|
|
4753
5387
|
...(lexical ? { lexicalPaths: true as const } : {}),
|
|
5388
|
+
...(crossLinkRoot !== undefined ? { crossLink: true as const, crossLinkRoot } : {}),
|
|
5389
|
+
...(crossLinkRoot !== undefined && crossLinkExpected !== undefined && crossLinkExpected.length > 0 ? { crossLinkExpected } : {}),
|
|
4754
5390
|
};
|
|
4755
5391
|
}
|
|
4756
5392
|
|
|
@@ -4862,22 +5498,23 @@ export async function readResult(
|
|
|
4862
5498
|
ctx.key(P.dirname(P.resolve(spec.reportPath))) === ctx.key(P.resolve(ctx.host.tmpdir)) &&
|
|
4863
5499
|
REPORT_NAME_RE.test(P.basename(spec.reportPath));
|
|
4864
5500
|
try {
|
|
4865
|
-
if (!allowed) return textResult(ctx, spec, execResult, `report path rejected: ${spec.reportPath}`);
|
|
5501
|
+
if (!allowed) return crossLinkCompleteness(ctx, spec, textResult(ctx, spec, execResult, `report path rejected: ${spec.reportPath}`));
|
|
4866
5502
|
let text: string | undefined;
|
|
4867
5503
|
try {
|
|
4868
5504
|
text = await fs.readFile(spec.reportPath);
|
|
4869
5505
|
} catch {
|
|
4870
5506
|
text = undefined; // Missing or unreadable: step 4.
|
|
4871
5507
|
}
|
|
4872
|
-
if (text === undefined) return textResult(ctx, spec, execResult, undefined);
|
|
5508
|
+
if (text === undefined) return crossLinkCompleteness(ctx, spec, textResult(ctx, spec, execResult, undefined));
|
|
4873
5509
|
let parsed: RunResult | undefined;
|
|
4874
5510
|
try {
|
|
4875
5511
|
parsed = spec.runner === "pytest" ? parseJunit(ctx, spec, text, execResult.code) : parseJestJson(ctx, spec, text, execResult.code);
|
|
4876
5512
|
} catch (err) {
|
|
4877
5513
|
// I step 1 (QA-1.3-12): a parser failure is an unusable report, never a rejection.
|
|
4878
|
-
return textResult(ctx, spec, execResult, `report could not be parsed: ${err instanceof Error ? err.message : String(err)}`);
|
|
5514
|
+
return crossLinkCompleteness(ctx, spec, textResult(ctx, spec, execResult, `report could not be parsed: ${err instanceof Error ? err.message : String(err)}`));
|
|
4879
5515
|
}
|
|
4880
|
-
|
|
5516
|
+
// QA-1 M2: a cross-link run is then checked for the consumer test files it had to run.
|
|
5517
|
+
return crossLinkCompleteness(ctx, spec, parsed ? zeroTestsGuard(spec, parsed) : textResult(ctx, spec, execResult, undefined));
|
|
4881
5518
|
} finally {
|
|
4882
5519
|
if (allowed) {
|
|
4883
5520
|
try {
|
|
@@ -5059,22 +5696,59 @@ function isJsTestPath(p: string): boolean {
|
|
|
5059
5696
|
/**
|
|
5060
5697
|
* I step 2a (QA-1.3-1, QA-1.3-19): a report that lists no test at all is not trusted when the
|
|
5061
5698
|
* inputs say tests must have run, for every runner: a rerun, inputs that are test files (pytest,
|
|
5062
|
-
* or a JS test file given to related),
|
|
5063
|
-
* both match nothing through a junction cwd)
|
|
5699
|
+
* or a JS test file given to related), any spec planned without realpath (jest and vitest
|
|
5700
|
+
* both match nothing through a junction cwd), and a cross-link spec (Y2: every way vitest fails to
|
|
5701
|
+
* follow the link, such as resolve.preserveSymlinks or a built entry, selects 0 tests).
|
|
5064
5702
|
*/
|
|
5065
5703
|
function zeroTestsGuard(spec: ScopedSpec, r: RunResult): RunResult {
|
|
5066
5704
|
if (r.total !== 0 || !r.complete || r.failingIds.length > 0 || r.collectionError || spec.inputs.length === 0) return r;
|
|
5067
5705
|
const note =
|
|
5068
5706
|
spec.mode === "rerun"
|
|
5069
5707
|
? "rerun ran no tests although every input is a test file"
|
|
5070
|
-
: spec.
|
|
5071
|
-
?
|
|
5072
|
-
: spec.
|
|
5073
|
-
? `${spec.runner} ran no tests
|
|
5074
|
-
:
|
|
5708
|
+
: spec.crossLink === true
|
|
5709
|
+
? crossLinkZeroNote(spec)
|
|
5710
|
+
: spec.inputsAreTests || spec.inputs.some(isJsTestPath)
|
|
5711
|
+
? `${spec.runner} ran no tests although a test file was passed`
|
|
5712
|
+
: spec.lexicalPaths === true
|
|
5713
|
+
? `${spec.runner} ran no tests and the paths were not canonicalized (no realpath seam)`
|
|
5714
|
+
: undefined;
|
|
5075
5715
|
return note === undefined ? r : { ...r, complete: false, note };
|
|
5076
5716
|
}
|
|
5077
5717
|
|
|
5718
|
+
/** Y2: the zero-tests note of a cross-link related run; the fix is a full run. */
|
|
5719
|
+
function crossLinkZeroNote(spec: ScopedSpec): string {
|
|
5720
|
+
const root = spec.crossLinkRoot ?? "the linked repository";
|
|
5721
|
+
return (
|
|
5722
|
+
`vitest selected no test in ${spec.cwd} for the change in ${root}; the link may not be followed ` +
|
|
5723
|
+
"(resolve.preserveSymlinks, a built entry, or no test imports the changed files): use scope=full"
|
|
5724
|
+
);
|
|
5725
|
+
}
|
|
5726
|
+
|
|
5727
|
+
/**
|
|
5728
|
+
* QA-1 M2 (completeness check): a cross-link run must have run every consumer test file that names a
|
|
5729
|
+
* package of the linked repository (ScopedSpec.crossLinkExpected, G.4b). Each one is looked up in the
|
|
5730
|
+
* run's per-file results (testsByFile, cwd-relative "/" keys, compared by ctx.key: case-insensitive on
|
|
5731
|
+
* win32); a missing one makes the run incomplete, so it never passes. Without per-file results (the
|
|
5732
|
+
* text fallback) a complete result cannot be checked and is incomplete too. A spec without
|
|
5733
|
+
* crossLinkExpected, or a result already incomplete, is returned unchanged.
|
|
5734
|
+
*/
|
|
5735
|
+
function crossLinkCompleteness(ctx: Ctx, spec: ScopedSpec, r: RunResult): RunResult {
|
|
5736
|
+
const expected = spec.crossLinkExpected;
|
|
5737
|
+
if (spec.crossLink !== true || expected === undefined || expected.length === 0 || !r.complete) return r;
|
|
5738
|
+
if (r.testsByFile === undefined) {
|
|
5739
|
+
return { ...r, complete: false, note: "vitest gave no per-file results, so the consumer test files that import the linked repository cannot be checked: use scope=full" };
|
|
5740
|
+
}
|
|
5741
|
+
const ran = new Set(Object.keys(r.testsByFile).map((k) => ctx.key(k)));
|
|
5742
|
+
const missing = expected.map((f) => relSlash(ctx, spec.cwd, f)).filter((rel) => !ran.has(ctx.key(rel)));
|
|
5743
|
+
if (missing.length === 0) return r;
|
|
5744
|
+
const shown = missing.slice(0, 3).join(", ") + (missing.length > 3 ? ", …" : "");
|
|
5745
|
+
return {
|
|
5746
|
+
...r,
|
|
5747
|
+
complete: false,
|
|
5748
|
+
note: `vitest did not run ${missing.length} consumer test file(s) that import the linked repository (${shown}); the link may not be followed: use scope=full`,
|
|
5749
|
+
};
|
|
5750
|
+
}
|
|
5751
|
+
|
|
5078
5752
|
const XML_ENTITIES: Record<string, string> = { amp: "&", lt: "<", gt: ">", quot: '"', apos: "'" };
|
|
5079
5753
|
|
|
5080
5754
|
/** A code point String.fromCodePoint accepts and XML allows to be a character reference. */
|