@diffci.com/diffci 0.3.29 → 0.3.31
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 +78 -5
- package/dist-client/src/client/command-batches.d.ts +22 -0
- package/dist-client/src/client/command-batches.js +82 -9
- package/dist-client/src/client/coverage-map.d.ts +46 -0
- package/dist-client/src/client/coverage-map.js +213 -0
- package/dist-client/src/client/failure-baseline.js +0 -0
- package/dist-client/src/client/observe.js +3 -0
- package/dist-client/src/client/outcome-log.d.ts +40 -0
- package/dist-client/src/client/outcome-log.js +38 -1
- package/dist-client/src/client/report.d.ts +3 -0
- package/dist-client/src/client/selected-coverage.d.ts +3 -0
- package/dist-client/src/client/selected-coverage.js +35 -5
- package/dist-client/src/client/test-ranking.d.ts +39 -0
- package/dist-client/src/client/test-ranking.js +127 -0
- package/dist-client/src/client/test-results.d.ts +27 -0
- package/dist-client/src/client/test-results.js +54 -0
- package/dist-client/src/client/test-shards.d.ts +36 -0
- package/dist-client/src/client/test-shards.js +68 -0
- package/dist-client/src/client/verify-savings.d.ts +6 -0
- package/dist-client/src/client/verify-savings.js +4 -0
- package/dist-client/src/client/verify.d.ts +36 -1
- package/dist-client/src/client/verify.js +171 -13
- package/node_modules/@babel/helper-string-parser/lib/index.js +5 -5
- package/node_modules/@babel/helper-string-parser/lib/index.js.map +1 -1
- package/node_modules/@babel/helper-string-parser/package.json +1 -1
- package/node_modules/@babel/parser/lib/index.js +6306 -6143
- package/node_modules/@babel/parser/lib/index.js.map +1 -1
- package/node_modules/@babel/parser/package.json +3 -3
- package/node_modules/@babel/types/lib/definitions/typescript.js +2 -1
- package/node_modules/@babel/types/lib/definitions/typescript.js.map +1 -1
- package/node_modules/@babel/types/package.json +3 -3
- package/node_modules/@diffci.com/core/dist/cache/graph-cache.d.ts +1 -1
- package/node_modules/@diffci.com/core/dist/cache/graph-cache.js +2 -1
- package/node_modules/@diffci.com/core/dist/cache/graph-cache.js.map +1 -1
- package/node_modules/@diffci.com/core/dist/git/git-diff.js +59 -0
- package/node_modules/@diffci.com/core/dist/git/git-diff.js.map +1 -1
- package/node_modules/@diffci.com/core/dist/git/types.d.ts +4 -0
- package/node_modules/@diffci.com/core/dist/planner/test-command.d.ts +11 -0
- package/node_modules/@diffci.com/core/dist/planner/test-command.js +65 -9
- package/node_modules/@diffci.com/core/dist/planner/test-command.js.map +1 -1
- package/node_modules/@diffci.com/core/dist/repo/file-references.d.ts +10 -1
- package/node_modules/@diffci.com/core/dist/repo/file-references.js +96 -18
- package/node_modules/@diffci.com/core/dist/repo/file-references.js.map +1 -1
- package/node_modules/@diffci.com/core/dist/repo/impact-types.d.ts +4 -1
- package/node_modules/@diffci.com/core/dist/repo/impact.d.ts +20 -0
- package/node_modules/@diffci.com/core/dist/repo/impact.js +147 -25
- package/node_modules/@diffci.com/core/dist/repo/impact.js.map +1 -1
- package/node_modules/@diffci.com/core/dist/repo/repo-config.d.ts +11 -0
- package/node_modules/@diffci.com/core/dist/repo/repo-config.js +11 -1
- package/node_modules/@diffci.com/core/dist/repo/repo-config.js.map +1 -1
- package/node_modules/@diffci.com/core/dist/repo/route-visits.d.ts +34 -0
- package/node_modules/@diffci.com/core/dist/repo/route-visits.js +93 -0
- package/node_modules/@diffci.com/core/dist/repo/route-visits.js.map +1 -0
- package/node_modules/@diffci.com/core/dist/repo/test-fixture-ownership.d.ts +1 -1
- package/node_modules/@diffci.com/core/dist/repo/test-fixture-ownership.js +48 -5
- package/node_modules/@diffci.com/core/dist/repo/test-fixture-ownership.js.map +1 -1
- package/node_modules/@diffci.com/core/package.json +3 -3
- package/node_modules/@diffci.com/core/src/cache/graph-cache.ts +2 -1
- package/node_modules/@diffci.com/core/src/git/git-diff.ts +48 -0
- package/node_modules/@diffci.com/core/src/git/types.ts +4 -0
- package/node_modules/@diffci.com/core/src/planner/test-command.ts +54 -9
- package/node_modules/@diffci.com/core/src/repo/file-references.ts +92 -20
- package/node_modules/@diffci.com/core/src/repo/impact-types.ts +5 -0
- package/node_modules/@diffci.com/core/src/repo/impact.ts +134 -25
- package/node_modules/@diffci.com/core/src/repo/repo-config.ts +23 -1
- package/node_modules/@diffci.com/core/src/repo/route-visits.ts +88 -0
- package/node_modules/@diffci.com/core/src/repo/test-fixture-ownership.ts +39 -5
- package/node_modules/@vue/compiler-core/dist/compiler-core.cjs.js +4 -3
- package/node_modules/@vue/compiler-core/dist/compiler-core.cjs.prod.js +4 -3
- package/node_modules/@vue/compiler-core/dist/compiler-core.esm-bundler.js +4 -3
- package/node_modules/@vue/compiler-core/package.json +4 -4
- package/node_modules/@vue/compiler-dom/dist/compiler-dom.cjs.js +9 -6
- package/node_modules/@vue/compiler-dom/dist/compiler-dom.cjs.prod.js +41 -4
- package/node_modules/@vue/compiler-dom/dist/compiler-dom.esm-browser.js +10 -7
- package/node_modules/@vue/compiler-dom/dist/compiler-dom.esm-browser.prod.js +12 -11
- package/node_modules/@vue/compiler-dom/dist/compiler-dom.esm-bundler.js +5 -3
- package/node_modules/@vue/compiler-dom/dist/compiler-dom.global.js +10 -7
- package/node_modules/@vue/compiler-dom/dist/compiler-dom.global.prod.js +12 -11
- package/node_modules/@vue/compiler-dom/package.json +3 -3
- package/node_modules/@vue/compiler-sfc/dist/compiler-sfc.cjs.js +155 -20
- package/node_modules/@vue/compiler-sfc/dist/compiler-sfc.esm-browser.js +431 -98
- package/node_modules/@vue/compiler-sfc/package.json +10 -10
- package/node_modules/@vue/compiler-ssr/dist/compiler-ssr.cjs.js +1 -1
- package/node_modules/@vue/compiler-ssr/package.json +3 -3
- package/node_modules/@vue/shared/dist/shared.cjs.js +51 -32
- package/node_modules/@vue/shared/dist/shared.cjs.prod.js +51 -32
- package/node_modules/@vue/shared/dist/shared.d.ts +2 -1
- package/node_modules/@vue/shared/dist/shared.esm-bundler.js +51 -32
- package/node_modules/@vue/shared/package.json +1 -1
- package/node_modules/nanoid/async/index.d.cts +56 -0
- package/node_modules/nanoid/index.cjs +12 -7
- package/node_modules/nanoid/index.js +1 -1
- package/node_modules/nanoid/package.json +3 -3
- package/node_modules/postcss/lib/input.js +1 -1
- package/node_modules/postcss/lib/lazy-result.js +1 -1
- package/node_modules/postcss/lib/list.js +19 -1
- package/node_modules/postcss/lib/map-generator.js +9 -3
- package/node_modules/postcss/lib/no-work-result.js +1 -1
- package/node_modules/postcss/lib/node.js +2 -2
- package/node_modules/postcss/lib/parser.js +6 -1
- package/node_modules/postcss/lib/processor.js +1 -1
- package/node_modules/postcss/lib/stringifier.js +16 -28
- package/node_modules/postcss/lib/stringify.js +84 -2
- package/node_modules/postcss/lib/warning.js +1 -0
- package/node_modules/postcss/package.json +3 -3
- package/node_modules/yaml/browser/dist/compose/resolve-flow-scalar.js +19 -18
- package/node_modules/yaml/browser/dist/nodes/Alias.js +25 -23
- package/node_modules/yaml/dist/compose/resolve-flow-scalar.js +19 -18
- package/node_modules/yaml/dist/nodes/Alias.js +25 -23
- package/node_modules/yaml/package.json +1 -1
- package/package.json +2 -2
|
@@ -54,6 +54,9 @@ import { observerIdentity } from "./package-identity.js";
|
|
|
54
54
|
import { buildPilotWorkflow, diffciVerificationWorkflow, diffciWorkflow } from "./workflow-templates.js";
|
|
55
55
|
import { buildMissReport, formatMissReportMarkdown, parseJunit } from "./enforce-misses.js";
|
|
56
56
|
import { appendOutcome, formatOutcomeSummary, outcomeLogPath, readOutcomes, summarizeOutcomes } from "./outcome-log.js";
|
|
57
|
+
import { buildCoverageMap, formatCoverageRun } from "./coverage-map.js";
|
|
58
|
+
import { confidenceCurve, formatConfidenceCurve } from "./test-ranking.js";
|
|
59
|
+
import { parseShard, readTimings, timingsFromOutcomes } from "./test-shards.js";
|
|
57
60
|
import { findReceipt, findWindowStart, inferRerunArgs, mergedPullRequests, MISS_REPORT_FILE, rerunFailingFiles, spawnRunner, } from "./enforce-misses-collect.js";
|
|
58
61
|
function parseArgs(argv) {
|
|
59
62
|
const args = argv.slice(2);
|
|
@@ -354,6 +357,27 @@ async function runVerifyCommand(flags, env) {
|
|
|
354
357
|
console.error(`Refusing to write the verification receipt inside the repository: ${reportPath}. Use --out with a path outside the checkout.`);
|
|
355
358
|
return 2;
|
|
356
359
|
}
|
|
360
|
+
const shardFlag = stringFlag(flags, "shard");
|
|
361
|
+
const shard = shardFlag === undefined ? undefined : parseShard(shardFlag);
|
|
362
|
+
if (shardFlag !== undefined && !shard) {
|
|
363
|
+
console.error(`diffci verify --shard takes i/N with 1 <= i <= N, got ${JSON.stringify(shardFlag)}`);
|
|
364
|
+
return 2;
|
|
365
|
+
}
|
|
366
|
+
const timingsFlag = stringFlag(flags, "timings");
|
|
367
|
+
let timings;
|
|
368
|
+
if (timingsFlag !== undefined) {
|
|
369
|
+
if (!shard) {
|
|
370
|
+
console.error("diffci verify --timings balances --shard; pass both");
|
|
371
|
+
return 2;
|
|
372
|
+
}
|
|
373
|
+
try {
|
|
374
|
+
timings = readTimings(resolve(timingsFlag));
|
|
375
|
+
}
|
|
376
|
+
catch (error) {
|
|
377
|
+
console.error(error instanceof Error ? error.message : String(error));
|
|
378
|
+
return 2;
|
|
379
|
+
}
|
|
380
|
+
}
|
|
357
381
|
const identity = observerIdentity();
|
|
358
382
|
const common = {
|
|
359
383
|
repoPath,
|
|
@@ -366,6 +390,12 @@ async function runVerifyCommand(flags, env) {
|
|
|
366
390
|
baselineOnFailure: flags["baseline-on-failure"] === true || env.DIFFCI_BASELINE_ON_FAILURE === "1",
|
|
367
391
|
// Gate checks are for before push; in CI the repository's own check jobs already run them.
|
|
368
392
|
skipChecks: flags["no-checks"] === true || env.DIFFCI_CHECKS === "0" || (Boolean(env.CI) && env.CI !== "false" && flags.checks !== true),
|
|
393
|
+
reuse: flags["no-reuse"] !== true && env.DIFFCI_REUSE !== "0",
|
|
394
|
+
rank: flags["no-rank"] !== true && env.DIFFCI_RANK !== "0",
|
|
395
|
+
failFast: flags["fail-fast"] === true,
|
|
396
|
+
coverage: flags["no-coverage"] !== true && env.DIFFCI_COVERAGE !== "0",
|
|
397
|
+
...(shard ? { shard } : {}),
|
|
398
|
+
...(timings ? { timings } : {}),
|
|
369
399
|
};
|
|
370
400
|
const report = changed
|
|
371
401
|
? await verifyChanged(common)
|
|
@@ -391,6 +421,17 @@ async function runVerifyCommand(flags, env) {
|
|
|
391
421
|
}
|
|
392
422
|
return verificationExitCode(report);
|
|
393
423
|
}
|
|
424
|
+
function runCoverageCommand(flags, env) {
|
|
425
|
+
const repoPath = resolve(stringFlag(flags, "repo") ?? env.GITHUB_WORKSPACE ?? process.cwd());
|
|
426
|
+
const command = stringFlag(flags, "command") ?? inferFullCommand(repoPath).command;
|
|
427
|
+
if (!command) {
|
|
428
|
+
console.error(`diffci coverage: no full test command could be inferred for ${repoPath}; pass --command`);
|
|
429
|
+
return 2;
|
|
430
|
+
}
|
|
431
|
+
const run = buildCoverageMap(repoPath, command, { timeoutMs: numberFlag(flags, "timeout-ms") ?? 60 * 60 * 1000 });
|
|
432
|
+
console.log(flags.json === true ? JSON.stringify({ ...(run.path ? { path: run.path } : {}), ...(run.error ? { error: run.error } : {}), exit_code: run.execution.exitCode, ...(run.map ? { tests: Object.keys(run.map.tests).length } : {}) }, null, 2) : formatCoverageRun(run));
|
|
433
|
+
return run.map ? 0 : 1;
|
|
434
|
+
}
|
|
394
435
|
function runOutcomesCommand(flags, env) {
|
|
395
436
|
const repoPath = resolve(stringFlag(flags, "repo") ?? env.GITHUB_WORKSPACE ?? process.cwd());
|
|
396
437
|
const path = outcomeLogPath(repoPath);
|
|
@@ -398,7 +439,17 @@ function runOutcomesCommand(flags, env) {
|
|
|
398
439
|
console.error(`Not a Git repository: ${repoPath}`);
|
|
399
440
|
return 2;
|
|
400
441
|
}
|
|
401
|
-
const
|
|
442
|
+
const records = readOutcomes(path);
|
|
443
|
+
if (flags.timings === true) {
|
|
444
|
+
console.log(JSON.stringify(timingsFromOutcomes(records), null, 2));
|
|
445
|
+
return 0;
|
|
446
|
+
}
|
|
447
|
+
if (flags.curve === true) {
|
|
448
|
+
const curve = confidenceCurve(records);
|
|
449
|
+
console.log(flags.json === true ? JSON.stringify({ log: path, ...curve }, null, 2) : formatConfidenceCurve(curve));
|
|
450
|
+
return 0;
|
|
451
|
+
}
|
|
452
|
+
const summary = summarizeOutcomes(records);
|
|
402
453
|
console.log(flags.json === true ? JSON.stringify({ log: path, ...summary }, null, 2) : formatOutcomeSummary(summary, path));
|
|
403
454
|
return 0;
|
|
404
455
|
}
|
|
@@ -521,6 +572,11 @@ function summarise(report, executionFollows = false) {
|
|
|
521
572
|
lines.push(` graph: ${result.graph.nodes} nodes, confidence ${result.graph.effectiveConfidence ?? result.graph.confidence}`);
|
|
522
573
|
if (result.fallbackReasons.length > 0) {
|
|
523
574
|
lines.push(` fallback: ${result.fallbackReasons.join("; ")}`);
|
|
575
|
+
for (const [path, blockers] of Object.entries(result.fallbackDetails ?? {})) {
|
|
576
|
+
lines.push(` why ${path} is unknown:`);
|
|
577
|
+
for (const blocker of blockers)
|
|
578
|
+
lines.push(` - ${blocker}`);
|
|
579
|
+
}
|
|
524
580
|
}
|
|
525
581
|
for (const command of result.proposedCommands)
|
|
526
582
|
lines.push(` would have run: ${command}`);
|
|
@@ -1101,7 +1157,8 @@ Usage:
|
|
|
1101
1157
|
diffci mcp
|
|
1102
1158
|
diffci verify [--changed | --base <sha> --head <sha>] [--policy enforce] [--repo <path>] [--out <file>] [--json]
|
|
1103
1159
|
[--redact-paths] [--timeout-ms <ms>] [--baseline-on-failure] [--no-checks | --checks]
|
|
1104
|
-
[--share-usage] [--no-send] [--no-log]
|
|
1160
|
+
[--share-usage] [--no-send] [--no-log] [--no-reuse] [--no-rank] [--fail-fast]
|
|
1161
|
+
[--shard <i/N> [--timings <file>]] [--no-coverage]
|
|
1105
1162
|
diffci telemetry [--mode off|anonymous|installations] [--internal-usage]
|
|
1106
1163
|
diffci check [--repo <path>] [--out <file>] [--base <sha> --head <sha>]
|
|
1107
1164
|
[--redact-paths] [--json] [--quiet] [--fail-on-error] [--timeout-ms <ms>] [--share-usage]
|
|
@@ -1126,7 +1183,8 @@ Usage:
|
|
|
1126
1183
|
diffci gate --plan-out <file> [--base <sha> --head <sha>] [--script <name,...>] [--repo <path>]
|
|
1127
1184
|
diffci enforce-misses --junit <file> --out-dir <dir> [--repository <owner/name>] [--repo <path>]
|
|
1128
1185
|
[--head <sha>] [--rerun-junit <file>] [--open-issue]
|
|
1129
|
-
diffci outcomes [--repo <path>] [--json]
|
|
1186
|
+
diffci outcomes [--repo <path>] [--curve | --timings] [--json]
|
|
1187
|
+
diffci coverage [--repo <path>] [--command <cmd>] [--timeout-ms <ms>] [--json]
|
|
1130
1188
|
diffci version
|
|
1131
1189
|
|
|
1132
1190
|
init writes AGENTS.md, CLAUDE.md, Cursor rules, Copilot instructions, and diffci.config.json. It also
|
|
@@ -1166,10 +1224,22 @@ and writes DiffCI's decisions, for a gate that runs without git history; --plan
|
|
|
1166
1224
|
analysing, and --expect-head ignores a plan made for another commit. It sends nothing.
|
|
1167
1225
|
enforce-misses classifies a full run's failures on main against the enforce dry-run receipts of the pull
|
|
1168
1226
|
requests merged since the last recorded run, and exits 1 on a miss. It never edits configuration.
|
|
1169
|
-
verify appends each run (plan, selection reasons, checks, results, durations, failing tests) to
|
|
1227
|
+
verify appends each run (plan, selection reasons, checks, results, per-file durations, failing tests) to
|
|
1170
1228
|
.git/diffci/outcomes.jsonl, which is never committed and never sent; --no-log or DIFFCI_OUTCOME_LOG=0 skips it.
|
|
1229
|
+
When an earlier run in that log passed on the exact same tree and covered the same tests and checks, verify
|
|
1230
|
+
reuses it and runs nothing; --no-reuse or DIFFCI_REUSE=0 runs everything again. Selected tests that have
|
|
1231
|
+
failed before in that log, or that the change edited, run first (--no-rank keeps the selection's order);
|
|
1232
|
+
--fail-fast runs them as a first batch and stops there if one fails. --shard i/N runs job i's share of the
|
|
1233
|
+
selection in an N-job CI matrix; every job splits it the same way, balanced by --timings (a file from
|
|
1234
|
+
diffci outcomes --timings that every job reads) or else by file count. The full suite, test-script phases
|
|
1235
|
+
and a selection that cannot be split run in shard 1.
|
|
1236
|
+
coverage runs the full node:test suite once under a probe and V8 coverage and keeps, per test file, the files
|
|
1237
|
+
it loaded, read or listed in .git/diffci/coverage-map.json. verify then also runs tests that map connects to a
|
|
1238
|
+
changed file when the dependency graph did not select them; it only ever adds tests (--no-coverage ignores it).
|
|
1171
1239
|
outcomes summarises that log: results, selected and full runs, top full-run reasons, agents, and possible
|
|
1172
|
-
misses (a selected run that passed and a later full run of the same tree that failed).
|
|
1240
|
+
misses (a selected run that passed and a later full run of the same tree that failed). --curve replays the
|
|
1241
|
+
failing runs to show how soon the first failure is seen, ranked by history against path order. --timings
|
|
1242
|
+
prints each test file's typical duration as JSON, for verify --shard --timings.
|
|
1173
1243
|
Failures are re-run with the package.json tsx --test runner, or read from --rerun-junit for other runners.
|
|
1174
1244
|
|
|
1175
1245
|
The report is sent only when both --api-url and --api-token are given (or DIFFCI_API_URL and
|
|
@@ -1248,6 +1318,9 @@ async function main() {
|
|
|
1248
1318
|
case "enforce-misses":
|
|
1249
1319
|
process.exitCode = runEnforceMisses(flags, env);
|
|
1250
1320
|
return;
|
|
1321
|
+
case "coverage":
|
|
1322
|
+
process.exitCode = runCoverageCommand(flags, env);
|
|
1323
|
+
return;
|
|
1251
1324
|
case "outcomes":
|
|
1252
1325
|
process.exitCode = runOutcomesCommand(flags, env);
|
|
1253
1326
|
return;
|
|
@@ -13,15 +13,37 @@ import { type CommandMeasurement } from "./verify-savings.js";
|
|
|
13
13
|
* whole, because rewriting a command that is not understood could change what it runs.
|
|
14
14
|
*/
|
|
15
15
|
export declare const COMMAND_LINE_LIMIT: number;
|
|
16
|
+
/**
|
|
17
|
+
* `command` with its selected paths in `order` (test-ranking.ts, 2026-11-06), or unchanged when it does not
|
|
18
|
+
* end in exactly the selected paths. Paths missing from `order` keep their place after the ordered ones.
|
|
19
|
+
*/
|
|
20
|
+
export declare function orderCommand(command: string, order: readonly string[]): string;
|
|
21
|
+
/**
|
|
22
|
+
* `command` as two invocations of the same runner, the `first` paths and then the rest, for `--fail-fast`;
|
|
23
|
+
* `[command]` when it cannot be split safely or one side would be empty.
|
|
24
|
+
*/
|
|
25
|
+
export declare function splitCommand(command: string, paths: readonly string[], first: readonly string[]): string[];
|
|
26
|
+
/**
|
|
27
|
+
* `command` keeping only the `keep` paths (`verify --shard`, test-shards.ts), `null` when it keeps none,
|
|
28
|
+
* or undefined when `command` does not end in exactly selected paths and so cannot be cut safely.
|
|
29
|
+
*/
|
|
30
|
+
export declare function subsetCommand(command: string, paths: readonly string[], keep: ReadonlySet<string>): string | null | undefined;
|
|
31
|
+
/**
|
|
32
|
+
* `command` with `extra` test files appended (coverage-map.ts), or undefined when `command` does not end in
|
|
33
|
+
* exactly the selected paths or an extra path would need quoting, so it cannot be extended safely.
|
|
34
|
+
*/
|
|
35
|
+
export declare function appendToCommand(command: string, paths: readonly string[], extra: readonly string[]): string | undefined;
|
|
16
36
|
/** `command` split so each part fits `limit`, or `[command]` when it fits or cannot be split safely. */
|
|
17
37
|
export declare function batchCommand(command: string, paths: readonly string[], limit?: number): string[];
|
|
18
38
|
/**
|
|
19
39
|
* Runs `commands` in order as one verification. Every part runs, so one receipt carries every failing
|
|
20
40
|
* test; the first non-zero exit is the result, and the remaining time budget is shared between parts.
|
|
41
|
+
* With `stopOnFailure` (`--fail-fast`, 2026-11-06) the parts after the first failing one do not run.
|
|
21
42
|
*/
|
|
22
43
|
export declare function measureCommands(commands: readonly string[], options: {
|
|
23
44
|
cwd: string;
|
|
24
45
|
timeoutMs: number;
|
|
25
46
|
tailBytes: number;
|
|
26
47
|
env?: Record<string, string>;
|
|
48
|
+
stopOnFailure?: boolean;
|
|
27
49
|
}): CommandMeasurement;
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { commandArguments } from "./selected-coverage.js";
|
|
2
|
+
import { mergeTestFileResults } from "./test-results.js";
|
|
2
3
|
import { measureCommand } from "./verify-savings.js";
|
|
3
4
|
/**
|
|
4
5
|
* Selected-test commands too long for the shell (2026-10-21).
|
|
@@ -14,23 +15,86 @@ import { measureCommand } from "./verify-savings.js";
|
|
|
14
15
|
* whole, because rewriting a command that is not understood could change what it runs.
|
|
15
16
|
*/
|
|
16
17
|
export const COMMAND_LINE_LIMIT = process.platform === "win32" ? 8000 : 100_000;
|
|
17
|
-
/**
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
18
|
+
/**
|
|
19
|
+
* The runner prefix and the selected paths `command` ends with, one token each, or undefined when it does
|
|
20
|
+
* not end in exactly selected paths. Every rewrite here (batching, reordering, splitting) needs this shape.
|
|
21
|
+
*/
|
|
22
|
+
function selectedTail(command, paths) {
|
|
21
23
|
const tokens = command.split(" ");
|
|
22
24
|
const selected = new Set(paths);
|
|
23
25
|
// A `node --test` path with brackets arrives quoted and class-escaped: "src/app/@([[])id@([]])/x.test.ts"
|
|
24
26
|
// (Core before 2026-11-02 emitted the bare class, "src/app/[[]id[]]/x.test.ts").
|
|
25
|
-
const
|
|
26
|
-
|
|
27
|
+
const pathOf = (token) => {
|
|
28
|
+
if (selected.has(token))
|
|
29
|
+
return token;
|
|
30
|
+
const decoded = (commandArguments(token)[0] ?? "").replace(/@\(\[(.)\]\)|\[(.)\]/g, (_, wrapped, bare) => wrapped ?? bare ?? "");
|
|
31
|
+
return selected.has(decoded) ? decoded : undefined;
|
|
32
|
+
};
|
|
27
33
|
let start = tokens.length;
|
|
28
|
-
while (start > 0 &&
|
|
34
|
+
while (start > 0 && pathOf(tokens[start - 1]) !== undefined)
|
|
29
35
|
start--;
|
|
30
36
|
const trailing = tokens.slice(start);
|
|
31
37
|
if (trailing.length === 0 || new Set(trailing).size !== trailing.length)
|
|
38
|
+
return undefined;
|
|
39
|
+
return { prefix: tokens.slice(0, start).join(" "), tokens: trailing.map((token) => ({ token, path: pathOf(token) })) };
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* `command` with its selected paths in `order` (test-ranking.ts, 2026-11-06), or unchanged when it does not
|
|
43
|
+
* end in exactly the selected paths. Paths missing from `order` keep their place after the ordered ones.
|
|
44
|
+
*/
|
|
45
|
+
export function orderCommand(command, order) {
|
|
46
|
+
const tail = selectedTail(command, order);
|
|
47
|
+
if (!tail)
|
|
48
|
+
return command;
|
|
49
|
+
const rank = new Map(order.map((path, index) => [path, index]));
|
|
50
|
+
const sorted = tail.tokens.map((entry, index) => ({ ...entry, index }))
|
|
51
|
+
.sort((a, b) => (rank.get(a.path) ?? order.length + a.index) - (rank.get(b.path) ?? order.length + b.index));
|
|
52
|
+
return `${tail.prefix} ${sorted.map((entry) => entry.token).join(" ")}`;
|
|
53
|
+
}
|
|
54
|
+
/**
|
|
55
|
+
* `command` as two invocations of the same runner, the `first` paths and then the rest, for `--fail-fast`;
|
|
56
|
+
* `[command]` when it cannot be split safely or one side would be empty.
|
|
57
|
+
*/
|
|
58
|
+
export function splitCommand(command, paths, first) {
|
|
59
|
+
const tail = selectedTail(command, paths);
|
|
60
|
+
if (!tail)
|
|
61
|
+
return [command];
|
|
62
|
+
const head = new Set(first);
|
|
63
|
+
const early = tail.tokens.filter((entry) => head.has(entry.path));
|
|
64
|
+
const late = tail.tokens.filter((entry) => !head.has(entry.path));
|
|
65
|
+
if (early.length === 0 || late.length === 0)
|
|
32
66
|
return [command];
|
|
33
|
-
|
|
67
|
+
return [early, late].map((part) => `${tail.prefix} ${part.map((entry) => entry.token).join(" ")}`);
|
|
68
|
+
}
|
|
69
|
+
/**
|
|
70
|
+
* `command` keeping only the `keep` paths (`verify --shard`, test-shards.ts), `null` when it keeps none,
|
|
71
|
+
* or undefined when `command` does not end in exactly selected paths and so cannot be cut safely.
|
|
72
|
+
*/
|
|
73
|
+
export function subsetCommand(command, paths, keep) {
|
|
74
|
+
const tail = selectedTail(command, paths);
|
|
75
|
+
if (!tail)
|
|
76
|
+
return undefined;
|
|
77
|
+
const kept = tail.tokens.filter((entry) => keep.has(entry.path));
|
|
78
|
+
return kept.length ? `${tail.prefix} ${kept.map((entry) => entry.token).join(" ")}` : null;
|
|
79
|
+
}
|
|
80
|
+
/**
|
|
81
|
+
* `command` with `extra` test files appended (coverage-map.ts), or undefined when `command` does not end in
|
|
82
|
+
* exactly the selected paths or an extra path would need quoting, so it cannot be extended safely.
|
|
83
|
+
*/
|
|
84
|
+
export function appendToCommand(command, paths, extra) {
|
|
85
|
+
if (!selectedTail(command, paths) || !extra.every((path) => /^[\w./@+-]+$/.test(path)))
|
|
86
|
+
return undefined;
|
|
87
|
+
return `${command} ${extra.join(" ")}`;
|
|
88
|
+
}
|
|
89
|
+
/** `command` split so each part fits `limit`, or `[command]` when it fits or cannot be split safely. */
|
|
90
|
+
export function batchCommand(command, paths, limit = COMMAND_LINE_LIMIT) {
|
|
91
|
+
if (command.length <= limit || paths.length === 0)
|
|
92
|
+
return [command];
|
|
93
|
+
const tail = selectedTail(command, paths);
|
|
94
|
+
if (!tail)
|
|
95
|
+
return [command];
|
|
96
|
+
const { prefix } = tail;
|
|
97
|
+
const trailing = tail.tokens.map((entry) => entry.token);
|
|
34
98
|
if (prefix.length + 1 + Math.max(...trailing.map((t) => t.length)) > limit)
|
|
35
99
|
return [command];
|
|
36
100
|
const batches = [[]];
|
|
@@ -51,12 +115,14 @@ export function batchCommand(command, paths, limit = COMMAND_LINE_LIMIT) {
|
|
|
51
115
|
/**
|
|
52
116
|
* Runs `commands` in order as one verification. Every part runs, so one receipt carries every failing
|
|
53
117
|
* test; the first non-zero exit is the result, and the remaining time budget is shared between parts.
|
|
118
|
+
* With `stopOnFailure` (`--fail-fast`, 2026-11-06) the parts after the first failing one do not run.
|
|
54
119
|
*/
|
|
55
120
|
export function measureCommands(commands, options) {
|
|
56
121
|
if (commands.length === 1)
|
|
57
122
|
return measureCommand(commands[0], options);
|
|
58
123
|
const started = Date.now();
|
|
59
124
|
const parts = [];
|
|
125
|
+
let stopped = false;
|
|
60
126
|
for (const command of commands) {
|
|
61
127
|
const remaining = options.timeoutMs - (Date.now() - started);
|
|
62
128
|
if (remaining <= 0)
|
|
@@ -65,17 +131,22 @@ export function measureCommands(commands, options) {
|
|
|
65
131
|
parts.push(part);
|
|
66
132
|
if (part.timedOut)
|
|
67
133
|
break;
|
|
134
|
+
if (options.stopOnFailure && (part.exitCode !== 0 || part.signal !== null) && parts.length < commands.length) {
|
|
135
|
+
stopped = true;
|
|
136
|
+
break;
|
|
137
|
+
}
|
|
68
138
|
}
|
|
69
139
|
const failed = parts.find((part) => part.exitCode !== 0 || part.signal !== null || part.timedOut);
|
|
70
140
|
const ranAll = parts.length === commands.length;
|
|
71
141
|
const failingTests = [...new Set(parts.flatMap((part) => part.failingTests ?? []))].sort();
|
|
72
142
|
const counted = ranAll && parts.every((part) => part.runnerTestCount !== undefined);
|
|
143
|
+
const testResults = mergeTestFileResults(...parts.map((part) => part.testResults));
|
|
73
144
|
const tail = (key) => parts.map((part) => part[key]).join("").slice(-Math.max(options.tailBytes, 0) || undefined);
|
|
74
145
|
return {
|
|
75
146
|
command: commands.join(" && "),
|
|
76
147
|
exitCode: failed ? failed.exitCode : ranAll ? 0 : null,
|
|
77
148
|
signal: failed?.signal ?? null,
|
|
78
|
-
timedOut: parts.some((part) => part.timedOut) || !ranAll,
|
|
149
|
+
timedOut: parts.some((part) => part.timedOut) || (!ranAll && !stopped),
|
|
79
150
|
startedAt: parts[0]?.startedAt ?? new Date(started).toISOString(),
|
|
80
151
|
finishedAt: parts[parts.length - 1]?.finishedAt ?? new Date().toISOString(),
|
|
81
152
|
wallMs: Date.now() - started,
|
|
@@ -83,5 +154,7 @@ export function measureCommands(commands, options) {
|
|
|
83
154
|
stderrTail: options.tailBytes > 0 ? tail("stderrTail") : "",
|
|
84
155
|
...(failingTests.length ? { failingTests } : {}),
|
|
85
156
|
...(counted ? { runnerTestCount: parts.reduce((sum, part) => sum + part.runnerTestCount, 0) } : {}),
|
|
157
|
+
...(testResults.length ? { testResults } : {}),
|
|
158
|
+
...(stopped ? { partsNotRun: commands.length - parts.length } : {}),
|
|
86
159
|
};
|
|
87
160
|
}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import { type CommandMeasurement } from "./verify-savings.js";
|
|
2
|
+
/**
|
|
3
|
+
* The coverage map (2026-11-06), the idea of Datadog Test Impact Analysis and pytest-testmon.
|
|
4
|
+
*
|
|
5
|
+
* WHY. The dependency graph sees imports. A test also reaches files it never imports: a fixture it reads
|
|
6
|
+
* by name, a directory it lists, a module loaded through a computed specifier or a framework. Those edges
|
|
7
|
+
* are the commonest reason a change runs the full suite, and the ones static analysis cannot find.
|
|
8
|
+
*
|
|
9
|
+
* WHAT. `diffci coverage` runs the full test command once with every `node --test` process (one per test
|
|
10
|
+
* file) under a probe and V8 coverage. The probe records the files the test reads and the directories it
|
|
11
|
+
* lists; V8 coverage records every module it loads, ESM included. The result, per test file, is kept in
|
|
12
|
+
* `<git common dir>/diffci/coverage-map.json` beside the outcome log, never committed and never sent.
|
|
13
|
+
*
|
|
14
|
+
* Phase A, the only use so far: a verify run adds the tests whose map entry names a changed file and the
|
|
15
|
+
* graph did not select. Adding a test is always safe, so a stale map costs time, never a miss. Replacing
|
|
16
|
+
* a full-suite fallback with what the map says (phase B) waits until a replay shows it loses no catches.
|
|
17
|
+
* Only node:test is supported: Vitest and Jest run many files in one worker, so reads cannot be told apart.
|
|
18
|
+
*/
|
|
19
|
+
export declare const COVERAGE_MAP_SCHEMA: "diffci.coverage-map.v1";
|
|
20
|
+
export interface CoverageMap {
|
|
21
|
+
schema: typeof COVERAGE_MAP_SCHEMA;
|
|
22
|
+
produced_at: string;
|
|
23
|
+
command: string;
|
|
24
|
+
/** Repository-relative files each test file loaded or read, and directories (ending in `/`) it listed. */
|
|
25
|
+
tests: Record<string, string[]>;
|
|
26
|
+
}
|
|
27
|
+
export declare function coverageMapPath(repoPath: string): string | undefined;
|
|
28
|
+
export declare function readCoverageMap(repoPath: string): CoverageMap | undefined;
|
|
29
|
+
export interface CoverageRun {
|
|
30
|
+
map?: CoverageMap;
|
|
31
|
+
path?: string;
|
|
32
|
+
execution: CommandMeasurement;
|
|
33
|
+
error?: string;
|
|
34
|
+
}
|
|
35
|
+
/** Runs `command` under the probe and V8 coverage, and writes the map. */
|
|
36
|
+
export declare function buildCoverageMap(repoPath: string, command: string, options: {
|
|
37
|
+
timeoutMs: number;
|
|
38
|
+
tailBytes?: number;
|
|
39
|
+
nodeOptions?: string;
|
|
40
|
+
}): CoverageRun;
|
|
41
|
+
/** Tests whose map entry names one of `changed` (or lists a directory holding one), that `selected` lacks. */
|
|
42
|
+
export declare function coverageAdditions(map: CoverageMap, changed: readonly string[], selected: readonly string[]): Array<{
|
|
43
|
+
test: string;
|
|
44
|
+
changed_file: string;
|
|
45
|
+
}>;
|
|
46
|
+
export declare function formatCoverageRun(run: CoverageRun): string;
|
|
@@ -0,0 +1,213 @@
|
|
|
1
|
+
import { existsSync, mkdirSync, mkdtempSync, readdirSync, readFileSync, realpathSync, rmSync, statSync, writeFileSync } from "node:fs";
|
|
2
|
+
import { tmpdir } from "node:os";
|
|
3
|
+
import { isAbsolute, join, relative, sep } from "node:path";
|
|
4
|
+
import { fileURLToPath } from "node:url";
|
|
5
|
+
import { outcomeLogPath } from "./outcome-log.js";
|
|
6
|
+
import { measureCommand } from "./verify-savings.js";
|
|
7
|
+
/**
|
|
8
|
+
* The coverage map (2026-11-06), the idea of Datadog Test Impact Analysis and pytest-testmon.
|
|
9
|
+
*
|
|
10
|
+
* WHY. The dependency graph sees imports. A test also reaches files it never imports: a fixture it reads
|
|
11
|
+
* by name, a directory it lists, a module loaded through a computed specifier or a framework. Those edges
|
|
12
|
+
* are the commonest reason a change runs the full suite, and the ones static analysis cannot find.
|
|
13
|
+
*
|
|
14
|
+
* WHAT. `diffci coverage` runs the full test command once with every `node --test` process (one per test
|
|
15
|
+
* file) under a probe and V8 coverage. The probe records the files the test reads and the directories it
|
|
16
|
+
* lists; V8 coverage records every module it loads, ESM included. The result, per test file, is kept in
|
|
17
|
+
* `<git common dir>/diffci/coverage-map.json` beside the outcome log, never committed and never sent.
|
|
18
|
+
*
|
|
19
|
+
* Phase A, the only use so far: a verify run adds the tests whose map entry names a changed file and the
|
|
20
|
+
* graph did not select. Adding a test is always safe, so a stale map costs time, never a miss. Replacing
|
|
21
|
+
* a full-suite fallback with what the map says (phase B) waits until a replay shows it loses no catches.
|
|
22
|
+
* Only node:test is supported: Vitest and Jest run many files in one worker, so reads cannot be told apart.
|
|
23
|
+
*/
|
|
24
|
+
export const COVERAGE_MAP_SCHEMA = "diffci.coverage-map.v1";
|
|
25
|
+
const PROBE = `"use strict";
|
|
26
|
+
if (process.env.NODE_TEST_CONTEXT && process.argv[1] && process.env.DIFFCI_COVERAGE_LOG) {
|
|
27
|
+
const fs = require("node:fs");
|
|
28
|
+
const { fileURLToPath } = require("node:url");
|
|
29
|
+
const file = process.argv[1];
|
|
30
|
+
const reads = new Set();
|
|
31
|
+
const listed = new Set();
|
|
32
|
+
const note = (set, target) => {
|
|
33
|
+
try { set.add(typeof target === "string" ? target : target instanceof URL ? fileURLToPath(target) : Buffer.isBuffer(target) ? target.toString() : ""); } catch {}
|
|
34
|
+
};
|
|
35
|
+
const wrap = (owner, name, set) => {
|
|
36
|
+
const original = owner[name];
|
|
37
|
+
if (typeof original !== "function") return;
|
|
38
|
+
owner[name] = function (target, ...rest) { note(set, target); return original.call(this, target, ...rest); };
|
|
39
|
+
};
|
|
40
|
+
for (const name of ["readFileSync", "readFile", "createReadStream", "existsSync"]) wrap(fs, name, reads);
|
|
41
|
+
for (const name of ["readdirSync", "readdir", "opendirSync", "opendir"]) wrap(fs, name, listed);
|
|
42
|
+
wrap(fs.promises, "readFile", reads);
|
|
43
|
+
wrap(fs.promises, "readdir", listed);
|
|
44
|
+
wrap(fs.promises, "opendir", listed);
|
|
45
|
+
try { require("node:module").syncBuiltinESMExports(); } catch {}
|
|
46
|
+
process.on("exit", () => {
|
|
47
|
+
try { fs.appendFileSync(process.env.DIFFCI_COVERAGE_LOG, JSON.stringify({ file, pid: process.pid, reads: [...reads], listed: [...listed] }) + "\\n"); } catch {}
|
|
48
|
+
});
|
|
49
|
+
}
|
|
50
|
+
`;
|
|
51
|
+
export function coverageMapPath(repoPath) {
|
|
52
|
+
const log = outcomeLogPath(repoPath);
|
|
53
|
+
return log ? join(log, "..", "coverage-map.json") : undefined;
|
|
54
|
+
}
|
|
55
|
+
export function readCoverageMap(repoPath) {
|
|
56
|
+
const path = coverageMapPath(repoPath);
|
|
57
|
+
if (!path || !existsSync(path))
|
|
58
|
+
return undefined;
|
|
59
|
+
try {
|
|
60
|
+
const map = JSON.parse(readFileSync(path, "utf8"));
|
|
61
|
+
return map.schema === COVERAGE_MAP_SCHEMA && map.tests && typeof map.tests === "object" ? map : undefined;
|
|
62
|
+
}
|
|
63
|
+
catch {
|
|
64
|
+
return undefined;
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
/** Runs `command` under the probe and V8 coverage, and writes the map. */
|
|
68
|
+
export function buildCoverageMap(repoPath, command, options) {
|
|
69
|
+
const dir = mkdtempSync(join(tmpdir(), "diffci-coverage-"));
|
|
70
|
+
try {
|
|
71
|
+
const probe = join(dir, "probe.cjs");
|
|
72
|
+
const log = join(dir, "reads.jsonl");
|
|
73
|
+
const v8 = join(dir, "v8");
|
|
74
|
+
mkdirSync(v8);
|
|
75
|
+
writeFileSync(probe, PROBE);
|
|
76
|
+
const nodeOptions = options.nodeOptions ?? process.env.NODE_OPTIONS;
|
|
77
|
+
const required = `--require "${probe.split(sep).join("/")}"`;
|
|
78
|
+
const execution = measureCommand(command, {
|
|
79
|
+
cwd: repoPath,
|
|
80
|
+
timeoutMs: options.timeoutMs,
|
|
81
|
+
tailBytes: options.tailBytes ?? 4000,
|
|
82
|
+
env: { NODE_OPTIONS: nodeOptions?.trim() ? `${nodeOptions} ${required}` : required, DIFFCI_COVERAGE_LOG: log, NODE_V8_COVERAGE: v8 },
|
|
83
|
+
});
|
|
84
|
+
let records = [];
|
|
85
|
+
try {
|
|
86
|
+
records = readFileSync(log, "utf8").split("\n").filter(Boolean).flatMap((line) => { try {
|
|
87
|
+
return [JSON.parse(line)];
|
|
88
|
+
}
|
|
89
|
+
catch {
|
|
90
|
+
return [];
|
|
91
|
+
} });
|
|
92
|
+
}
|
|
93
|
+
catch { }
|
|
94
|
+
if (records.length === 0) {
|
|
95
|
+
return { execution, error: "no node --test process reported to the probe; the coverage map needs node:test, which runs each test file in its own process" };
|
|
96
|
+
}
|
|
97
|
+
const root = realpath(repoPath);
|
|
98
|
+
const inRepo = (absolute) => {
|
|
99
|
+
if (!absolute || !isAbsolute(absolute))
|
|
100
|
+
return undefined;
|
|
101
|
+
const path = relative(root, realpath(absolute)).split(sep).join("/");
|
|
102
|
+
if (!path || path.startsWith("..") || isAbsolute(path))
|
|
103
|
+
return undefined;
|
|
104
|
+
if (path.split("/").some((part) => part === "node_modules" || part === ".git"))
|
|
105
|
+
return undefined;
|
|
106
|
+
return path;
|
|
107
|
+
};
|
|
108
|
+
const loaded = loadedModulesByPid(v8);
|
|
109
|
+
const tests = {};
|
|
110
|
+
for (const record of records) {
|
|
111
|
+
const test = inRepo(record.file);
|
|
112
|
+
if (!test)
|
|
113
|
+
continue;
|
|
114
|
+
const entry = tests[test] ??= new Set();
|
|
115
|
+
for (const read of [...record.reads, ...(loaded.get(record.pid) ?? [])]) {
|
|
116
|
+
const path = inRepo(read);
|
|
117
|
+
if (path && path !== test && isFile(join(root, path)))
|
|
118
|
+
entry.add(path);
|
|
119
|
+
}
|
|
120
|
+
for (const listed of record.listed) {
|
|
121
|
+
const path = inRepo(listed);
|
|
122
|
+
if (path && isDirectory(join(root, path)))
|
|
123
|
+
entry.add(`${path}/`);
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
const map = {
|
|
127
|
+
schema: COVERAGE_MAP_SCHEMA,
|
|
128
|
+
produced_at: new Date().toISOString(),
|
|
129
|
+
command,
|
|
130
|
+
tests: Object.fromEntries(Object.entries(tests).sort(([a], [b]) => a.localeCompare(b)).map(([test, paths]) => [test, [...paths].sort()])),
|
|
131
|
+
};
|
|
132
|
+
const path = coverageMapPath(repoPath);
|
|
133
|
+
if (path) {
|
|
134
|
+
mkdirSync(join(path, ".."), { recursive: true });
|
|
135
|
+
writeFileSync(path, `${JSON.stringify(map)}\n`, "utf8");
|
|
136
|
+
}
|
|
137
|
+
return { map, ...(path ? { path } : {}), execution };
|
|
138
|
+
}
|
|
139
|
+
finally {
|
|
140
|
+
rmSync(dir, { recursive: true, force: true });
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
/** Script URLs in each process's V8 coverage file (`coverage-<pid>-<time>-<n>.json`), by pid. */
|
|
144
|
+
function loadedModulesByPid(dir) {
|
|
145
|
+
const byPid = new Map();
|
|
146
|
+
for (const name of readdirSync(dir)) {
|
|
147
|
+
const pid = Number(/^coverage-(\d+)-/.exec(name)?.[1]);
|
|
148
|
+
if (!Number.isFinite(pid))
|
|
149
|
+
continue;
|
|
150
|
+
try {
|
|
151
|
+
const { result } = JSON.parse(readFileSync(join(dir, name), "utf8"));
|
|
152
|
+
const files = result.flatMap(({ url }) => { try {
|
|
153
|
+
return url.startsWith("file:") ? [fileURLToPath(url)] : isAbsolute(url) ? [url] : [];
|
|
154
|
+
}
|
|
155
|
+
catch {
|
|
156
|
+
return [];
|
|
157
|
+
} });
|
|
158
|
+
byPid.set(pid, [...(byPid.get(pid) ?? []), ...files]);
|
|
159
|
+
}
|
|
160
|
+
catch { }
|
|
161
|
+
}
|
|
162
|
+
return byPid;
|
|
163
|
+
}
|
|
164
|
+
function realpath(path) {
|
|
165
|
+
try {
|
|
166
|
+
return realpathSync.native(path);
|
|
167
|
+
}
|
|
168
|
+
catch {
|
|
169
|
+
return path;
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
function isFile(path) {
|
|
173
|
+
try {
|
|
174
|
+
return statSync(path).isFile();
|
|
175
|
+
}
|
|
176
|
+
catch {
|
|
177
|
+
return false;
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
|
+
function isDirectory(path) {
|
|
181
|
+
try {
|
|
182
|
+
return statSync(path).isDirectory();
|
|
183
|
+
}
|
|
184
|
+
catch {
|
|
185
|
+
return false;
|
|
186
|
+
}
|
|
187
|
+
}
|
|
188
|
+
/** Tests whose map entry names one of `changed` (or lists a directory holding one), that `selected` lacks. */
|
|
189
|
+
export function coverageAdditions(map, changed, selected) {
|
|
190
|
+
const have = new Set(selected);
|
|
191
|
+
const additions = [];
|
|
192
|
+
for (const [test, paths] of Object.entries(map.tests)) {
|
|
193
|
+
if (have.has(test))
|
|
194
|
+
continue;
|
|
195
|
+
const hit = changed.find((file) => paths.some((path) => path === file || (path.endsWith("/") && file.startsWith(path))));
|
|
196
|
+
if (hit)
|
|
197
|
+
additions.push({ test, changed_file: hit });
|
|
198
|
+
}
|
|
199
|
+
return additions;
|
|
200
|
+
}
|
|
201
|
+
export function formatCoverageRun(run) {
|
|
202
|
+
if (!run.map)
|
|
203
|
+
return `diffci coverage: ${run.error ?? "no map was built"}`;
|
|
204
|
+
const tests = Object.keys(run.map.tests).length;
|
|
205
|
+
const files = new Set(Object.values(run.map.tests).flat()).size;
|
|
206
|
+
const lines = [`DiffCI coverage map: ${tests} test file(s), ${files} file(s) and directories they load, read or list`];
|
|
207
|
+
if (run.path)
|
|
208
|
+
lines.push(` written to ${run.path} (inside .git, never committed or sent)`);
|
|
209
|
+
if (run.execution.exitCode !== 0)
|
|
210
|
+
lines.push(` the test command exited ${String(run.execution.exitCode)}; the map still records what each test touched`);
|
|
211
|
+
lines.push(" verify now adds tests this map connects to a changed file when the dependency graph did not select them");
|
|
212
|
+
return lines.join("\n");
|
|
213
|
+
}
|
|
Binary file
|
|
@@ -250,6 +250,8 @@ export async function observe(options) {
|
|
|
250
250
|
const outsideSuite = [...(impact.testsOutsideFullSuite ?? []).map((test) => test.path), ...planOutside].sort();
|
|
251
251
|
const outsidePlan = outsideSuite.length ? planSelectiveTestCommands(profile, outsideSuite) : undefined;
|
|
252
252
|
markPhase("impactAndCommands");
|
|
253
|
+
// Newer than some bundled engines, which never return it.
|
|
254
|
+
const fallbackDetails = impact.fallbackDetails;
|
|
253
255
|
return finish("OBSERVED", "complete", {
|
|
254
256
|
result: {
|
|
255
257
|
mode: impact.fallbackRequired ? "FULL" : "SELECTIVE",
|
|
@@ -265,6 +267,7 @@ export async function observe(options) {
|
|
|
265
267
|
outsideSuiteCommands: outsidePlan?.refusalReason ? [] : (outsidePlan?.commands ?? []).map(commandSpecToString),
|
|
266
268
|
} : {}),
|
|
267
269
|
fallbackReasons: impact.fallbackReasons,
|
|
270
|
+
...(fallbackDetails ? { fallbackDetails } : {}),
|
|
268
271
|
proposedCommands: (commandPlan?.commands ?? []).map(commandSpecToString),
|
|
269
272
|
...(impact.testPhases?.length ? { testPhases: [...impact.testPhases] } : {}),
|
|
270
273
|
workspaceCommands: Boolean(profile.workspaceTestPackages?.length),
|