@diffci.com/diffci 0.3.54 → 0.3.56
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/agent-selection.d.ts +9 -2
- package/dist-client/src/client/agent-selection.js +20 -8
- package/dist-client/src/client/agent-setup.js +1 -1
- package/dist-client/src/client/cli.js +19 -7
- package/dist-client/src/client/command-batches.js +3 -2
- package/dist-client/src/client/context.d.ts +2 -0
- package/dist-client/src/client/context.js +51 -2
- package/dist-client/src/client/coverage-map.js +6 -1
- package/dist-client/src/client/full-command.js +22 -14
- package/dist-client/src/client/gate.js +24 -10
- package/dist-client/src/client/hook.d.ts +17 -0
- package/dist-client/src/client/hook.js +53 -1
- package/dist-client/src/client/install.d.ts +6 -0
- package/dist-client/src/client/install.js +29 -1
- 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/mcp.js +4 -0
- package/dist-client/src/client/observe.js +4 -3
- package/dist-client/src/client/report.d.ts +8 -1
- package/dist-client/src/client/report.js +11 -0
- package/dist-client/src/client/shared-graph-cache.js +4 -2
- package/dist-client/src/client/telemetry.js +2 -1
- package/dist-client/src/client/usage-signal.d.ts +1 -1
- package/dist-client/src/client/verify-savings.d.ts +6 -0
- package/dist-client/src/client/verify-savings.js +15 -3
- package/dist-client/src/client/verify.js +124 -22
- 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 +17 -10
- package/node_modules/@diffci.com/core/dist/ci-inference/expression.d.ts +5 -0
- package/node_modules/@diffci.com/core/dist/ci-inference/expression.js +38 -5
- package/node_modules/@diffci.com/core/dist/ci-inference/expression.js.map +1 -1
- package/node_modules/@diffci.com/core/dist/ci-inference/infer.js +26 -6
- package/node_modules/@diffci.com/core/dist/ci-inference/infer.js.map +1 -1
- package/node_modules/@diffci.com/core/dist/ci-inference/jobs.d.ts +2 -1
- package/node_modules/@diffci.com/core/dist/ci-inference/jobs.js +7 -2
- package/node_modules/@diffci.com/core/dist/ci-inference/jobs.js.map +1 -1
- package/node_modules/@diffci.com/core/dist/ci-inference/matrix.js +15 -8
- package/node_modules/@diffci.com/core/dist/ci-inference/matrix.js.map +1 -1
- package/node_modules/@diffci.com/core/dist/ci-inference/purpose.js +6 -2
- package/node_modules/@diffci.com/core/dist/ci-inference/purpose.js.map +1 -1
- package/node_modules/@diffci.com/core/dist/ci-inference/resolve.js +38 -5
- package/node_modules/@diffci.com/core/dist/ci-inference/resolve.js.map +1 -1
- package/node_modules/@diffci.com/core/dist/git/ci-config-paths.js +13 -1
- package/node_modules/@diffci.com/core/dist/git/ci-config-paths.js.map +1 -1
- package/node_modules/@diffci.com/core/dist/git/git-diff.d.ts +5 -0
- package/node_modules/@diffci.com/core/dist/git/git-diff.js +64 -31
- package/node_modules/@diffci.com/core/dist/git/git-diff.js.map +1 -1
- package/node_modules/@diffci.com/core/dist/planner/check-narrowing.js +22 -1
- package/node_modules/@diffci.com/core/dist/planner/check-narrowing.js.map +1 -1
- package/node_modules/@diffci.com/core/dist/planner/pipeline-steps.d.ts +6 -0
- package/node_modules/@diffci.com/core/dist/planner/pipeline-steps.js +14 -2
- package/node_modules/@diffci.com/core/dist/planner/pipeline-steps.js.map +1 -1
- package/node_modules/@diffci.com/core/dist/planner/planner.js +65 -14
- package/node_modules/@diffci.com/core/dist/planner/planner.js.map +1 -1
- package/node_modules/@diffci.com/core/dist/planner/rust-command.js +43 -1
- package/node_modules/@diffci.com/core/dist/planner/rust-command.js.map +1 -1
- package/node_modules/@diffci.com/core/dist/planner/script-reads.js +5 -2
- package/node_modules/@diffci.com/core/dist/planner/script-reads.js.map +1 -1
- package/node_modules/@diffci.com/core/dist/planner/test-command.js +17 -2
- package/node_modules/@diffci.com/core/dist/planner/test-command.js.map +1 -1
- package/node_modules/@diffci.com/core/dist/planner/type-program.js +27 -1
- package/node_modules/@diffci.com/core/dist/planner/type-program.js.map +1 -1
- package/node_modules/@diffci.com/core/dist/repo/adapters/go.js +5 -1
- package/node_modules/@diffci.com/core/dist/repo/adapters/go.js.map +1 -1
- package/node_modules/@diffci.com/core/dist/repo/adapters/maven.js +71 -9
- package/node_modules/@diffci.com/core/dist/repo/adapters/maven.js.map +1 -1
- package/node_modules/@diffci.com/core/dist/repo/adapters/python.d.ts +9 -1
- package/node_modules/@diffci.com/core/dist/repo/adapters/python.js +259 -18
- 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.d.ts +1 -0
- package/node_modules/@diffci.com/core/dist/repo/adapters/rust.js +338 -24
- 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 +10 -0
- package/node_modules/@diffci.com/core/dist/repo/adapters/types.js.map +1 -1
- package/node_modules/@diffci.com/core/dist/repo/file-references.d.ts +16 -0
- package/node_modules/@diffci.com/core/dist/repo/file-references.js +76 -5
- package/node_modules/@diffci.com/core/dist/repo/file-references.js.map +1 -1
- package/node_modules/@diffci.com/core/dist/repo/graph.js +101 -30
- package/node_modules/@diffci.com/core/dist/repo/graph.js.map +1 -1
- package/node_modules/@diffci.com/core/dist/repo/impact.d.ts +7 -0
- package/node_modules/@diffci.com/core/dist/repo/impact.js +56 -9
- package/node_modules/@diffci.com/core/dist/repo/impact.js.map +1 -1
- package/node_modules/@diffci.com/core/dist/repo/layout.js +4 -1
- package/node_modules/@diffci.com/core/dist/repo/layout.js.map +1 -1
- package/node_modules/@diffci.com/core/dist/repo/runner-universe.js +10 -1
- package/node_modules/@diffci.com/core/dist/repo/runner-universe.js.map +1 -1
- package/node_modules/@diffci.com/core/dist/repo/script-universe.js +1 -1
- package/node_modules/@diffci.com/core/dist/repo/script-universe.js.map +1 -1
- package/node_modules/@diffci.com/core/dist/repo/test-discovery.js +5 -1
- package/node_modules/@diffci.com/core/dist/repo/test-discovery.js.map +1 -1
- package/node_modules/@diffci.com/core/dist/repo/types.d.ts +3 -0
- package/node_modules/@diffci.com/core/dist/repo/workflow-test-steps.js +3 -3
- package/node_modules/@diffci.com/core/dist/repo/workflow-test-steps.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/dist/research/baseline/matcher.js +65 -13
- package/node_modules/@diffci.com/core/dist/research/baseline/matcher.js.map +1 -1
- package/node_modules/@diffci.com/core/dist/research/baseline/workflow-parser.js +47 -2
- package/node_modules/@diffci.com/core/dist/research/baseline/workflow-parser.js.map +1 -1
- package/node_modules/@diffci.com/core/package.json +1 -0
- package/node_modules/@diffci.com/core/src/ci-inference/expression.ts +38 -5
- package/node_modules/@diffci.com/core/src/ci-inference/infer.ts +21 -6
- package/node_modules/@diffci.com/core/src/ci-inference/jobs.ts +7 -2
- package/node_modules/@diffci.com/core/src/ci-inference/matrix.ts +15 -8
- package/node_modules/@diffci.com/core/src/ci-inference/purpose.ts +6 -2
- package/node_modules/@diffci.com/core/src/ci-inference/resolve.ts +37 -5
- package/node_modules/@diffci.com/core/src/git/ci-config-paths.ts +8 -1
- package/node_modules/@diffci.com/core/src/git/git-diff.ts +57 -32
- package/node_modules/@diffci.com/core/src/planner/check-narrowing.ts +22 -1
- package/node_modules/@diffci.com/core/src/planner/pipeline-steps.ts +13 -2
- package/node_modules/@diffci.com/core/src/planner/planner.ts +42 -14
- package/node_modules/@diffci.com/core/src/planner/rust-command.ts +37 -1
- package/node_modules/@diffci.com/core/src/planner/script-reads.ts +5 -1
- package/node_modules/@diffci.com/core/src/planner/test-command.ts +17 -2
- package/node_modules/@diffci.com/core/src/planner/type-program.ts +25 -1
- package/node_modules/@diffci.com/core/src/repo/adapters/go.ts +5 -1
- package/node_modules/@diffci.com/core/src/repo/adapters/maven.ts +74 -9
- package/node_modules/@diffci.com/core/src/repo/adapters/python.ts +209 -18
- 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 +264 -24
- package/node_modules/@diffci.com/core/src/repo/adapters/types.ts +10 -1
- package/node_modules/@diffci.com/core/src/repo/file-references.ts +70 -5
- package/node_modules/@diffci.com/core/src/repo/graph.ts +82 -21
- package/node_modules/@diffci.com/core/src/repo/impact.ts +57 -8
- package/node_modules/@diffci.com/core/src/repo/layout.ts +5 -1
- package/node_modules/@diffci.com/core/src/repo/runner-universe.ts +11 -1
- package/node_modules/@diffci.com/core/src/repo/script-universe.ts +1 -1
- package/node_modules/@diffci.com/core/src/repo/test-discovery.ts +4 -1
- package/node_modules/@diffci.com/core/src/repo/types.ts +3 -1
- package/node_modules/@diffci.com/core/src/repo/workflow-test-steps.ts +3 -3
- 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/node_modules/@diffci.com/core/src/research/baseline/matcher.ts +43 -13
- package/node_modules/@diffci.com/core/src/research/baseline/workflow-parser.ts +44 -2
- package/package.json +2 -2
|
@@ -16,6 +16,7 @@ export interface CargoTarget {
|
|
|
16
16
|
export interface CargoPackage {
|
|
17
17
|
id: string;
|
|
18
18
|
name: string;
|
|
19
|
+
version?: string;
|
|
19
20
|
manifest_path: string;
|
|
20
21
|
targets: CargoTarget[];
|
|
21
22
|
source?: string | null;
|
|
@@ -124,7 +125,8 @@ export function parseCargoMetadata(output: string): CargoMetadata {
|
|
|
124
125
|
if (!object(pkg) || typeof pkg.id !== "string" || !pkg.id || typeof pkg.name !== "string"
|
|
125
126
|
|| !/^[A-Za-z0-9_][A-Za-z0-9_-]*$/.test(pkg.name) || typeof pkg.manifest_path !== "string"
|
|
126
127
|
|| !isAbsolute(pkg.manifest_path) || !Array.isArray(pkg.targets) || !pkg.targets.length
|
|
127
|
-
|| (pkg.source !== undefined && pkg.source !== null && typeof pkg.source !== "string")
|
|
128
|
+
|| (pkg.source !== undefined && pkg.source !== null && typeof pkg.source !== "string")
|
|
129
|
+
|| (pkg.version !== undefined && typeof pkg.version !== "string")) {
|
|
128
130
|
throw new Error("Invalid Cargo package metadata");
|
|
129
131
|
}
|
|
130
132
|
for (const target of pkg.targets) {
|
|
@@ -197,7 +199,7 @@ function completeRustInventory(root: string, files: ReadonlySet<string>, trees:
|
|
|
197
199
|
|
|
198
200
|
/** A small lexer, not a Rust parser: ignore comments/strings, but never guess
|
|
199
201
|
* a computed include. Nested comments and raw strings must not hide an input. */
|
|
200
|
-
function rustInputs(source: string): { inputs: Array<{ path: string; code: boolean }>; paths: string[]; compiles: boolean; navigates: boolean; documentation: boolean } | undefined {
|
|
202
|
+
function rustInputs(source: string): { inputs: Array<{ path: string; code: boolean; module?: string[] }>; paths: string[]; compiles: boolean; navigates: boolean; documentation: boolean; runsPrograms: boolean } | undefined {
|
|
201
203
|
const tokens: Array<{ value: string; literal?: string }> = [];
|
|
202
204
|
for (let i = 0; i < source.length;) {
|
|
203
205
|
if (/\s/.test(source[i]!)) { i++; continue; }
|
|
@@ -212,7 +214,9 @@ function rustInputs(source: string): { inputs: Array<{ path: string; code: boole
|
|
|
212
214
|
if (depth) return undefined;
|
|
213
215
|
continue;
|
|
214
216
|
}
|
|
215
|
-
|
|
217
|
+
// Byte and C raw strings (`br"\"`, `cr#"say "hi""#`) take no escapes either; read as a `b`/`c`
|
|
218
|
+
// identifier and an ordinary string, a backslash or quote inside would hide the code after them.
|
|
219
|
+
const raw = /^[bc]?r(#{0,255})"/.exec(source.slice(i));
|
|
216
220
|
if (raw) {
|
|
217
221
|
const start = i + raw[0].length, end = source.indexOf(`"${raw[1]}`, start);
|
|
218
222
|
if (end < 0) return undefined;
|
|
@@ -238,23 +242,54 @@ function rustInputs(source: string): { inputs: Array<{ path: string; code: boole
|
|
|
238
242
|
// dependency edge cannot see is code that reaches another crate's modelled Rust inputs at run or
|
|
239
243
|
// build time. Report literal paths (the caller checks which crates they reach) and Cargo/rustc
|
|
240
244
|
// invocations; ordinary identifiers such as `fs`, `process`, `unsafe` or `metadata` are not inputs.
|
|
241
|
-
const inputs: Array<{ path: string; code: boolean }> = [];
|
|
245
|
+
const inputs: Array<{ path: string; code: boolean; module?: string[] }> = [];
|
|
246
|
+
// Inline `mod name { ... }` blocks open around each token, for `#[path]` (null: any other brace).
|
|
247
|
+
const blocks: Array<string | null> = [];
|
|
242
248
|
const paths: string[] = [];
|
|
243
249
|
let compiles = false;
|
|
250
|
+
let runsPrograms = false;
|
|
244
251
|
const includeArguments = new Set<number>();
|
|
245
252
|
for (let i = 0; i < tokens.length; i++) {
|
|
246
253
|
if (tokens[i]!.value === "mod" && tokens[i + 1]?.value === "target" && tokens[i + 2]?.value === ";") return undefined;
|
|
254
|
+
if (tokens[i]!.value === "{") blocks.push(tokens[i - 2]?.value === "mod" && /^[A-Za-z_]/.test(tokens[i - 1]?.value ?? "") ? tokens[i - 1]!.value : null);
|
|
255
|
+
if (tokens[i]!.value === "}") blocks.pop();
|
|
247
256
|
if (tokens[i]!.value === "#") {
|
|
248
257
|
let j = i + 1;
|
|
249
258
|
if (tokens[j]?.value === "!") j++;
|
|
250
259
|
if (tokens[j]?.value === "[") {
|
|
251
260
|
let depth = 1;
|
|
261
|
+
const paths: string[] = [];
|
|
252
262
|
for (j++; j < tokens.length && depth; j++) {
|
|
253
263
|
if (tokens[j]!.value === "[") depth++;
|
|
254
264
|
if (tokens[j]!.value === "]") depth--;
|
|
255
|
-
if (tokens[j]!.value === "path" && tokens[j + 1]?.value === "=")
|
|
265
|
+
if (tokens[j]!.value === "path" && tokens[j + 1]?.value === "=") {
|
|
266
|
+
// `#[path = "x.rs"]` or `#[cfg_attr(pred, path = "x.rs")]` with a plain literal.
|
|
267
|
+
const literal = tokens[j + 2]?.literal;
|
|
268
|
+
if (tokens[i + 1]?.value === "!" || !["[", ","].includes(tokens[j - 1]?.value ?? "") || literal === undefined
|
|
269
|
+
|| !["]", ",", ")"].includes(tokens[j + 3]?.value ?? "") || /[\0\r\n]/.test(literal)) return undefined;
|
|
270
|
+
paths.push(literal);
|
|
271
|
+
}
|
|
256
272
|
}
|
|
257
273
|
if (depth) return undefined;
|
|
274
|
+
if (paths.length) {
|
|
275
|
+
// Only on a file module (`mod name;`), after any other attributes and visibility: on an
|
|
276
|
+
// inline module the path would move every module declared inside it.
|
|
277
|
+
let k = j;
|
|
278
|
+
for (;;) {
|
|
279
|
+
if (tokens[k]?.value === "#" && tokens[k + 1]?.value === "[") {
|
|
280
|
+
let nested = 1;
|
|
281
|
+
for (k += 2; k < tokens.length && nested; k++) nested += tokens[k]!.value === "[" ? 1 : tokens[k]!.value === "]" ? -1 : 0;
|
|
282
|
+
} else if (tokens[k]?.value === "pub" && tokens[k + 1]?.value === "(") {
|
|
283
|
+
k = tokens.findIndex((token, index) => index > k && token.value === ")") + 1;
|
|
284
|
+
if (!k) return undefined;
|
|
285
|
+
} else if (tokens[k]?.value === "pub") k++;
|
|
286
|
+
else break;
|
|
287
|
+
}
|
|
288
|
+
if (tokens[k]?.value !== "mod" || !/^[A-Za-z_]/.test(tokens[k + 1]?.value ?? "") || tokens[k + 2]?.value !== ";") return undefined;
|
|
289
|
+
const module = blocks.filter((name): name is string => name !== null);
|
|
290
|
+
if (blocks.length !== module.length) return undefined;
|
|
291
|
+
for (const path of paths) inputs.push({ path, code: true, module });
|
|
292
|
+
}
|
|
258
293
|
}
|
|
259
294
|
}
|
|
260
295
|
if (tokens[i]!.value === "use") {
|
|
@@ -266,6 +301,13 @@ function rustInputs(source: string): { inputs: Array<{ path: string; code: boole
|
|
|
266
301
|
}
|
|
267
302
|
if (tokens[i]!.value === "Command" && tokens[i + 1]?.value === ":" && tokens[i + 2]?.value === ":" && tokens[i + 3]?.value === "new"
|
|
268
303
|
&& tokens[i + 4]?.value === "(" && /^(?:cargo|rustc|rustdoc)(?:\.exe)?$|^cargo-/.test(tokens[i + 5]?.literal ?? "")) compiles = true;
|
|
304
|
+
// Any other program (a script, a shell, a tool) could read files no Rust edge shows. Running the
|
|
305
|
+
// package's own binary (`env!("CARGO_BIN_EXE_name")`) is Rust code Cargo already models. This is a
|
|
306
|
+
// token heuristic: clap's `Command::new("app")` counts too, which only fails closed.
|
|
307
|
+
if (tokens[i]!.value === "Command" && tokens[i + 1]?.value === ":" && tokens[i + 2]?.value === ":" && tokens[i + 3]?.value === "new"
|
|
308
|
+
&& tokens[i + 4]?.value === "(" && !/^(?:cargo|rustc|rustdoc)(?:\.exe)?$|^cargo-/.test(tokens[i + 5]?.literal ?? "")
|
|
309
|
+
&& !(tokens[i + 5]?.value === "env" && tokens[i + 6]?.value === "!" && tokens[i + 7]?.value === "(" && /^CARGO_BIN_EXE_/.test(tokens[i + 8]?.literal ?? ""))) runsPrograms = true;
|
|
310
|
+
if (["duct", "xshell", "subprocess"].includes(tokens[i]!.value) || (tokens[i]!.value === "cmd" && tokens[i + 1]?.value === "!")) runsPrograms = true;
|
|
269
311
|
// `env!("CARGO")`, `env::var("RUSTC")` and similar name the toolchain a test is about to run.
|
|
270
312
|
if (["CARGO", "RUSTC", "RUSTDOC", "RUSTC_WRAPPER"].includes(tokens[i]!.literal ?? "")) compiles = true;
|
|
271
313
|
if (!["include", "include_str", "include_bytes"].includes(tokens[i]!.value) || tokens[i + 1]?.value !== "!") continue;
|
|
@@ -288,7 +330,7 @@ function rustInputs(source: string): { inputs: Array<{ path: string; code: boole
|
|
|
288
330
|
});
|
|
289
331
|
const navigates = navigatesUpward(tokens);
|
|
290
332
|
// Code that climbs out of its crate can walk to README or docs without naming them.
|
|
291
|
-
return { inputs, paths, compiles, navigates, documentation: documentation || navigates };
|
|
333
|
+
return { inputs, paths, compiles, navigates, documentation: documentation || navigates, runsPrograms };
|
|
292
334
|
}
|
|
293
335
|
|
|
294
336
|
/** Code that climbs out of its crate directory in code (`.parent()`, `.ancestors()`, `PathBuf::pop`,
|
|
@@ -307,6 +349,89 @@ function navigatesUpward(tokens: ReadonlyArray<{ value: string; literal?: string
|
|
|
307
349
|
});
|
|
308
350
|
}
|
|
309
351
|
|
|
352
|
+
/** Doc-comment words that keep a fenced block Rust (rustdoc's doctest attributes). Any other word
|
|
353
|
+
* (`text`, `toml`, `sh`, ...) makes the block another language unless `rust` is also given. */
|
|
354
|
+
const DOCTEST_ATTRIBUTE = /^(?:rust|ignore(?:-\S+)?|should_panic|no_run|compile_fail|edition\d{4}|standalone_crate|test_harness|allow_fail|E\d{4})$/;
|
|
355
|
+
|
|
356
|
+
/** Rustdoc compiles and runs the code blocks in doc comments (`///`, `//!`, `/** *\/`, `/*! *\/`)
|
|
357
|
+
* as doctests, from the crate directory. The input scan skips comments, so this returns the code of
|
|
358
|
+
* every block that may be Rust: fenced blocks with no other language and indented blocks, with
|
|
359
|
+
* rustdoc's hidden-line `# ` prefix removed. */
|
|
360
|
+
function doctestCode(source: string): string {
|
|
361
|
+
const code: string[] = [];
|
|
362
|
+
for (const group of docComments(source)) {
|
|
363
|
+
const indent = Math.min(...group.filter(line => line.trim()).map(line => /^\s*/.exec(line)![0].length));
|
|
364
|
+
let fence: string | undefined; let rust = false; let previousBlank = true; let indented = false;
|
|
365
|
+
for (const raw of group) {
|
|
366
|
+
const line = raw.slice(Number.isFinite(indent) ? indent : 0);
|
|
367
|
+
const marker = /^ {0,3}(`{3,}|~{3,})(.*)$/.exec(line);
|
|
368
|
+
if (fence === undefined && marker) {
|
|
369
|
+
const words = marker[2]!.split(/[\s,{}.]+/).filter(Boolean);
|
|
370
|
+
fence = marker[1]!; rust = !words.length || words.includes("rust") || words.every(word => DOCTEST_ATTRIBUTE.test(word));
|
|
371
|
+
} else if (fence !== undefined && marker && marker[1]!.startsWith(fence) && !marker[2]!.trim()) fence = undefined;
|
|
372
|
+
else if (fence !== undefined) { if (rust) code.push(line.replace(/^\s*#(?: |$)/, "")); }
|
|
373
|
+
// An indented block (four spaces after a blank line) is a doctest too.
|
|
374
|
+
else if (/^ {4}/.test(line) && (previousBlank || indented)) { code.push(line.slice(4).replace(/^\s*#(?: |$)/, "")); indented = true; continue; }
|
|
375
|
+
if (line.trim()) indented = false;
|
|
376
|
+
previousBlank = !line.trim();
|
|
377
|
+
}
|
|
378
|
+
}
|
|
379
|
+
return code.join("\n");
|
|
380
|
+
}
|
|
381
|
+
|
|
382
|
+
/** The text of each doc comment in a file, as lines: a run of `///` or `//!` lines, or one `/** *\/`
|
|
383
|
+
* or `/*! *\/` block (leading `*` removed). Strings, character literals and plain comments are skipped
|
|
384
|
+
* the way the input scan skips them, so a `"/**"` glob or a commented-out `///` is not a doc comment. */
|
|
385
|
+
function docComments(source: string): string[][] {
|
|
386
|
+
const groups: string[][] = [];
|
|
387
|
+
let lineGroup: string[] | undefined; let lineGroupEnd = -1;
|
|
388
|
+
for (let i = 0; i < source.length;) {
|
|
389
|
+
if (source.startsWith("//", i)) {
|
|
390
|
+
const end = source.indexOf("\n", i) < 0 ? source.length : source.indexOf("\n", i);
|
|
391
|
+
const doc = /^\/\/(?:\/(?!\/)|!)(.*)$/.exec(source.slice(i, end).replace(/\r$/, ""));
|
|
392
|
+
if (doc) {
|
|
393
|
+
if (!lineGroup || !/^[ \t]*\r?\n[ \t]*$/.test(source.slice(lineGroupEnd, i))) groups.push(lineGroup = []);
|
|
394
|
+
lineGroup.push(doc[1]!); lineGroupEnd = end;
|
|
395
|
+
}
|
|
396
|
+
i = end; continue;
|
|
397
|
+
}
|
|
398
|
+
if (source.startsWith("/*", i)) {
|
|
399
|
+
const start = i; let depth = 1; i += 2;
|
|
400
|
+
while (i < source.length && depth) {
|
|
401
|
+
if (source.startsWith("/*", i)) { depth++; i += 2; }
|
|
402
|
+
else if (source.startsWith("*/", i)) { depth--; i += 2; }
|
|
403
|
+
else i++;
|
|
404
|
+
}
|
|
405
|
+
if (/^\/\*(?:\*(?![*/])|!)/.test(source.slice(start, start + 4))) {
|
|
406
|
+
const lines = source.slice(start + 3, depth ? i : i - 2).split(/\r?\n/);
|
|
407
|
+
const starred = lines.slice(1).filter(line => line.trim()).every(line => /^\s*\*/.test(line));
|
|
408
|
+
groups.push(starred ? lines.map((line, index) => index ? line.replace(/^\s*\*/, "") : line) : lines);
|
|
409
|
+
}
|
|
410
|
+
continue;
|
|
411
|
+
}
|
|
412
|
+
const raw = /^[bc]?r(#{0,255})"/.exec(source.slice(i, i + 260));
|
|
413
|
+
if (raw) { const end = source.indexOf(`"${raw[1]}`, i + raw[0].length); i = end < 0 ? source.length : end + raw[1]!.length + 1; continue; }
|
|
414
|
+
if (source[i] === '"') { for (i++; i < source.length && source[i] !== '"'; i++) if (source[i] === "\\") i++; i++; continue; }
|
|
415
|
+
const character = /^'(?:\\.|[^'\\\n])'/.exec(source.slice(i, i + 4));
|
|
416
|
+
if (character) { i += character[0].length; continue; }
|
|
417
|
+
const identifier = /^[A-Za-z0-9_]+/.exec(source.slice(i, i + 256));
|
|
418
|
+
i += identifier ? identifier[0].length : 1;
|
|
419
|
+
}
|
|
420
|
+
return groups;
|
|
421
|
+
}
|
|
422
|
+
|
|
423
|
+
/** The inputs of a Rust file's code and of its doctests. */
|
|
424
|
+
function rustSourceInputs(source: string): ReturnType<typeof rustInputs> {
|
|
425
|
+
const code = rustInputs(source);
|
|
426
|
+
const docs = code && rustInputs(doctestCode(source));
|
|
427
|
+
if (!code || !docs) return undefined;
|
|
428
|
+
const merged: Record<string, unknown> = { ...code, inputs: [...code.inputs, ...docs.inputs], paths: [...code.paths, ...docs.paths] };
|
|
429
|
+
// Each flag is set when either scan sets it. Combining them by key keeps that true for a flag
|
|
430
|
+
// rustInputs gains later (such as one #250 adds), instead of silently dropping the doctests' value.
|
|
431
|
+
for (const [key, value] of Object.entries(docs)) if (typeof value === "boolean") merged[key] = merged[key] === true || value;
|
|
432
|
+
return merged as NonNullable<ReturnType<typeof rustInputs>>;
|
|
433
|
+
}
|
|
434
|
+
|
|
310
435
|
/** A string that names a file or directory rather than ordinary text. */
|
|
311
436
|
function pathLike(value: string): boolean {
|
|
312
437
|
if (!value || value.length > 4096 || /[\0\r\n]/.test(value)) return false;
|
|
@@ -334,10 +459,23 @@ export function analyzeRustMetadata(context: AdapterContext, output: string, res
|
|
|
334
459
|
const defaults = metadata.workspace_default_members;
|
|
335
460
|
if (!defaults) result.blockers.push("Cargo metadata without default workspace members requires full validation; use Cargo 1.71 or later");
|
|
336
461
|
const tested = new Set(defaults ?? []);
|
|
462
|
+
result.rustAllMembersTested = defaults !== undefined && metadata.workspace_members.every(id => tested.has(id));
|
|
337
463
|
if (new Set(members.map(pkg => pkg.name)).size !== members.length) {
|
|
338
464
|
result.blockers.push("Ambiguous Cargo workspace package names require full validation");
|
|
339
465
|
return result;
|
|
340
466
|
}
|
|
467
|
+
// `cargo test -p NAME` and `cargo tree -p NAME` stop with "specification is ambiguous" when a
|
|
468
|
+
// dependency has a member's name (an older release of the same crate, say). Name such a member
|
|
469
|
+
// NAME@VERSION, which Cargo accepts, or fall back when even that cannot tell them apart.
|
|
470
|
+
const specs = new Map<string, string>();
|
|
471
|
+
for (const pkg of members) {
|
|
472
|
+
const named = metadata.packages.filter(other => other.name === pkg.name);
|
|
473
|
+
if (named.length === 1) specs.set(pkg.id, pkg.name);
|
|
474
|
+
else if (pkg.version && /^\d+\.\d+\.\d+(?:-[0-9A-Za-z.-]+)?$/.test(pkg.version) && named.filter(other => other.version === pkg.version).length === 1) {
|
|
475
|
+
specs.set(pkg.id, `${pkg.name}@${pkg.version}`);
|
|
476
|
+
} else result.blockers.push(`Cargo package ${pkg.name} has no unambiguous package specification; full validation required`);
|
|
477
|
+
}
|
|
478
|
+
const spec = (pkg: CargoPackage) => specs.get(pkg.id) ?? pkg.name;
|
|
341
479
|
const packages: Array<{ pkg: CargoPackage; directory: string; manifest: string }> = [];
|
|
342
480
|
for (const pkg of members) {
|
|
343
481
|
const manifest = repositoryPath(root, pkg.manifest_path, known);
|
|
@@ -358,7 +496,16 @@ export function analyzeRustMetadata(context: AdapterContext, output: string, res
|
|
|
358
496
|
// package outside the workspace appears, no member depends on these crates: they are fixtures or
|
|
359
497
|
// excluded crates. Their files stay unmodelled, so changing one keeps the full suite (impact.ts)
|
|
360
498
|
// without blocking changes elsewhere. Otherwise the repository-wide fallback stays.
|
|
361
|
-
|
|
499
|
+
// Local path packages that are not workspace members. Inside the repository they are unmodelled
|
|
500
|
+
// boundaries like fixture crates: a change to one keeps the full suite, and dependency edges
|
|
501
|
+
// through them are followed below. Outside the repository their changes are invisible to the diff.
|
|
502
|
+
const localNonMembers = metadata.packages.filter(pkg => !metadata.workspace_members.includes(pkg.id) && (pkg.source === undefined || pkg.source === null));
|
|
503
|
+
const localInside = new Map<string, string>();
|
|
504
|
+
for (const pkg of localNonMembers) {
|
|
505
|
+
const manifest = repositoryPath(root, pkg.manifest_path, known);
|
|
506
|
+
if (manifest && /(?:^|\/)Cargo\.toml$/.test(manifest) && manifest !== "Cargo.toml" && unmodeledManifests.includes(manifest)) localInside.set(pkg.id, manifest);
|
|
507
|
+
}
|
|
508
|
+
const localDependencyOutside = localNonMembers.some(pkg => !localInside.has(pkg.id));
|
|
362
509
|
const unmodeledBoundary = (file: string) => !localDependencyOutside
|
|
363
510
|
&& unmodeledManifests.some(manifest => under(file, manifest.slice(0, -"/Cargo.toml".length)));
|
|
364
511
|
if (unmodeledManifests.length && localDependencyOutside) result.blockers.push(`Cargo manifests outside workspace membership require full validation: ${unmodeledManifests.join(", ")}`);
|
|
@@ -412,13 +559,22 @@ export function analyzeRustMetadata(context: AdapterContext, output: string, res
|
|
|
412
559
|
continue;
|
|
413
560
|
}
|
|
414
561
|
result.testFiles.push(path);
|
|
415
|
-
result.testPackages[path] = pkg
|
|
416
|
-
|
|
562
|
+
result.testPackages[path] = spec(pkg);
|
|
563
|
+
// Plain `cargo test` builds and runs a target with `required-features` only when Cargo enabled
|
|
564
|
+
// those features for its package, and skips it silently otherwise. The planner keeps such a
|
|
565
|
+
// package whole (`-p name`, never `--test name`), so Cargo makes the same decision for the
|
|
566
|
+
// selected command as for the full run: the feature check below gives the package the full
|
|
567
|
+
// run's features.
|
|
568
|
+
const requiredFeatures = target["required-features"]?.length ? [...target["required-features"]].sort() : undefined;
|
|
569
|
+
result.rustTestTargets[path] = { name: target.name, kind, ...(requiredFeatures ? { requiredFeatures } : {}) };
|
|
417
570
|
}
|
|
418
571
|
}
|
|
419
572
|
const moduleTrees = packages.flatMap(({ pkg }) => pkg.targets.map(target => resolvedPath(root, target.src_path)))
|
|
420
573
|
.filter((path): path is string => path !== undefined).map(path => dirname(path) === "." ? "" : dirname(path));
|
|
421
574
|
if (!completeRustInventory(root, known, moduleTrees)) result.blockers.push("Incomplete Rust source inventory or symlinked inputs require full validation");
|
|
575
|
+
// Crate roots, for `#[path]` inside inline modules; directories of `#[path]` modules, checked below.
|
|
576
|
+
const targetRoots = new Set(packages.flatMap(({ pkg }) => pkg.targets.map(target => resolvedPath(root, target.src_path))));
|
|
577
|
+
const pathModuleTrees: string[] = [];
|
|
422
578
|
result.sourcePaths = [...new Set(result.sourcePaths)].sort();
|
|
423
579
|
result.testFiles.sort();
|
|
424
580
|
if (!result.testFiles.length) result.blockers.push("Cargo metadata found no supported test targets");
|
|
@@ -433,6 +589,46 @@ export function analyzeRustMetadata(context: AdapterContext, output: string, res
|
|
|
433
589
|
const anchor = owner(file)?.manifest;
|
|
434
590
|
if (anchor && anchor !== file) result.edges.push({ from: anchor, to: file, kind: "import" }, { from: file, to: anchor, kind: "import" });
|
|
435
591
|
}
|
|
592
|
+
// Every in-repository local package that is not a workspace member (a vendored or excluded
|
|
593
|
+
// "bridge" crate) is scanned up front, whether or not a member reaches it. Its build scripts and
|
|
594
|
+
// documentation readers count as readers, as members' do, so a docs change keeps the full suite;
|
|
595
|
+
// code that runs programs turns off crate scoping; and code that could read other crates' files
|
|
596
|
+
// makes the members that reach it depend on every workspace crate (below). What cannot be scanned
|
|
597
|
+
// counts as all three.
|
|
598
|
+
const bridgeOpaque = new Map<string, boolean>();
|
|
599
|
+
for (const [id, manifest] of localInside) {
|
|
600
|
+
const directory = manifest.slice(0, -"/Cargo.toml".length);
|
|
601
|
+
const pkg = localNonMembers.find(candidate => candidate.id === id)!;
|
|
602
|
+
const bridgeRoots = new Set(pkg.targets.map(target => resolvedPath(root, target.src_path)));
|
|
603
|
+
let isOpaque = false;
|
|
604
|
+
for (const target of pkg.targets.filter(target => target.kind.includes("custom-build"))) {
|
|
605
|
+
isOpaque = true;
|
|
606
|
+
(result.rustDocumentationReaders ??= []).push(repositoryPath(root, target.src_path, known) ?? manifest);
|
|
607
|
+
}
|
|
608
|
+
for (const file of context.files.filter(file => file.endsWith(".rs") && under(file, directory))) {
|
|
609
|
+
let scanned: ReturnType<typeof rustInputs>;
|
|
610
|
+
try { scanned = rustInputs(readFileSync(resolve(root, file), "utf8")); } catch { scanned = undefined; }
|
|
611
|
+
if (!scanned) {
|
|
612
|
+
isOpaque = true;
|
|
613
|
+
(result.rustDocumentationReaders ??= []).push(file);
|
|
614
|
+
result.rustRunsPrograms = true;
|
|
615
|
+
continue;
|
|
616
|
+
}
|
|
617
|
+
if (scanned.documentation) (result.rustDocumentationReaders ??= []).push(file);
|
|
618
|
+
if (scanned.runsPrograms) result.rustRunsPrograms = true;
|
|
619
|
+
// `#[path]` is relative to the file's directory, and inside inline modules to their names as
|
|
620
|
+
// well, which is only resolvable from a crate root or mod.rs (as for members, below).
|
|
621
|
+
const modRs = bridgeRoots.has(file) || /(?:^|\/)mod\.rs$/.test(file);
|
|
622
|
+
if (scanned.compiles || scanned.navigates || scanned.documentation || scanned.paths.length > 0
|
|
623
|
+
|| scanned.inputs.some(input => {
|
|
624
|
+
if (input.module?.length && !modRs) return true;
|
|
625
|
+
const base = input.module ? posix.join(dirname(file), ...input.module) : dirname(file);
|
|
626
|
+
const path = repositoryPath(root, resolve(root, base, input.path), known);
|
|
627
|
+
return !path || !under(path, directory);
|
|
628
|
+
})) isOpaque = true;
|
|
629
|
+
}
|
|
630
|
+
bridgeOpaque.set(id, isOpaque);
|
|
631
|
+
}
|
|
436
632
|
// Cargo resolves all target platforms unless --filter-platform is supplied.
|
|
437
633
|
// --all-features below unions optional dependencies too; cfg(feature) code
|
|
438
634
|
// stays crate-granular and does not itself make the graph unsafe.
|
|
@@ -444,21 +640,42 @@ export function analyzeRustMetadata(context: AdapterContext, output: string, res
|
|
|
444
640
|
|| metadata.workspace_members.some(id => !nodes.some(node => node.id === id))) {
|
|
445
641
|
result.blockers.push("Cargo dependency resolution is missing or incomplete; full validation required");
|
|
446
642
|
} else {
|
|
643
|
+
// A member can depend on another member through packages outside the workspace (a local path
|
|
644
|
+
// package that itself depends on a member, or a `[patch]`ed crate). Follow dependencies through
|
|
645
|
+
// non-members until they reach members. An in-repository local package whose own code could
|
|
646
|
+
// read other crates' files (a build script, Cargo or program runs, climbing out of its
|
|
647
|
+
// directory, path literals or includes) makes the member depend on every workspace crate.
|
|
648
|
+
const byId = new Map(nodes.map(node => [node.id, node]));
|
|
649
|
+
const opaque = new Map([...localInside.keys()].map(id => [id, bridgeOpaque.get(id) === true]));
|
|
650
|
+
const opaqueLocal = (id: string) => opaque.get(id) === true;
|
|
447
651
|
for (const node of nodes) {
|
|
448
652
|
const anchor = anchors.get(node.id);
|
|
449
653
|
if (!anchor) continue;
|
|
450
|
-
|
|
654
|
+
const reached = new Set<string>();
|
|
655
|
+
let everything = false;
|
|
656
|
+
const seen = new Set<string>([node.id]);
|
|
657
|
+
const pending = [...node.dependencies];
|
|
658
|
+
while (pending.length) {
|
|
659
|
+
const dependency = pending.pop()!;
|
|
660
|
+
if (seen.has(dependency)) continue;
|
|
661
|
+
seen.add(dependency);
|
|
451
662
|
const target = anchors.get(dependency);
|
|
452
|
-
if (target
|
|
663
|
+
if (target) { reached.add(target); continue; }
|
|
664
|
+
if (opaqueLocal(dependency)) everything = true;
|
|
665
|
+
pending.push(...(byId.get(dependency)?.dependencies ?? []));
|
|
453
666
|
}
|
|
667
|
+
if (everything) for (const other of packages) reached.add(other.manifest);
|
|
668
|
+
reached.delete(anchor);
|
|
669
|
+
for (const target of reached) result.edges.push({ from: anchor, to: target, kind: "import" });
|
|
454
670
|
}
|
|
455
671
|
}
|
|
456
672
|
// Registry and Git dependencies are locked and immutable unless Cargo.lock changes, and a
|
|
457
673
|
// Cargo.lock change keeps the full suite. Their build scripts and procedural macros run the same
|
|
458
674
|
// code for the selected and the full invocation; anything they read from this repository outside
|
|
459
675
|
// modelled Rust sources is a changed path that keeps the full suite. A local path dependency that
|
|
460
|
-
// is not a workspace member
|
|
461
|
-
|
|
676
|
+
// is not a workspace member and lives outside the repository can change without the diff showing it,
|
|
677
|
+
// so it still blocks the repository; one inside the repository is an unmodelled boundary (above).
|
|
678
|
+
const localOutside = localNonMembers.filter(pkg => !localInside.has(pkg.id));
|
|
462
679
|
if (localOutside.length) {
|
|
463
680
|
result.blockers.push(`Local Cargo path dependencies outside the workspace require full validation: ${localOutside.map(pkg => pkg.name).sort().join(", ")}`);
|
|
464
681
|
}
|
|
@@ -470,13 +687,10 @@ export function analyzeRustMetadata(context: AdapterContext, output: string, res
|
|
|
470
687
|
const anchor = anchors.get(id)!;
|
|
471
688
|
for (const other of packages) if (other.manifest !== anchor) result.edges.push({ from: anchor, to: other.manifest, kind: "import" });
|
|
472
689
|
}
|
|
473
|
-
if (packages.some(({ pkg }) => pkg.targets.some(target => target["required-features"]?.length))) {
|
|
474
|
-
result.blockers.push("Cargo targets requiring features need an explicitly supported test invocation; full validation required");
|
|
475
|
-
}
|
|
476
690
|
for (const source of result.sourcePaths.filter(path => path.endsWith(".rs"))) {
|
|
477
691
|
const sourceOwner = owner(source);
|
|
478
692
|
if (!sourceOwner) continue;
|
|
479
|
-
const scanned =
|
|
693
|
+
const scanned = rustSourceInputs(readFileSync(resolve(root, source), "utf8"));
|
|
480
694
|
if (scanned === undefined) {
|
|
481
695
|
result.blockers.push(`Rust computed includes or path attributes require full validation: ${source}`);
|
|
482
696
|
continue;
|
|
@@ -486,16 +700,21 @@ export function analyzeRustMetadata(context: AdapterContext, output: string, res
|
|
|
486
700
|
// file). Code that climbs out of its crate in code can reach any crate, like code that compiles.
|
|
487
701
|
// Model these as dependencies of this crate instead of blocking the repository.
|
|
488
702
|
if (scanned.documentation) (result.rustDocumentationReaders ??= []).push(source);
|
|
703
|
+
if (scanned.runsPrograms) result.rustRunsPrograms = true;
|
|
489
704
|
const reached = new Set<string>();
|
|
490
705
|
if (scanned.compiles || scanned.navigates) for (const other of packages) reached.add(other.manifest);
|
|
491
706
|
for (const literal of scanned.paths) {
|
|
492
707
|
const clean = literal.replace(/\\/g, "/").replace(/^(?:[A-Za-z]:)?\/+/, "");
|
|
493
708
|
const glob = clean.search(/[*?[{]/);
|
|
494
709
|
const prefix = glob < 0 ? clean : clean.slice(0, clean.lastIndexOf("/", glob) + 1);
|
|
495
|
-
|
|
710
|
+
// Also from the workspace root: rustc and proc macros run there, and `[env]` paths such as
|
|
711
|
+
// CARGO_WORKSPACE_DIR start there. From the root, only a path below it names a crate.
|
|
712
|
+
const bases = [sourceOwner.directory, dirname(source) === "." ? "" : dirname(source)];
|
|
713
|
+
for (const [index, base] of [...bases, ""].entries()) {
|
|
496
714
|
const joined = posix.normalize(posix.join(base || ".", prefix || "."));
|
|
497
715
|
if (joined === ".." || joined.startsWith("../")) continue;
|
|
498
716
|
const rel = joined === "." ? "" : joined.replace(/\/+$/, "");
|
|
717
|
+
if (index === bases.length && !rel) continue;
|
|
499
718
|
const inside = rel ? owner(rel) ?? owner(`${rel}/`) : packages.find(pkg => pkg.directory === "");
|
|
500
719
|
if (inside) reached.add(inside.manifest);
|
|
501
720
|
for (const other of packages) if (other.directory && (rel === "" || under(other.directory, rel) || other.directory === rel)) reached.add(other.manifest);
|
|
@@ -504,7 +723,15 @@ export function analyzeRustMetadata(context: AdapterContext, output: string, res
|
|
|
504
723
|
reached.delete(sourceOwner.manifest);
|
|
505
724
|
for (const manifest of reached) result.edges.push({ from: sourceOwner.manifest, to: manifest, kind: "import" });
|
|
506
725
|
for (const input of scanned.inputs) {
|
|
507
|
-
|
|
726
|
+
// A `#[path]` is relative to the file's directory; inside inline modules, also to their
|
|
727
|
+
// names, below the file's stem unless it is a crate root or mod.rs.
|
|
728
|
+
const modRs = targetRoots.has(source) || /(?:^|\/)mod\.rs$/.test(source);
|
|
729
|
+
if (input.module?.length && !modRs) {
|
|
730
|
+
result.blockers.push(`Rust computed includes or path attributes require full validation: ${source}`);
|
|
731
|
+
continue;
|
|
732
|
+
}
|
|
733
|
+
const base = input.module ? posix.join(dirname(source), ...input.module) : dirname(source);
|
|
734
|
+
const path = repositoryPath(root, resolve(root, base, input.path), known);
|
|
508
735
|
if (!path || owner(path)?.pkg.id !== sourceOwner.pkg.id) {
|
|
509
736
|
result.blockers.push(`Rust include outside its crate or unavailable requires full validation: ${source}`);
|
|
510
737
|
continue;
|
|
@@ -513,27 +740,37 @@ export function analyzeRustMetadata(context: AdapterContext, output: string, res
|
|
|
513
740
|
result.blockers.push(`Rust include code with a non-Rust extension requires full validation: ${source}`);
|
|
514
741
|
continue;
|
|
515
742
|
}
|
|
743
|
+
if (input.module) {
|
|
744
|
+
// Module source of the same crate: already a source of it. What it declares is looked up
|
|
745
|
+
// from its own directory, so that tree must be complete too.
|
|
746
|
+
pathModuleTrees.push(dirname(path) === "." ? "" : dirname(path));
|
|
747
|
+
result.edges.push({ from: source, to: path, kind: "import" });
|
|
748
|
+
continue;
|
|
749
|
+
}
|
|
516
750
|
if (!result.sourcePaths.includes(path)) result.assetPaths.push(path);
|
|
517
751
|
result.edges.push({ from: source, to: path, kind: "asset" });
|
|
518
752
|
}
|
|
519
753
|
}
|
|
754
|
+
if (pathModuleTrees.length && !completeRustInventory(root, known, pathModuleTrees)) result.blockers.push("Incomplete Rust source inventory or symlinked inputs require full validation");
|
|
520
755
|
result.assetPaths = [...new Set(result.assetPaths)].sort();
|
|
756
|
+
result.rustCrateDirectories = [...new Set(packages.map(({ directory }) => directory))].sort();
|
|
757
|
+
result.rustRunsPrograms ??= false;
|
|
521
758
|
// Selective commands must give every package the features the full invocation gives it. Cargo
|
|
522
759
|
// resolves each tested crate alone and with its dependents (what a change to it selects); the
|
|
523
760
|
// planner checks each selected set against those units.
|
|
524
761
|
if (!cargoFeaturesVary(metadata)) result.rustFeatureCoverage = { deficits: {}, units: [] };
|
|
525
762
|
else {
|
|
526
|
-
const testedNames = packages.filter(({ pkg }) => tested.has(pkg.id)).map(({ pkg }) => pkg
|
|
763
|
+
const testedNames = packages.filter(({ pkg }) => tested.has(pkg.id)).map(({ pkg }) => spec(pkg));
|
|
527
764
|
const dependents = new Map<string, string[]>();
|
|
528
765
|
for (const edge of result.edges) {
|
|
529
766
|
if (edge.from.endsWith("Cargo.toml") && edge.to.endsWith("Cargo.toml") && edge.from !== edge.to) {
|
|
530
767
|
dependents.set(edge.to, [...(dependents.get(edge.to) ?? []), edge.from]);
|
|
531
768
|
}
|
|
532
769
|
}
|
|
533
|
-
const byManifest = new Map(packages.map(({ pkg, manifest }) => [manifest, pkg
|
|
770
|
+
const byManifest = new Map(packages.map(({ pkg, manifest }) => [manifest, spec(pkg)]));
|
|
534
771
|
const units = new Map<string, string[]>();
|
|
535
772
|
for (const { pkg, manifest } of packages) {
|
|
536
|
-
if (tested.has(pkg.id)) units.set(pkg
|
|
773
|
+
if (tested.has(pkg.id)) units.set(spec(pkg), [spec(pkg)]);
|
|
537
774
|
const seen = new Set([manifest]); const pending = [manifest];
|
|
538
775
|
while (pending.length) for (const next of dependents.get(pending.pop()!) ?? []) if (!seen.has(next)) { seen.add(next); pending.push(next); }
|
|
539
776
|
const closure = [...seen].map(path => byManifest.get(path)).filter((name): name is string => name !== undefined && testedNames.includes(name)).sort();
|
|
@@ -568,11 +805,14 @@ function cargoFeatureResolver(repoPath: string): CargoFeatureResolver {
|
|
|
568
805
|
/** Configuration keys that change how crates are compiled, which code is compiled or what runs the
|
|
569
806
|
* tests. Aliases, registries, network, terminal, `[env]` and target-dir settings apply equally to
|
|
570
807
|
* the selected and the full invocation, so they do not block. */
|
|
571
|
-
const BUILD_CONFIG = /^\s*(?:build\s*\.\s*)?(?:rustflags|rustdocflags|target|rustc|rustdoc|rustc-wrapper|rustc-workspace-wrapper)\s*=|^\s*\[\s*(?:target|patch|unstable)\b|^\s*(?:target|patch|unstable)\s*\.|^\s*(?:paths|include)\s*=/m;
|
|
808
|
+
const BUILD_CONFIG = /^\s*(?:build\s*\.\s*)?(?:rustflags|rustdocflags|target|rustc|rustdoc|rustc-wrapper|rustc-workspace-wrapper)\s*=|^\s*\[\s*(?:target|patch|unstable)\b|^\s*(?:target|patch|unstable)\s*\.|^\s*(?:paths|include)\s*=|^\s*(?:build|patch|unstable)\s*=/m;
|
|
572
809
|
const COMPILER_ENVIRONMENT = /^(?:RUSTFLAGS|RUSTDOCFLAGS|CARGO_ENCODED_RUST(?:DOC)?FLAGS|CARGO_BUILD_RUST(?:DOC)?FLAGS|CARGO_BUILD_TARGET|RUSTC|RUSTDOC|RUSTC_WRAPPER|RUSTC_WORKSPACE_WRAPPER|CARGO_BUILD_RUSTC(?:_WRAPPER|_WORKSPACE_WRAPPER)?|CARGO_BUILD_RUSTDOC|CARGO_TARGET_.+_(?:RUNNER|RUSTFLAGS))$/;
|
|
573
810
|
|
|
811
|
+
/** TOML spells the same key bare, quoted (`"build".rustflags`) or as an inline table
|
|
812
|
+
* (`build = { rustflags = [...] }`); Cargo reads them all. Unquote simple keys before matching, and
|
|
813
|
+
* treat a whole `build`, `patch` or `unstable` inline table as build-changing. */
|
|
574
814
|
function changesBuild(path: string): boolean {
|
|
575
|
-
try { return BUILD_CONFIG.test(readFileSync(path, "utf8")); }
|
|
815
|
+
try { return BUILD_CONFIG.test(readFileSync(path, "utf8").replace(/(["'])([A-Za-z0-9_-]+)\1/g, "$2")); }
|
|
576
816
|
catch { return existsSync(path); }
|
|
577
817
|
}
|
|
578
818
|
|
|
@@ -21,10 +21,19 @@ export interface AdapterContribution {
|
|
|
21
21
|
testFiles: string[];
|
|
22
22
|
testPackages: Record<string, string>;
|
|
23
23
|
/** Cargo target roots; a lib/bin root represents the crate's unit tests. */
|
|
24
|
-
rustTestTargets?: Record<string, { name: string; kind: "lib" | "bin" | "test" | "bench" | "example" }>;
|
|
24
|
+
rustTestTargets?: Record<string, { name: string; kind: "lib" | "bin" | "test" | "bench" | "example"; requiredFeatures?: string[] }>;
|
|
25
25
|
/** Rust files that may read documentation: workspace build scripts, and sources naming a
|
|
26
26
|
* documentation path in a string literal. */
|
|
27
27
|
rustDocumentationReaders?: string[];
|
|
28
|
+
/** Directories of the workspace's Cargo packages ("" for a root package), for confining blockers on
|
|
29
|
+
* non-Rust files to the crate that owns them. */
|
|
30
|
+
rustCrateDirectories?: string[];
|
|
31
|
+
/** Whether any workspace Rust source starts an external program other than Cargo, rustc or the
|
|
32
|
+
* package's own binaries. Such a program could read any file, so nothing can be confined to a crate. */
|
|
33
|
+
rustRunsPrograms?: boolean;
|
|
34
|
+
/** Cargo's default workspace members cover every member (so `--workspace`/`--all` is equivalent to
|
|
35
|
+
* plain `cargo test`). Missing evidence is deliberately false. */
|
|
36
|
+
rustAllMembersTested?: boolean;
|
|
28
37
|
/** Packages whose Cargo features change when a tested crate runs without the rest of the full invocation. */
|
|
29
38
|
rustFeatureCoverage?: { deficits: Record<string, string[]>; units: Array<{ crates: string[]; covers: string[] }> };
|
|
30
39
|
executionEnv?: Record<string, string>;
|
|
@@ -36,6 +36,26 @@ import { join, posix } from "node:path";
|
|
|
36
36
|
import { matchesGlob } from "./test-discovery.js";
|
|
37
37
|
import { LOCKFILE_NAMES } from "./lockfiles.js";
|
|
38
38
|
|
|
39
|
+
/** Trailing slashes. The lookbehind starts a match only at the first slash of a run; `/\/+$/` alone retries from every
|
|
40
|
+
* slash of a run that is not at the end, which is quadratic on long runs (CodeQL alerts 16, 17). */
|
|
41
|
+
const TRAILING_SLASHES = /(?<!\/)\/+$/;
|
|
42
|
+
|
|
43
|
+
/**
|
|
44
|
+
* `glob` with each `[...]` (up to the next `]`) replaced by `?`, as `/\[[^\]]*\]/g` would, in linear time: that
|
|
45
|
+
* regex rescans to the end from every `[` of a line with no `]`, quadratic on a long run of `[` (CodeQL alert 18).
|
|
46
|
+
*/
|
|
47
|
+
export function widenCharacterClasses(glob: string): string {
|
|
48
|
+
let out = "";
|
|
49
|
+
let from = 0;
|
|
50
|
+
for (let open = glob.indexOf("["); open !== -1; open = glob.indexOf("[", from)) {
|
|
51
|
+
const close = glob.indexOf("]", open + 1);
|
|
52
|
+
if (close === -1) break;
|
|
53
|
+
out += `${glob.slice(from, open)}?`;
|
|
54
|
+
from = close + 1;
|
|
55
|
+
}
|
|
56
|
+
return out + glob.slice(from);
|
|
57
|
+
}
|
|
58
|
+
|
|
39
59
|
const MAX_READ_BYTES = 1_048_576;
|
|
40
60
|
|
|
41
61
|
/** Reads repo-relative text files from a checkout at HEAD, the same tree the dependency graph reads.
|
|
@@ -269,11 +289,11 @@ export function scriptNamesPath(body: string, target: string, pattern: RegExp, {
|
|
|
269
289
|
if (posix.basename(candidate) === targetBase || pattern.test(` ${candidate} `)) return true;
|
|
270
290
|
continue;
|
|
271
291
|
}
|
|
272
|
-
const resolved = posix.normalize(posix.join(cwd || ".", candidate)).replace(
|
|
292
|
+
const resolved = posix.normalize(posix.join(cwd || ".", candidate)).replace(TRAILING_SLASHES, "");
|
|
273
293
|
if (GLOB_CHARS.test(candidate)) {
|
|
274
294
|
// Character classes are widened to any character, so an unsupported class syntax can only
|
|
275
295
|
// over-match. A glob naming a directory (`ops/*`) reaches the files inside it.
|
|
276
|
-
const widened = resolved
|
|
296
|
+
const widened = widenCharacterClasses(resolved);
|
|
277
297
|
if ([target, ...dirs].some((path) => matchesGlob(path, widened))) return true;
|
|
278
298
|
continue;
|
|
279
299
|
}
|
|
@@ -335,7 +355,8 @@ function namesDirectoryOf(content: string, readerPath: string, target: string):
|
|
|
335
355
|
const dir = posix.dirname(target);
|
|
336
356
|
if (dir === "." || posix.dirname(readerPath) === dir) return true;
|
|
337
357
|
const names = dir.split("/").filter(Boolean);
|
|
338
|
-
|
|
358
|
+
// `\\s`, not `\s`: in a template literal `\s` is just `s` (CodeQL alerts 27, 28).
|
|
359
|
+
return names.some((name) => new RegExp(`(?:^|["'\`/\\s(])${escape(name)}(?=$|["'\`/\\s),])`, "m").test(content));
|
|
339
360
|
}
|
|
340
361
|
|
|
341
362
|
/**
|
|
@@ -364,7 +385,7 @@ export function contentNamesPath(content: string, readerPath: string, target: st
|
|
|
364
385
|
// an unknown directory (2026-11-04: a LobeHub composite action blocked every changed file under scripts/).
|
|
365
386
|
const variable = /^\$(?:\{[\w.]+\}|\w+)\/(.+)$/.exec(word);
|
|
366
387
|
if (variable && !/[*?{}[\]!$]/.test(variable[1]!)) {
|
|
367
|
-
const rest = variable[1]!.replace(/^(?:\.\.?\/)+/, "").replace(
|
|
388
|
+
const rest = variable[1]!.replace(/^(?:\.\.?\/)+/, "").replace(TRAILING_SLASHES, "");
|
|
368
389
|
if (names.some((name) => name === rest || name.endsWith(`/${rest}`) || rest.endsWith(`/${name}`))) return true;
|
|
369
390
|
continue;
|
|
370
391
|
}
|
|
@@ -380,7 +401,7 @@ export function contentNamesPath(content: string, readerPath: string, target: st
|
|
|
380
401
|
if (names.some((name) => globs.some((glob) => matchesGlob(name, glob)))) return true;
|
|
381
402
|
continue;
|
|
382
403
|
}
|
|
383
|
-
const trimmed = word.replace(
|
|
404
|
+
const trimmed = word.replace(TRAILING_SLASHES, "");
|
|
384
405
|
const resolved = [posix.normalize(posix.join(readerDir, trimmed))];
|
|
385
406
|
if (!trimmed.startsWith("../")) resolved.push(posix.normalize(trimmed.replace(/^\/+/, "")));
|
|
386
407
|
if (resolved.some((path) => names.includes(path))) return true;
|
|
@@ -542,6 +563,50 @@ function directTestPhases(content: string, target: string, pattern: RegExp, ance
|
|
|
542
563
|
return found.length > 0 ? found : undefined;
|
|
543
564
|
}
|
|
544
565
|
|
|
566
|
+
const PROGRAM_INTERPRETERS = new Set(["node", "tsx", "ts-node", "bun"]);
|
|
567
|
+
const NO_PROGRAM_FLAGS = /^(?:--test(?:=|$)|--run(?:=|$)|-e$|--eval(?:=|$)|-p$|--print(?:=|$)|--check$|-c$|--help$|-h$|--version$|-v$)/;
|
|
568
|
+
|
|
569
|
+
/**
|
|
570
|
+
* The programs the root test closure runs with an interpreter, by repository path, each with the `&&`
|
|
571
|
+
* phases that run it and whether every one of them can run alone (`direct`, as for directTestPhases)
|
|
572
|
+
* (2026-11-18). `node scripts/check.mjs && node --test` runs `scripts/check.mjs` as part of the suite,
|
|
573
|
+
* though no test imports it, so a change to it, or to code it imports, is a change to the suite.
|
|
574
|
+
* `node --test`, `node -e` and similar phases run no program file.
|
|
575
|
+
*/
|
|
576
|
+
export function testScriptPrograms(scripts: Readonly<Record<string, string>>): Map<string, { phases: string[]; direct: boolean }> {
|
|
577
|
+
const programs = new Map<string, { phases: string[]; direct: boolean }>();
|
|
578
|
+
for (const name of testScriptClosure(scripts)) {
|
|
579
|
+
// A phase of `a || b` or `a; b` is not one that can run alone, so only whole `&&` phases are direct.
|
|
580
|
+
const parts = (scripts[name] ?? "").split("&&").flatMap((part) => {
|
|
581
|
+
const pieces = part.split(/\|\||;/).map((piece) => piece.trim());
|
|
582
|
+
return pieces.map((phase) => ({ phase, alone: pieces.length === 1 }));
|
|
583
|
+
});
|
|
584
|
+
for (const { phase, alone } of parts) {
|
|
585
|
+
const words = phase.split(/\s+/).map((word) => word.replace(/^[\x22\x27]+|[\x22\x27]+$/g, ""));
|
|
586
|
+
// An `npx tsx` or `npx --yes tsx` prefix runs the same interpreter.
|
|
587
|
+
let start = 0;
|
|
588
|
+
if (words[0] === "npx") { start = 1; while (words[start]?.startsWith("-")) start += 1; }
|
|
589
|
+
if (!PROGRAM_INTERPRETERS.has(words[start] ?? "")) continue;
|
|
590
|
+
let index = start + 1;
|
|
591
|
+
let runsNoProgram = false;
|
|
592
|
+
while (index < words.length && words[index]!.startsWith("-")) {
|
|
593
|
+
if (NO_PROGRAM_FLAGS.test(words[index]!)) runsNoProgram = true;
|
|
594
|
+
index += PHASE_VALUE_FLAGS.has(words[index]!) ? 2 : 1;
|
|
595
|
+
}
|
|
596
|
+
const program = words[index];
|
|
597
|
+
if (runsNoProgram || !program || !/\.[cm]?[jt]sx?$/.test(program) || /[*?[\]{}$\x60]/.test(program)) continue;
|
|
598
|
+
const path = posix.normalize(program);
|
|
599
|
+
if (path.startsWith("../") || posix.isAbsolute(path)) continue;
|
|
600
|
+
const direct = alone && start === 0 && index === words.length - 1 && !/[|;<>\x60$(]/.test(phase);
|
|
601
|
+
const entry = programs.get(path) ?? { phases: [], direct: true };
|
|
602
|
+
if (!entry.phases.includes(phase)) entry.phases.push(phase);
|
|
603
|
+
entry.direct &&= direct;
|
|
604
|
+
programs.set(path, entry);
|
|
605
|
+
}
|
|
606
|
+
}
|
|
607
|
+
return programs;
|
|
608
|
+
}
|
|
609
|
+
|
|
545
610
|
function packageJsonNames(content: string, pattern: RegExp, target: string, ancestors: boolean, cwd: string): "yes" | "no" | "unparseable" {
|
|
546
611
|
let parsed: unknown;
|
|
547
612
|
try { parsed = JSON.parse(content); } catch { return "unparseable"; }
|