@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,244 @@
|
|
|
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
|
+
|
|
33
|
+
import { posix } from "node:path";
|
|
34
|
+
import { parse } from "yaml";
|
|
35
|
+
import type { ChangedPath } from "./check-narrowing.js";
|
|
36
|
+
import type { GateCheck } from "./pipeline-steps.js";
|
|
37
|
+
|
|
38
|
+
export interface PythonCheck extends GateCheck {
|
|
39
|
+
/** True when the check only runs Python tools, so a change without Python files cannot fail it. */
|
|
40
|
+
pythonOnly: boolean;
|
|
41
|
+
/** Repository paths besides Python files and configuration whose change runs the check. */
|
|
42
|
+
triggers: string[];
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
export interface WorkflowFile {
|
|
46
|
+
/** Repository-relative path, such as `.github/workflows/style.yml`. */
|
|
47
|
+
path: string;
|
|
48
|
+
text: string;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
const MAKE_LINE = /^make(?:\s+-C\s+([\w./-]+))?\s+([\w.-]+)$/;
|
|
52
|
+
const CHECK_TARGET = /^(?:check|checks|lint|typecheck|type-check|types|mypy|pyright|pyrefly|ruff|validate)(?:[-_:][\w.-]+)?$/;
|
|
53
|
+
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+)?/;
|
|
54
|
+
const TOOL = /^(mypy|pyright|basedpyright|pyrefly\s+check|ruff\s+check|ruff\s+format)(?=\s|$)/;
|
|
55
|
+
const SAFE_ARG = /^[\w./@:=,+-]+$/;
|
|
56
|
+
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)(?:=|$)/;
|
|
57
|
+
const CONTEXT_CHANGE = /^(?:cd|pushd|popd|source|\.|export|set|unset|alias)\s|\\$/;
|
|
58
|
+
const PY_TOOL = /\b(?:mypy|pyright|basedpyright|pyrefly|ruff|pylint|flake8|black|isort|pytype|lint-imports)\b/;
|
|
59
|
+
const JS_TOOL = /\b(?:npm|npx|pnpm|yarn|node|tsc|eslint|prettier|bun|deno|vp|turbo|nx)\b/;
|
|
60
|
+
const PY_FILE = /\.(?:py|pyi|pyx|pxd|ipynb)$/;
|
|
61
|
+
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))$/;
|
|
62
|
+
const MAKEFILES = ["GNUmakefile", "makefile", "Makefile"];
|
|
63
|
+
|
|
64
|
+
function normalizeDir(dir: string): string | undefined {
|
|
65
|
+
if (/\$\{\{|\.\.|^\//.test(dir)) return undefined;
|
|
66
|
+
const normalized = posix.normalize(dir.replace(/\\/g, "/")).replace(/\/+$/, "");
|
|
67
|
+
return normalized === "." ? "" : normalized.replace(/^\.\//, "");
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
function workingDirectory(...levels: unknown[]): string | undefined {
|
|
71
|
+
for (const level of levels) {
|
|
72
|
+
const dir = (level as { "working-directory"?: unknown } | undefined)?.["working-directory"];
|
|
73
|
+
if (dir === undefined) continue;
|
|
74
|
+
return typeof dir === "string" ? normalizeDir(dir) : undefined;
|
|
75
|
+
}
|
|
76
|
+
return "";
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
function disabled(condition: unknown): boolean {
|
|
80
|
+
return condition === false || (typeof condition === "string" && /^\s*(?:\$\{\{\s*)?false(?:\s*\}\})?\s*$/.test(condition));
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
/** Rewrites files, so never run as a check: fixers and formatters without a check flag. */
|
|
84
|
+
function rewrites(line: string): boolean {
|
|
85
|
+
if (/(?:^|\s)--(?:fix|fix-only|unsafe-fixes)\b/.test(line)) return true;
|
|
86
|
+
if (/\bruff\s+format\b/.test(line) && !/\s--(?:check|diff)\b/.test(line)) return true;
|
|
87
|
+
if (/\bblack\b/.test(line) && !/\s--(?:check|diff)\b/.test(line)) return true;
|
|
88
|
+
if (/\bisort\b/.test(line) && !/\s(?:--check|--check-only|--diff|-c)\b/.test(line)) return true;
|
|
89
|
+
return false;
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
/** A direct Python tool call, normalized, with its kind; undefined when the line is anything else. */
|
|
93
|
+
export function directToolCall(line: string): { command: string; kind: GateCheck["kind"] } | undefined {
|
|
94
|
+
const command = line.trim().replace(/\s+/g, " ");
|
|
95
|
+
const prefix = RUNNER_PREFIX.exec(command)![0];
|
|
96
|
+
const rest = command.slice(prefix.length);
|
|
97
|
+
const tool = TOOL.exec(rest);
|
|
98
|
+
if (!tool) return undefined;
|
|
99
|
+
const args = rest.slice(tool[0].length).trim().split(" ").filter(Boolean);
|
|
100
|
+
if (args.some((arg) => !SAFE_ARG.test(arg) || REWRITING_ARG.test(arg))) return undefined;
|
|
101
|
+
const name = tool[1]!.replace(/\s+/, " ");
|
|
102
|
+
if (name === "ruff format" && !args.some((arg) => arg === "--check" || arg === "--diff")) return undefined;
|
|
103
|
+
const kind = name === "ruff check" ? "lint" : name === "ruff format" ? "format" : "typecheck";
|
|
104
|
+
return { command, kind };
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
interface MakeTarget { path: string; prerequisites: string; recipe: string[] }
|
|
108
|
+
|
|
109
|
+
function makeTarget(dir: string, target: string, read: (path: string) => string | undefined): MakeTarget | undefined {
|
|
110
|
+
for (const name of MAKEFILES) {
|
|
111
|
+
const path = dir ? `${dir}/${name}` : name;
|
|
112
|
+
const text = read(path);
|
|
113
|
+
if (text === undefined) continue;
|
|
114
|
+
const lines = text.replace(/\r\n/g, "\n").split("\n");
|
|
115
|
+
const escaped = target.replace(/[.+^${}()|[\]\\]/g, "\\$&");
|
|
116
|
+
const header = new RegExp(`^(?:[\\w.-]+\\s+)*${escaped}(?:\\s+[\\w.-]+)*\\s*:(?![:=])(.*)$`);
|
|
117
|
+
const at = lines.findIndex((line) => header.test(line));
|
|
118
|
+
if (at < 0) return undefined;
|
|
119
|
+
const prerequisites = header.exec(lines[at]!)![1]!.replace(/#.*$/, "").trim();
|
|
120
|
+
const recipe: string[] = [];
|
|
121
|
+
for (let i = at + 1; i < lines.length; i++) {
|
|
122
|
+
const line = lines[i]!;
|
|
123
|
+
if (line.startsWith("\t")) { recipe.push(line.slice(1).trim()); continue; }
|
|
124
|
+
if (line.trim() === "" || line.trim().startsWith("#")) continue;
|
|
125
|
+
break;
|
|
126
|
+
}
|
|
127
|
+
return { path, prerequisites, recipe: recipe.filter((line) => line && !line.startsWith("#")) };
|
|
128
|
+
}
|
|
129
|
+
return undefined;
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
/** True when every recipe line is an echo, a Python tool call, or a repository script that calls a Python
|
|
133
|
+
* tool and no JavaScript tool; also returns those scripts. Undefined when any line is something else. */
|
|
134
|
+
function pythonOnlyRecipe(target: MakeTarget, dir: string, read: (path: string) => string | undefined): string[] | undefined {
|
|
135
|
+
if (target.prerequisites.includes(";")) return undefined;
|
|
136
|
+
const scripts: string[] = [];
|
|
137
|
+
let usesPython = false;
|
|
138
|
+
for (const raw of target.recipe) {
|
|
139
|
+
const line = raw.replace(/^[@+-]+/, "").trim();
|
|
140
|
+
if (/\$\(MAKE\)|\$\{MAKE\}|(?:^|\s)make\s/.test(line)) return undefined;
|
|
141
|
+
if (/^(?:echo\b|printf\b|true$|:$)/.test(line)) continue;
|
|
142
|
+
if (JS_TOOL.test(line)) return undefined;
|
|
143
|
+
const script = /^(?:(?:bash|sh)\s+)?(\.?\/?[\w./-]+)(?:\s|$)/.exec(line)?.[1];
|
|
144
|
+
if (directToolCall(line.replace(/\s+\$\([\w]+\)/g, ""))) { usesPython = true; continue; }
|
|
145
|
+
if (script && script.includes("/")) {
|
|
146
|
+
const path = posix.normalize(posix.join(dir, script.replace(/^\.\//, "")));
|
|
147
|
+
const text = path.startsWith("..") ? undefined : read(path);
|
|
148
|
+
if (text === undefined || JS_TOOL.test(text) || !PY_TOOL.test(text)) return undefined;
|
|
149
|
+
scripts.push(path);
|
|
150
|
+
usesPython = true;
|
|
151
|
+
continue;
|
|
152
|
+
}
|
|
153
|
+
return undefined;
|
|
154
|
+
}
|
|
155
|
+
return usesPython ? scripts : undefined;
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
function makeKind(target: string, recipe: readonly string[]): GateCheck["kind"] {
|
|
159
|
+
if (/type|mypy|pyright|pyrefly/.test(target)) return "typecheck";
|
|
160
|
+
if (/lint|ruff/.test(target)) return "lint";
|
|
161
|
+
const text = recipe.join("\n");
|
|
162
|
+
if (/\b(?:mypy|pyright|basedpyright|pyrefly)\b/.test(text)) return "typecheck";
|
|
163
|
+
if (/\b(?:ruff\s+check|pylint|flake8)\b/.test(text)) return "lint";
|
|
164
|
+
return "script";
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
/**
|
|
168
|
+
* The Python checks CI workflows run, in workflow order. Reads the workflows and, through `read`, the
|
|
169
|
+
* Makefiles and scripts they name. Every check starts as RUN.
|
|
170
|
+
*/
|
|
171
|
+
export function discoverPythonChecks(workflows: readonly WorkflowFile[], read: (path: string) => string | undefined): PythonCheck[] {
|
|
172
|
+
const checks: PythonCheck[] = [];
|
|
173
|
+
const seen = new Set<string>();
|
|
174
|
+
for (const workflow of workflows) {
|
|
175
|
+
let doc: { jobs?: unknown; defaults?: { run?: unknown } } | null;
|
|
176
|
+
try { doc = parse(workflow.text) as typeof doc; } catch { continue; }
|
|
177
|
+
if (!doc?.jobs || typeof doc.jobs !== "object") continue;
|
|
178
|
+
for (const job of Object.values(doc.jobs as Record<string, unknown>)) {
|
|
179
|
+
if (!job || typeof job !== "object") continue;
|
|
180
|
+
const { steps, if: condition, defaults } = job as { steps?: unknown; if?: unknown; defaults?: { run?: unknown } };
|
|
181
|
+
if (disabled(condition) || !Array.isArray(steps)) continue;
|
|
182
|
+
for (const step of steps) {
|
|
183
|
+
const { run, if: stepCondition } = (step ?? {}) as { run?: unknown; if?: unknown };
|
|
184
|
+
if (typeof run !== "string" || disabled(stepCondition)) continue;
|
|
185
|
+
const dir = workingDirectory(step, defaults?.run, doc.defaults?.run);
|
|
186
|
+
if (dir === undefined) continue;
|
|
187
|
+
const lines = run.replace(/\r\n/g, "\n").split("\n").map((line) => line.trim()).filter((line) => line && !line.startsWith("#"));
|
|
188
|
+
if (lines.some((line) => CONTEXT_CHANGE.test(line) || line.includes("${{"))) continue;
|
|
189
|
+
for (const line of lines) {
|
|
190
|
+
const check = makeCheck(line, dir, workflow.path, read) ?? (dir === "" ? toolCheck(line, workflow.path) : undefined);
|
|
191
|
+
if (!check || seen.has(check.command)) continue;
|
|
192
|
+
seen.add(check.command);
|
|
193
|
+
checks.push(check);
|
|
194
|
+
}
|
|
195
|
+
}
|
|
196
|
+
}
|
|
197
|
+
}
|
|
198
|
+
return checks;
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
function makeCheck(line: string, stepDir: string, workflowPath: string, read: (path: string) => string | undefined): PythonCheck | undefined {
|
|
202
|
+
const match = MAKE_LINE.exec(line.replace(/\s+/g, " "));
|
|
203
|
+
if (!match) return undefined;
|
|
204
|
+
const [, cDir, target] = match;
|
|
205
|
+
if (!CHECK_TARGET.test(target!)) return undefined;
|
|
206
|
+
const dir = normalizeDir(posix.join(stepDir || ".", cDir ?? "."));
|
|
207
|
+
if (dir === undefined) return undefined;
|
|
208
|
+
const found = makeTarget(dir, target!, read);
|
|
209
|
+
if (!found || found.recipe.some(rewrites)) return undefined;
|
|
210
|
+
const scripts = found.prerequisites ? undefined : pythonOnlyRecipe(found, dir, read);
|
|
211
|
+
const command = dir ? `make -C ${dir} ${target}` : `make ${target}`;
|
|
212
|
+
return {
|
|
213
|
+
id: command,
|
|
214
|
+
script: workflowPath,
|
|
215
|
+
runsScript: false,
|
|
216
|
+
command,
|
|
217
|
+
kind: makeKind(target!, found.recipe),
|
|
218
|
+
decision: "RUN",
|
|
219
|
+
reason: `run by CI workflow ${workflowPath}`,
|
|
220
|
+
pythonOnly: scripts !== undefined,
|
|
221
|
+
triggers: [found.path, ...(scripts ?? [])],
|
|
222
|
+
};
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
function toolCheck(line: string, workflowPath: string): PythonCheck | undefined {
|
|
226
|
+
const call = directToolCall(line);
|
|
227
|
+
if (!call) return undefined;
|
|
228
|
+
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: [] };
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
function pythonRelevant(path: string): boolean {
|
|
232
|
+
return PY_FILE.test(path) || PY_CONFIG.test(posix.basename(path)) || path.startsWith(".github/workflows/");
|
|
233
|
+
}
|
|
234
|
+
|
|
235
|
+
/** Skips Python-only checks for a change with no Python file, Python configuration or trigger in it. */
|
|
236
|
+
export function narrowPythonChecks(checks: readonly PythonCheck[], changes: readonly ChangedPath[]): PythonCheck[] {
|
|
237
|
+
return checks.map((check) => {
|
|
238
|
+
if (!check.pythonOnly) return { ...check, reason: `${check.reason}; not read as Python-only, runs as written` };
|
|
239
|
+
const hit = changes.find((change) => pythonRelevant(change.path) || check.triggers.includes(change.path));
|
|
240
|
+
return hit
|
|
241
|
+
? { ...check, reason: `${check.reason}; ${hit.path} changed` }
|
|
242
|
+
: { ...check, decision: "SKIP", reason: `${check.reason}; no changed Python file or Python configuration` };
|
|
243
|
+
});
|
|
244
|
+
}
|
|
@@ -11,6 +11,29 @@ interface Pom {
|
|
|
11
11
|
parent?: Coordinates;
|
|
12
12
|
dependencies: Coordinates[];
|
|
13
13
|
customSourceRoots: boolean;
|
|
14
|
+
/** The module's Java test root relative to the repository, or undefined when it can't be resolved for certain. */
|
|
15
|
+
testRoot?: string;
|
|
16
|
+
/** Every `<testSourceDirectory>` the POM declares, including those inside profiles. */
|
|
17
|
+
declaredTestRoots: string[];
|
|
18
|
+
/** Whether a `<testSourceDirectory>` sits inside a profile, which may or may not be active. */
|
|
19
|
+
profileTestRoot: boolean;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
const DEFAULT_TEST_ROOT = "src/test/java";
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* Resolves a `<testSourceDirectory>` to a repository path. Only a plain relative path inside the module
|
|
26
|
+
* resolves; a `${property}`, an absolute path, a path leaving the module, or several declarations (a
|
|
27
|
+
* profile can override the root) don't, so the caller falls back. Never guess (#163).
|
|
28
|
+
*/
|
|
29
|
+
function resolveTestRoot(dir: string, declared: string[]): string | undefined {
|
|
30
|
+
const roots = [...new Set(declared)];
|
|
31
|
+
if (roots.length > 1) return undefined;
|
|
32
|
+
const root = roots[0] ?? DEFAULT_TEST_ROOT;
|
|
33
|
+
if (!root || root.includes("${") || root.startsWith("/") || /^[A-Za-z]:/.test(root) || root.includes("\\")) return undefined;
|
|
34
|
+
const local = posix.normalize(root).replace(/\/+$/, "");
|
|
35
|
+
if (local === "." || local === ".." || local.startsWith("../")) return undefined;
|
|
36
|
+
return dir ? `${dir}/${local}` : local;
|
|
14
37
|
}
|
|
15
38
|
|
|
16
39
|
function tags(xml: string, name: string): string[] {
|
|
@@ -47,6 +70,10 @@ function parsePom(path: string, source: string): Pom {
|
|
|
47
70
|
// Nested plugin/dependency coordinates are not the project's own identity. In
|
|
48
71
|
// particular, a dependency's ${project.groupId} must not shadow an inherited ID.
|
|
49
72
|
const identity = own.replace(/<(dependencies|dependencyManagement|build|profiles|reporting|properties)\b[^>]*>[\s\S]*?<\/\1>/g, "");
|
|
73
|
+
// A profile's <testSourceDirectory> applies only when that profile is active, which this static
|
|
74
|
+
// adapter can't tell, so such a POM falls back.
|
|
75
|
+
const declaredTestRoots = tags(xml, "testSourceDirectory");
|
|
76
|
+
const profileTestRoot = declaredTestRoots.length !== tags(xml.replace(/<profiles\b[^>]*>[\s\S]*?<\/profiles>/g, ""), "testSourceDirectory").length;
|
|
50
77
|
const dependencies = tags(xml, "dependency")
|
|
51
78
|
.map(value => ({ groupId: first(value, "groupId") ?? "", artifactId: first(value, "artifactId") ?? "" }))
|
|
52
79
|
.filter(value => value.artifactId);
|
|
@@ -56,8 +83,9 @@ function parsePom(path: string, source: string): Pom {
|
|
|
56
83
|
artifactId: first(identity, "artifactId"),
|
|
57
84
|
parent: parent === undefined ? undefined : { groupId: first(parent, "groupId") ?? "", artifactId: first(parent, "artifactId") ?? "" },
|
|
58
85
|
dependencies,
|
|
59
|
-
customSourceRoots: tags(xml, "sourceDirectory").some(root => root !== "src/main/java")
|
|
60
|
-
|
|
86
|
+
customSourceRoots: tags(xml, "sourceDirectory").some(root => root !== "src/main/java"),
|
|
87
|
+
testRoot: profileTestRoot ? undefined : resolveTestRoot(dir, declaredTestRoots),
|
|
88
|
+
declaredTestRoots, profileTestRoot,
|
|
61
89
|
};
|
|
62
90
|
}
|
|
63
91
|
|
|
@@ -65,9 +93,13 @@ function under(dir: string, path: string): boolean { return !dir || path === dir
|
|
|
65
93
|
function owningPom(poms: Pom[], file: string): Pom | undefined {
|
|
66
94
|
return poms.filter(pom => under(pom.dir, file)).sort((a, b) => b.dir.length - a.dir.length)[0];
|
|
67
95
|
}
|
|
68
|
-
/**
|
|
69
|
-
|
|
70
|
-
|
|
96
|
+
/**
|
|
97
|
+
* Surefire's default includes (Test*, *Test, *Tests, *TestCase) and Failsafe's (IT*, *IT, *ITCase), under the
|
|
98
|
+
* module's Java test root or src/test/kotlin.
|
|
99
|
+
*/
|
|
100
|
+
function isTest(pom: Pom, path: string): boolean {
|
|
101
|
+
const roots = [pom.testRoot!, pom.dir ? `${pom.dir}/src/test/kotlin` : "src/test/kotlin"];
|
|
102
|
+
return roots.some(root => path.startsWith(root + "/")) &&
|
|
71
103
|
/^(?:Test.*|IT.*|.*(?:Test|Tests|TestCase|IT|ITCase))\.(?:java|kt)$/.test(posix.basename(path));
|
|
72
104
|
}
|
|
73
105
|
|
|
@@ -83,8 +115,22 @@ export function analyzeMaven(context: AdapterContext): AdapterContribution {
|
|
|
83
115
|
const resources = new Map<Pom, string[]>();
|
|
84
116
|
const anchors = new Map<Pom, string>();
|
|
85
117
|
|
|
118
|
+
// A module that declares no <testSourceDirectory> inherits the nearest local parent's. Unless that is
|
|
119
|
+
// the default root, fall back rather than assume src/test/java.
|
|
120
|
+
for (const pom of poms) {
|
|
121
|
+
if (pom.declaredTestRoots.length) continue;
|
|
122
|
+
const visited = new Set<Pom>([pom]);
|
|
123
|
+
let ancestor = pom.parent && findPom(pom.parent);
|
|
124
|
+
while (ancestor && !visited.has(ancestor) && !ancestor.declaredTestRoots.length) {
|
|
125
|
+
visited.add(ancestor);
|
|
126
|
+
ancestor = ancestor.parent && findPom(ancestor.parent);
|
|
127
|
+
}
|
|
128
|
+
if (ancestor && !visited.has(ancestor) &&
|
|
129
|
+
(ancestor.profileTestRoot || resolveTestRoot("", ancestor.declaredTestRoots) !== DEFAULT_TEST_ROOT)) pom.testRoot = undefined;
|
|
130
|
+
}
|
|
131
|
+
|
|
86
132
|
for (const pom of poms) {
|
|
87
|
-
if (pom.customSourceRoots) result.blockers.push(`Maven ${pom.path}: custom source roots require full validation`);
|
|
133
|
+
if (pom.customSourceRoots || pom.testRoot === undefined) result.blockers.push(`Maven ${pom.path}: custom source roots require full validation`);
|
|
88
134
|
// This static adapter does not construct Maven's effective model. A local parent's
|
|
89
135
|
// dependency declarations cannot safely be treated as belonging only to that POM.
|
|
90
136
|
const visited = new Set<Pom>([pom]);
|
|
@@ -99,7 +145,8 @@ export function analyzeMaven(context: AdapterContext): AdapterContribution {
|
|
|
99
145
|
}
|
|
100
146
|
|
|
101
147
|
const owned = context.files.filter(file => owningPom(poms, file) === pom);
|
|
102
|
-
const sources = owned.filter(file =>
|
|
148
|
+
const sources = owned.filter(file => /\.(?:java|kt)$/.test(file) &&
|
|
149
|
+
(/\/src\/(?:main|test)\/(?:java|kotlin)\//.test("/" + file) || (pom.testRoot !== undefined && file.startsWith(pom.testRoot + "/"))));
|
|
103
150
|
const assets = owned.filter(file => /\/src\/(?:main|test)\/resources\//.test("/" + file));
|
|
104
151
|
members.set(pom, sources);
|
|
105
152
|
resources.set(pom, assets);
|
|
@@ -108,7 +155,7 @@ export function analyzeMaven(context: AdapterContext): AdapterContribution {
|
|
|
108
155
|
result.sourcePaths.push(...sources);
|
|
109
156
|
result.assetPaths.push(...assets);
|
|
110
157
|
for (const file of sources) {
|
|
111
|
-
if (isTest(file)) { result.testFiles.push(file); result.testPackages[file] = pom.dir || "."; }
|
|
158
|
+
if (pom.testRoot !== undefined && isTest(pom, file)) { result.testFiles.push(file); result.testPackages[file] = pom.dir || "."; }
|
|
112
159
|
}
|
|
113
160
|
}
|
|
114
161
|
|
|
@@ -65,7 +65,7 @@ export type PythonImport = [module: string, level: number, names: string[]];
|
|
|
65
65
|
export interface PythonFileImports { imports?: PythonImport[]; dynamic?: boolean; error?: string }
|
|
66
66
|
|
|
67
67
|
const EXCLUDED_DIRS = new Set([".venv", "venv", "env", ".env", ".tox", ".nox", "site-packages", "__pycache__", ".eggs", ".mypy_cache", ".pytest_cache", ".ruff_cache"]);
|
|
68
|
-
const PROJECT_FILES = ["pyproject.toml", "setup.py", "setup.cfg", "pytest.ini", ".pytest.ini", "tox.ini", "conftest.py"];
|
|
68
|
+
const PROJECT_FILES = ["pyproject.toml", "setup.py", "setup.cfg", "pytest.toml", ".pytest.toml", "pytest.ini", ".pytest.ini", "tox.ini", "conftest.py"];
|
|
69
69
|
|
|
70
70
|
export function isPythonSource(path: string): boolean {
|
|
71
71
|
return path.endsWith(".py") && !path.split("/").some((part) => EXCLUDED_DIRS.has(part) || part.endsWith(".egg-info"));
|
|
@@ -163,35 +163,107 @@ export function readPytestSettings(read: (path: string) => string | undefined):
|
|
|
163
163
|
if (plugins.length) settings.plugins = plugins;
|
|
164
164
|
} else settings[key] = values;
|
|
165
165
|
};
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
//
|
|
169
|
-
|
|
166
|
+
const escape = (text: string) => text.replace(/[\\^$.*+?()[\]{}|]/g, "\\$&");
|
|
167
|
+
const isToml = (file: string) => file.endsWith(".toml");
|
|
168
|
+
// A table header may be indented and followed by a comment (`[pytest] # selection`). TOML also allows
|
|
169
|
+
// spaces inside the brackets and quoted keys (`[ pytest ]`, `[tool."pytest"]`), which this reader doesn't
|
|
170
|
+
// match: a header that only matches with spaces and quotes removed makes the file unreadable instead.
|
|
171
|
+
const section = (file: string, text: string, header: string): string | undefined => {
|
|
172
|
+
const comment = isToml(file) ? "#" : "#;";
|
|
173
|
+
return new RegExp(`^[ \\t]*\\[${escape(header)}\\][ \\t]*(?:[${comment}].*)?$([\\s\\S]*?)(?=^[ \\t]*\\[|(?![\\s\\S]))`, "m").exec(text)?.[1];
|
|
174
|
+
};
|
|
175
|
+
const looseHeader = (file: string, text: string, header: string): boolean =>
|
|
176
|
+
isToml(file) && [...text.matchAll(/^[ \t]*\[([^\]\n]*)\]/gm)].some((match) =>
|
|
177
|
+
match[1]!.replace(/[\s"']/g, "") === header && section(file, match[0]!.trim(), header) === undefined);
|
|
178
|
+
const hasEntries = (body: string) => /^[ \t]*[^\s#]/m.test(body);
|
|
179
|
+
const keyAt = (key: string) => `^[ \\t]*${key}[ \\t]*=`;
|
|
180
|
+
// A quoted or dotted key (`"testpaths" = …`, `ini_options.testpaths = …`) can't be told apart from the
|
|
181
|
+
// keys selection reads, so a TOML table with one is unreadable.
|
|
182
|
+
const unclassified = (body: string) => /^[ \t]*(?:"[^"\n]*"|'[^'\n]*'|[A-Za-z0-9_-]+)[ \t]*\./m.test(body) ||
|
|
183
|
+
/^[ \t]*(?:"[^"\n]*"|'[^'\n]*')[ \t]*=/m.test(body);
|
|
184
|
+
// pytest 9's native TOML mode (`pytest.toml`, `[tool.pytest]`): every key selection reads is a list of
|
|
185
|
+
// strings, and each `addopts` item is one argument. Any other type is an error in pytest, so it can't be read.
|
|
186
|
+
const readNative = (file: string, body: string) => {
|
|
187
|
+
if (unclassified(body)) { settings.unreadable = `${file} key DiffCI can't classify`; return settings; }
|
|
188
|
+
for (const key of keys) {
|
|
189
|
+
const array = new RegExp(`${keyAt(key)}[ \\t]*(?=\\[)`, "m").exec(body);
|
|
190
|
+
if (array) {
|
|
191
|
+
const values = readTomlStringArray(body, array.index + array[0].length);
|
|
192
|
+
if (values) apply(key, values);
|
|
193
|
+
else settings.unreadable = `${file} ${key}`;
|
|
194
|
+
} else if (new RegExp(keyAt(key), "m").test(body)) 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"]] as const;
|
|
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: number): string | undefined => {
|
|
203
|
+
for (const [file, header] of order.slice(from)) {
|
|
204
|
+
const text = read(file);
|
|
205
|
+
if (text === undefined || file === ".pytest.toml") continue;
|
|
206
|
+
if (file === "pytest.ini" || file === ".pytest.ini" || section(file, text, header) !== undefined) return file;
|
|
207
|
+
}
|
|
208
|
+
return undefined;
|
|
209
|
+
};
|
|
210
|
+
const native = (file: string, body: string | undefined, index: number) => {
|
|
211
|
+
const older = olderPytestFile(index);
|
|
212
|
+
if (older) { settings.unreadable = `${file} is ignored before pytest 9, which reads ${older}`; return settings; }
|
|
213
|
+
return body === undefined ? settings : readNative(file, body);
|
|
214
|
+
};
|
|
215
|
+
// pytest's search order. `pytest.toml`, `.pytest.toml`, `pytest.ini` and `.pytest.ini` match even when
|
|
216
|
+
// empty or without their `[pytest]` table, and then pytest uses its defaults; the other files only match
|
|
217
|
+
// with their section. The first match wins and options are never merged.
|
|
218
|
+
for (const [index, [file, header]] of order.entries()) {
|
|
170
219
|
const text = read(file);
|
|
171
220
|
if (text === undefined) continue;
|
|
172
|
-
|
|
173
|
-
|
|
221
|
+
if (looseHeader(file, text, "pytest") || looseHeader(file, text, "tool.pytest") || looseHeader(file, text, "tool.pytest.ini_options")) {
|
|
222
|
+
settings.unreadable = `${file} pytest table header DiffCI can't read`;
|
|
223
|
+
return settings;
|
|
224
|
+
}
|
|
225
|
+
if (file === "pytest.toml" || file === ".pytest.toml") {
|
|
226
|
+
const body = section(file, text, "pytest");
|
|
227
|
+
// pytest rejects options written above any table.
|
|
228
|
+
if (body === undefined && hasEntries(text.split(/^[ \t]*\[/m, 1)[0]!)) { settings.unreadable = `${file} options outside [pytest]`; return settings; }
|
|
229
|
+
return native(file, body, index + 1);
|
|
230
|
+
}
|
|
231
|
+
if (file === "pyproject.toml") {
|
|
232
|
+
// `[tool.pytest]` holds native TOML values, `[tool.pytest.ini_options]` INI-style ones. pytest refuses a
|
|
233
|
+
// file that sets both, and an `ini_options` key inside `[tool.pytest]` is a form this reader doesn't parse.
|
|
234
|
+
const nativeBody = section(file, text, "tool.pytest");
|
|
235
|
+
const ini = section(file, text, header);
|
|
236
|
+
if (nativeBody !== undefined && new RegExp(`^[ \\t]*ini_options[ \\t]*[.=]`, "m").test(nativeBody)) { settings.unreadable = `${file} [tool.pytest] ini_options`; return settings; }
|
|
237
|
+
if (nativeBody !== undefined && hasEntries(nativeBody)) {
|
|
238
|
+
if (ini !== undefined && hasEntries(ini)) { settings.unreadable = `${file} [tool.pytest] and [tool.pytest.ini_options]`; return settings; }
|
|
239
|
+
// An empty [tool.pytest.ini_options] beside it is what pytest 8 reads.
|
|
240
|
+
if (ini !== undefined) { settings.unreadable = `${file} [tool.pytest] is ignored before pytest 9, which reads [tool.pytest.ini_options]`; return settings; }
|
|
241
|
+
return native(file, nativeBody, index + 1);
|
|
242
|
+
}
|
|
243
|
+
}
|
|
244
|
+
const body = section(file, text, header);
|
|
245
|
+
if (body === undefined) {
|
|
174
246
|
if (file === "pytest.ini" || file === ".pytest.ini") return settings;
|
|
175
247
|
continue;
|
|
176
248
|
}
|
|
177
|
-
|
|
249
|
+
if (file === "pyproject.toml" && unclassified(body)) { settings.unreadable = `${file} key DiffCI can't classify`; return settings; }
|
|
178
250
|
for (const key of keys) {
|
|
179
251
|
if (file === "pyproject.toml") {
|
|
180
|
-
const match = new RegExp(
|
|
181
|
-
const array = new RegExp(
|
|
252
|
+
const match = new RegExp(`${keyAt(key)}[ \\t]*("[^"]*"|'[^']*')`, "m").exec(body);
|
|
253
|
+
const array = new RegExp(`${keyAt(key)}[ \\t]*(?=\\[)`, "m").exec(body);
|
|
182
254
|
// A multi-line string would otherwise match as an empty one. Its contents are read as one string;
|
|
183
255
|
// a basic string's line-ending backslash only joins lines. An unterminated one cannot be read.
|
|
184
|
-
const multiline = new RegExp(
|
|
256
|
+
const multiline = new RegExp(`${keyAt(key)}[ \\t]*("""|'{3})([\\s\\S]*?)\\1`, "m").exec(body);
|
|
185
257
|
if (multiline) apply(key, splitList(multiline[1] === '"""' ? multiline[2]!.replace(/\\\r?\n/g, " ") : multiline[2]!));
|
|
186
|
-
else if (new RegExp(
|
|
258
|
+
else if (new RegExp(`${keyAt(key)}[ \\t]*(?:"""|'{3})`, "m").test(body)) settings.unreadable = `${file} ${key}`;
|
|
187
259
|
else if (array) {
|
|
188
260
|
const values = readTomlStringArray(body, array.index + array[0].length);
|
|
189
261
|
if (values) apply(key, key === "addopts" ? values.flatMap(splitList) : values);
|
|
190
262
|
else settings.unreadable = `${file} ${key}`;
|
|
191
263
|
} else if (match) apply(key, splitList(match[1]!));
|
|
192
|
-
else if (new RegExp(
|
|
264
|
+
else if (new RegExp(keyAt(key), "m").test(body)) settings.unreadable = `${file} ${key}`;
|
|
193
265
|
} else {
|
|
194
|
-
// INI values continue on indented lines.
|
|
266
|
+
// INI values continue on indented lines, so a key starts at the beginning of a line.
|
|
195
267
|
const match = new RegExp(`^${key}\\s*=\\s*(.*(?:\\r?\\n[ \\t]+.*)*)`, "m").exec(body);
|
|
196
268
|
if (match) apply(key, splitList(match[1]!));
|
|
197
269
|
}
|
|
@@ -8,6 +8,11 @@ function record(value: unknown): value is Record<string, unknown> {
|
|
|
8
8
|
|
|
9
9
|
const plain = (value: unknown): boolean => typeof value === "string" && value.trim() === "cargo test";
|
|
10
10
|
|
|
11
|
+
/** `--workspace` (or its old name `--all`) tests every member. That is plain `cargo test` exactly when
|
|
12
|
+
* plain `cargo test` already covers every member: a single crate, or a virtual workspace without
|
|
13
|
+
* `default-members`. The adapter says which. */
|
|
14
|
+
const wholeWorkspace = (value: unknown): boolean => typeof value === "string" && /^cargo test --(?:workspace|all)$/.test(value.trim());
|
|
15
|
+
|
|
11
16
|
/** Steps that install a toolchain, restore caches or check out the code. They choose which compiler
|
|
12
17
|
* runs, the same for the selected and the full command, but not which tests run or with what flags. */
|
|
13
18
|
const SETUP_ACTION = /^(?:actions\/checkout|actions\/cache(?:\/restore)?|actions\/upload-artifact|Swatinem\/rust-cache|dtolnay\/rust-toolchain|actions-rust-lang\/setup-rust-toolchain|actions-rs\/toolchain)@[A-Za-z0-9._/-]+$/;
|
|
@@ -16,12 +21,44 @@ const SETUP_ACTION = /^(?:actions\/checkout|actions\/cache(?:\/restore)?|actions
|
|
|
16
21
|
* per step: chaining, substitution or redirection could hide another invocation. */
|
|
17
22
|
const NON_TEST_COMMAND = /^(?:cargo (?:build|check|clippy|fmt|doc)|rustup (?:component|target|toolchain|default|show|update))(?: [A-Za-z0-9_.,:=@+/-]+)*$/;
|
|
18
23
|
|
|
24
|
+
/** rustup commands chained with `&&` (`rustup default stable && rustup update --no-self-update`),
|
|
25
|
+
* where an argument may be a matrix value. Only rustup, so the chain cannot hide a test run. */
|
|
26
|
+
const RUSTUP_ARGUMENT = String.raw`(?:[A-Za-z0-9_.,:=@+/-]+|\$\{\{ ?matrix\.([A-Za-z0-9_-]+) ?\}\})`;
|
|
27
|
+
const RUSTUP_COMMAND = new RegExp(String.raw`^rustup (?:component|target|toolchain|default|show|update)(?: ${RUSTUP_ARGUMENT})*$`);
|
|
28
|
+
|
|
29
|
+
/** A matrix value is pasted into the script as text, so each one a rustup step uses must be a plain
|
|
30
|
+
* toolchain-like word, in the matrix and in every `include` entry. */
|
|
31
|
+
function plainMatrixValues(strategy: unknown, key: string): boolean {
|
|
32
|
+
if (!record(strategy) || !record(strategy.matrix)) return false;
|
|
33
|
+
const word = (value: unknown) => (typeof value === "string" || typeof value === "number") && /^[A-Za-z0-9_.-]+$/.test(String(value));
|
|
34
|
+
const values = strategy.matrix[key];
|
|
35
|
+
const include = strategy.matrix.include;
|
|
36
|
+
if (include !== undefined && (!Array.isArray(include) || include.some(entry => !record(entry) || (key in entry && !word(entry[key]))))) return false;
|
|
37
|
+
if (values === undefined) return Array.isArray(include) && include.some(entry => record(entry) && key in entry);
|
|
38
|
+
return Array.isArray(values) && values.length > 0 && values.every(word);
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
function setupCommand(run: string, strategy: unknown): boolean {
|
|
42
|
+
if (NON_TEST_COMMAND.test(run)) return true;
|
|
43
|
+
const parts = run.split(" && ");
|
|
44
|
+
return parts.every(part => {
|
|
45
|
+
if (!RUSTUP_COMMAND.test(part)) return false;
|
|
46
|
+
return [...part.matchAll(/\$\{\{ ?matrix\.([A-Za-z0-9_-]+) ?\}\}/g)].every(match => plainMatrixValues(strategy, match[1]!));
|
|
47
|
+
});
|
|
48
|
+
}
|
|
49
|
+
|
|
19
50
|
/** Environment that changes output or retries, never what is compiled or tested. */
|
|
20
|
-
const NEUTRAL_ENV = new Set(["CARGO_TERM_COLOR", "CARGO_INCREMENTAL", "CARGO_NET_RETRY", "CARGO_NET_GIT_FETCH_WITH_CLI",
|
|
51
|
+
const NEUTRAL_ENV = new Set(["CARGO_TERM_COLOR", "CARGO_TERM_VERBOSE", "CARGO_INCREMENTAL", "CARGO_NET_RETRY", "CARGO_NET_GIT_FETCH_WITH_CLI",
|
|
21
52
|
"CARGO_REGISTRIES_CRATES_IO_PROTOCOL", "RUST_BACKTRACE", "RUSTUP_MAX_RETRIES", "CI"]);
|
|
22
53
|
|
|
54
|
+
/** `RUSTFLAGS: -Dwarnings` (and the same for rustdoc) turns warnings into errors. It changes neither
|
|
55
|
+
* what is compiled nor which tests run, and applies equally to the selected and the full command.
|
|
56
|
+
* Any other flag (cfg, codegen, target features, sanitizers) still makes the evidence advisory. */
|
|
57
|
+
const DENY_WARNINGS = /^\s*(?:(?:-D ?warnings|--deny[= ]warnings)\s*)+$/;
|
|
58
|
+
|
|
23
59
|
const neutralEnv = (value: unknown): boolean => value === undefined || record(value)
|
|
24
|
-
&& Object.entries(value).every(([key, setting]) =>
|
|
60
|
+
&& Object.entries(value).every(([key, setting]) => ["string", "number", "boolean"].includes(typeof setting) && !String(setting).includes("${{")
|
|
61
|
+
&& (NEUTRAL_ENV.has(key) || ["RUSTFLAGS", "RUSTDOCFLAGS"].includes(key) && DENY_WARNINGS.test(String(setting))));
|
|
25
62
|
|
|
26
63
|
/** Workflow and job keys with no effect on how a step's command runs. */
|
|
27
64
|
const WORKFLOW_KEYS = new Set(["name", "run-name", "on", "true", "permissions", "concurrency", "env", "jobs"]);
|
|
@@ -31,8 +68,9 @@ const TEST_STEP_KEYS = new Set(["name", "id", "run", "env", "timeout-minutes"]);
|
|
|
31
68
|
|
|
32
69
|
/** Evidence for the one invocation whose flags and execution context we can reproduce.
|
|
33
70
|
* Do not turn a Cargo manifest, a wrapper or a feature-specific CI run into plain cargo test. */
|
|
34
|
-
export function rustTestInvocation(repoPath: string, files: readonly string[]): "cargo test" | undefined {
|
|
71
|
+
export function rustTestInvocation(repoPath: string, files: readonly string[], options: { allMembersTested?: boolean } = {}): "cargo test" | undefined {
|
|
35
72
|
let found = false;
|
|
73
|
+
const testCommand = (value: unknown) => plain(value) || options.allMembersTested === true && wholeWorkspace(value);
|
|
36
74
|
if (files.includes("package.json")) {
|
|
37
75
|
try {
|
|
38
76
|
const manifest: unknown = JSON.parse(readFileSync(join(repoPath, "package.json"), "utf8"));
|
|
@@ -41,7 +79,7 @@ export function rustTestInvocation(repoPath: string, files: readonly string[]):
|
|
|
41
79
|
if (!record(manifest.scripts)) return undefined;
|
|
42
80
|
// A plain command under an unrelated script name is not evidence that the actual
|
|
43
81
|
// test entrypoint has the same semantics. Unknown scripts may wrap additional suites.
|
|
44
|
-
if (!
|
|
82
|
+
if (!testCommand(manifest.scripts.test) || Object.values(manifest.scripts).some(script => !testCommand(script))) return undefined;
|
|
45
83
|
if (Object.keys(manifest.scripts).some(name => /^(?:pre|post)/.test(name))) return undefined;
|
|
46
84
|
found = true;
|
|
47
85
|
}
|
|
@@ -61,11 +99,11 @@ export function rustTestInvocation(repoPath: string, files: readonly string[]):
|
|
|
61
99
|
for (const step of job.steps) {
|
|
62
100
|
if (!record(step)) return undefined;
|
|
63
101
|
if ("run" in step) {
|
|
64
|
-
if (
|
|
102
|
+
if (testCommand(step.run)) {
|
|
65
103
|
// The test step itself runs unconditionally, in the checkout root, with the default shell.
|
|
66
104
|
if (Object.keys(step).some(key => !TEST_STEP_KEYS.has(key)) || !neutralEnv(step.env)) return undefined;
|
|
67
105
|
found = true;
|
|
68
|
-
} else if (typeof step.run !== "string" || !
|
|
106
|
+
} else if (typeof step.run !== "string" || !setupCommand(step.run.trim(), job.strategy)
|
|
69
107
|
|| Object.keys(step).some(key => !["name", "id", "run", "env", "if", "timeout-minutes", "continue-on-error"].includes(key)) || !neutralEnv(step.env)) {
|
|
70
108
|
// Wrappers, nextest, cargo make, just, other `cargo test` flags and unknown scripts are
|
|
71
109
|
// not reproduced, before or after the test and in any job.
|