@holmes-lab/holmes-kit 0.40.0 → 0.40.1
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 +234 -0
- package/README.md +70 -4
- package/dist/.build-id +1 -1
- package/dist/holmes/cli/index.js +25 -19
- package/dist/holmes/cli/interactive-prompt.d.ts +39 -2
- package/dist/holmes/cli/interactive-prompt.js +98 -16
- package/dist/holmes/config/config.d.ts +17 -0
- package/dist/holmes/config/config.js +13 -1
- package/dist/holmes/governance/autonomy.d.ts +7 -0
- package/dist/holmes/governance/autonomy.js +36 -5
- package/dist/holmes/governance/push-gate-runner.d.ts +2 -0
- package/dist/holmes/governance/push-gate-runner.js +40 -3
- package/dist/holmes/governance/push-gate.d.ts +13 -2
- package/dist/holmes/governance/push-gate.js +106 -14
- package/dist/holmes/guardrail/advisory-line.d.ts +102 -0
- package/dist/holmes/guardrail/advisory-line.js +718 -0
- package/dist/holmes/guardrail/impact-gate.d.ts +6 -0
- package/dist/holmes/guardrail/impact-gate.js +32 -5
- package/dist/holmes/hooks/pre-tool-use.d.ts +11 -0
- package/dist/holmes/hooks/pre-tool-use.js +44 -5
- package/dist/holmes/hooks/session-start.js +17 -1
- package/dist/holmes/mcp/handlers/maintenance-analysis.d.ts +13 -0
- package/dist/holmes/mcp/handlers/maintenance-analysis.js +59 -2
- package/dist/holmes/mcp/handlers/test-execution.d.ts +470 -3
- package/dist/holmes/mcp/handlers/test-execution.js +199 -21
- package/dist/holmes/mcp/handlers.d.ts +468 -3
- package/dist/holmes/mcp/handlers.js +5 -1
- package/dist/holmes/mcp/maintenance-analyze.d.ts +5 -0
- package/dist/holmes/mcp/maintenance-analyze.js +4 -2
- package/dist/holmes/mcp/maintenance-evidence.d.ts +9 -0
- package/dist/holmes/mcp/maintenance-evidence.js +4 -1
- package/dist/holmes/mcp/tool-schemas.js +13 -7
- package/dist/holmes/project/baseline.d.ts +15 -2
- package/dist/holmes/project/baseline.js +11 -6
- package/dist/holmes/project/bounded-io.d.ts +1 -0
- package/dist/holmes/project/bounded-io.js +4 -2
- package/dist/holmes/project/change-source.d.ts +4 -0
- package/dist/holmes/project/change-source.js +13 -5
- package/dist/holmes/project/root.js +3 -1
- package/dist/holmes/review/evidence-mode.d.ts +21 -0
- package/dist/holmes/review/evidence-mode.js +33 -0
- package/dist/holmes/review/head-worktree.d.ts +55 -0
- package/dist/holmes/review/head-worktree.js +329 -0
- package/dist/holmes/review/mrp.js +13 -3
- package/dist/holmes/review/run-provenance.d.ts +45 -0
- package/dist/holmes/review/run-provenance.js +314 -0
- package/dist/holmes/review/test-evidence.d.ts +174 -0
- package/dist/holmes/review/test-evidence.js +330 -2
- package/dist/holmes/review/test-reports.d.ts +94 -0
- package/dist/holmes/review/test-reports.js +382 -0
- package/dist/holmes/review/test-runner.d.ts +176 -65
- package/dist/holmes/review/test-runner.js +531 -316
- package/dist/holmes/review/test-units.d.ts +159 -0
- package/dist/holmes/review/test-units.js +814 -0
- package/package.json +1 -1
- package/playbooks/publish/PLAYBOOK.md +2 -1
|
@@ -0,0 +1,814 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
+
var ownKeys = function(o) {
|
|
20
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
+
var ar = [];
|
|
22
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
+
return ar;
|
|
24
|
+
};
|
|
25
|
+
return ownKeys(o);
|
|
26
|
+
};
|
|
27
|
+
return function (mod) {
|
|
28
|
+
if (mod && mod.__esModule) return mod;
|
|
29
|
+
var result = {};
|
|
30
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
+
__setModuleDefault(result, mod);
|
|
32
|
+
return result;
|
|
33
|
+
};
|
|
34
|
+
})();
|
|
35
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
|
+
exports.BUILD_ROOTS = void 0;
|
|
37
|
+
exports.goFileForHost = goFileForHost;
|
|
38
|
+
exports.normaliseExcludeDirs = normaliseExcludeDirs;
|
|
39
|
+
exports.excludedDir = excludedDir;
|
|
40
|
+
exports.pytestRules = pytestRules;
|
|
41
|
+
exports.pytestInifile = pytestInifile;
|
|
42
|
+
exports.pytestSelection = pytestSelection;
|
|
43
|
+
exports.goflagsSelection = goflagsSelection;
|
|
44
|
+
exports.projectFiles = projectFiles;
|
|
45
|
+
exports.scanEcosystems = scanEcosystems;
|
|
46
|
+
exports.jestConfigSurface = jestConfigSurface;
|
|
47
|
+
exports.goWorkEnv = goWorkEnv;
|
|
48
|
+
exports.goListTests = goListTests;
|
|
49
|
+
// @implements A-SPEC-128.9, A-SPEC-128.10, A-SPEC-128.11, A-SPEC-128.12, A-SPEC-128.13
|
|
50
|
+
/**
|
|
51
|
+
* What a full test run runs, and where: the EXECUTION UNITS of a project (A-SPEC-128.9 E1). Detection moved here from
|
|
52
|
+
* test-runner.ts (A-SPEC-647, A-SPEC-128.5 to 128.8 describe its earlier rules); test-runner re-exports these names.
|
|
53
|
+
*
|
|
54
|
+
* Six review rounds broke on one axis: holmes inferring, BEFORE a run, which test runs where (A-SPEC-128.10). The scan
|
|
55
|
+
* now only lists what exists — the files git sees (I4), the units a build or runner configuration declares (I5), the
|
|
56
|
+
* tests each unit must report, and the code each build root holds. Whether coverage held is decided AFTER the run, by
|
|
57
|
+
* comparing what the runners reported with this list (I3, in test-runner). A tree the user excludes — `.gitignore` or
|
|
58
|
+
* `ax.config.json` `testRun.excludeDirs` — is not listed, not counted and not run (owner, 2026-11-06).
|
|
59
|
+
*
|
|
60
|
+
* A-SPEC-128.13: this module is also THE one place that judges the 0.40.x supported surface — the static part here
|
|
61
|
+
* (`outsideSurface`), and jest's resolved configuration through `jestConfigSurface`, which the runner calls with what
|
|
62
|
+
* `jest --showConfig` printed. It forms no verdict on a run's result; the runner and test-evidence do.
|
|
63
|
+
*/
|
|
64
|
+
const fs = __importStar(require("node:fs"));
|
|
65
|
+
const path = __importStar(require("node:path"));
|
|
66
|
+
const node_child_process_1 = require("node:child_process");
|
|
67
|
+
const root_1 = require("../project/root");
|
|
68
|
+
const bounded_io_1 = require("../project/bounded-io");
|
|
69
|
+
/**
|
|
70
|
+
* @implements A-SPEC-128.9 — THE table of build and configuration roots (B L2: three tables became one). A directory
|
|
71
|
+
* holding one of these is where that ecosystem's runner runs.
|
|
72
|
+
*/
|
|
73
|
+
exports.BUILD_ROOTS = [
|
|
74
|
+
{ re: /^go\.mod$/, ecosystem: 'go' },
|
|
75
|
+
{ re: /^Cargo\.toml$/, ecosystem: 'rust' },
|
|
76
|
+
{ re: /^(pom\.xml|build\.gradle|build\.gradle\.kts|settings\.gradle|settings\.gradle\.kts)$/, ecosystem: 'java' },
|
|
77
|
+
{ re: /\.(csproj|sln)$/, ecosystem: 'dotnet' },
|
|
78
|
+
{ re: /^package\.json$/, ecosystem: 'jest' },
|
|
79
|
+
{ re: /^(pyproject\.toml|pytest\.ini|setup\.py|setup\.cfg|tox\.ini)$/, ecosystem: 'pytest' },
|
|
80
|
+
];
|
|
81
|
+
/** Implementation sources by the ecosystem whose runner tests them (A-SPEC-128.10: groovy and scala are java's). */
|
|
82
|
+
const SOURCE_ECO = [
|
|
83
|
+
[/\.(ts|tsx|js|jsx|mjs|cjs|mts|cts)$/, 'jest'], [/\.py$/, 'pytest'], [/\.go$/, 'go'], [/\.rs$/, 'rust'],
|
|
84
|
+
[/\.(java|kt|groovy|scala)$/, 'java'], [/\.cs$/, 'dotnet'],
|
|
85
|
+
];
|
|
86
|
+
/** @implements A-SPEC-128.10 — configuration and docs files are not implementation code (the owner's "단순 설정 파일"). */
|
|
87
|
+
const CONFIG_FILE = /\.config\.[^.]+$|^conf\.py$|^\.eslintrc(\..+)?$|^setup\.py$|\.d\.ts$/;
|
|
88
|
+
/** The build file a language needs before its runner can run at all (A M1). */
|
|
89
|
+
const BUILD_FILE_OF = { go: 'go.mod', rust: 'Cargo.toml', java: 'pom.xml or build.gradle', dotnet: 'a *.csproj' };
|
|
90
|
+
const JEST_TEST = /\.(test|spec)\.(ts|tsx|js|jsx|mjs|cjs|mts|cts)$/;
|
|
91
|
+
const JS_FILE = /\.(ts|tsx|js|jsx|mjs|cjs|mts|cts)$/;
|
|
92
|
+
const JEST_CONFIG = /^jest\.config\.(js|ts|mjs|cjs|mts|cts|json)$/;
|
|
93
|
+
/** @implements A-SPEC-128.13 — pytest's default norecursedirs: directories pytest never collects from by itself. */
|
|
94
|
+
const PY_NORECURSE = (seg) => seg.startsWith('.') || ['build', 'dist', 'node_modules', 'venv', 'CVS', '_darcs', '{arch}'].includes(seg) || seg.endsWith('.egg');
|
|
95
|
+
/** @implements A-SPEC-128.13 — build files of ecosystems 0.40.x has no runner for. */
|
|
96
|
+
const UNSUPPORTED_BUILD = /^(Gemfile|composer\.json|Package\.swift|build\.sbt|mix\.exs|CMakeLists\.txt|pubspec\.yaml)$/;
|
|
97
|
+
/** @implements A-SPEC-128.13 — a package.json script that runs jest with a configuration it chooses. */
|
|
98
|
+
const JEST_SCRIPT_CONFIG = /\bjest\b[^&|;]*?\s(?:-c|--config)(?:\s|=)\s*(\S+)/;
|
|
99
|
+
const DEFAULT_PY_FILES = ['test_*.py', '*_test.py'];
|
|
100
|
+
/** @implements A-SPEC-128.12 — S4: a go file whose test functions `go test` would run; names are Unicode identifiers. */
|
|
101
|
+
const GO_TEST_FUNC = /^func\s+(Test|Benchmark|Example|Fuzz)[\p{L}\p{N}_]*\s*\(/mu;
|
|
102
|
+
/**
|
|
103
|
+
* @implements A-SPEC-128.12 — S4: directories `go test ./...` never builds (`testdata`, `_x`, `.x`). A module's own
|
|
104
|
+
* `vendor/` is left out by the caller, which knows the module root; a nested `internal/vendor` is an ordinary package
|
|
105
|
+
* that go runs (measured), so it stays expected.
|
|
106
|
+
*/
|
|
107
|
+
const goSkipped = (rel) => rel.split('/').slice(0, -1).some((s) => s === 'testdata' || s.startsWith('_') || s.startsWith('.'));
|
|
108
|
+
const GOOS = new Set(['aix', 'android', 'darwin', 'dragonfly', 'freebsd', 'hurd', 'illumos', 'ios', 'js', 'linux', 'nacl', 'netbsd', 'openbsd', 'plan9', 'solaris', 'wasip1', 'windows', 'zos']);
|
|
109
|
+
const GOARCH = new Set(['386', 'amd64', 'amd64p32', 'arm', 'armbe', 'arm64', 'arm64be', 'loong64', 'mips', 'mipsle', 'mips64', 'mips64le', 'mips64p32',
|
|
110
|
+
'mips64p32le', 'ppc', 'ppc64', 'ppc64le', 'riscv', 'riscv64', 's390', 's390x', 'sparc', 'sparc64', 'wasm']);
|
|
111
|
+
const HOST_GOOS = process.platform === 'win32' ? 'windows' : process.platform === 'sunos' ? 'solaris' : process.platform;
|
|
112
|
+
const HOST_GOARCH = { x64: 'amd64', ia32: '386', mipsel: 'mipsle' }[process.arch] ?? process.arch;
|
|
113
|
+
/**
|
|
114
|
+
* @implements A-SPEC-128.12 — S4: go's file-name constraint (go/build goodOSArchFile): after the first `_`, a trailing
|
|
115
|
+
* `_GOOS`, `_GOARCH` or `_GOOS_GOARCH` (before `_test`) builds only on that platform. A file for another is not expected.
|
|
116
|
+
*/
|
|
117
|
+
function goFileForHost(rel, goos = HOST_GOOS, goarch = HOST_GOARCH) {
|
|
118
|
+
const name = path.posix.basename(rel).replace(/\.go$/, '');
|
|
119
|
+
const i = name.indexOf('_');
|
|
120
|
+
if (i < 0)
|
|
121
|
+
return true;
|
|
122
|
+
let l = name.slice(i).split('_');
|
|
123
|
+
if (l[l.length - 1] === 'test')
|
|
124
|
+
l = l.slice(0, -1);
|
|
125
|
+
const n = l.length;
|
|
126
|
+
if (n >= 2 && GOOS.has(l[n - 2]) && GOARCH.has(l[n - 1]))
|
|
127
|
+
return l[n - 2] === goos && l[n - 1] === goarch;
|
|
128
|
+
if (GOOS.has(l[n - 1]))
|
|
129
|
+
return l[n - 1] === goos;
|
|
130
|
+
if (GOARCH.has(l[n - 1]))
|
|
131
|
+
return l[n - 1] === goarch;
|
|
132
|
+
return true;
|
|
133
|
+
}
|
|
134
|
+
const WALK_SKIP = new Set(['node_modules', '.git']);
|
|
135
|
+
/** A bound on the notDetected list (a monorepo can hold hundreds of modules). */
|
|
136
|
+
const NOT_DETECTED_CAP = 20;
|
|
137
|
+
/**
|
|
138
|
+
* @implements A-SPEC-128.9 — one reading of `testRun.excludeDirs` (its rules are A-SPEC-128.8's). An entry holding `/`
|
|
139
|
+
* (or `\`) is a root-relative path, folded (`./`, `//`, `/./`, a trailing `/`): `./vendorx` and `fixtures/` are root
|
|
140
|
+
* paths, not names. An entry without one is a directory name at any depth. An absolute entry, one that leaves the root
|
|
141
|
+
* and one that names nothing match nothing and are returned in `ignored`, so the answer can name them.
|
|
142
|
+
*/
|
|
143
|
+
function normaliseExcludeDirs(entries) {
|
|
144
|
+
const valid = [];
|
|
145
|
+
const ignored = [];
|
|
146
|
+
for (const entry of entries) {
|
|
147
|
+
const raw = entry.split('\\').join('/');
|
|
148
|
+
if (raw.startsWith('/') || /^[A-Za-z]:\//.test(raw)) {
|
|
149
|
+
ignored.push({ entry, reason: 'an absolute path — entries are relative to the root' });
|
|
150
|
+
continue;
|
|
151
|
+
}
|
|
152
|
+
// posix.normalize folds `./`, `//` and `/./` (a leading `./x` comes back as `x`); only a trailing `/` is left to drop
|
|
153
|
+
const folded = raw.includes('/') ? path.posix.normalize(raw).replace(/\/+$/, '') : raw;
|
|
154
|
+
if (folded === '' || folded === '.') {
|
|
155
|
+
ignored.push({ entry, reason: 'names nothing' });
|
|
156
|
+
continue;
|
|
157
|
+
}
|
|
158
|
+
if (folded === '..' || folded.startsWith('../')) {
|
|
159
|
+
ignored.push({ entry, reason: 'leaves the root' });
|
|
160
|
+
continue;
|
|
161
|
+
}
|
|
162
|
+
valid.push(raw.includes('/') ? { kind: 'path', value: folded } : { kind: 'name', value: folded });
|
|
163
|
+
}
|
|
164
|
+
return { valid, ignored };
|
|
165
|
+
}
|
|
166
|
+
/** A `testRun.excludeDirs` entry holding `/` is a root-relative path prefix; one without is a directory name at any depth. */
|
|
167
|
+
function excludedDir(relPath, name, excludeDirs) {
|
|
168
|
+
const rel = relPath.split('\\').join('/');
|
|
169
|
+
return normaliseExcludeDirs(excludeDirs).valid.some((e) => (e.kind === 'path' ? rel === e.value || rel.startsWith(`${e.value}/`) : name === e.value));
|
|
170
|
+
}
|
|
171
|
+
/** A glob of pytest's `python_files` kind (`*`, `?`) as an anchored expression over a file name. */
|
|
172
|
+
function globToRe(glob) {
|
|
173
|
+
return new RegExp(`^${glob.replace(/[.+^${}()|[\]\\]/g, '\\$&').replace(/\*/g, '.*').replace(/\?/g, '.')}$`);
|
|
174
|
+
}
|
|
175
|
+
/**
|
|
176
|
+
* @implements A-SPEC-128.9 — a directory's declared pytest collection rules (A L3): `testpaths` and `python_files` from
|
|
177
|
+
* pyproject `[tool.pytest.ini_options]`, `pytest.ini [pytest]`, `setup.cfg [tool:pytest]` or `tox.ini [pytest]`. Null when
|
|
178
|
+
* none is declared.
|
|
179
|
+
*/
|
|
180
|
+
function pytestRules(cwd) {
|
|
181
|
+
const read = (n) => { try {
|
|
182
|
+
return fs.readFileSync(path.join(cwd, n), 'utf8');
|
|
183
|
+
}
|
|
184
|
+
catch {
|
|
185
|
+
return '';
|
|
186
|
+
} };
|
|
187
|
+
const section = (text, header) => {
|
|
188
|
+
const m = header.exec(text);
|
|
189
|
+
if (!m)
|
|
190
|
+
return '';
|
|
191
|
+
const rest = text.slice(m.index + m[0].length);
|
|
192
|
+
const next = /^\s*\[/m.exec(rest);
|
|
193
|
+
return next ? rest.slice(0, next.index) : rest;
|
|
194
|
+
};
|
|
195
|
+
const sections = [
|
|
196
|
+
section(read('pyproject.toml'), /^\s*\[tool\.pytest\.ini_options\]\s*$/m),
|
|
197
|
+
section(read('pytest.ini'), /^\s*\[pytest\]\s*$/m),
|
|
198
|
+
section(read('setup.cfg'), /^\s*\[tool:pytest\]\s*$/m),
|
|
199
|
+
section(read('tox.ini'), /^\s*\[pytest\]\s*$/m),
|
|
200
|
+
];
|
|
201
|
+
const value = (key) => {
|
|
202
|
+
for (const s of sections) {
|
|
203
|
+
const m = new RegExp(`^\\s*${key}\\s*=\\s*(.+)$`, 'm').exec(s);
|
|
204
|
+
if (!m)
|
|
205
|
+
continue;
|
|
206
|
+
const v = m[1].trim();
|
|
207
|
+
const items = v.startsWith('[') ? [...v.matchAll(/["']([^"']+)["']/g)].map((x) => x[1]) : v.split(/\s+/).filter(Boolean);
|
|
208
|
+
return items.map((i) => i.replace(/^\.\//, '').replace(/\/+$/, ''));
|
|
209
|
+
}
|
|
210
|
+
return null;
|
|
211
|
+
};
|
|
212
|
+
const testpaths = value('testpaths');
|
|
213
|
+
const pythonFiles = value('python_files');
|
|
214
|
+
// @implements A-SPEC-128.13 — selections below the file: declared names of functions and classes, and addopts
|
|
215
|
+
const pythonFunctions = value('python_functions');
|
|
216
|
+
const pythonClasses = value('python_classes');
|
|
217
|
+
const addopts = value('addopts');
|
|
218
|
+
return testpaths === null && pythonFiles === null && pythonFunctions === null && pythonClasses === null && addopts === null
|
|
219
|
+
? null : { testpaths, pythonFiles, pythonFunctions, pythonClasses, addopts };
|
|
220
|
+
}
|
|
221
|
+
/** pytest's configuration files, in its own order of precedence within one directory, with the section each must hold. */
|
|
222
|
+
const PYTEST_FILES = [
|
|
223
|
+
['pytest.ini', null], ['.pytest.ini', null],
|
|
224
|
+
['pyproject.toml', /^\s*\[tool\.pytest(?:\.ini_options)?\]\s*$/m], ['tox.ini', /^\s*\[pytest\]\s*$/m], ['setup.cfg', /^\s*\[tool:pytest\]\s*$/m],
|
|
225
|
+
];
|
|
226
|
+
const HEADER = /^\s*\[[A-Za-z0-9_.:\- ]+\]\s*$/;
|
|
227
|
+
/** The text of every pytest section of one file (the whole file for an ini that needs no section header but has one). */
|
|
228
|
+
function pytestSections(text) {
|
|
229
|
+
const out = [];
|
|
230
|
+
let on = false;
|
|
231
|
+
let cur = [];
|
|
232
|
+
for (const line of text.split(/\r\n|\r|\n/)) {
|
|
233
|
+
if (HEADER.test(line)) {
|
|
234
|
+
if (on)
|
|
235
|
+
out.push(cur.join('\n'));
|
|
236
|
+
on = /^\s*\[(?:pytest|tool:pytest|tool\.pytest|tool\.pytest\.ini_options)\]\s*$/.test(line);
|
|
237
|
+
cur = [];
|
|
238
|
+
}
|
|
239
|
+
else if (on)
|
|
240
|
+
cur.push(line);
|
|
241
|
+
}
|
|
242
|
+
if (on)
|
|
243
|
+
out.push(cur.join('\n'));
|
|
244
|
+
return out;
|
|
245
|
+
}
|
|
246
|
+
const dirsUp = (unitDir) => { const out = [unitDir]; let d = unitDir; while (d !== '') {
|
|
247
|
+
d = d.includes('/') ? d.slice(0, d.lastIndexOf('/')) : '';
|
|
248
|
+
out.push(d);
|
|
249
|
+
} return out; };
|
|
250
|
+
/**
|
|
251
|
+
* @implements A-SPEC-128.14 — P1: the configuration file pytest would choose for a unit, searched in HEAD from the unit
|
|
252
|
+
* up to the run root (never above it), as an absolute path; null when HEAD has none.
|
|
253
|
+
*/
|
|
254
|
+
function pytestInifile(runRoot, unitDir) {
|
|
255
|
+
for (const d of dirsUp(unitDir)) {
|
|
256
|
+
for (const [name, needs] of PYTEST_FILES) {
|
|
257
|
+
const abs = path.join(runRoot, ...(d === '' ? [] : d.split('/')), name);
|
|
258
|
+
let text;
|
|
259
|
+
try {
|
|
260
|
+
text = fs.readFileSync(abs, 'utf8');
|
|
261
|
+
}
|
|
262
|
+
catch {
|
|
263
|
+
continue;
|
|
264
|
+
}
|
|
265
|
+
if (needs === null || needs.test(text))
|
|
266
|
+
return abs;
|
|
267
|
+
}
|
|
268
|
+
}
|
|
269
|
+
return null;
|
|
270
|
+
}
|
|
271
|
+
/**
|
|
272
|
+
* P2: a short-option cluster read left to right — k or m selects; a value-taking option (c, n, o, p, r, W) ends the
|
|
273
|
+
* cluster, so `-Wmodule`, `-pmypkg` and `-o` values are not selections (A-SPEC-128.15 P3) — or a long option that selects
|
|
274
|
+
* or reorders by history.
|
|
275
|
+
*/
|
|
276
|
+
function shortSelection(text) {
|
|
277
|
+
for (const m of text.matchAll(/(?:^|[\s"'[,=])-([A-Za-z][A-Za-z0-9_.:-]*)/gm)) {
|
|
278
|
+
for (const ch of m[1]) {
|
|
279
|
+
if (ch === 'k' || ch === 'm')
|
|
280
|
+
return `-${m[1]}`;
|
|
281
|
+
if ('cnoprW'.includes(ch) || !/[A-Za-z]/.test(ch))
|
|
282
|
+
break;
|
|
283
|
+
}
|
|
284
|
+
}
|
|
285
|
+
return null;
|
|
286
|
+
}
|
|
287
|
+
const SELECT_LONG = /--(?:deselect|lf|last-failed|sw|stepwise|stepwise-skip)(?![A-Za-z-])/;
|
|
288
|
+
/** A key starts at column 0; an indented line continues the value (A-SPEC-128.15 P3). */
|
|
289
|
+
const KEY_LINE = /^[A-Za-z_][A-Za-z0-9_.-]*\s*[=:]/;
|
|
290
|
+
/** The addopts value of one section's text: its line and every following line up to the next key or header. */
|
|
291
|
+
function addoptsText(section) {
|
|
292
|
+
const lines = section.split('\n').filter((l) => !/^\s*[#;]/.test(l));
|
|
293
|
+
const out = [];
|
|
294
|
+
let on = false;
|
|
295
|
+
for (const l of lines) {
|
|
296
|
+
if (KEY_LINE.test(l))
|
|
297
|
+
on = /^\s*addopts\s*[=:]/.test(l);
|
|
298
|
+
if (on)
|
|
299
|
+
out.push(on && /^\s*addopts\s*[=:]/.test(l) ? l.replace(/^\s*addopts\s*[=:]/, ' ') : l);
|
|
300
|
+
}
|
|
301
|
+
return out.join('\n');
|
|
302
|
+
}
|
|
303
|
+
/**
|
|
304
|
+
* @implements A-SPEC-128.14 — P2 (conservative): a selection in the addopts of ANY pytest configuration file at the unit
|
|
305
|
+
* or above it within the run root — the text searched, not parsed, so continuation lines, TOML strings and multi-line
|
|
306
|
+
* arrays are all covered. A section a pytest.ini shadows still counts (a named over-block). Null when none.
|
|
307
|
+
*/
|
|
308
|
+
function pytestSelection(runRoot, unitDir) {
|
|
309
|
+
for (const d of dirsUp(unitDir)) {
|
|
310
|
+
for (const [name] of PYTEST_FILES) {
|
|
311
|
+
const rel = d === '' ? name : `${d}/${name}`;
|
|
312
|
+
let text;
|
|
313
|
+
try {
|
|
314
|
+
text = fs.readFileSync(path.join(runRoot, ...rel.split('/')), 'utf8');
|
|
315
|
+
}
|
|
316
|
+
catch {
|
|
317
|
+
continue;
|
|
318
|
+
}
|
|
319
|
+
for (const s of pytestSections(text)) {
|
|
320
|
+
const a = addoptsText(s);
|
|
321
|
+
const m = shortSelection(a) ?? SELECT_LONG.exec(a)?.[0] ?? null;
|
|
322
|
+
if (m)
|
|
323
|
+
return `a selection in ${rel} addopts (${m.trim()}) — 0.40.x evidences a run of every collected test`;
|
|
324
|
+
}
|
|
325
|
+
}
|
|
326
|
+
}
|
|
327
|
+
return null;
|
|
328
|
+
}
|
|
329
|
+
/**
|
|
330
|
+
* @implements A-SPEC-128.14 — V1: GOFLAGS that select tests narrow a full go run.
|
|
331
|
+
* @implements A-SPEC-128.15 — O3: go's own value (`go env GOFLAGS`, so a GOENV file counts), and the -test.run spelling.
|
|
332
|
+
*/
|
|
333
|
+
function goflagsSelection(unitDir, env = process.env) {
|
|
334
|
+
let flags = env.GOFLAGS ?? '';
|
|
335
|
+
try {
|
|
336
|
+
flags = (0, node_child_process_1.execFileSync)('go', ['env', 'GOFLAGS'], { cwd: unitDir, env, encoding: 'utf8', timeout: 30_000, stdio: ['ignore', 'pipe', 'ignore'] }).trim();
|
|
337
|
+
}
|
|
338
|
+
catch { /* go cannot answer: the variable */ }
|
|
339
|
+
return /(?:^|\s)--?(?:test\.)?(?:run|skip)(?:=|\s|$)/.test(flags) ? `GOFLAGS selects tests (${flags.trim()}) — 0.40.x evidences a run of every test` : null;
|
|
340
|
+
}
|
|
341
|
+
const dirOf = (rel) => (rel.includes('/') ? rel.slice(0, rel.lastIndexOf('/')) : '');
|
|
342
|
+
const under = (rel, dir) => dir === '' || rel === dir || rel.startsWith(`${dir}/`);
|
|
343
|
+
/**
|
|
344
|
+
* @implements A-SPEC-128.10 — I4: the file universe is what git sees — tracked and untracked files minus what the
|
|
345
|
+
* project's ignore rules (every `.gitignore`, info/exclude, the global file) leave out; tracked files under an ignore
|
|
346
|
+
* pattern stay in. `ignored` is git's own list of ignored untracked paths (directories collapsed, ending in `/`), the
|
|
347
|
+
* runners' skip list. Without git, a walk with the injected matcher stands in.
|
|
348
|
+
* @implements A-SPEC-128.11 — P4: an entry git lists that is a directory (a gitlink, mode 160000, or an untracked nested
|
|
349
|
+
* repository) is a submodule: returned apart, never a file. P6: entries tagged `S` (skip-worktree) are returned apart.
|
|
350
|
+
*/
|
|
351
|
+
function projectFiles(cwd, isIgnored) {
|
|
352
|
+
const git = (args) => (0, node_child_process_1.execFileSync)('git', ['-C', cwd, ...args], {
|
|
353
|
+
encoding: 'utf8', maxBuffer: 512 * 1024 * 1024, timeout: bounded_io_1.GIT_TIMEOUT_MS * 4, env: (0, root_1.cleanSubprocessEnv)(), stdio: ['ignore', 'pipe', 'ignore'],
|
|
354
|
+
}).split('\0').filter(Boolean);
|
|
355
|
+
try {
|
|
356
|
+
// `-t` tags each entry: `S` skip-worktree, `H`/`?`/others present or untracked
|
|
357
|
+
const tagged = git(['ls-files', '-t', '--cached', '--others', '--exclude-standard', '-z']).map((e) => ({ tag: e.slice(0, 1), rel: e.slice(2) }));
|
|
358
|
+
const ignored = git(['ls-files', '--others', '--ignored', '--exclude-standard', '--directory', '-z'])
|
|
359
|
+
.filter((p) => !p.split('/').includes('node_modules') && !p.startsWith('.git/'));
|
|
360
|
+
const skipWorktree = tagged.filter((t) => t.tag === 'S').map((t) => t.rel);
|
|
361
|
+
const present = [];
|
|
362
|
+
const submodules = [];
|
|
363
|
+
for (const { tag, rel } of tagged) {
|
|
364
|
+
if (tag === 'S')
|
|
365
|
+
continue;
|
|
366
|
+
const abs = path.join(cwd, rel);
|
|
367
|
+
let st;
|
|
368
|
+
try {
|
|
369
|
+
st = fs.lstatSync(abs);
|
|
370
|
+
}
|
|
371
|
+
catch {
|
|
372
|
+
continue;
|
|
373
|
+
}
|
|
374
|
+
// a real directory only: a tracked symbolic link stays a file, as before (and a dangling one is not present)
|
|
375
|
+
if (st.isDirectory())
|
|
376
|
+
submodules.push(rel.replace(/\/+$/, ''));
|
|
377
|
+
else if (!st.isSymbolicLink() || fs.existsSync(abs))
|
|
378
|
+
present.push(rel);
|
|
379
|
+
}
|
|
380
|
+
// a git that lists no file that exists has not described this tree (an empty answer, a stand-in binary): walk it
|
|
381
|
+
if (present.length > 0)
|
|
382
|
+
return { files: present, ignored, source: 'git', submodules: [...new Set(submodules)], skipWorktree };
|
|
383
|
+
}
|
|
384
|
+
catch { /* not a git work tree, or git could not answer: the walk below */ }
|
|
385
|
+
const files = [];
|
|
386
|
+
const ignored = [];
|
|
387
|
+
const walk = (dir, rel, depth) => {
|
|
388
|
+
if (depth > 24)
|
|
389
|
+
return;
|
|
390
|
+
let entries;
|
|
391
|
+
try {
|
|
392
|
+
entries = fs.readdirSync(dir, { withFileTypes: true });
|
|
393
|
+
}
|
|
394
|
+
catch {
|
|
395
|
+
return;
|
|
396
|
+
}
|
|
397
|
+
for (const e of entries) {
|
|
398
|
+
const relPath = rel === '' ? e.name : `${rel}/${e.name}`;
|
|
399
|
+
if (e.isDirectory()) {
|
|
400
|
+
if (WALK_SKIP.has(e.name))
|
|
401
|
+
continue;
|
|
402
|
+
if (isIgnored(relPath) || isIgnored(`${relPath}/`)) {
|
|
403
|
+
ignored.push(`${relPath}/`);
|
|
404
|
+
continue;
|
|
405
|
+
}
|
|
406
|
+
walk(path.join(dir, e.name), relPath, depth + 1);
|
|
407
|
+
}
|
|
408
|
+
else if (e.isFile()) {
|
|
409
|
+
if (isIgnored(relPath))
|
|
410
|
+
ignored.push(relPath);
|
|
411
|
+
else
|
|
412
|
+
files.push(relPath);
|
|
413
|
+
}
|
|
414
|
+
}
|
|
415
|
+
};
|
|
416
|
+
walk(cwd, '', 0);
|
|
417
|
+
return { files, ignored, source: 'walk', submodules: [], skipWorktree: [] };
|
|
418
|
+
}
|
|
419
|
+
/**
|
|
420
|
+
* @implements A-SPEC-128.9, A-SPEC-128.10 — what exists, listed once: units, the tests each must report, code by build
|
|
421
|
+
* root, and the trees left out. No verdict is formed here.
|
|
422
|
+
*
|
|
423
|
+
* Units (I5):
|
|
424
|
+
* - jest: the nearest ancestor with its own jest configuration (`jest.config.*`, or a package.json `jest` field), else
|
|
425
|
+
* the root; a configured child is its own unit and its parent skips it;
|
|
426
|
+
* - pytest: the nearest ancestor with pytest configuration (`pytest.ini`, pyproject `[tool.pytest`, setup.cfg
|
|
427
|
+
* `[tool:pytest]`, tox.ini `[pytest]`), else the root; a configured child is skipped by its parent;
|
|
428
|
+
* - go: the nearest `go.mod` holding go sources;
|
|
429
|
+
* - rust, java, dotnet: the nearest build root holding test files of their language.
|
|
430
|
+
*/
|
|
431
|
+
function scanEcosystems(cwd, opts = {}) {
|
|
432
|
+
const excludeDirs = opts.excludeDirs ?? [];
|
|
433
|
+
const isIgnored = opts.isIgnored ?? (() => false);
|
|
434
|
+
const listed = projectFiles(cwd, isIgnored);
|
|
435
|
+
const read = (rel, max = 65536) => {
|
|
436
|
+
try {
|
|
437
|
+
const fd = fs.openSync(path.join(cwd, rel), 'r');
|
|
438
|
+
try {
|
|
439
|
+
const b = Buffer.alloc(max);
|
|
440
|
+
const n = fs.readSync(fd, b, 0, b.length, 0);
|
|
441
|
+
return b.subarray(0, n).toString('utf8');
|
|
442
|
+
}
|
|
443
|
+
finally {
|
|
444
|
+
fs.closeSync(fd);
|
|
445
|
+
}
|
|
446
|
+
}
|
|
447
|
+
catch {
|
|
448
|
+
return '';
|
|
449
|
+
}
|
|
450
|
+
};
|
|
451
|
+
// the universe: git's files, minus node_modules, hidden directories, virtualenvs and the user's excludeDirs
|
|
452
|
+
// @implements A-SPEC-128.11 — P7: each directory's fate is decided once (memoised), not once per file under it
|
|
453
|
+
const excludedTrees = new Set();
|
|
454
|
+
const venvDirs = new Set(listed.files.filter((f) => path.posix.basename(f) === 'pyvenv.cfg').map(dirOf));
|
|
455
|
+
const validExcludes = normaliseExcludeDirs(excludeDirs).valid;
|
|
456
|
+
const fateOf = new Map(); // false: kept; null: dropped unnamed; a tree: excluded
|
|
457
|
+
const dirFate = (d) => {
|
|
458
|
+
const known = fateOf.get(d);
|
|
459
|
+
if (known !== undefined)
|
|
460
|
+
return known;
|
|
461
|
+
let v = false;
|
|
462
|
+
if (d !== '') {
|
|
463
|
+
const up = dirFate(dirOf(d));
|
|
464
|
+
const name = path.posix.basename(d);
|
|
465
|
+
if (up !== false)
|
|
466
|
+
v = up;
|
|
467
|
+
else if (name === 'node_modules' || name.startsWith('.') || venvDirs.has(d))
|
|
468
|
+
v = null;
|
|
469
|
+
else if (validExcludes.some((e) => (e.kind === 'path' ? d === e.value || d.startsWith(`${e.value}/`) : name === e.value)))
|
|
470
|
+
v = `${d}/`;
|
|
471
|
+
}
|
|
472
|
+
fateOf.set(d, v);
|
|
473
|
+
return v;
|
|
474
|
+
};
|
|
475
|
+
const files = listed.files.filter((f) => {
|
|
476
|
+
const fate = dirFate(dirOf(f));
|
|
477
|
+
if (fate === false)
|
|
478
|
+
return true;
|
|
479
|
+
if (fate !== null)
|
|
480
|
+
excludedTrees.add(fate);
|
|
481
|
+
return false;
|
|
482
|
+
});
|
|
483
|
+
// @implements A-SPEC-128.11 — P4: a git submodule is an excluded tree, named; its tests are another repository's
|
|
484
|
+
// @implements A-SPEC-128.12 — S6: always, whatever excludeDirs says (an entry naming the gitlink dropped it, R3)
|
|
485
|
+
// @implements A-SPEC-128.13 — T3: whatever its directory's name too (a gitlink under .deps/ was dropped)
|
|
486
|
+
const submodules = listed.submodules;
|
|
487
|
+
for (const s of submodules)
|
|
488
|
+
excludedTrees.add(`${s}/`);
|
|
489
|
+
const excluded = [...new Set([...listed.ignored, ...excludedTrees])].sort();
|
|
490
|
+
const names = new Map(); // dir → file names in it
|
|
491
|
+
for (const f of files) {
|
|
492
|
+
const d = dirOf(f);
|
|
493
|
+
if (!names.has(d))
|
|
494
|
+
names.set(d, new Set());
|
|
495
|
+
names.get(d).add(path.posix.basename(f));
|
|
496
|
+
}
|
|
497
|
+
const markers = new Map();
|
|
498
|
+
for (const [d, set] of names)
|
|
499
|
+
for (const n of set) {
|
|
500
|
+
const hit = exports.BUILD_ROOTS.find((b) => b.re.test(n));
|
|
501
|
+
if (!hit)
|
|
502
|
+
continue;
|
|
503
|
+
if (!markers.has(d))
|
|
504
|
+
markers.set(d, new Map());
|
|
505
|
+
if (!markers.get(d).has(hit.ecosystem))
|
|
506
|
+
markers.get(d).set(hit.ecosystem, n);
|
|
507
|
+
}
|
|
508
|
+
const join = (d, n) => (d === '' ? n : `${d}/${n}`);
|
|
509
|
+
const jestConfigDirs = new Set();
|
|
510
|
+
const pytestConfigDirs = new Set();
|
|
511
|
+
for (const [d, set] of names) {
|
|
512
|
+
if ([...set].some((n) => JEST_CONFIG.test(n)))
|
|
513
|
+
jestConfigDirs.add(d);
|
|
514
|
+
if (set.has('package.json')) {
|
|
515
|
+
try {
|
|
516
|
+
if (JSON.parse(read(join(d, 'package.json'))).jest !== undefined)
|
|
517
|
+
jestConfigDirs.add(d);
|
|
518
|
+
}
|
|
519
|
+
catch { /* not a config */ }
|
|
520
|
+
}
|
|
521
|
+
if (set.has('pytest.ini')
|
|
522
|
+
|| (set.has('pyproject.toml') && read(join(d, 'pyproject.toml')).includes('[tool.pytest'))
|
|
523
|
+
|| (set.has('setup.cfg') && read(join(d, 'setup.cfg')).includes('[tool:pytest]'))
|
|
524
|
+
|| (set.has('tox.ini') && /^\s*\[(pytest|tool:pytest)\]/m.test(read(join(d, 'tox.ini')))))
|
|
525
|
+
pytestConfigDirs.add(d);
|
|
526
|
+
}
|
|
527
|
+
// @implements A-SPEC-128.11 — P7: a nearest-root lookup per set, memoised by directory
|
|
528
|
+
const nearestBy = new Map();
|
|
529
|
+
const nearestDir = (d, dirs) => {
|
|
530
|
+
let memo = nearestBy.get(dirs);
|
|
531
|
+
if (!memo) {
|
|
532
|
+
memo = new Map();
|
|
533
|
+
nearestBy.set(dirs, memo);
|
|
534
|
+
}
|
|
535
|
+
const known = memo.get(d);
|
|
536
|
+
if (known !== undefined)
|
|
537
|
+
return known;
|
|
538
|
+
const v = dirs.has(d) ? d : d === '' ? null : nearestDir(dirOf(d), dirs);
|
|
539
|
+
memo.set(d, v);
|
|
540
|
+
return v;
|
|
541
|
+
};
|
|
542
|
+
const nearestIn = (rel, dirs) => nearestDir(dirOf(rel), dirs);
|
|
543
|
+
const markerDirsOf = new Map();
|
|
544
|
+
const markerDirs = (eco) => {
|
|
545
|
+
let s = markerDirsOf.get(eco);
|
|
546
|
+
if (!s) {
|
|
547
|
+
s = new Set([...markers].filter(([, m]) => m.has(eco)).map(([d]) => d));
|
|
548
|
+
markerDirsOf.set(eco, s);
|
|
549
|
+
}
|
|
550
|
+
return s;
|
|
551
|
+
};
|
|
552
|
+
// test files of each language
|
|
553
|
+
const jestTests = files.filter((f) => JEST_TEST.test(f) || (f.split('/').includes('__tests__') && JS_FILE.test(f) && !f.endsWith('.d.ts')));
|
|
554
|
+
const jestOwner = (f) => nearestIn(f, jestConfigDirs) ?? '';
|
|
555
|
+
const pyOwner = (f) => nearestIn(f, pytestConfigDirs) ?? '';
|
|
556
|
+
const rulesOf = new Map();
|
|
557
|
+
const rules = (owner) => { if (!rulesOf.has(owner))
|
|
558
|
+
rulesOf.set(owner, pytestRules(path.join(cwd, owner))); return rulesOf.get(owner); };
|
|
559
|
+
const notTests = [];
|
|
560
|
+
const anyRoot = new Set([...markers.keys(), ...jestConfigDirs]);
|
|
561
|
+
// @implements A-SPEC-128.11 — P1: the expected python tests are the default names plus a declared `python_files`; a
|
|
562
|
+
// runner rule (testpaths, a narrower python_files) never removes a file, so a test it leaves uncollected is named by
|
|
563
|
+
// the comparison after the run, as collect
|
|
564
|
+
const pyTests = files.filter((f) => {
|
|
565
|
+
if (!f.endsWith('.py'))
|
|
566
|
+
return false;
|
|
567
|
+
const owner = pyOwner(f);
|
|
568
|
+
const declared = rules(owner)?.pythonFiles ?? null;
|
|
569
|
+
if (![...DEFAULT_PY_FILES, ...(declared ?? [])].map(globToRe).some((re) => re.test(path.posix.basename(f))))
|
|
570
|
+
return false;
|
|
571
|
+
// @implements A-SPEC-128.13 — pytest's own default: it never recurses into build/, dist/, venv/, .x/ and the rest
|
|
572
|
+
if ((owner === '' ? f : f.slice(owner.length + 1)).split('/').slice(0, -1).some(PY_NORECURSE))
|
|
573
|
+
return false;
|
|
574
|
+
// under no declared python_files, a test-named file holding no test function is not a test: named, never required
|
|
575
|
+
if (declared === null && !/^\s*(async\s+)?def\s+test|^\s*class\s+Test/m.test(read(f))) {
|
|
576
|
+
notTests.push(f);
|
|
577
|
+
return false;
|
|
578
|
+
}
|
|
579
|
+
return true;
|
|
580
|
+
});
|
|
581
|
+
// @implements A-SPEC-128.11 — P5: the go tool builds no testdata/, _x/ or .x/ directory; a _test.go with no test
|
|
582
|
+
// function runs nothing and is not a test (named)
|
|
583
|
+
const moduleVendor = (f) => {
|
|
584
|
+
const m = nearestIn(f, markerDirs('go'));
|
|
585
|
+
return m !== null && (m === '' ? f : f.slice(m.length + 1)).startsWith('vendor/');
|
|
586
|
+
};
|
|
587
|
+
const goFiles = files.filter((f) => f.endsWith('.go') && !goSkipped(f) && !moduleVendor(f) && goFileForHost(f));
|
|
588
|
+
const goTests = goFiles.filter((f) => {
|
|
589
|
+
if (!f.endsWith('_test.go'))
|
|
590
|
+
return false;
|
|
591
|
+
if (GO_TEST_FUNC.test(read(f, 1 << 20)))
|
|
592
|
+
return true;
|
|
593
|
+
notTests.push(f);
|
|
594
|
+
return false;
|
|
595
|
+
});
|
|
596
|
+
const javaFiles = files.filter((f) => /\.(java|kt|groovy|scala)$/.test(f));
|
|
597
|
+
const javaTests = javaFiles.filter((f) => /(^|\/)src\/test\//.test(f) || /(Test|Tests|Spec|IT)\.(java|kt|groovy|scala)$/.test(f));
|
|
598
|
+
const rsFiles = files.filter((f) => f.endsWith('.rs'));
|
|
599
|
+
const rsTests = rsFiles.filter((f) => f.split('/').includes('tests') || /#\[(cfg\()?test\)?\]/.test(read(f)));
|
|
600
|
+
const csFiles = files.filter((f) => f.endsWith('.cs'));
|
|
601
|
+
const csTests = csFiles.filter((f) => /Tests?\.cs$/.test(f) || [...(names.get(nearestIn(f, markerDirs('dotnet')) ?? '\0') ?? [])].some((n) => /test/i.test(n) && n.endsWith('.csproj')));
|
|
602
|
+
// units
|
|
603
|
+
const unitMap = new Map();
|
|
604
|
+
const addTo = (ecosystem, dir, file) => {
|
|
605
|
+
if (dir === null)
|
|
606
|
+
return;
|
|
607
|
+
const k = `${ecosystem}@${dir}`;
|
|
608
|
+
if (!unitMap.has(k))
|
|
609
|
+
unitMap.set(k, { ecosystem, dir, files: [] });
|
|
610
|
+
if (file)
|
|
611
|
+
unitMap.get(k).files.push(file);
|
|
612
|
+
};
|
|
613
|
+
for (const f of jestTests)
|
|
614
|
+
addTo('jest', jestOwner(f), f);
|
|
615
|
+
for (const f of pyTests)
|
|
616
|
+
addTo('pytest', pyOwner(f), f);
|
|
617
|
+
const goMods = markerDirs('go');
|
|
618
|
+
const goTestSet = new Set(goTests);
|
|
619
|
+
for (const f of goFiles)
|
|
620
|
+
addTo('go', nearestIn(f, goMods), goTestSet.has(f) ? f : undefined);
|
|
621
|
+
for (const [eco, tests] of [['rust', rsTests], ['java', javaTests], ['dotnet', csTests]]) {
|
|
622
|
+
const roots = markerDirs(eco);
|
|
623
|
+
for (const f of tests)
|
|
624
|
+
addTo(eco, nearestIn(f, roots), f);
|
|
625
|
+
}
|
|
626
|
+
const unitList = [...unitMap.values()].sort((a, b) => (a.ecosystem === b.ecosystem ? a.dir.localeCompare(b.dir) : a.ecosystem.localeCompare(b.ecosystem)));
|
|
627
|
+
const units = unitList.map((u) => {
|
|
628
|
+
const children = unitList.filter((c) => c.ecosystem === u.ecosystem && c.dir !== u.dir && under(c.dir, u.dir)).map((c) => `${c.dir}/`);
|
|
629
|
+
const skip = [...children, ...excluded].filter((x) => u.dir === '' || x.startsWith(`${u.dir}/`)).map((x) => (u.dir === '' ? x : x.slice(u.dir.length + 1)));
|
|
630
|
+
return { ecosystem: u.ecosystem, dir: u.dir, ignore: [...new Set(skip)] };
|
|
631
|
+
});
|
|
632
|
+
// I3's list: a jest or pytest unit reports per file; go credits each package's tests to its _test.go files
|
|
633
|
+
const expected = {};
|
|
634
|
+
for (const u of unitList)
|
|
635
|
+
if (u.ecosystem === 'jest' || u.ecosystem === 'pytest' || u.ecosystem === 'go')
|
|
636
|
+
expected[`${u.ecosystem}@${u.dir}`] = [...u.files].sort();
|
|
637
|
+
// R2: implementation code by the nearest build root of any kind; a language that needs a build file names it
|
|
638
|
+
const testSet = new Set([...jestTests, ...pyTests, ...goTests, ...javaTests, ...rsTests, ...csTests, ...notTests]);
|
|
639
|
+
const groups = new Map();
|
|
640
|
+
for (const f of files) {
|
|
641
|
+
const base = path.posix.basename(f);
|
|
642
|
+
if (testSet.has(f) || CONFIG_FILE.test(base) || (base.endsWith('.go') && goSkipped(f)))
|
|
643
|
+
continue;
|
|
644
|
+
const src = SOURCE_ECO.find(([re]) => re.test(base));
|
|
645
|
+
if (!src)
|
|
646
|
+
continue;
|
|
647
|
+
const root = nearestIn(f, anyRoot) ?? '';
|
|
648
|
+
if (!groups.has(root))
|
|
649
|
+
groups.set(root, { root, count: 0, sample: [] });
|
|
650
|
+
const g = groups.get(root);
|
|
651
|
+
g.count++;
|
|
652
|
+
if (g.sample.length < 3)
|
|
653
|
+
g.sample.push(f);
|
|
654
|
+
const needs = BUILD_FILE_OF[src[1]];
|
|
655
|
+
if (needs && !g.missingBuildFile && nearestIn(f, markerDirs(src[1])) === null)
|
|
656
|
+
g.missingBuildFile = needs;
|
|
657
|
+
}
|
|
658
|
+
const codeRoots = [...groups.values()].sort((a, b) => a.root.localeCompare(b.root));
|
|
659
|
+
const implementation = codeRoots.flatMap((g) => g.sample);
|
|
660
|
+
const implementationCount = codeRoots.reduce((a, g) => a + g.count, 0);
|
|
661
|
+
const detected = [...new Set(units.map((u) => u.ecosystem))].sort();
|
|
662
|
+
const detectedBy = {};
|
|
663
|
+
for (const u of unitList) {
|
|
664
|
+
if (detectedBy[u.ecosystem])
|
|
665
|
+
continue;
|
|
666
|
+
const marker = markers.get(u.dir)?.get(u.ecosystem);
|
|
667
|
+
detectedBy[u.ecosystem] = marker ? join(u.dir, marker) : u.files[0] ?? u.dir;
|
|
668
|
+
}
|
|
669
|
+
const notDetected = [];
|
|
670
|
+
if (names.get('')?.has('go.work') && !detected.includes('go')) {
|
|
671
|
+
notDetected.push({ path: 'go.work', ecosystem: 'go', reason: 'a go workspace with no member module holding go sources' });
|
|
672
|
+
}
|
|
673
|
+
for (const s of submodules)
|
|
674
|
+
notDetected.push({ path: s, ecosystem: 'git submodule', reason: 'a git submodule — outside the evidence' });
|
|
675
|
+
// @implements A-SPEC-128.11 — P6: a test file the sparse checkout left out cannot run here; the runner names it
|
|
676
|
+
const sparseTests = listed.skipWorktree.filter((f) => dirFate(dirOf(f)) === false && (JEST_TEST.test(f) || f.endsWith('_test.go')
|
|
677
|
+
|| (f.endsWith('.py') && DEFAULT_PY_FILES.map(globToRe).some((re) => re.test(path.posix.basename(f))))
|
|
678
|
+
|| (/\.(java|kt|groovy|scala|cs)$/.test(f) && /Tests?\.\w+$|(^|\/)src\/test\//.test(f)))).sort();
|
|
679
|
+
// @implements A-SPEC-128.12 — what 0.40.x does not evidence, named once each (the runner prefixes one message)
|
|
680
|
+
const outsideSurface = [];
|
|
681
|
+
// S1: a cargo, maven/gradle or dotnet build root holding tests or code. A source file of those languages under no such
|
|
682
|
+
// build root is a file of the root that holds it (this repository's CPG fixtures), as in 128.10
|
|
683
|
+
const foreign = new Map();
|
|
684
|
+
for (const u of unitList) {
|
|
685
|
+
if (u.ecosystem === 'rust' || u.ecosystem === 'java' || u.ecosystem === 'dotnet') {
|
|
686
|
+
foreign.set(`${u.ecosystem}@${u.dir}`, { ecosystem: u.ecosystem, dir: u.dir, reason: `${u.ecosystem} tests (${u.files[0]}) — 0.40.x evidences jest, pytest and go only` });
|
|
687
|
+
}
|
|
688
|
+
}
|
|
689
|
+
for (const f of files) {
|
|
690
|
+
const src = SOURCE_ECO.find(([re]) => re.test(path.posix.basename(f)));
|
|
691
|
+
if (!src || (src[1] !== 'rust' && src[1] !== 'java' && src[1] !== 'dotnet') || testSet.has(f))
|
|
692
|
+
continue;
|
|
693
|
+
const dir = nearestIn(f, markerDirs(src[1]));
|
|
694
|
+
if (dir === null)
|
|
695
|
+
continue;
|
|
696
|
+
if (!foreign.has(`${src[1]}@${dir}`))
|
|
697
|
+
foreign.set(`${src[1]}@${dir}`, { ecosystem: src[1], dir, reason: `${src[1]} code (${f}) — 0.40.x evidences jest, pytest and go only` });
|
|
698
|
+
}
|
|
699
|
+
outsideSurface.push(...[...foreign.values()].sort((a, b) => `${a.ecosystem}@${a.dir}`.localeCompare(`${b.ecosystem}@${b.dir}`)));
|
|
700
|
+
// @implements A-SPEC-128.13 — test files of a language under no build root of it: no runner can run them (A H4)
|
|
701
|
+
const rootless = [['rust', rsTests, markerDirs('rust')], ['java', javaTests, markerDirs('java')],
|
|
702
|
+
['dotnet', csTests, markerDirs('dotnet')], ['go', goTests, markerDirs('go')]];
|
|
703
|
+
for (const [eco, tests, roots] of rootless) {
|
|
704
|
+
const stray = tests.filter((f) => nearestIn(f, roots) === null);
|
|
705
|
+
if (stray.length > 0)
|
|
706
|
+
outsideSurface.push({ ecosystem: eco, dir: '', reason: `${eco} test files under no ${BUILD_FILE_OF[eco]} (${stray[0]}${stray.length > 1 ? ` and ${stray.length - 1} more` : ''})` });
|
|
707
|
+
}
|
|
708
|
+
// @implements A-SPEC-128.13 — a build file of an ecosystem 0.40.x has no runner for
|
|
709
|
+
for (const [d, set] of names)
|
|
710
|
+
for (const n of set) {
|
|
711
|
+
if (UNSUPPORTED_BUILD.test(n))
|
|
712
|
+
outsideSurface.push({ ecosystem: n, dir: d, reason: `${join(d, n)} — a build file 0.40.x has no runner for` });
|
|
713
|
+
}
|
|
714
|
+
// S2 (A-SPEC-128.13): one jest configuration source — the root's, or one configured directory's, never both; and no
|
|
715
|
+
// configuration chosen by a script's --config. A file's name alone chooses nothing (a jest.config.base.js fragment).
|
|
716
|
+
const jestRootDefault = unitList.some((u) => u.ecosystem === 'jest' && u.dir === '' && !jestConfigDirs.has(''));
|
|
717
|
+
if (jestConfigDirs.size > 1 || (jestConfigDirs.size === 1 && jestRootDefault)) {
|
|
718
|
+
const sources = [...jestConfigDirs].sort().map((d) => (d === '' ? 'the root' : d));
|
|
719
|
+
outsideSurface.push({ ecosystem: 'jest', dir: '', reason: `more than one jest configuration source (${[...(jestRootDefault ? ['jest tests at the root with no configuration'] : []), ...sources.map((s) => `${s}'s configuration`)].join(', ')}) — 0.40.x evidences one` });
|
|
720
|
+
}
|
|
721
|
+
for (const [d, set] of names) {
|
|
722
|
+
if (!set.has('package.json'))
|
|
723
|
+
continue;
|
|
724
|
+
let scripts = {};
|
|
725
|
+
try {
|
|
726
|
+
scripts = (JSON.parse(read(join(d, 'package.json'))).scripts) ?? {};
|
|
727
|
+
}
|
|
728
|
+
catch {
|
|
729
|
+
scripts = {};
|
|
730
|
+
}
|
|
731
|
+
for (const [name, cmd] of Object.entries(scripts)) {
|
|
732
|
+
const m = typeof cmd === 'string' ? JEST_SCRIPT_CONFIG.exec(cmd) : null;
|
|
733
|
+
if (m)
|
|
734
|
+
outsideSurface.push({ ecosystem: 'jest', dir: d, reason: `script "${name}" in ${join(d, 'package.json')} runs jest with --config ${m[1]}` });
|
|
735
|
+
}
|
|
736
|
+
}
|
|
737
|
+
// S3 (A-SPEC-128.13): pytest under default naming, with no selection below the file
|
|
738
|
+
for (const u of unitList) {
|
|
739
|
+
const r = u.ecosystem === 'pytest' ? rules(u.dir) : null;
|
|
740
|
+
if (!r)
|
|
741
|
+
continue;
|
|
742
|
+
const below = [r.pythonFiles ? `python_files (${r.pythonFiles.join(' ')})` : '', r.pythonFunctions ? `python_functions (${r.pythonFunctions.join(' ')})` : '',
|
|
743
|
+
r.pythonClasses ? `python_classes (${r.pythonClasses.join(' ')})` : ''].filter(Boolean);
|
|
744
|
+
if (below.length > 0)
|
|
745
|
+
outsideSurface.push({ ecosystem: 'pytest', dir: u.dir, reason: `a declared ${below.join(', ')}` });
|
|
746
|
+
}
|
|
747
|
+
// A-SPEC-128.14 P2 and V1: a selection anywhere in the unit's pytest configuration chain, and GOFLAGS that select
|
|
748
|
+
for (const u of unitList) {
|
|
749
|
+
const sel = u.ecosystem === 'pytest' ? pytestSelection(cwd, u.dir) : u.ecosystem === 'go' ? goflagsSelection(path.join(cwd, ...(u.dir === '' ? [] : u.dir.split('/'))), (0, root_1.cleanTestEnv)()) : null;
|
|
750
|
+
if (sel !== null)
|
|
751
|
+
outsideSurface.push({ ecosystem: u.ecosystem, dir: u.dir, reason: sel });
|
|
752
|
+
}
|
|
753
|
+
return {
|
|
754
|
+
detected, detectedBy, units, notDetected: notDetected.slice(0, NOT_DETECTED_CAP),
|
|
755
|
+
testFiles: [...jestTests, ...pyTests, ...goTests, ...javaTests, ...rsTests, ...csTests],
|
|
756
|
+
notTests, implementationCount, implementationSample: implementation.slice(0, 3), excluded, expected, codeRoots,
|
|
757
|
+
buildRoots: [...anyRoot].sort(), sparseTests, outsideSurface,
|
|
758
|
+
};
|
|
759
|
+
}
|
|
760
|
+
/**
|
|
761
|
+
* @implements A-SPEC-128.13 — S2's runtime half, in the same module as the static half: what `jest --showConfig` resolved
|
|
762
|
+
* that 0.40.x does not evidence — several projects, or a configured testNamePattern (a selection below the file). Null
|
|
763
|
+
* when the configuration is inside the surface.
|
|
764
|
+
*/
|
|
765
|
+
function jestConfigSurface(doc) {
|
|
766
|
+
if (doc.configs.length > 1)
|
|
767
|
+
return `jest projects (${doc.configs.length} configurations)`;
|
|
768
|
+
const g = doc.globalConfig && typeof doc.globalConfig === 'object' ? doc.globalConfig : {};
|
|
769
|
+
return typeof g.testNamePattern === 'string' && g.testNamePattern !== '' ? `jest testNamePattern ("${g.testNamePattern}")` : null;
|
|
770
|
+
}
|
|
771
|
+
/**
|
|
772
|
+
* @implements A-SPEC-128.13 — W2: go reads a go.work from any directory above it; inside HEAD's worktree that would be
|
|
773
|
+
* the work tree's own (untracked) one. Unless the repository itself holds a go.work, go runs with GOWORK=off.
|
|
774
|
+
*/
|
|
775
|
+
function goWorkEnv(root) {
|
|
776
|
+
return fs.existsSync(path.join(root, 'go.work')) ? {} : { GOWORK: 'off' };
|
|
777
|
+
}
|
|
778
|
+
/**
|
|
779
|
+
* @implements A-SPEC-128.13 — T4: the _test.go files `go list -e` names for one module on this platform with no tags
|
|
780
|
+
* (TestGoFiles and XTestGoFiles), root-relative, and the ones it leaves out (IgnoredGoFiles). Null when go cannot say.
|
|
781
|
+
*/
|
|
782
|
+
function goListTests(root, unitDir) {
|
|
783
|
+
const cwd = unitDir === '' ? root : path.join(root, unitDir);
|
|
784
|
+
let out;
|
|
785
|
+
try {
|
|
786
|
+
out = (0, node_child_process_1.execFileSync)('go', ['list', '-e', '-f', '{{.Dir}}\t{{join .TestGoFiles ","}}\t{{join .XTestGoFiles ","}}\t{{join .IgnoredGoFiles ","}}', './...'], { cwd, encoding: 'utf8', timeout: 120_000, maxBuffer: 64 * 1024 * 1024, env: { ...(0, root_1.cleanSubprocessEnv)(), ...goWorkEnv(root) }, stdio: ['ignore', 'pipe', 'ignore'] });
|
|
787
|
+
}
|
|
788
|
+
catch (e) {
|
|
789
|
+
out = e.stdout ?? '';
|
|
790
|
+
if (out === '')
|
|
791
|
+
return null;
|
|
792
|
+
}
|
|
793
|
+
const base = fs.realpathSync(root);
|
|
794
|
+
const built = new Set();
|
|
795
|
+
const ignored = [];
|
|
796
|
+
for (const line of out.split('\n')) {
|
|
797
|
+
const [dir, tests, xtests, ign] = line.split('\t');
|
|
798
|
+
if (!dir)
|
|
799
|
+
continue;
|
|
800
|
+
let rel;
|
|
801
|
+
try {
|
|
802
|
+
rel = path.relative(base, fs.realpathSync(dir)).split(path.sep).join('/');
|
|
803
|
+
}
|
|
804
|
+
catch {
|
|
805
|
+
continue;
|
|
806
|
+
}
|
|
807
|
+
const at = (f) => (rel === '' ? f : `${rel}/${f}`);
|
|
808
|
+
for (const f of [...(tests ?? '').split(','), ...(xtests ?? '').split(',')].filter(Boolean))
|
|
809
|
+
built.add(at(f));
|
|
810
|
+
for (const f of (ign ?? '').split(',').filter((x) => x.endsWith('_test.go')))
|
|
811
|
+
ignored.push(at(f));
|
|
812
|
+
}
|
|
813
|
+
return { built, ignored };
|
|
814
|
+
}
|