@diffci.com/diffci 0.3.55 → 0.3.57
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/dist-client/src/client/cli.js +4 -3
- package/dist-client/src/client/context.d.ts +2 -0
- package/dist-client/src/client/context.js +19 -0
- package/dist-client/src/client/full-command.js +5 -2
- package/dist-client/src/client/gate-checks.d.ts +5 -2
- package/dist-client/src/client/gate-checks.js +60 -5
- package/dist-client/src/client/gate.js +24 -10
- package/dist-client/src/client/job-summary.d.ts +1 -1
- package/dist-client/src/client/job-summary.js +2 -1
- package/dist-client/src/client/observe.js +1 -1
- package/dist-client/src/client/report.d.ts +7 -0
- package/dist-client/src/client/report.js +11 -0
- package/dist-client/src/client/workflow-guard.js +27 -6
- package/dist-client/src/client/workflow-templates.d.ts +11 -1
- package/dist-client/src/client/workflow-templates.js +43 -2
- package/node_modules/@diffci.com/core/README.md +6 -6
- package/node_modules/@diffci.com/core/dist/ci-inference/resolve.js +20 -2
- package/node_modules/@diffci.com/core/dist/ci-inference/resolve.js.map +1 -1
- package/node_modules/@diffci.com/core/dist/git/git-diff.js +49 -12
- package/node_modules/@diffci.com/core/dist/git/git-diff.js.map +1 -1
- package/node_modules/@diffci.com/core/dist/planner/python-checks.d.ts +55 -0
- package/node_modules/@diffci.com/core/dist/planner/python-checks.js +258 -0
- package/node_modules/@diffci.com/core/dist/planner/python-checks.js.map +1 -0
- package/node_modules/@diffci.com/core/dist/repo/adapters/maven.js +51 -8
- package/node_modules/@diffci.com/core/dist/repo/adapters/maven.js.map +1 -1
- package/node_modules/@diffci.com/core/dist/repo/adapters/python.js +111 -14
- package/node_modules/@diffci.com/core/dist/repo/adapters/python.js.map +1 -1
- package/node_modules/@diffci.com/core/dist/repo/adapters/rust-invocation.d.ts +3 -1
- package/node_modules/@diffci.com/core/dist/repo/adapters/rust-invocation.js +44 -6
- package/node_modules/@diffci.com/core/dist/repo/adapters/rust-invocation.js.map +1 -1
- package/node_modules/@diffci.com/core/dist/repo/adapters/rust.js +158 -9
- package/node_modules/@diffci.com/core/dist/repo/adapters/rust.js.map +1 -1
- package/node_modules/@diffci.com/core/dist/repo/adapters/types.d.ts +3 -0
- package/node_modules/@diffci.com/core/dist/repo/adapters/types.js.map +1 -1
- package/node_modules/@diffci.com/core/dist/repo/graph.js +1 -1
- package/node_modules/@diffci.com/core/dist/repo/graph.js.map +1 -1
- package/node_modules/@diffci.com/core/dist/repo/impact.js +5 -1
- package/node_modules/@diffci.com/core/dist/repo/impact.js.map +1 -1
- package/node_modules/@diffci.com/core/dist/repo/yarn-berry-lockfile.d.ts +11 -0
- package/node_modules/@diffci.com/core/dist/repo/yarn-berry-lockfile.js +208 -0
- package/node_modules/@diffci.com/core/dist/repo/yarn-berry-lockfile.js.map +1 -0
- package/node_modules/@diffci.com/core/dist/repo/yarn-lockfile.d.ts +3 -0
- package/node_modules/@diffci.com/core/dist/repo/yarn-lockfile.js +2 -2
- package/node_modules/@diffci.com/core/dist/repo/yarn-lockfile.js.map +1 -1
- package/node_modules/@diffci.com/core/src/ci-inference/resolve.ts +20 -2
- package/node_modules/@diffci.com/core/src/git/git-diff.ts +44 -12
- package/node_modules/@diffci.com/core/src/planner/python-checks.ts +244 -0
- package/node_modules/@diffci.com/core/src/repo/adapters/maven.ts +55 -8
- package/node_modules/@diffci.com/core/src/repo/adapters/python.ts +86 -14
- package/node_modules/@diffci.com/core/src/repo/adapters/rust-invocation.ts +44 -6
- package/node_modules/@diffci.com/core/src/repo/adapters/rust.ts +129 -9
- package/node_modules/@diffci.com/core/src/repo/adapters/types.ts +3 -0
- package/node_modules/@diffci.com/core/src/repo/graph.ts +1 -1
- package/node_modules/@diffci.com/core/src/repo/impact.ts +3 -1
- package/node_modules/@diffci.com/core/src/repo/yarn-berry-lockfile.ts +178 -0
- package/node_modules/@diffci.com/core/src/repo/yarn-lockfile.ts +2 -2
- package/package.json +2 -2
|
@@ -0,0 +1,258 @@
|
|
|
1
|
+
// SPDX-License-Identifier: MIT
|
|
2
|
+
/**
|
|
3
|
+
* Python gate checks read from CI workflows (2026-11-18).
|
|
4
|
+
*
|
|
5
|
+
* WHY. The gate (pipeline-steps.ts) is read from package.json scripts, so a Python repository had no
|
|
6
|
+
* checks at all. A sweep of public CI history found PRs that went red only on a Python type check: in
|
|
7
|
+
* langgenius/dify, 4 of 28 red PRs failed only in `make type-check-core` (pyrefly), each on a file the PR
|
|
8
|
+
* changed. Test selection cannot catch those. This module names the Python checks CI runs so verify can
|
|
9
|
+
* run them before the push.
|
|
10
|
+
*
|
|
11
|
+
* THE RULE. A check is a GitHub Actions `run` line that is exactly one of:
|
|
12
|
+
*
|
|
13
|
+
* - `make [-C dir] <target>` where the target is check-named (`check*`, `lint*`, `type-check*`,
|
|
14
|
+
* `typecheck*`, `mypy*`, `pyright*`, `pyrefly*`, `ruff*`, `validate*`) and the Makefile defines it with
|
|
15
|
+
* a recipe that does not rewrite files (`--fix`, `ruff format` or `black`/`isort` without a check flag);
|
|
16
|
+
* - a direct `mypy`, `pyright`, `basedpyright`, `pyrefly check`, `ruff check` or `ruff format --check`
|
|
17
|
+
* call, optionally behind `uv run`, `poetry run`, `pdm run`, `hatch run`, `pipenv run` or `python -m`,
|
|
18
|
+
* whose every argument is a plain word and none rewrites files or writes output.
|
|
19
|
+
*
|
|
20
|
+
* FAILING CLOSED. Here that means adding nothing: anything not read with certainty is left out, which
|
|
21
|
+
* is the behaviour before this module. Steps in disabled jobs, steps with expressions in their working
|
|
22
|
+
* directory, blocks that change directory or environment (`cd`, `source`, `export`, line continuations),
|
|
23
|
+
* and lines with shell syntax or `${{ }}` contribute nothing. A direct call in a step with a working
|
|
24
|
+
* directory other than the root is left out; `make` takes it through `-C`.
|
|
25
|
+
*
|
|
26
|
+
* NARROWING. A check is "Python-only" when it is a direct tool call, or a make target with no
|
|
27
|
+
* prerequisites whose recipe lines are only `echo`, Python tool calls, or repository scripts that call a
|
|
28
|
+
* Python tool and no JavaScript tool. A Python-only check is skipped when no changed path is a Python
|
|
29
|
+
* file, Python configuration, the Makefile or a script it runs, or a workflow file. Every other check
|
|
30
|
+
* runs as written.
|
|
31
|
+
*/
|
|
32
|
+
import { posix } from "node:path";
|
|
33
|
+
import { parse } from "yaml";
|
|
34
|
+
const MAKE_LINE = /^make(?:\s+-C\s+([\w./-]+))?\s+([\w.-]+)$/;
|
|
35
|
+
const CHECK_TARGET = /^(?:check|checks|lint|typecheck|type-check|types|mypy|pyright|pyrefly|ruff|validate)(?:[-_:][\w.-]+)?$/;
|
|
36
|
+
const RUNNER_PREFIX = /^(?:uv\s+run(?:\s+--(?:project|directory|group|extra|python)(?:=|\s+)[\w./-]+|\s+--(?:dev|frozen|locked|no-sync|all-extras|all-groups|isolated))*\s+|(?:poetry|pdm|hatch|pipenv)\s+run\s+|python3?\s+-m\s+)?/;
|
|
37
|
+
const TOOL = /^(mypy|pyright|basedpyright|pyrefly\s+check|ruff\s+check|ruff\s+format)(?=\s|$)/;
|
|
38
|
+
const SAFE_ARG = /^[\w./@:=,+-]+$/;
|
|
39
|
+
const REWRITING_ARG = /^(?:--fix|--fix-only|--unsafe-fixes|--watch|--install-types|--write|-o|--output|--output-file|--junit-xml|--html-report|--txt-report|--xml-report|--linecount-report|--cobertura-xml-report)(?:=|$)/;
|
|
40
|
+
const CONTEXT_CHANGE = /^(?:cd|pushd|popd|source|\.|export|set|unset|alias)\s|\\$/;
|
|
41
|
+
const PY_TOOL = /\b(?:mypy|pyright|basedpyright|pyrefly|ruff|pylint|flake8|black|isort|pytype|lint-imports)\b/;
|
|
42
|
+
const JS_TOOL = /\b(?:npm|npx|pnpm|yarn|node|tsc|eslint|prettier|bun|deno|vp|turbo|nx)\b/;
|
|
43
|
+
const PY_FILE = /\.(?:py|pyi|pyx|pxd|ipynb)$/;
|
|
44
|
+
const PY_CONFIG = /^(?:pyproject\.toml|setup\.cfg|setup\.py|mypy\.ini|\.mypy\.ini|pyrightconfig\.json|pyrefly\.toml|ruff\.toml|\.ruff\.toml|tox\.ini|uv\.lock|poetry\.lock|pdm\.lock|Pipfile|Pipfile\.lock|\.python-version|py\.typed|(?:requirements|constraints)[\w.-]*\.(?:txt|in))$/;
|
|
45
|
+
const MAKEFILES = ["GNUmakefile", "makefile", "Makefile"];
|
|
46
|
+
function normalizeDir(dir) {
|
|
47
|
+
if (/\$\{\{|\.\.|^\//.test(dir))
|
|
48
|
+
return undefined;
|
|
49
|
+
const normalized = posix.normalize(dir.replace(/\\/g, "/")).replace(/\/+$/, "");
|
|
50
|
+
return normalized === "." ? "" : normalized.replace(/^\.\//, "");
|
|
51
|
+
}
|
|
52
|
+
function workingDirectory(...levels) {
|
|
53
|
+
for (const level of levels) {
|
|
54
|
+
const dir = level?.["working-directory"];
|
|
55
|
+
if (dir === undefined)
|
|
56
|
+
continue;
|
|
57
|
+
return typeof dir === "string" ? normalizeDir(dir) : undefined;
|
|
58
|
+
}
|
|
59
|
+
return "";
|
|
60
|
+
}
|
|
61
|
+
function disabled(condition) {
|
|
62
|
+
return condition === false || (typeof condition === "string" && /^\s*(?:\$\{\{\s*)?false(?:\s*\}\})?\s*$/.test(condition));
|
|
63
|
+
}
|
|
64
|
+
/** Rewrites files, so never run as a check: fixers and formatters without a check flag. */
|
|
65
|
+
function rewrites(line) {
|
|
66
|
+
if (/(?:^|\s)--(?:fix|fix-only|unsafe-fixes)\b/.test(line))
|
|
67
|
+
return true;
|
|
68
|
+
if (/\bruff\s+format\b/.test(line) && !/\s--(?:check|diff)\b/.test(line))
|
|
69
|
+
return true;
|
|
70
|
+
if (/\bblack\b/.test(line) && !/\s--(?:check|diff)\b/.test(line))
|
|
71
|
+
return true;
|
|
72
|
+
if (/\bisort\b/.test(line) && !/\s(?:--check|--check-only|--diff|-c)\b/.test(line))
|
|
73
|
+
return true;
|
|
74
|
+
return false;
|
|
75
|
+
}
|
|
76
|
+
/** A direct Python tool call, normalized, with its kind; undefined when the line is anything else. */
|
|
77
|
+
export function directToolCall(line) {
|
|
78
|
+
const command = line.trim().replace(/\s+/g, " ");
|
|
79
|
+
const prefix = RUNNER_PREFIX.exec(command)[0];
|
|
80
|
+
const rest = command.slice(prefix.length);
|
|
81
|
+
const tool = TOOL.exec(rest);
|
|
82
|
+
if (!tool)
|
|
83
|
+
return undefined;
|
|
84
|
+
const args = rest.slice(tool[0].length).trim().split(" ").filter(Boolean);
|
|
85
|
+
if (args.some((arg) => !SAFE_ARG.test(arg) || REWRITING_ARG.test(arg)))
|
|
86
|
+
return undefined;
|
|
87
|
+
const name = tool[1].replace(/\s+/, " ");
|
|
88
|
+
if (name === "ruff format" && !args.some((arg) => arg === "--check" || arg === "--diff"))
|
|
89
|
+
return undefined;
|
|
90
|
+
const kind = name === "ruff check" ? "lint" : name === "ruff format" ? "format" : "typecheck";
|
|
91
|
+
return { command, kind };
|
|
92
|
+
}
|
|
93
|
+
function makeTarget(dir, target, read) {
|
|
94
|
+
for (const name of MAKEFILES) {
|
|
95
|
+
const path = dir ? `${dir}/${name}` : name;
|
|
96
|
+
const text = read(path);
|
|
97
|
+
if (text === undefined)
|
|
98
|
+
continue;
|
|
99
|
+
const lines = text.replace(/\r\n/g, "\n").split("\n");
|
|
100
|
+
const escaped = target.replace(/[.+^${}()|[\]\\]/g, "\\$&");
|
|
101
|
+
const header = new RegExp(`^(?:[\\w.-]+\\s+)*${escaped}(?:\\s+[\\w.-]+)*\\s*:(?![:=])(.*)$`);
|
|
102
|
+
const at = lines.findIndex((line) => header.test(line));
|
|
103
|
+
if (at < 0)
|
|
104
|
+
return undefined;
|
|
105
|
+
const prerequisites = header.exec(lines[at])[1].replace(/#.*$/, "").trim();
|
|
106
|
+
const recipe = [];
|
|
107
|
+
for (let i = at + 1; i < lines.length; i++) {
|
|
108
|
+
const line = lines[i];
|
|
109
|
+
if (line.startsWith("\t")) {
|
|
110
|
+
recipe.push(line.slice(1).trim());
|
|
111
|
+
continue;
|
|
112
|
+
}
|
|
113
|
+
if (line.trim() === "" || line.trim().startsWith("#"))
|
|
114
|
+
continue;
|
|
115
|
+
break;
|
|
116
|
+
}
|
|
117
|
+
return { path, prerequisites, recipe: recipe.filter((line) => line && !line.startsWith("#")) };
|
|
118
|
+
}
|
|
119
|
+
return undefined;
|
|
120
|
+
}
|
|
121
|
+
/** True when every recipe line is an echo, a Python tool call, or a repository script that calls a Python
|
|
122
|
+
* tool and no JavaScript tool; also returns those scripts. Undefined when any line is something else. */
|
|
123
|
+
function pythonOnlyRecipe(target, dir, read) {
|
|
124
|
+
if (target.prerequisites.includes(";"))
|
|
125
|
+
return undefined;
|
|
126
|
+
const scripts = [];
|
|
127
|
+
let usesPython = false;
|
|
128
|
+
for (const raw of target.recipe) {
|
|
129
|
+
const line = raw.replace(/^[@+-]+/, "").trim();
|
|
130
|
+
if (/\$\(MAKE\)|\$\{MAKE\}|(?:^|\s)make\s/.test(line))
|
|
131
|
+
return undefined;
|
|
132
|
+
if (/^(?:echo\b|printf\b|true$|:$)/.test(line))
|
|
133
|
+
continue;
|
|
134
|
+
if (JS_TOOL.test(line))
|
|
135
|
+
return undefined;
|
|
136
|
+
const script = /^(?:(?:bash|sh)\s+)?(\.?\/?[\w./-]+)(?:\s|$)/.exec(line)?.[1];
|
|
137
|
+
if (directToolCall(line.replace(/\s+\$\([\w]+\)/g, ""))) {
|
|
138
|
+
usesPython = true;
|
|
139
|
+
continue;
|
|
140
|
+
}
|
|
141
|
+
if (script && script.includes("/")) {
|
|
142
|
+
const path = posix.normalize(posix.join(dir, script.replace(/^\.\//, "")));
|
|
143
|
+
const text = path.startsWith("..") ? undefined : read(path);
|
|
144
|
+
if (text === undefined || JS_TOOL.test(text) || !PY_TOOL.test(text))
|
|
145
|
+
return undefined;
|
|
146
|
+
scripts.push(path);
|
|
147
|
+
usesPython = true;
|
|
148
|
+
continue;
|
|
149
|
+
}
|
|
150
|
+
return undefined;
|
|
151
|
+
}
|
|
152
|
+
return usesPython ? scripts : undefined;
|
|
153
|
+
}
|
|
154
|
+
function makeKind(target, recipe) {
|
|
155
|
+
if (/type|mypy|pyright|pyrefly/.test(target))
|
|
156
|
+
return "typecheck";
|
|
157
|
+
if (/lint|ruff/.test(target))
|
|
158
|
+
return "lint";
|
|
159
|
+
const text = recipe.join("\n");
|
|
160
|
+
if (/\b(?:mypy|pyright|basedpyright|pyrefly)\b/.test(text))
|
|
161
|
+
return "typecheck";
|
|
162
|
+
if (/\b(?:ruff\s+check|pylint|flake8)\b/.test(text))
|
|
163
|
+
return "lint";
|
|
164
|
+
return "script";
|
|
165
|
+
}
|
|
166
|
+
/**
|
|
167
|
+
* The Python checks CI workflows run, in workflow order. Reads the workflows and, through `read`, the
|
|
168
|
+
* Makefiles and scripts they name. Every check starts as RUN.
|
|
169
|
+
*/
|
|
170
|
+
export function discoverPythonChecks(workflows, read) {
|
|
171
|
+
const checks = [];
|
|
172
|
+
const seen = new Set();
|
|
173
|
+
for (const workflow of workflows) {
|
|
174
|
+
let doc;
|
|
175
|
+
try {
|
|
176
|
+
doc = parse(workflow.text);
|
|
177
|
+
}
|
|
178
|
+
catch {
|
|
179
|
+
continue;
|
|
180
|
+
}
|
|
181
|
+
if (!doc?.jobs || typeof doc.jobs !== "object")
|
|
182
|
+
continue;
|
|
183
|
+
for (const job of Object.values(doc.jobs)) {
|
|
184
|
+
if (!job || typeof job !== "object")
|
|
185
|
+
continue;
|
|
186
|
+
const { steps, if: condition, defaults } = job;
|
|
187
|
+
if (disabled(condition) || !Array.isArray(steps))
|
|
188
|
+
continue;
|
|
189
|
+
for (const step of steps) {
|
|
190
|
+
const { run, if: stepCondition } = (step ?? {});
|
|
191
|
+
if (typeof run !== "string" || disabled(stepCondition))
|
|
192
|
+
continue;
|
|
193
|
+
const dir = workingDirectory(step, defaults?.run, doc.defaults?.run);
|
|
194
|
+
if (dir === undefined)
|
|
195
|
+
continue;
|
|
196
|
+
const lines = run.replace(/\r\n/g, "\n").split("\n").map((line) => line.trim()).filter((line) => line && !line.startsWith("#"));
|
|
197
|
+
if (lines.some((line) => CONTEXT_CHANGE.test(line) || line.includes("${{")))
|
|
198
|
+
continue;
|
|
199
|
+
for (const line of lines) {
|
|
200
|
+
const check = makeCheck(line, dir, workflow.path, read) ?? (dir === "" ? toolCheck(line, workflow.path) : undefined);
|
|
201
|
+
if (!check || seen.has(check.command))
|
|
202
|
+
continue;
|
|
203
|
+
seen.add(check.command);
|
|
204
|
+
checks.push(check);
|
|
205
|
+
}
|
|
206
|
+
}
|
|
207
|
+
}
|
|
208
|
+
}
|
|
209
|
+
return checks;
|
|
210
|
+
}
|
|
211
|
+
function makeCheck(line, stepDir, workflowPath, read) {
|
|
212
|
+
const match = MAKE_LINE.exec(line.replace(/\s+/g, " "));
|
|
213
|
+
if (!match)
|
|
214
|
+
return undefined;
|
|
215
|
+
const [, cDir, target] = match;
|
|
216
|
+
if (!CHECK_TARGET.test(target))
|
|
217
|
+
return undefined;
|
|
218
|
+
const dir = normalizeDir(posix.join(stepDir || ".", cDir ?? "."));
|
|
219
|
+
if (dir === undefined)
|
|
220
|
+
return undefined;
|
|
221
|
+
const found = makeTarget(dir, target, read);
|
|
222
|
+
if (!found || found.recipe.some(rewrites))
|
|
223
|
+
return undefined;
|
|
224
|
+
const scripts = found.prerequisites ? undefined : pythonOnlyRecipe(found, dir, read);
|
|
225
|
+
const command = dir ? `make -C ${dir} ${target}` : `make ${target}`;
|
|
226
|
+
return {
|
|
227
|
+
id: command,
|
|
228
|
+
script: workflowPath,
|
|
229
|
+
runsScript: false,
|
|
230
|
+
command,
|
|
231
|
+
kind: makeKind(target, found.recipe),
|
|
232
|
+
decision: "RUN",
|
|
233
|
+
reason: `run by CI workflow ${workflowPath}`,
|
|
234
|
+
pythonOnly: scripts !== undefined,
|
|
235
|
+
triggers: [found.path, ...(scripts ?? [])],
|
|
236
|
+
};
|
|
237
|
+
}
|
|
238
|
+
function toolCheck(line, workflowPath) {
|
|
239
|
+
const call = directToolCall(line);
|
|
240
|
+
if (!call)
|
|
241
|
+
return undefined;
|
|
242
|
+
return { id: call.command, script: workflowPath, runsScript: false, command: call.command, kind: call.kind, decision: "RUN", reason: `run by CI workflow ${workflowPath}`, pythonOnly: true, triggers: [] };
|
|
243
|
+
}
|
|
244
|
+
function pythonRelevant(path) {
|
|
245
|
+
return PY_FILE.test(path) || PY_CONFIG.test(posix.basename(path)) || path.startsWith(".github/workflows/");
|
|
246
|
+
}
|
|
247
|
+
/** Skips Python-only checks for a change with no Python file, Python configuration or trigger in it. */
|
|
248
|
+
export function narrowPythonChecks(checks, changes) {
|
|
249
|
+
return checks.map((check) => {
|
|
250
|
+
if (!check.pythonOnly)
|
|
251
|
+
return { ...check, reason: `${check.reason}; not read as Python-only, runs as written` };
|
|
252
|
+
const hit = changes.find((change) => pythonRelevant(change.path) || check.triggers.includes(change.path));
|
|
253
|
+
return hit
|
|
254
|
+
? { ...check, reason: `${check.reason}; ${hit.path} changed` }
|
|
255
|
+
: { ...check, decision: "SKIP", reason: `${check.reason}; no changed Python file or Python configuration` };
|
|
256
|
+
});
|
|
257
|
+
}
|
|
258
|
+
//# sourceMappingURL=python-checks.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"python-checks.js","sourceRoot":"","sources":["../../src/planner/python-checks.ts"],"names":[],"mappings":"AAAA,+BAA+B;AAC/B;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA6BG;AAEH,OAAO,EAAE,KAAK,EAAE,MAAM,WAAW,CAAC;AAClC,OAAO,EAAE,KAAK,EAAE,MAAM,MAAM,CAAC;AAiB7B,MAAM,SAAS,GAAG,2CAA2C,CAAC;AAC9D,MAAM,YAAY,GAAG,wGAAwG,CAAC;AAC9H,MAAM,aAAa,GAAG,8MAA8M,CAAC;AACrO,MAAM,IAAI,GAAG,iFAAiF,CAAC;AAC/F,MAAM,QAAQ,GAAG,iBAAiB,CAAC;AACnC,MAAM,aAAa,GAAG,qMAAqM,CAAC;AAC5N,MAAM,cAAc,GAAG,2DAA2D,CAAC;AACnF,MAAM,OAAO,GAAG,8FAA8F,CAAC;AAC/G,M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AA4C,EAAE,CAAC;QAChH,MAAM,GAAG,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC,MAAM,EAAE,EAAE,CAAC,cAAc,CAAC,MAAM,CAAC,IAAI,CAAC,IAAI,KAAK,CAAC,QAAQ,CAAC,QAAQ,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC,CAAC;QAC1G,OAAO,GAAG;YACR,CAAC,CAAC,EAAE,GAAG,KAAK,EAAE,MAAM,EAAE,GAAG,KAAK,CAAC,MAAM,KAAK,GAAG,CAAC,IAAI,UAAU,EAAE;YAC9D,CAAC,CAAC,EAAE,GAAG,KAAK,EAAE,QAAQ,EAAE,MAAM,EAAE,MAAM,EAAE,GAAG,KAAK,CAAC,MAAM,kDAAkD,EAAE,CAAC;IAChH,CAAC,CAAC,CAAC;AACL,CAAC"}
|
|
@@ -1,6 +1,24 @@
|
|
|
1
1
|
import { readFileSync } from "node:fs";
|
|
2
2
|
import { posix } from "node:path";
|
|
3
3
|
import { contribution } from "./types.js";
|
|
4
|
+
const DEFAULT_TEST_ROOT = "src/test/java";
|
|
5
|
+
/**
|
|
6
|
+
* Resolves a `<testSourceDirectory>` to a repository path. Only a plain relative path inside the module
|
|
7
|
+
* resolves; a `${property}`, an absolute path, a path leaving the module, or several declarations (a
|
|
8
|
+
* profile can override the root) don't, so the caller falls back. Never guess (#163).
|
|
9
|
+
*/
|
|
10
|
+
function resolveTestRoot(dir, declared) {
|
|
11
|
+
const roots = [...new Set(declared)];
|
|
12
|
+
if (roots.length > 1)
|
|
13
|
+
return undefined;
|
|
14
|
+
const root = roots[0] ?? DEFAULT_TEST_ROOT;
|
|
15
|
+
if (!root || root.includes("${") || root.startsWith("/") || /^[A-Za-z]:/.test(root) || root.includes("\\"))
|
|
16
|
+
return undefined;
|
|
17
|
+
const local = posix.normalize(root).replace(/\/+$/, "");
|
|
18
|
+
if (local === "." || local === ".." || local.startsWith("../"))
|
|
19
|
+
return undefined;
|
|
20
|
+
return dir ? `${dir}/${local}` : local;
|
|
21
|
+
}
|
|
4
22
|
function tags(xml, name) {
|
|
5
23
|
const re = new RegExp(`<${name}\\b[^>]*>([\\s\\S]*?)<\\/${name}>`, "g");
|
|
6
24
|
const out = [];
|
|
@@ -35,6 +53,10 @@ function parsePom(path, source) {
|
|
|
35
53
|
// Nested plugin/dependency coordinates are not the project's own identity. In
|
|
36
54
|
// particular, a dependency's ${project.groupId} must not shadow an inherited ID.
|
|
37
55
|
const identity = own.replace(/<(dependencies|dependencyManagement|build|profiles|reporting|properties)\b[^>]*>[\s\S]*?<\/\1>/g, "");
|
|
56
|
+
// A profile's <testSourceDirectory> applies only when that profile is active, which this static
|
|
57
|
+
// adapter can't tell, so such a POM falls back.
|
|
58
|
+
const declaredTestRoots = tags(xml, "testSourceDirectory");
|
|
59
|
+
const profileTestRoot = declaredTestRoots.length !== tags(xml.replace(/<profiles\b[^>]*>[\s\S]*?<\/profiles>/g, ""), "testSourceDirectory").length;
|
|
38
60
|
const dependencies = tags(xml, "dependency")
|
|
39
61
|
.map(value => ({ groupId: first(value, "groupId") ?? "", artifactId: first(value, "artifactId") ?? "" }))
|
|
40
62
|
.filter(value => value.artifactId);
|
|
@@ -44,17 +66,22 @@ function parsePom(path, source) {
|
|
|
44
66
|
artifactId: first(identity, "artifactId"),
|
|
45
67
|
parent: parent === undefined ? undefined : { groupId: first(parent, "groupId") ?? "", artifactId: first(parent, "artifactId") ?? "" },
|
|
46
68
|
dependencies,
|
|
47
|
-
customSourceRoots: tags(xml, "sourceDirectory").some(root => root !== "src/main/java")
|
|
48
|
-
|
|
69
|
+
customSourceRoots: tags(xml, "sourceDirectory").some(root => root !== "src/main/java"),
|
|
70
|
+
testRoot: profileTestRoot ? undefined : resolveTestRoot(dir, declaredTestRoots),
|
|
71
|
+
declaredTestRoots, profileTestRoot,
|
|
49
72
|
};
|
|
50
73
|
}
|
|
51
74
|
function under(dir, path) { return !dir || path === dir || path.startsWith(dir + "/"); }
|
|
52
75
|
function owningPom(poms, file) {
|
|
53
76
|
return poms.filter(pom => under(pom.dir, file)).sort((a, b) => b.dir.length - a.dir.length)[0];
|
|
54
77
|
}
|
|
55
|
-
/**
|
|
56
|
-
|
|
57
|
-
|
|
78
|
+
/**
|
|
79
|
+
* Surefire's default includes (Test*, *Test, *Tests, *TestCase) and Failsafe's (IT*, *IT, *ITCase), under the
|
|
80
|
+
* module's Java test root or src/test/kotlin.
|
|
81
|
+
*/
|
|
82
|
+
function isTest(pom, path) {
|
|
83
|
+
const roots = [pom.testRoot, pom.dir ? `${pom.dir}/src/test/kotlin` : "src/test/kotlin"];
|
|
84
|
+
return roots.some(root => path.startsWith(root + "/")) &&
|
|
58
85
|
/^(?:Test.*|IT.*|.*(?:Test|Tests|TestCase|IT|ITCase))\.(?:java|kt)$/.test(posix.basename(path));
|
|
59
86
|
}
|
|
60
87
|
export function analyzeMaven(context) {
|
|
@@ -71,8 +98,23 @@ export function analyzeMaven(context) {
|
|
|
71
98
|
const members = new Map();
|
|
72
99
|
const resources = new Map();
|
|
73
100
|
const anchors = new Map();
|
|
101
|
+
// A module that declares no <testSourceDirectory> inherits the nearest local parent's. Unless that is
|
|
102
|
+
// the default root, fall back rather than assume src/test/java.
|
|
103
|
+
for (const pom of poms) {
|
|
104
|
+
if (pom.declaredTestRoots.length)
|
|
105
|
+
continue;
|
|
106
|
+
const visited = new Set([pom]);
|
|
107
|
+
let ancestor = pom.parent && findPom(pom.parent);
|
|
108
|
+
while (ancestor && !visited.has(ancestor) && !ancestor.declaredTestRoots.length) {
|
|
109
|
+
visited.add(ancestor);
|
|
110
|
+
ancestor = ancestor.parent && findPom(ancestor.parent);
|
|
111
|
+
}
|
|
112
|
+
if (ancestor && !visited.has(ancestor) &&
|
|
113
|
+
(ancestor.profileTestRoot || resolveTestRoot("", ancestor.declaredTestRoots) !== DEFAULT_TEST_ROOT))
|
|
114
|
+
pom.testRoot = undefined;
|
|
115
|
+
}
|
|
74
116
|
for (const pom of poms) {
|
|
75
|
-
if (pom.customSourceRoots)
|
|
117
|
+
if (pom.customSourceRoots || pom.testRoot === undefined)
|
|
76
118
|
result.blockers.push(`Maven ${pom.path}: custom source roots require full validation`);
|
|
77
119
|
// This static adapter does not construct Maven's effective model. A local parent's
|
|
78
120
|
// dependency declarations cannot safely be treated as belonging only to that POM.
|
|
@@ -87,7 +129,8 @@ export function analyzeMaven(context) {
|
|
|
87
129
|
parent = parent.parent && findPom(parent.parent);
|
|
88
130
|
}
|
|
89
131
|
const owned = context.files.filter(file => owningPom(poms, file) === pom);
|
|
90
|
-
const sources = owned.filter(file =>
|
|
132
|
+
const sources = owned.filter(file => /\.(?:java|kt)$/.test(file) &&
|
|
133
|
+
(/\/src\/(?:main|test)\/(?:java|kotlin)\//.test("/" + file) || (pom.testRoot !== undefined && file.startsWith(pom.testRoot + "/"))));
|
|
91
134
|
const assets = owned.filter(file => /\/src\/(?:main|test)\/resources\//.test("/" + file));
|
|
92
135
|
members.set(pom, sources);
|
|
93
136
|
resources.set(pom, assets);
|
|
@@ -97,7 +140,7 @@ export function analyzeMaven(context) {
|
|
|
97
140
|
result.sourcePaths.push(...sources);
|
|
98
141
|
result.assetPaths.push(...assets);
|
|
99
142
|
for (const file of sources) {
|
|
100
|
-
if (isTest(file)) {
|
|
143
|
+
if (pom.testRoot !== undefined && isTest(pom, file)) {
|
|
101
144
|
result.testFiles.push(file);
|
|
102
145
|
result.testPackages[file] = pom.dir || ".";
|
|
103
146
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"maven.js","sourceRoot":"","sources":["../../../src/repo/adapters/maven.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AACvC,OAAO,EAAE,KAAK,EAAE,MAAM,WAAW,CAAC;AAClC,OAAO,EAAE,YAAY,EAAyE,MAAM,YAAY,CAAC;
|
|
1
|
+
{"version":3,"file":"maven.js","sourceRoot":"","sources":["../../../src/repo/adapters/maven.ts"],"names":[],"mappings":"AAAA,OAAO,EAA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M,CAAC,MAAM,YAAY,GAAsB;IAC7C,EAAE,EAAE,OAAO,EAAE,OAAO,EAAE,GAAG,EAAE,IAAI,EAAE,UAAU;IAC3C,MAAM,EAAE,CAAC,EAAE,KAAK,EAAE,EAAE,EAAE,CAAC,KAAK,CAAC,QAAQ,CAAC,SAAS,CAAC,IAAI,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC,IAAI,CAAC,QAAQ,CAAC,OAAO,CAAC,IAAI,IAAI,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC;IACtH,OAAO,EAAE,YAAY;CACtB,CAAC"}
|
|
@@ -59,7 +59,7 @@ for path in json.load(sys.stdin):
|
|
|
59
59
|
json.dump(out, sys.stdout)
|
|
60
60
|
`;
|
|
61
61
|
const EXCLUDED_DIRS = new Set([".venv", "venv", "env", ".env", ".tox", ".nox", "site-packages", "__pycache__", ".eggs", ".mypy_cache", ".pytest_cache", ".ruff_cache"]);
|
|
62
|
-
const PROJECT_FILES = ["pyproject.toml", "setup.py", "setup.cfg", "pytest.ini", ".pytest.ini", "tox.ini", "conftest.py"];
|
|
62
|
+
const PROJECT_FILES = ["pyproject.toml", "setup.py", "setup.cfg", "pytest.toml", ".pytest.toml", "pytest.ini", ".pytest.ini", "tox.ini", "conftest.py"];
|
|
63
63
|
export function isPythonSource(path) {
|
|
64
64
|
return path.endsWith(".py") && !path.split("/").some((part) => EXCLUDED_DIRS.has(part) || part.endsWith(".egg-info"));
|
|
65
65
|
}
|
|
@@ -158,30 +158,127 @@ export function readPytestSettings(read) {
|
|
|
158
158
|
else
|
|
159
159
|
settings[key] = values;
|
|
160
160
|
};
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
//
|
|
164
|
-
|
|
161
|
+
const escape = (text) => text.replace(/[\\^$.*+?()[\]{}|]/g, "\\$&");
|
|
162
|
+
const isToml = (file) => file.endsWith(".toml");
|
|
163
|
+
// A table header may be indented and followed by a comment (`[pytest] # selection`). TOML also allows
|
|
164
|
+
// spaces inside the brackets and quoted keys (`[ pytest ]`, `[tool."pytest"]`), which this reader doesn't
|
|
165
|
+
// match: a header that only matches with spaces and quotes removed makes the file unreadable instead.
|
|
166
|
+
const section = (file, text, header) => {
|
|
167
|
+
const comment = isToml(file) ? "#" : "#;";
|
|
168
|
+
return new RegExp(`^[ \\t]*\\[${escape(header)}\\][ \\t]*(?:[${comment}].*)?$([\\s\\S]*?)(?=^[ \\t]*\\[|(?![\\s\\S]))`, "m").exec(text)?.[1];
|
|
169
|
+
};
|
|
170
|
+
const looseHeader = (file, text, header) => isToml(file) && [...text.matchAll(/^[ \t]*\[([^\]\n]*)\]/gm)].some((match) => match[1].replace(/[\s"']/g, "") === header && section(file, match[0].trim(), header) === undefined);
|
|
171
|
+
const hasEntries = (body) => /^[ \t]*[^\s#]/m.test(body);
|
|
172
|
+
const keyAt = (key) => `^[ \\t]*${key}[ \\t]*=`;
|
|
173
|
+
// A quoted or dotted key (`"testpaths" = …`, `ini_options.testpaths = …`) can't be told apart from the
|
|
174
|
+
// keys selection reads, so a TOML table with one is unreadable.
|
|
175
|
+
const unclassified = (body) => /^[ \t]*(?:"[^"\n]*"|'[^'\n]*'|[A-Za-z0-9_-]+)[ \t]*\./m.test(body) ||
|
|
176
|
+
/^[ \t]*(?:"[^"\n]*"|'[^'\n]*')[ \t]*=/m.test(body);
|
|
177
|
+
// pytest 9's native TOML mode (`pytest.toml`, `[tool.pytest]`): every key selection reads is a list of
|
|
178
|
+
// strings, and each `addopts` item is one argument. Any other type is an error in pytest, so it can't be read.
|
|
179
|
+
const readNative = (file, body) => {
|
|
180
|
+
if (unclassified(body)) {
|
|
181
|
+
settings.unreadable = `${file} key DiffCI can't classify`;
|
|
182
|
+
return settings;
|
|
183
|
+
}
|
|
184
|
+
for (const key of keys) {
|
|
185
|
+
const array = new RegExp(`${keyAt(key)}[ \\t]*(?=\\[)`, "m").exec(body);
|
|
186
|
+
if (array) {
|
|
187
|
+
const values = readTomlStringArray(body, array.index + array[0].length);
|
|
188
|
+
if (values)
|
|
189
|
+
apply(key, values);
|
|
190
|
+
else
|
|
191
|
+
settings.unreadable = `${file} ${key}`;
|
|
192
|
+
}
|
|
193
|
+
else if (new RegExp(keyAt(key), "m").test(body))
|
|
194
|
+
settings.unreadable = `${file} ${key}`;
|
|
195
|
+
}
|
|
196
|
+
return settings;
|
|
197
|
+
};
|
|
198
|
+
const order = [["pytest.toml", "pytest"], [".pytest.toml", "pytest"], ["pytest.ini", "pytest"], [".pytest.ini", "pytest"], ["pyproject.toml", "tool.pytest.ini_options"], ["tox.ini", "pytest"], ["setup.cfg", "tool:pytest"]];
|
|
199
|
+
// pytest before 9 ignores `pytest.toml`, `.pytest.toml` and `[tool.pytest]`, and uses the first of the
|
|
200
|
+
// other files that matches. When a native config wins and such a file also exists, the answer depends on
|
|
201
|
+
// the installed pytest, so it can't be read.
|
|
202
|
+
const olderPytestFile = (from) => {
|
|
203
|
+
for (const [file, header] of order.slice(from)) {
|
|
204
|
+
const text = read(file);
|
|
205
|
+
if (text === undefined || file === ".pytest.toml")
|
|
206
|
+
continue;
|
|
207
|
+
if (file === "pytest.ini" || file === ".pytest.ini" || section(file, text, header) !== undefined)
|
|
208
|
+
return file;
|
|
209
|
+
}
|
|
210
|
+
return undefined;
|
|
211
|
+
};
|
|
212
|
+
const native = (file, body, index) => {
|
|
213
|
+
const older = olderPytestFile(index);
|
|
214
|
+
if (older) {
|
|
215
|
+
settings.unreadable = `${file} is ignored before pytest 9, which reads ${older}`;
|
|
216
|
+
return settings;
|
|
217
|
+
}
|
|
218
|
+
return body === undefined ? settings : readNative(file, body);
|
|
219
|
+
};
|
|
220
|
+
// pytest's search order. `pytest.toml`, `.pytest.toml`, `pytest.ini` and `.pytest.ini` match even when
|
|
221
|
+
// empty or without their `[pytest]` table, and then pytest uses its defaults; the other files only match
|
|
222
|
+
// with their section. The first match wins and options are never merged.
|
|
223
|
+
for (const [index, [file, header]] of order.entries()) {
|
|
165
224
|
const text = read(file);
|
|
166
225
|
if (text === undefined)
|
|
167
226
|
continue;
|
|
168
|
-
|
|
169
|
-
|
|
227
|
+
if (looseHeader(file, text, "pytest") || looseHeader(file, text, "tool.pytest") || looseHeader(file, text, "tool.pytest.ini_options")) {
|
|
228
|
+
settings.unreadable = `${file} pytest table header DiffCI can't read`;
|
|
229
|
+
return settings;
|
|
230
|
+
}
|
|
231
|
+
if (file === "pytest.toml" || file === ".pytest.toml") {
|
|
232
|
+
const body = section(file, text, "pytest");
|
|
233
|
+
// pytest rejects options written above any table.
|
|
234
|
+
if (body === undefined && hasEntries(text.split(/^[ \t]*\[/m, 1)[0])) {
|
|
235
|
+
settings.unreadable = `${file} options outside [pytest]`;
|
|
236
|
+
return settings;
|
|
237
|
+
}
|
|
238
|
+
return native(file, body, index + 1);
|
|
239
|
+
}
|
|
240
|
+
if (file === "pyproject.toml") {
|
|
241
|
+
// `[tool.pytest]` holds native TOML values, `[tool.pytest.ini_options]` INI-style ones. pytest refuses a
|
|
242
|
+
// file that sets both, and an `ini_options` key inside `[tool.pytest]` is a form this reader doesn't parse.
|
|
243
|
+
const nativeBody = section(file, text, "tool.pytest");
|
|
244
|
+
const ini = section(file, text, header);
|
|
245
|
+
if (nativeBody !== undefined && new RegExp(`^[ \\t]*ini_options[ \\t]*[.=]`, "m").test(nativeBody)) {
|
|
246
|
+
settings.unreadable = `${file} [tool.pytest] ini_options`;
|
|
247
|
+
return settings;
|
|
248
|
+
}
|
|
249
|
+
if (nativeBody !== undefined && hasEntries(nativeBody)) {
|
|
250
|
+
if (ini !== undefined && hasEntries(ini)) {
|
|
251
|
+
settings.unreadable = `${file} [tool.pytest] and [tool.pytest.ini_options]`;
|
|
252
|
+
return settings;
|
|
253
|
+
}
|
|
254
|
+
// An empty [tool.pytest.ini_options] beside it is what pytest 8 reads.
|
|
255
|
+
if (ini !== undefined) {
|
|
256
|
+
settings.unreadable = `${file} [tool.pytest] is ignored before pytest 9, which reads [tool.pytest.ini_options]`;
|
|
257
|
+
return settings;
|
|
258
|
+
}
|
|
259
|
+
return native(file, nativeBody, index + 1);
|
|
260
|
+
}
|
|
261
|
+
}
|
|
262
|
+
const body = section(file, text, header);
|
|
263
|
+
if (body === undefined) {
|
|
170
264
|
if (file === "pytest.ini" || file === ".pytest.ini")
|
|
171
265
|
return settings;
|
|
172
266
|
continue;
|
|
173
267
|
}
|
|
174
|
-
|
|
268
|
+
if (file === "pyproject.toml" && unclassified(body)) {
|
|
269
|
+
settings.unreadable = `${file} key DiffCI can't classify`;
|
|
270
|
+
return settings;
|
|
271
|
+
}
|
|
175
272
|
for (const key of keys) {
|
|
176
273
|
if (file === "pyproject.toml") {
|
|
177
|
-
const match = new RegExp(
|
|
178
|
-
const array = new RegExp(
|
|
274
|
+
const match = new RegExp(`${keyAt(key)}[ \\t]*("[^"]*"|'[^']*')`, "m").exec(body);
|
|
275
|
+
const array = new RegExp(`${keyAt(key)}[ \\t]*(?=\\[)`, "m").exec(body);
|
|
179
276
|
// A multi-line string would otherwise match as an empty one. Its contents are read as one string;
|
|
180
277
|
// a basic string's line-ending backslash only joins lines. An unterminated one cannot be read.
|
|
181
|
-
const multiline = new RegExp(
|
|
278
|
+
const multiline = new RegExp(`${keyAt(key)}[ \\t]*("""|'{3})([\\s\\S]*?)\\1`, "m").exec(body);
|
|
182
279
|
if (multiline)
|
|
183
280
|
apply(key, splitList(multiline[1] === '"""' ? multiline[2].replace(/\\\r?\n/g, " ") : multiline[2]));
|
|
184
|
-
else if (new RegExp(
|
|
281
|
+
else if (new RegExp(`${keyAt(key)}[ \\t]*(?:"""|'{3})`, "m").test(body))
|
|
185
282
|
settings.unreadable = `${file} ${key}`;
|
|
186
283
|
else if (array) {
|
|
187
284
|
const values = readTomlStringArray(body, array.index + array[0].length);
|
|
@@ -192,11 +289,11 @@ export function readPytestSettings(read) {
|
|
|
192
289
|
}
|
|
193
290
|
else if (match)
|
|
194
291
|
apply(key, splitList(match[1]));
|
|
195
|
-
else if (new RegExp(
|
|
292
|
+
else if (new RegExp(keyAt(key), "m").test(body))
|
|
196
293
|
settings.unreadable = `${file} ${key}`;
|
|
197
294
|
}
|
|
198
295
|
else {
|
|
199
|
-
// INI values continue on indented lines.
|
|
296
|
+
// INI values continue on indented lines, so a key starts at the beginning of a line.
|
|
200
297
|
const match = new RegExp(`^${key}\\s*=\\s*(.*(?:\\r?\\n[ \\t]+.*)*)`, "m").exec(body);
|
|
201
298
|
if (match)
|
|
202
299
|
apply(key, splitList(match[1]));
|