@diffci.com/diffci 0.3.53 → 0.3.55
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 +81 -1
- package/dist-client/src/client/agent-selection.js +107 -4
- package/dist-client/src/client/agent-setup.js +1 -1
- package/dist-client/src/client/cli.js +140 -18
- package/dist-client/src/client/command-batches.js +3 -2
- package/dist-client/src/client/context.js +32 -2
- package/dist-client/src/client/coverage-map.js +6 -1
- package/dist-client/src/client/full-command.js +19 -14
- 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 +30 -1
- package/dist-client/src/client/isolated-worktree.d.ts +31 -0
- package/dist-client/src/client/isolated-worktree.js +130 -0
- package/dist-client/src/client/mcp.js +23 -4
- package/dist-client/src/client/observe.d.ts +2 -0
- package/dist-client/src/client/observe.js +7 -2
- package/dist-client/src/client/report.d.ts +1 -1
- 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.d.ts +47 -3
- package/dist-client/src/client/verify.js +244 -22
- package/dist-client/src/client/working-tree.d.ts +22 -0
- package/dist-client/src/client/working-tree.js +45 -6
- 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 +19 -4
- 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 +22 -20
- 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 +21 -2
- 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 +158 -14
- package/node_modules/@diffci.com/core/dist/repo/adapters/python.js.map +1 -1
- package/node_modules/@diffci.com/core/dist/repo/adapters/rust.d.ts +1 -0
- package/node_modules/@diffci.com/core/dist/repo/adapters/rust.js +180 -15
- 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 +7 -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 +100 -29
- 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 +55 -8
- 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/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 +18 -4
- 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 +20 -21
- 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 +20 -2
- package/node_modules/@diffci.com/core/src/repo/adapters/python.ts +133 -14
- package/node_modules/@diffci.com/core/src/repo/adapters/rust.ts +136 -16
- package/node_modules/@diffci.com/core/src/repo/adapters/types.ts +7 -1
- package/node_modules/@diffci.com/core/src/repo/file-references.ts +70 -5
- package/node_modules/@diffci.com/core/src/repo/graph.ts +81 -20
- package/node_modules/@diffci.com/core/src/repo/impact.ts +56 -7
- 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/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
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import { createHash } from "node:crypto";
|
|
2
|
+
import { commandSpecToString, nodeTestGlobForPath } from "@diffci.com/core/planner/test-command";
|
|
1
3
|
import { mkdtempSync, rmSync } from "node:fs";
|
|
2
4
|
import { tmpdir } from "node:os";
|
|
3
5
|
import { join, resolve } from "node:path";
|
|
@@ -7,13 +9,15 @@ import { checkAtBaseline, compareWithBaseline } from "./failure-baseline.js";
|
|
|
7
9
|
import { collectEnforcementContext, evaluateEnforcement } from "./enforce-policy.js";
|
|
8
10
|
import { inferFullCommand, inferPlannedCommands, inferSelectedCommand, inferSelectedCommands } from "./full-command.js";
|
|
9
11
|
import { plannedChecks, runChecks } from "./gate-checks.js";
|
|
10
|
-
import { makeGitRunner, observe } from "./observe.js";
|
|
12
|
+
import { makeGitRunner, observe, separateProjectReason } from "./observe.js";
|
|
13
|
+
import { redactPath } from "./report.js";
|
|
14
|
+
import { createIsolatedWorktree } from "./isolated-worktree.js";
|
|
11
15
|
import { selectedNodeTests, traceNodeTestFiles, unmatchedNodeTests, unstartedNodeTests } from "./selected-coverage.js";
|
|
12
16
|
import { outcomeLogPath, readOutcomes, reusablePass } from "./outcome-log.js";
|
|
13
17
|
import { likelyFailures, rankTests, testHistory } from "./test-ranking.js";
|
|
14
18
|
import { assignShards } from "./test-shards.js";
|
|
15
19
|
import { mergeTestFileResults } from "./test-results.js";
|
|
16
|
-
import { captureWorkingTreeSnapshot, snapshotChanges } from "./working-tree.js";
|
|
20
|
+
import { captureScopedTree, captureWorkingTreeSnapshot, snapshotChanges } from "./working-tree.js";
|
|
17
21
|
export const VERIFICATION_SCHEMA = "diffci.verification.v1";
|
|
18
22
|
function receiptRange(range) {
|
|
19
23
|
if (!range)
|
|
@@ -58,10 +62,13 @@ function unknownSnapshot() {
|
|
|
58
62
|
return { baseSha: "unknown", treeSha: "unknown", commitSha: "unknown", changed: true };
|
|
59
63
|
}
|
|
60
64
|
async function executeObservation(options, scope, before, observation) {
|
|
61
|
-
|
|
62
|
-
|
|
65
|
+
// The analysis sees real paths, but under --redact-paths enforce keeps treating the paths as redacted.
|
|
66
|
+
const context = options.policy === "enforce" ? collectEnforcementContext(makeGitRunner(options.repoPath), options.env, observation) : undefined;
|
|
67
|
+
const enforcement = context
|
|
68
|
+
? evaluateEnforcement(options.redactPaths ? { ...context, pathsRedacted: true } : context, observation)
|
|
63
69
|
: undefined;
|
|
64
|
-
const
|
|
70
|
+
const executed = await executeWithPolicy(options, scope, before, observation, enforcement);
|
|
71
|
+
const report = options.redactPaths ? redactReceipt(executed, observation.result, options.repoPath) : executed;
|
|
65
72
|
if (!enforcement)
|
|
66
73
|
return report;
|
|
67
74
|
return { ...report, enforcement: { ...enforcement, applied: enforcement.fired_fallback === null && report.selection === "selected" } };
|
|
@@ -221,11 +228,22 @@ async function executeWithPolicy(options, scope, before, observation, enforcemen
|
|
|
221
228
|
};
|
|
222
229
|
}
|
|
223
230
|
const checkBaseline = options.baselineOnFailure && checkBase && checkHead
|
|
224
|
-
|
|
231
|
+
// With no time left the base rerun would get a 0ms limit, which means none: report it as unknown instead.
|
|
232
|
+
? (check, remainingMs) => remainingMs <= 0
|
|
233
|
+
? { status: "unknown", base_sha: checkBase, reason: "the time limit ran out before the base run" }
|
|
234
|
+
: checkAtBaseline({ repoPath: options.repoPath, baseSha: checkBase, headSha: checkHead, command: check.command, timeoutMs: remainingMs })
|
|
225
235
|
: undefined;
|
|
226
236
|
const checkRun = options.skipChecks ? undefined : runChecks(planned, { cwd: options.repoPath, timeoutMs: options.timeoutMs, tailBytes: options.tailBytes, baseline: checkBaseline });
|
|
227
237
|
const checks = checkRun?.results.length ? checkRun.results : undefined;
|
|
228
238
|
const failedCheck = checkRun?.failure?.check;
|
|
239
|
+
// Checks the time limit left no room for were never run, so the tests must not run (with no limit) either.
|
|
240
|
+
const unrunChecks = checkRun?.outOfTime ? checkRun.results.filter((check) => check.status === "not_run") : [];
|
|
241
|
+
// Every check can run and still use the whole budget (a slow last check, or a base rerun after a
|
|
242
|
+
// failure that also fails at the base). The tests would then get a 0ms limit, which means none.
|
|
243
|
+
const testBudgetMs = options.timeoutMs - (checkRun?.wallMs ?? 0);
|
|
244
|
+
const budgetUsedByChecks = Boolean(checkRun && !checkRun.failure && !unrunChecks.length && testBudgetMs <= 0
|
|
245
|
+
&& checkRun.results.some((check) => check.status !== "skipped" && check.status !== "not_run"));
|
|
246
|
+
const testsOutOfTime = unrunChecks.length > 0 || budgetUsedByChecks;
|
|
229
247
|
// Checks that also fail at the base: still a failed verdict (required CI fails either way), but they
|
|
230
248
|
// no longer stop the run before the change's own failures.
|
|
231
249
|
const preexistingChecks = checkRun?.preexisting ?? [];
|
|
@@ -235,13 +253,15 @@ async function executeWithPolicy(options, scope, before, observation, enforcemen
|
|
|
235
253
|
// Every test run goes under a probe that records which `node --test` files started (selected ones must)
|
|
236
254
|
// and each one's duration and result for the outcome log (2026-11-06). Outside node:test it does nothing.
|
|
237
255
|
const expectedNodeTests = selection === "selected" && result ? selectedNodeTests(command, result.selectedTests) : [];
|
|
238
|
-
const trace = !checkRun?.failure ? traceNodeTestFiles(options.repoPath) : undefined;
|
|
256
|
+
const trace = !checkRun?.failure && !testsOutOfTime ? traceNodeTestFiles(options.repoPath) : undefined;
|
|
239
257
|
let startedNodeTests;
|
|
240
258
|
let execution;
|
|
241
259
|
try {
|
|
242
260
|
execution = checkRun?.failure
|
|
243
261
|
? checkRun.failure.measurement
|
|
244
|
-
:
|
|
262
|
+
: testsOutOfTime
|
|
263
|
+
? checksOutOfTime(command, checkRun?.wallMs ?? 0)
|
|
264
|
+
: measureCommands(runCommands, { cwd: options.repoPath, timeoutMs: testBudgetMs, tailBytes: options.tailBytes, env: trace?.env, stopOnFailure: options.failFast, stopOnFailureWithin: firstPass?.parts.length });
|
|
245
265
|
startedNodeTests = trace?.read();
|
|
246
266
|
const nodeResults = trace?.results() ?? [];
|
|
247
267
|
if (nodeResults.length)
|
|
@@ -307,15 +327,19 @@ async function executeWithPolicy(options, scope, before, observation, enforcemen
|
|
|
307
327
|
? `the runner reported ${String(execution.runnerTestCount)} test(s) for ${selectedCount} selected test file(s), so some selected tests did not run; run the full test command instead`
|
|
308
328
|
: succeeded
|
|
309
329
|
? checks ? `${reason}; ${checkSummary(checks)}` : reason
|
|
310
|
-
:
|
|
311
|
-
? `gate check ${
|
|
312
|
-
:
|
|
313
|
-
? `
|
|
314
|
-
:
|
|
315
|
-
?
|
|
316
|
-
:
|
|
330
|
+
: unrunChecks.length
|
|
331
|
+
? `gate check(s) ${unrunChecks.map((check) => check.id).join(", ")} did not run within the ${options.timeoutMs}ms time limit; tests were not run`
|
|
332
|
+
: budgetUsedByChecks
|
|
333
|
+
? `gate checks used the whole ${options.timeoutMs}ms time limit (${String(checkRun?.wallMs ?? 0)}ms); tests were not run`
|
|
334
|
+
: failedCheck
|
|
335
|
+
? `gate check ${failedCheck.id} ${failedCheck.status === "timed_out" ? "timed out" : `failed with exit code ${String(failedCheck.exit_code)}`}; tests were not run (${failedCheck.command})`
|
|
336
|
+
: execution.timedOut
|
|
337
|
+
? `verification timed out after ${options.timeoutMs}ms${preexistingNote}`
|
|
338
|
+
: testsPassed
|
|
339
|
+
? `${preexistingChecks.length} gate check(s) failed that also fail at the base commit; nothing this change introduced failed (${preexistingChecks.map((check) => check.id).join(", ")})`
|
|
340
|
+
: `verification command failed with exit code ${String(execution.exitCode)}${preexistingNote}`;
|
|
317
341
|
const baselineSha = scope === "commit-range" ? range?.baseSha : before.baseSha;
|
|
318
|
-
const failureBaseline = verification === "failed" && !failedCheck && !execution.timedOut && options.baselineOnFailure && baselineSha
|
|
342
|
+
const failureBaseline = verification === "failed" && !failedCheck && !testsOutOfTime && !execution.timedOut && options.baselineOnFailure && baselineSha
|
|
319
343
|
// The base reruns only the parts that ran here: a first-pass failure is compared without the full suite.
|
|
320
344
|
? compareWithBaseline({ repoPath: options.repoPath, baseSha: baselineSha, headSha: scope === "commit-range" ? before.baseSha : before.commitSha, commands: stoppedInFirstPass ? firstPass.parts : commands, headFailures: execution.failingTests ?? [], timeoutMs: options.timeoutMs })
|
|
321
345
|
: undefined;
|
|
@@ -354,13 +378,13 @@ async function executeWithPolicy(options, scope, before, observation, enforcemen
|
|
|
354
378
|
...coverageField,
|
|
355
379
|
};
|
|
356
380
|
}
|
|
357
|
-
function stamped(report, version) {
|
|
381
|
+
function stamped(report, version, redactPaths) {
|
|
358
382
|
const { schema, schema_version, produced_at, ...rest } = report;
|
|
359
|
-
return { schema, schema_version, produced_at, diffci_version: version, ...rest };
|
|
383
|
+
return { schema, schema_version, produced_at, diffci_version: version, ...rest, ...(redactPaths ? { snapshot: redactSnapshot(report.snapshot) } : {}) };
|
|
360
384
|
}
|
|
361
385
|
/** Verify exactly the staged, unstaged, and non-ignored untracked content currently on disk. */
|
|
362
386
|
export async function verifyChanged(options) {
|
|
363
|
-
return stamped(await verifyChangedSnapshot(options), options.version);
|
|
387
|
+
return stamped(await verifyChangedSnapshot(options), options.version, options.redactPaths);
|
|
364
388
|
}
|
|
365
389
|
async function verifyChangedSnapshot(options) {
|
|
366
390
|
const repoPath = resolve(options.repoPath);
|
|
@@ -401,9 +425,10 @@ async function verifyChangedSnapshot(options) {
|
|
|
401
425
|
engineSha: options.engineSha,
|
|
402
426
|
baseOverride: before.baseSha,
|
|
403
427
|
headOverride: before.commitSha,
|
|
404
|
-
|
|
428
|
+
// Planned with real paths so the selected tests can run; only the receipt is redacted (redactReceipt).
|
|
405
429
|
reportPath: join(temporaryDirectory, "observation.json"),
|
|
406
430
|
selectTestPhases: true,
|
|
431
|
+
...(options.onGraph ? { onGraph: options.onGraph } : {}),
|
|
407
432
|
});
|
|
408
433
|
return await executeObservation({ ...options, repoPath }, "working-tree", before, observation);
|
|
409
434
|
}
|
|
@@ -411,9 +436,116 @@ async function verifyChangedSnapshot(options) {
|
|
|
411
436
|
rmSync(temporaryDirectory, { recursive: true, force: true });
|
|
412
437
|
}
|
|
413
438
|
}
|
|
439
|
+
/**
|
|
440
|
+
* Verify HEAD plus only the staged content (`--staged`) or only the named files (`--paths`), 2026-11-17.
|
|
441
|
+
*
|
|
442
|
+
* The scoped tree is checked out in a temporary worktree of HEAD (isolated-worktree.ts) and verified
|
|
443
|
+
* there exactly as `--changed` verifies a checkout, so every other uncommitted file in this checkout is
|
|
444
|
+
* at its HEAD version for analysis and for the tests: it can neither fail nor rescue the result. The
|
|
445
|
+
* receipt names the verified files and the excluded dirty ones. Its tree is the tree a commit of the
|
|
446
|
+
* staged files has, so the pre-push hook reuses a pass of it (outcome-log.ts, reusablePass).
|
|
447
|
+
*/
|
|
448
|
+
/** The scoped tree, the files it changes from HEAD, and the checkout's other changed files (excluded). */
|
|
449
|
+
export function scopedChanges(repoPath, scope) {
|
|
450
|
+
const scoped = captureScopedTree(repoPath, scope);
|
|
451
|
+
const checkout = captureWorkingTreeSnapshot(repoPath);
|
|
452
|
+
return {
|
|
453
|
+
scoped,
|
|
454
|
+
verified: snapshotChanges(repoPath, `${scoped.baseSha}^{tree}`, scoped.treeSha),
|
|
455
|
+
excluded: snapshotChanges(repoPath, scoped.treeSha, checkout.treeSha),
|
|
456
|
+
};
|
|
457
|
+
}
|
|
458
|
+
export async function verifyScoped(options) {
|
|
459
|
+
return stamped(await verifyScopedTree(options), options.version, options.redactPaths);
|
|
460
|
+
}
|
|
461
|
+
async function verifyScopedTree(options) {
|
|
462
|
+
const repoPath = resolve(options.repoPath);
|
|
463
|
+
const kind = options.scope.kind;
|
|
464
|
+
const shown = (path) => options.redactPaths ? redactPath(path, (input) => createHash("sha256").update(input).digest("hex")) : path;
|
|
465
|
+
let scoped;
|
|
466
|
+
let verified;
|
|
467
|
+
let excluded;
|
|
468
|
+
try {
|
|
469
|
+
({ scoped, verified, excluded } = scopedChanges(repoPath, options.scope));
|
|
470
|
+
}
|
|
471
|
+
catch (error) {
|
|
472
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
473
|
+
return blocked(unknownSnapshot(), kind, message, { status: "ERROR", stage: "context", fallback_reasons: [], error: message });
|
|
474
|
+
}
|
|
475
|
+
const scopedField = {
|
|
476
|
+
kind,
|
|
477
|
+
isolation: "temporary-worktree",
|
|
478
|
+
verified_files: verified.map((change) => shown(change.path)),
|
|
479
|
+
excluded_dirty_files: excluded.length,
|
|
480
|
+
excluded_dirty_paths: excluded.slice(0, 50).map((change) => shown(change.path)),
|
|
481
|
+
};
|
|
482
|
+
if (!scoped.changed) {
|
|
483
|
+
return {
|
|
484
|
+
...baseReport(scoped, kind),
|
|
485
|
+
verification: "passed",
|
|
486
|
+
safe_to_continue: true,
|
|
487
|
+
reason: kind === "staged" ? "nothing is staged: the index matches HEAD" : "the given paths do not differ from HEAD",
|
|
488
|
+
changed_files: 0,
|
|
489
|
+
tests_available: 0,
|
|
490
|
+
tests_selected: 0,
|
|
491
|
+
selection: "none",
|
|
492
|
+
snapshot: { ...baseReport(scoped, kind).snapshot, after_base_sha: scoped.baseSha, after_tree_sha: scoped.treeSha, unchanged: true },
|
|
493
|
+
analysis: { status: "not_needed", fallback_reasons: [] },
|
|
494
|
+
required_actions: [],
|
|
495
|
+
scoped: scopedField,
|
|
496
|
+
};
|
|
497
|
+
}
|
|
498
|
+
const worktree = createIsolatedWorktree(repoPath, scoped.baseSha, scoped.treeSha);
|
|
499
|
+
if ("error" in worktree) {
|
|
500
|
+
return { ...blocked(scoped, kind, worktree.error, { status: "not_needed", fallback_reasons: [] }, { changedFiles: verified.length }), scoped: scopedField };
|
|
501
|
+
}
|
|
502
|
+
let forward;
|
|
503
|
+
let inner;
|
|
504
|
+
let cleaned;
|
|
505
|
+
try {
|
|
506
|
+
inner = await verifyChangedSnapshot({ ...options, repoPath: worktree.path, onGraph: (graph) => { forward = graph.graph.forward; } });
|
|
507
|
+
}
|
|
508
|
+
finally {
|
|
509
|
+
cleaned = worktree.dispose();
|
|
510
|
+
}
|
|
511
|
+
if (!cleaned)
|
|
512
|
+
scopedField.cleanup_failed = worktree.path;
|
|
513
|
+
// Excluded dirty files a verified file imports were verified at their HEAD version: say which.
|
|
514
|
+
const excludedPaths = new Set(excluded.map((change) => change.path));
|
|
515
|
+
const imports = forward
|
|
516
|
+
? verified.flatMap((change) => {
|
|
517
|
+
const targets = (forward[change.path] ?? []).filter((target) => excludedPaths.has(target));
|
|
518
|
+
return targets.length ? [{ file: shown(change.path), imports: [...new Set(targets)].sort().map(shown) }] : [];
|
|
519
|
+
})
|
|
520
|
+
: [];
|
|
521
|
+
if (imports.length)
|
|
522
|
+
scopedField.head_version_imports = imports;
|
|
523
|
+
// The verdict is for the tree captured at the start: HEAD and the scoped files must still be it.
|
|
524
|
+
let after;
|
|
525
|
+
try {
|
|
526
|
+
after = captureScopedTree(repoPath, options.scope);
|
|
527
|
+
}
|
|
528
|
+
catch {
|
|
529
|
+
after = undefined;
|
|
530
|
+
}
|
|
531
|
+
const moved = !after ? "could not re-read the verified files after the run"
|
|
532
|
+
: after.baseSha !== scoped.baseSha ? "HEAD moved while verification was running"
|
|
533
|
+
: after.treeSha !== scoped.treeSha ? (kind === "staged" ? "the index changed while verification was running (another session may have staged files)" : "the given files changed while verification was running")
|
|
534
|
+
: inner.snapshot.before_tree_sha !== scoped.treeSha ? "the temporary worktree did not reproduce the verified files"
|
|
535
|
+
: undefined;
|
|
536
|
+
const importNote = imports.length
|
|
537
|
+
? `; ${imports.length} verified file(s) import files changed outside the scope, verified at their HEAD version (${imports.slice(0, 3).map((entry) => `${entry.file} -> ${entry.imports.join(", ")}`).join("; ")})`
|
|
538
|
+
: "";
|
|
539
|
+
const report = { ...inner, scope: kind, reason: `${inner.reason}${importNote}`, scoped: scopedField };
|
|
540
|
+
if (moved) {
|
|
541
|
+
const reason = `${moved}; rerun DiffCI for the new ${kind === "staged" ? "index" : "files"}`;
|
|
542
|
+
return { ...report, verification: "blocked", safe_to_continue: false, reason, required_actions: [reason] };
|
|
543
|
+
}
|
|
544
|
+
return report;
|
|
545
|
+
}
|
|
414
546
|
/** Verify a real commit range and bind the receipt to the clean commit that was actually executed. */
|
|
415
547
|
export async function verifyRange(options) {
|
|
416
|
-
return stamped(await verifyCommitRange(options), options.version);
|
|
548
|
+
return stamped(await verifyCommitRange(options), options.version, options.redactPaths);
|
|
417
549
|
}
|
|
418
550
|
async function verifyCommitRange(options) {
|
|
419
551
|
const repoPath = resolve(options.repoPath);
|
|
@@ -438,7 +570,7 @@ async function verifyCommitRange(options) {
|
|
|
438
570
|
engineSha: options.engineSha,
|
|
439
571
|
baseOverride: options.baseOverride,
|
|
440
572
|
headOverride: options.headOverride,
|
|
441
|
-
|
|
573
|
+
// Planned with real paths so the selected tests can run; only the receipt is redacted (redactReceipt).
|
|
442
574
|
reportPath: join(temporaryDirectory, "observation.json"),
|
|
443
575
|
selectTestPhases: true,
|
|
444
576
|
});
|
|
@@ -448,12 +580,93 @@ async function verifyCommitRange(options) {
|
|
|
448
580
|
rmSync(temporaryDirectory, { recursive: true, force: true });
|
|
449
581
|
}
|
|
450
582
|
}
|
|
583
|
+
/**
|
|
584
|
+
* Under --redact-paths the analysis plans with real paths, so the selected tests can run, and the receipt
|
|
585
|
+
* carries digests instead (the same sha256-12 as the observation report): the selected tests and their
|
|
586
|
+
* reasons, and those paths wherever the command and reason text name them. The text also names the files
|
|
587
|
+
* the snapshot lists (a file the run changed); `stamped` digests the lists themselves (redactSnapshot).
|
|
588
|
+
*/
|
|
589
|
+
function redactReceipt(report, result, repoPath) {
|
|
590
|
+
const digest = (path) => redactPath(path, (input) => createHash("sha256").update(input).digest("hex"));
|
|
591
|
+
const snapshot = report.snapshot;
|
|
592
|
+
const known = [...new Set([
|
|
593
|
+
...(result?.selectedTests ?? []), ...(result?.testsOutsideFullSuite ?? []), ...(result?.changedFiles ?? []),
|
|
594
|
+
...(snapshot.written_during_verification ?? []), ...(snapshot.changed_during_verification ?? []).map((change) => change.path),
|
|
595
|
+
...(snapshot.line_ending_only_changes ?? []),
|
|
596
|
+
])].filter((path) => path.length > 0);
|
|
597
|
+
// A command names a path as written, or as the `node --test` glob that matches only it, either one
|
|
598
|
+
// shell-escaped when it holds glob characters: `d[1].test.js` runs as "d@([[])1@([]]).test.js".
|
|
599
|
+
const shellForm = (text) => commandSpecToString({ executable: "", args: [text] }).slice(1);
|
|
600
|
+
const forms = known.flatMap((path) => {
|
|
601
|
+
const glob = nodeTestGlobForPath(path);
|
|
602
|
+
return [...new Set([path, shellForm(path), ...(glob ? [glob, shellForm(glob)] : [])])].map((form) => [form, digest(path)]);
|
|
603
|
+
});
|
|
604
|
+
// The outside-suite reason names the separate project's directory, which is no file the run knows.
|
|
605
|
+
const outside = result?.testsOutsideFullSuite ?? [];
|
|
606
|
+
const projectReason = outside.length ? separateProjectReason(repoPath, outside) : undefined;
|
|
607
|
+
if (projectReason)
|
|
608
|
+
forms.push([projectReason, separateProjectReason(repoPath, outside, digest)]);
|
|
609
|
+
forms.sort((left, right) => right[0].length - left[0].length);
|
|
610
|
+
const scrub = (text) => forms.reduce((current, [form, hidden]) => current.split(form).join(hidden), text);
|
|
611
|
+
return {
|
|
612
|
+
...report,
|
|
613
|
+
reason: scrub(report.reason),
|
|
614
|
+
required_actions: report.required_actions.map(scrub),
|
|
615
|
+
...(report.selected_tests ? { selected_tests: report.selected_tests.map(digest) } : {}),
|
|
616
|
+
...(report.selection_reasons ? {
|
|
617
|
+
selection_reasons: Object.fromEntries(Object.entries(report.selection_reasons).map(([test, why]) => [digest(test), { ...why, changed_file: digest(why.changed_file) }])),
|
|
618
|
+
} : {}),
|
|
619
|
+
...(report.command !== undefined ? { command: scrub(report.command) } : {}),
|
|
620
|
+
...(report.commands ? { commands: report.commands.map(scrub) } : {}),
|
|
621
|
+
...(report.first_pass ? { first_pass: { ...report.first_pass, commands: report.first_pass.commands.map(scrub) } } : {}),
|
|
622
|
+
...(report.execution ? { execution: redactMeasurement(report.execution, scrub) } : {}),
|
|
623
|
+
// Gate checks name the changed files in their reasons, and a NARROWED check's command lists them.
|
|
624
|
+
...(report.checks ? { checks: report.checks.map((check) => ({ ...check, command: scrub(check.command), reason: scrub(check.reason) })) } : {}),
|
|
625
|
+
...(report.failure_baseline ? {
|
|
626
|
+
failure_baseline: {
|
|
627
|
+
...report.failure_baseline,
|
|
628
|
+
reason: scrub(report.failure_baseline.reason),
|
|
629
|
+
preexisting: report.failure_baseline.preexisting.map(scrub),
|
|
630
|
+
introduced: report.failure_baseline.introduced.map(scrub),
|
|
631
|
+
},
|
|
632
|
+
} : {}),
|
|
633
|
+
};
|
|
634
|
+
}
|
|
635
|
+
/**
|
|
636
|
+
* The snapshot's file lists under --redact-paths: the files the run wrote or changed, and the files that
|
|
637
|
+
* differ only by line endings. Applied to every receipt, including the ones that return before the run.
|
|
638
|
+
*/
|
|
639
|
+
function redactSnapshot(snapshot) {
|
|
640
|
+
const digest = (path) => redactPath(path, (input) => createHash("sha256").update(input).digest("hex"));
|
|
641
|
+
return {
|
|
642
|
+
...snapshot,
|
|
643
|
+
...(snapshot.written_during_verification ? { written_during_verification: snapshot.written_during_verification.map(digest) } : {}),
|
|
644
|
+
...(snapshot.changed_during_verification ? { changed_during_verification: snapshot.changed_during_verification.map((change) => ({ ...change, path: digest(change.path) })) } : {}),
|
|
645
|
+
...(snapshot.line_ending_only_changes ? { line_ending_only_changes: snapshot.line_ending_only_changes.map(digest) } : {}),
|
|
646
|
+
};
|
|
647
|
+
}
|
|
648
|
+
/** The run's command, output tails, failing test names and per-file results, with the known paths as digests. */
|
|
649
|
+
function redactMeasurement(execution, scrub) {
|
|
650
|
+
return {
|
|
651
|
+
...execution,
|
|
652
|
+
command: scrub(execution.command),
|
|
653
|
+
stdoutTail: scrub(execution.stdoutTail),
|
|
654
|
+
stderrTail: scrub(execution.stderrTail),
|
|
655
|
+
...(execution.failingTests ? { failingTests: execution.failingTests.map(scrub) } : {}),
|
|
656
|
+
...(execution.testResults ? { testResults: execution.testResults.map((result) => ({ ...result, file: scrub(result.file) })) } : {}),
|
|
657
|
+
};
|
|
658
|
+
}
|
|
451
659
|
function checkSummary(checks) {
|
|
452
660
|
const ran = checks.filter((check) => check.status === "passed").length;
|
|
453
661
|
const narrowed = checks.filter((check) => check.status === "passed" && check.decision === "NARROWED").length;
|
|
454
662
|
const skipped = checks.length - ran;
|
|
455
663
|
return `ran ${ran} gate check(s) first${narrowed ? ` (${narrowed} narrowed to changed files)` : ""}${skipped ? `, skipped ${skipped} the change does not affect` : ""}`;
|
|
456
664
|
}
|
|
665
|
+
/** The measurement recorded when the time limit ran out during the gate checks, before the tests started. */
|
|
666
|
+
function checksOutOfTime(command, wallMs) {
|
|
667
|
+
const now = new Date().toISOString();
|
|
668
|
+
return { command, exitCode: null, signal: null, timedOut: true, startedAt: now, finishedAt: now, wallMs: 0, stdoutTail: "", stderrTail: `gate checks used the time limit (${wallMs}ms); tests were not run` };
|
|
669
|
+
}
|
|
457
670
|
export function verificationExitCode(report) {
|
|
458
671
|
if (report.verification === "passed")
|
|
459
672
|
return 0;
|
|
@@ -472,6 +685,15 @@ export function formatVerificationSummary(report) {
|
|
|
472
685
|
];
|
|
473
686
|
if (report.commit_range)
|
|
474
687
|
lines.splice(2, 0, ` range: ${report.commit_range.base_sha.slice(0, 12)}..${report.commit_range.head_sha.slice(0, 12)}`);
|
|
688
|
+
const scoped = report.scoped;
|
|
689
|
+
if (scoped) {
|
|
690
|
+
const list = (paths, total) => `${paths.slice(0, 5).join(", ")}${total > 5 ? `, ${total - 5} more` : ""}`;
|
|
691
|
+
lines.splice(2, 0, ` verified files (HEAD + ${scoped.kind === "staged" ? "index" : "given paths"}, temporary worktree): ${scoped.verified_files.length}${scoped.verified_files.length ? ` (${list(scoped.verified_files, scoped.verified_files.length)})` : ""}`);
|
|
692
|
+
if (scoped.excluded_dirty_files)
|
|
693
|
+
lines.splice(3, 0, ` excluded: ${scoped.excluded_dirty_files} other changed file(s) in this checkout, verified at HEAD (${list(scoped.excluded_dirty_paths, scoped.excluded_dirty_files)})`);
|
|
694
|
+
if (scoped.cleanup_failed)
|
|
695
|
+
lines.push(` warning: could not remove the temporary worktree ${scoped.cleanup_failed}; delete it and run git worktree prune`);
|
|
696
|
+
}
|
|
475
697
|
const lineEndings = report.snapshot.line_ending_only_changes;
|
|
476
698
|
if (lineEndings?.length) {
|
|
477
699
|
lines.push(` line endings only: ${lineEndings.length}${lineEndings.length === 20 ? "+" : ""} checked-out file(s) differ from HEAD only by CRLF (${lineEndings.slice(0, 3).join(", ")}${lineEndings.length > 3 ? ", ..." : ""}); verified as checked out`);
|
|
@@ -24,5 +24,27 @@ export interface SnapshotChange {
|
|
|
24
24
|
* used only by DiffCI's existing commit-to-commit analyzer.
|
|
25
25
|
*/
|
|
26
26
|
export declare function captureWorkingTreeSnapshot(repoPathInput: string): WorkingTreeSnapshot;
|
|
27
|
+
/** What a scoped verification covers: HEAD plus the index (`--staged`), or HEAD plus these working-tree paths (`--paths`). */
|
|
28
|
+
export type VerificationTreeScope = {
|
|
29
|
+
kind: "staged";
|
|
30
|
+
} | {
|
|
31
|
+
kind: "paths";
|
|
32
|
+
paths: readonly string[];
|
|
33
|
+
};
|
|
34
|
+
/**
|
|
35
|
+
* The tree a scoped verification checks (2026-11-17): HEAD plus only the staged content, or HEAD plus only
|
|
36
|
+
* the named working-tree paths, built in a temporary index like the working-tree snapshot.
|
|
37
|
+
*
|
|
38
|
+
* WHY. Several agent sessions shared one DentalPresence checkout; `verify --changed` before a 3-file commit
|
|
39
|
+
* verified another session's 30 uncommitted files too (341 of 638 test files, about 8 minutes, failed on
|
|
40
|
+
* the other session's code). HEAD plus those 3 files alone selected 12 test files and passed in 12 s.
|
|
41
|
+
*
|
|
42
|
+
* `--staged` reads a copy of the real index, so another session staging at the same moment can never see a
|
|
43
|
+
* half-written index of ours, and ours is never rewritten. `--paths` are literal pathspecs: Next.js route
|
|
44
|
+
* folders such as `app/[slug]` are names, not globs. A path deleted in the working tree is a deletion.
|
|
45
|
+
*/
|
|
46
|
+
export declare function captureScopedTree(repoPathInput: string, scope: VerificationTreeScope): WorkingTreeSnapshot;
|
|
47
|
+
/** The tree of HEAD, for comparing a snapshot with the checked-out commit. */
|
|
48
|
+
export declare function headTree(repoPathInput: string): string;
|
|
27
49
|
/** The paths that differ between two snapshot trees of the same repository. */
|
|
28
50
|
export declare function snapshotChanges(repoPathInput: string, beforeTreeSha: string, afterTreeSha: string): SnapshotChange[];
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { spawnSync } from "node:child_process";
|
|
2
|
-
import { mkdtempSync, readFileSync, rmSync } from "node:fs";
|
|
2
|
+
import { copyFileSync, existsSync, mkdtempSync, readFileSync, rmSync } from "node:fs";
|
|
3
3
|
import { tmpdir } from "node:os";
|
|
4
4
|
import { join, resolve } from "node:path";
|
|
5
5
|
function runGit(repoPath, args, env, input) {
|
|
@@ -90,6 +90,24 @@ function crlfCheckouts(repoPath, baseTreeSha, indexEnvironment) {
|
|
|
90
90
|
* used only by DiffCI's existing commit-to-commit analyzer.
|
|
91
91
|
*/
|
|
92
92
|
export function captureWorkingTreeSnapshot(repoPathInput) {
|
|
93
|
+
return captureTree(repoPathInput, { kind: "working-tree" });
|
|
94
|
+
}
|
|
95
|
+
/**
|
|
96
|
+
* The tree a scoped verification checks (2026-11-17): HEAD plus only the staged content, or HEAD plus only
|
|
97
|
+
* the named working-tree paths, built in a temporary index like the working-tree snapshot.
|
|
98
|
+
*
|
|
99
|
+
* WHY. Several agent sessions shared one DentalPresence checkout; `verify --changed` before a 3-file commit
|
|
100
|
+
* verified another session's 30 uncommitted files too (341 of 638 test files, about 8 minutes, failed on
|
|
101
|
+
* the other session's code). HEAD plus those 3 files alone selected 12 test files and passed in 12 s.
|
|
102
|
+
*
|
|
103
|
+
* `--staged` reads a copy of the real index, so another session staging at the same moment can never see a
|
|
104
|
+
* half-written index of ours, and ours is never rewritten. `--paths` are literal pathspecs: Next.js route
|
|
105
|
+
* folders such as `app/[slug]` are names, not globs. A path deleted in the working tree is a deletion.
|
|
106
|
+
*/
|
|
107
|
+
export function captureScopedTree(repoPathInput, scope) {
|
|
108
|
+
return captureTree(repoPathInput, scope);
|
|
109
|
+
}
|
|
110
|
+
function captureTree(repoPathInput, scope) {
|
|
93
111
|
const repoPath = resolve(repoPathInput);
|
|
94
112
|
const baseSha = requireGit(repoPath, ["rev-parse", "--verify", "HEAD^{commit}"], "could not resolve repository HEAD");
|
|
95
113
|
const baseTreeSha = requireGit(repoPath, ["rev-parse", "--verify", "HEAD^{tree}"], "could not resolve repository HEAD tree");
|
|
@@ -100,11 +118,28 @@ export function captureWorkingTreeSnapshot(repoPathInput) {
|
|
|
100
118
|
const temporaryIndex = join(temporaryDirectory, "index");
|
|
101
119
|
const indexEnvironment = { GIT_INDEX_FILE: temporaryIndex };
|
|
102
120
|
try {
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
121
|
+
let lineEndingOnly = [];
|
|
122
|
+
if (scope.kind === "staged") {
|
|
123
|
+
const indexPath = resolve(repoPath, requireGit(repoPath, ["rev-parse", "--git-path", "index"], "could not locate the repository index"));
|
|
124
|
+
if (existsSync(indexPath))
|
|
125
|
+
copyFileSync(indexPath, temporaryIndex);
|
|
126
|
+
else
|
|
127
|
+
requireGit(repoPath, ["read-tree", baseSha], "could not initialize the verification snapshot", indexEnvironment);
|
|
128
|
+
}
|
|
129
|
+
else {
|
|
130
|
+
requireGit(repoPath, ["read-tree", baseSha], "could not initialize the verification snapshot", indexEnvironment);
|
|
131
|
+
if (scope.kind === "working-tree") {
|
|
132
|
+
requireGit(repoPath, ["add", "-A", "--", "."], "could not capture the working tree", indexEnvironment);
|
|
133
|
+
}
|
|
134
|
+
else {
|
|
135
|
+
if (scope.paths.length === 0)
|
|
136
|
+
throw new Error("--paths needs at least one path");
|
|
137
|
+
requireGit(repoPath, ["--literal-pathspecs", "add", "-A", "--pathspec-from-file=-", "--pathspec-file-nul"], "could not capture the given paths", indexEnvironment, `${scope.paths.join("\0")}\0`);
|
|
138
|
+
}
|
|
139
|
+
lineEndingOnly = crlfCheckouts(repoPath, baseTreeSha, indexEnvironment);
|
|
140
|
+
if (lineEndingOnly.length > 0) {
|
|
141
|
+
requireGit(repoPath, ["reset", "-q", baseSha, "--pathspec-from-file=-", "--pathspec-file-nul"], "could not leave line-ending-only files out of the snapshot", indexEnvironment, `${lineEndingOnly.join("\0")}\0`);
|
|
142
|
+
}
|
|
108
143
|
}
|
|
109
144
|
const treeSha = requireGit(repoPath, ["write-tree"], "could not write the verification tree", indexEnvironment);
|
|
110
145
|
const identityEnvironment = {
|
|
@@ -122,6 +157,10 @@ export function captureWorkingTreeSnapshot(repoPathInput) {
|
|
|
122
157
|
rmSync(temporaryDirectory, { recursive: true, force: true });
|
|
123
158
|
}
|
|
124
159
|
}
|
|
160
|
+
/** The tree of HEAD, for comparing a snapshot with the checked-out commit. */
|
|
161
|
+
export function headTree(repoPathInput) {
|
|
162
|
+
return requireGit(resolve(repoPathInput), ["rev-parse", "--verify", "HEAD^{tree}"], "could not resolve repository HEAD tree");
|
|
163
|
+
}
|
|
125
164
|
/** The paths that differ between two snapshot trees of the same repository. */
|
|
126
165
|
export function snapshotChanges(repoPathInput, beforeTreeSha, afterTreeSha) {
|
|
127
166
|
if (beforeTreeSha === afterTreeSha)
|
|
@@ -1,11 +1,17 @@
|
|
|
1
1
|
# DiffCI Core
|
|
2
2
|
|
|
3
|
+
[](https://github.com/DiffCI/core/actions/workflows/ci.yml)
|
|
4
|
+
[](https://scorecard.dev/viewer/?uri=github.com/DiffCI/core)
|
|
5
|
+
[](https://www.bestpractices.dev/projects/16835)
|
|
6
|
+
[](https://www.npmjs.com/package/@diffci.com/diffci#provenance)
|
|
7
|
+
[](LICENSE)
|
|
8
|
+
|
|
3
9
|
[](https://www.npmjs.com/package/@diffci.com/diffci)
|
|
4
10
|
[](https://github.com/marketplace/actions/diffci-change-impact)
|
|
5
|
-
[](https://gitlab.com/explore/catalog/diffci/diffci)
|
|
12
|
+
[](https://github.com/sponsors/DiffCI)
|
|
7
13
|
|
|
8
|
-
**Verification for AI coding agents.** DiffCI tells Claude Code, Codex, Cursor (or you) which tests and checks a change affects, runs them before the push instead of letting them fail at the full CI gate afterwards, and leaves a receipt of what ran and what was skipped. MIT licensed, runs locally,
|
|
14
|
+
**Verification for AI coding agents.** DiffCI tells Claude Code, Codex, Cursor (or you) which tests and checks a change affects, runs them before the push instead of letting them fail at the full CI gate afterwards, and leaves a receipt of what ran and what was skipped. MIT licensed, runs locally, never uploads your code or reports unless you configure it (it does count runs by default: [usage counting](docs/telemetry.md)), and falls back to the full suite whenever the evidence is incomplete.
|
|
9
15
|
|
|
10
16
|
```sh
|
|
11
17
|
npx "@diffci.com/diffci@latest" check
|
|
@@ -21,7 +27,7 @@ If DiffCI saves you CI time, a ⭐ helps others find it.
|
|
|
21
27
|
|
|
22
28
|
```yaml
|
|
23
29
|
- uses: actions/checkout@v7
|
|
24
|
-
- uses: DiffCI/core@v0.3.
|
|
30
|
+
- uses: DiffCI/core@v0.3.54
|
|
25
31
|
```
|
|
26
32
|
|
|
27
33
|
Add `with: comment: "true"` (and `pull-requests: write` on the job) and the same answer appears on the pull request itself, updated in place on each push:
|
|
@@ -56,7 +62,8 @@ This repository contains DiffCI's MCP server. It is implemented in
|
|
|
56
62
|
and published as the `diffci-mcp` binary of `@diffci.com/diffci`: a local
|
|
57
63
|
stdio server speaking JSON-RPC 2.0 (`initialize`, `tools/list`, `tools/call`)
|
|
58
64
|
that runs against the checkout it is pointed at. It needs no account and sends
|
|
59
|
-
|
|
65
|
+
no code or reports; like the CLI, it counts runs by default
|
|
66
|
+
([usage counting](docs/telemetry.md)).
|
|
60
67
|
|
|
61
68
|
```sh
|
|
62
69
|
npx -y -p @diffci.com/diffci@latest diffci-mcp
|
|
@@ -142,7 +149,7 @@ The [v0.3.10 corresponding source](https://github.com/DiffCI/core/tree/4c76be14c
|
|
|
142
149
|
remains publicly available at tagged Core commit `4c76be14` (`cli-v0.3.10-source`)
|
|
143
150
|
while distribution migrates to the Core-native CLI package.
|
|
144
151
|
|
|
145
|
-
`diffci check` compares full and selected runtime when safe to measure, writes reports outside the checkout, and
|
|
152
|
+
`diffci check` compares full and selected runtime when safe to measure, writes reports outside the checkout, and uploads no report by default; it does send a usage count ([usage counting](docs/telemetry.md)). Test commands can generate files; keep required CI authoritative.
|
|
146
153
|
|
|
147
154
|
**Measured example:** one controlled Cal.com sandbox replay measured **44.2% net reduction** in install + pretest + test runtime including analysis overhead. This is a job-equivalent comparison, not production savings or a forecast for your repository. [Method and limitations](https://diffci.com/case-studies/calcom).
|
|
148
155
|
|
|
@@ -275,15 +282,15 @@ Most open work is teaching DiffCI to narrow changes it currently treats as "run
|
|
|
275
282
|
|
|
276
283
|
Thank you to everyone who has improved DiffCI:
|
|
277
284
|
|
|
278
|
-
- <a href="https://github.com/KingEmma7"><img src="https://github.com/KingEmma7.png?size=80" width="40" height="40" alt="@KingEmma7"></a> **[Emmanuel Mawulolo Tagbor](https://github.com/KingEmma7)**: [`diffci check-plan`](docs/using-diffci.md#compare-a-plan-with-a-full-suite-junit-report) for comparing a saved plan with full-suite JUnit results ([#74](https://github.com/DiffCI/core/pull/74)), Yarn Classic lockfile narrowing ([#63](https://github.com/DiffCI/core/pull/63)), and follow-ups ([#67](https://github.com/DiffCI/core/pull/67), [#70](https://github.com/DiffCI/core/pull/70)).
|
|
279
|
-
- <a href="https://github.com/FredApps"><img src="https://github.com/FredApps.png?size=80" width="40" height="40" alt="@FredApps"></a> **[@FredApps](https://github.com/FredApps)**, **[Area maintainer: Rust](CONTRIBUTING.md#contributor-tiers)**: the [Rust (Cargo) adapter](https://github.com/DiffCI/core/issues/62), from Cargo package and test-target mapping ([#91](https://github.com/DiffCI/core/pull/91)) through crate-dependency selection ([#92](https://github.com/DiffCI/core/pull/92)), conservative `cargo test` commands ([#93](https://github.com/DiffCI/core/pull/93)), registration inside the release boundary ([#94](https://github.com/DiffCI/core/pull/94)) and a pinned public replay on hosted CI ([#95](https://github.com/DiffCI/core/pull/95)), and five safety fixes for runtime module dependencies, Maven module resources, runner suites, deleted assets and Go runtime inputs ([#32](https://github.com/DiffCI/core/pull/32)–[#36](https://github.com/DiffCI/core/pull/36)).
|
|
285
|
+
- <a href="https://github.com/KingEmma7"><img src="https://github.com/KingEmma7.png?size=80" width="40" height="40" alt="@KingEmma7"></a> **[Emmanuel Mawulolo Tagbor](https://github.com/KingEmma7)**, **[Regular contributor](CONTRIBUTING.md#contributor-tiers)**: [`diffci check-plan`](docs/using-diffci.md#compare-a-plan-with-a-full-suite-junit-report) for comparing a saved plan with full-suite JUnit results ([#74](https://github.com/DiffCI/core/pull/74)), Yarn Classic lockfile narrowing ([#63](https://github.com/DiffCI/core/pull/63)), and follow-ups ([#67](https://github.com/DiffCI/core/pull/67), [#70](https://github.com/DiffCI/core/pull/70)).
|
|
286
|
+
- <a href="https://github.com/FredApps"><img src="https://github.com/FredApps.png?size=80" width="40" height="40" alt="@FredApps"></a> **[@FredApps](https://github.com/FredApps)**, **[Area maintainer: Rust](CONTRIBUTING.md#contributor-tiers)**: the [Rust (Cargo) adapter](https://github.com/DiffCI/core/issues/62), from Cargo package and test-target mapping ([#91](https://github.com/DiffCI/core/pull/91)) through crate-dependency selection ([#92](https://github.com/DiffCI/core/pull/92)), conservative `cargo test` commands ([#93](https://github.com/DiffCI/core/pull/93)), registration inside the release boundary ([#94](https://github.com/DiffCI/core/pull/94)) and a pinned public replay on hosted CI ([#95](https://github.com/DiffCI/core/pull/95)), and five safety fixes for runtime module dependencies, Maven module resources, runner suites, deleted assets and Go runtime inputs ([#32](https://github.com/DiffCI/core/pull/32)–[#36](https://github.com/DiffCI/core/pull/36)); match the verify usage line that lists --staged and --paths ([#203](https://github.com/DiffCI/core/pull/203)); list npm run agent:check with the local checks in CONTRIBUTING ([#289](https://github.com/DiffCI/core/pull/289)); say Rust is supported experimentally in the roadmap ([#291](https://github.com/DiffCI/core/pull/291)); retry removing Cargo-built fixtures on Windows ([#235](https://github.com/DiffCI/core/pull/235)); assert the interpreter the analysis recorded, not a second probe ([#310](https://github.com/DiffCI/core/pull/310)); build dist-client once instead of in every test file ([#202](https://github.com/DiffCI/core/pull/202)); find the npm-cli.js npm runs, not one under its global prefix ([#240](https://github.com/DiffCI/core/pull/240)); drop the dead --share-usage flag from the help ([#312](https://github.com/DiffCI/core/pull/312)); expand matrix include the way GitHub does ([#165](https://github.com/DiffCI/core/pull/165)); compare if: strings ignoring case, as GitHub does ([#170](https://github.com/DiffCI/core/pull/170)); an empty or comment-only workflow file no longer crashes diffci plan ([#171](https://github.com/DiffCI/core/pull/171)); parse numstat -z renames so renamed files keep isBinary ([#176](https://github.com/DiffCI/core/pull/176)); compile globs character by character so regex metacharacters stay literal ([#179](https://github.com/DiffCI/core/pull/179)); split run lines into argv the way sh would ([#181](https://github.com/DiffCI/core/pull/181)); read GitHub Actions path filters from the workflow's on: triggers ([#182](https://github.com/DiffCI/core/pull/182)); plan a purpose from a job that runs its step ([#185](https://github.com/DiffCI/core/pull/185)); treat Azure Pipelines and other CI providers' pipeline files as CI config ([#186](https://github.com/DiffCI/core/pull/186)); only an ancestor script makes a cycle ([#188](https://github.com/DiffCI/core/pull/188)); match task input patterns as path globs ([#174](https://github.com/DiffCI/core/pull/174)); read template text after a substitution in script checks ([#219](https://github.com/DiffCI/core/pull/219)); treat a change to an extended tsconfig base as global ([#237](https://github.com/DiffCI/core/pull/237)); lint changed files of types the ESLint config adds ([#242](https://github.com/DiffCI/core/pull/242)); check double-quoted expansion in linear time ([#302](https://github.com/DiffCI/core/pull/302)); resolve imports against a test package's basedir ([#205](https://github.com/DiffCI/core/pull/205)); follow pytest plugins that addopts loads with -p ([#207](https://github.com/DiffCI/core/pull/207)); expand wildcards in pytest testpaths ([#209](https://github.com/DiffCI/core/pull/209)); recognise Failsafe's IT* and *ITCase test names ([#211](https://github.com/DiffCI/core/pull/211)); ignore XML comments when reading a POM ([#213](https://github.com/DiffCI/core/pull/213)); ignore go.mod fixtures under testdata, _ and . directories ([#215](https://github.com/DiffCI/core/pull/215)); keep +, $ and ^ literal in globs, and match everything with ** ([#249](https://github.com/DiffCI/core/pull/249)); resolve a leading <rootDir> in testPathIgnorePatterns ([#253](https://github.com/DiffCI/core/pull/253)); install with --mode=skip-build on Yarn 2 and later ([#200](https://github.com/DiffCI/core/pull/200)); coverage map records files a test reads by relative path ([#201](https://github.com/DiffCI/core/pull/201)); turn the shared graph cache off when its secret is too short ([#264](https://github.com/DiffCI/core/pull/264)); answer ping with an empty result ([#295](https://github.com/DiffCI/core/pull/295)); list both paths of a renamed file in changed_files ([#299](https://github.com/DiffCI/core/pull/299)); replace a local action-v tag left by a rejected push on rerun ([#280](https://github.com/DiffCI/core/pull/280)); do not persist write-scoped checkout tokens in publish and merge-gate ([#282](https://github.com/DiffCI/core/pull/282)); count observe runs as the GitHub Action surface ([#285](https://github.com/DiffCI/core/pull/285)); say usage counting is on where the docs said DiffCI sends nothing ([#287](https://github.com/DiffCI/core/pull/287)); count Azure DevOps task runs as surface azure-devops-task ([#307](https://github.com/DiffCI/core/pull/307)); resolve Vue paths aliases against the declaring tsconfig without baseUrl ([#268](https://github.com/DiffCI/core/pull/268)); link the implementation next to a resolved declaration file ([#270](https://github.com/DiffCI/core/pull/270)); name the adapter runner when a repository has no test files ([#217](https://github.com/DiffCI/core/pull/217)); fall back when an npm lockfile bump meets undeclared imports ([#246](https://github.com/DiffCI/core/pull/246)); translate wildcards inside import.meta.glob brace alternatives ([#274](https://github.com/DiffCI/core/pull/274)); treat modelled Python files as code when resolving readers ([#257](https://github.com/DiffCI/core/pull/257)); let declared inputs and alwaysRunTests select pytest and Maven tests ([#272](https://github.com/DiffCI/core/pull/272)); cover a program the test script runs directly ([#306](https://github.com/DiffCI/core/pull/306)); keep a GitLab subgroup project's full path in the report ([#266](https://github.com/DiffCI/core/pull/266)); name a member NAME@VERSION when a dependency shares its name ([#232](https://github.com/DiffCI/core/pull/232)); keep required-feature targets' packages whole instead of blocking the repository ([#248](https://github.com/DiffCI/core/pull/248)); confine helper scripts and native sources to the crate that owns them ([#250](https://github.com/DiffCI/core/pull/250)); add covering crates instead of refusing when features would differ ([#254](https://github.com/DiffCI/core/pull/254)); pinned anstyle replay narrows real revisions with the same failures ([#258](https://github.com/DiffCI/core/pull/258)); read byte and C raw strings as raw in the input scan ([#228](https://github.com/DiffCI/core/pull/228)); treat quoted keys and inline tables in Cargo config as build settings ([#229](https://github.com/DiffCI/core/pull/229)); scan doctest code in doc comments for inputs ([#230](https://github.com/DiffCI/core/pull/230)); resolve literal paths from the workspace root too ([#231](https://github.com/DiffCI/core/pull/231)); list the Rust planner's no-command reasons and check them ([#233](https://github.com/DiffCI/core/pull/233)); restore the non-Windows branch of the .mcp.json MCP launcher ([#167](https://github.com/DiffCI/core/pull/167)).
|
|
280
287
|
- <a href="https://github.com/shounakjoshi88-a11y"><img src="https://github.com/shounakjoshi88-a11y.png?size=80" width="40" height="40" alt="@shounakjoshi88-a11y"></a> **[Shounak Joshi](https://github.com/shounakjoshi88-a11y)**: Go package-owned `testdata` selection, so a golden-file edit runs the owning package's tests instead of the full suite ([#85](https://github.com/DiffCI/core/pull/85)).
|
|
281
288
|
- <a href="https://github.com/bfs2021"><img src="https://github.com/bfs2021.png?size=80" width="40" height="40" alt="@bfs2021"></a> **[@bfs2021](https://github.com/bfs2021)**: `bun.lock` and `npm-shrinkwrap.json` recognition in the lockfile signal ([#64](https://github.com/DiffCI/core/pull/64)).
|
|
282
|
-
- <a href="https://github.com/sarankumar1325"><img src="https://github.com/sarankumar1325.png?size=80" width="40" height="40" alt="@sarankumar1325"></a> **[@sarankumar1325](https://github.com/sarankumar1325)**: lockfile and config-file signals. One shared lockfile list replaced every hand-written copy in `src/` ([#97](https://github.com/DiffCI/core/issues/97)): reference resolution, impact analysis and the lockfile-free dependency check ([#118](https://github.com/DiffCI/core/pull/118)–[#120](https://github.com/DiffCI/core/pull/120)), config-file discovery and impact classification, where `npm-shrinkwrap.json` is now a config change like every other lockfile ([#151](https://github.com/DiffCI/core/pull/151), [#152](https://github.com/DiffCI/core/pull/152)), the Vue analysis cache ([#107](https://github.com/DiffCI/core/pull/107)), CI inference ([#105](https://github.com/DiffCI/core/pull/105), [#146](https://github.com/DiffCI/core/pull/146)) and both path baselines, which now also fall back on `npm-shrinkwrap.json` ([#147](https://github.com/DiffCI/core/pull/147), [#148](https://github.com/DiffCI/core/pull/148)). A full run when only `babel.config.*` or `.babelrc*` changes ([#108](https://github.com/DiffCI/core/pull/108)) or a package's Jest, Vitest or Babel config changes ([#121](https://github.com/DiffCI/core/pull/121)), where these files used to select no tests. Regression tests for `vite.config`-only changes in Vitest projects ([#109](https://github.com/DiffCI/core/pull/109)) and for a root Vitest config that turns isolation off ([#149](https://github.com/DiffCI/core/pull/149)), and removal of dead config-file patterns with a test for every entry ([#106](https://github.com/DiffCI/core/pull/106)). Go `replace` targets inside the repository modelled under root-module scope instead of forcing the full suite ([#110](https://github.com/DiffCI/core/pull/110)). The [no-runnable-command reasons](docs/using-diffci.md#no-runnable-command), documented with a test that keeps the table complete ([#150](https://github.com/DiffCI/core/pull/150)), and `"\0"` escapes in place of raw NUL bytes, so git and ripgrep can search those source files again ([#145](https://github.com/DiffCI/core/pull/145)); document verify-workflow, pilot-packet, validate-specs and telemetry ([#153](https://github.com/DiffCI/core/pull/153)).
|
|
289
|
+
- <a href="https://github.com/sarankumar1325"><img src="https://github.com/sarankumar1325.png?size=80" width="40" height="40" alt="@sarankumar1325"></a> **[@sarankumar1325](https://github.com/sarankumar1325)**: lockfile and config-file signals. One shared lockfile list replaced every hand-written copy in `src/` ([#97](https://github.com/DiffCI/core/issues/97)): reference resolution, impact analysis and the lockfile-free dependency check ([#118](https://github.com/DiffCI/core/pull/118)–[#120](https://github.com/DiffCI/core/pull/120)), config-file discovery and impact classification, where `npm-shrinkwrap.json` is now a config change like every other lockfile ([#151](https://github.com/DiffCI/core/pull/151), [#152](https://github.com/DiffCI/core/pull/152)), the Vue analysis cache ([#107](https://github.com/DiffCI/core/pull/107)), CI inference ([#105](https://github.com/DiffCI/core/pull/105), [#146](https://github.com/DiffCI/core/pull/146)) and both path baselines, which now also fall back on `npm-shrinkwrap.json` ([#147](https://github.com/DiffCI/core/pull/147), [#148](https://github.com/DiffCI/core/pull/148)). A full run when only `babel.config.*` or `.babelrc*` changes ([#108](https://github.com/DiffCI/core/pull/108)) or a package's Jest, Vitest or Babel config changes ([#121](https://github.com/DiffCI/core/pull/121)), where these files used to select no tests. Regression tests for `vite.config`-only changes in Vitest projects ([#109](https://github.com/DiffCI/core/pull/109)) and for a root Vitest config that turns isolation off ([#149](https://github.com/DiffCI/core/pull/149)), and removal of dead config-file patterns with a test for every entry ([#106](https://github.com/DiffCI/core/pull/106)). Go `replace` targets inside the repository modelled under root-module scope instead of forcing the full suite ([#110](https://github.com/DiffCI/core/pull/110)). The [no-runnable-command reasons](docs/using-diffci.md#no-runnable-command), documented with a test that keeps the table complete ([#150](https://github.com/DiffCI/core/pull/150)), and `"\0"` escapes in place of raw NUL bytes, so git and ripgrep can search those source files again ([#145](https://github.com/DiffCI/core/pull/145)); document verify-workflow, pilot-packet, validate-specs and telemetry ([#153](https://github.com/DiffCI/core/pull/153)); pytest.ini wins even when empty, and read .pytest.ini ([#314](https://github.com/DiffCI/core/pull/314)).
|
|
283
290
|
- <a href="https://github.com/robertwmccarty-caelum"><img src="https://github.com/robertwmccarty-caelum.png?size=80" width="40" height="40" alt="@robertwmccarty-caelum"></a> **[@robertwmccarty-caelum](https://github.com/robertwmccarty-caelum)**: the Vitest reporter/timeout config fixture and its narrowing conditions ([#53](https://github.com/DiffCI/core/issues/53#issuecomment-6514436312), landed in [#65](https://github.com/DiffCI/core/pull/65)).
|
|
284
291
|
- <a href="https://github.com/varshith84"><img src="https://github.com/varshith84.png?size=80" width="40" height="40" alt="@varshith84"></a> **[Varshith Sai Pasupuleti](https://github.com/varshith84)**: tests for transitive Vue selection and full fallback ([#16](https://github.com/DiffCI/core/pull/16)).
|
|
285
292
|
- <a href="https://github.com/aniKet0753"><img src="https://github.com/aniKet0753.png?size=80" width="40" height="40" alt="@aniKet0753"></a> **[@aniKet0753](https://github.com/aniKet0753)**: a `diffci help` command list and `USAGE` text that match the commands the CLI runs, with a test that fails when a command is missing ([#130](https://github.com/DiffCI/core/pull/130)).
|
|
286
|
-
- <a href="https://github.com/tyza66"><img src="https://github.com/tyza66.png?size=80" width="40" height="40" alt="@tyza66"></a> **[@tyza66](https://github.com/tyza66)**: name the tool configuration behind a fallback instead of "Unknown changed file" ([#144](https://github.com/DiffCI/core/pull/144)); name a tsconfig variant as TypeScript configuration instead of unknown ([#155](https://github.com/DiffCI/core/pull/155)).
|
|
293
|
+
- <a href="https://github.com/tyza66"><img src="https://github.com/tyza66.png?size=80" width="40" height="40" alt="@tyza66"></a> **[@tyza66](https://github.com/tyza66)**: name the tool configuration behind a fallback instead of "Unknown changed file" ([#144](https://github.com/DiffCI/core/pull/144)); name a tsconfig variant as TypeScript configuration instead of unknown ([#155](https://github.com/DiffCI/core/pull/155)); fall back for Mocha configuration, and say so ([#156](https://github.com/DiffCI/core/pull/156)).
|
|
287
294
|
|
|
288
295
|
Every merged contribution is credited in the release notes, here, on [diffci.com/contributors](https://diffci.com/contributors), and next to the feature in the docs. The README and website entries are added automatically when a pull request merges. A [contributor tier](CONTRIBUTING.md#contributor-tiers) above Contributor is written after the name, as in **[Area maintainer: Rust](CONTRIBUTING.md#contributor-tiers)**, and diffci.com copies it from here.
|
|
289
296
|
|
|
@@ -42,6 +42,11 @@ export interface ExpressionContext {
|
|
|
42
42
|
}
|
|
43
43
|
/** Resolves one `${{ ... }}` body against the context, structurally. */
|
|
44
44
|
export declare function resolveExpression(expression: string, context: ExpressionContext): Resolution;
|
|
45
|
+
/**
|
|
46
|
+
* Replaces each `${{ body }}` whose body has no `}`, as `/\$\{\{([^}]*)\}\}/g` would, in linear time: the
|
|
47
|
+
* regex rescans to the next `}` from every `${{`, which is quadratic on a line of repeated `${{` (CodeQL alert 12).
|
|
48
|
+
*/
|
|
49
|
+
export declare function replaceExpressions(line: string, replace: (body: string) => string): string;
|
|
45
50
|
export interface RenderedCommand {
|
|
46
51
|
/** The line with every expression substituted as GitHub would substitute it. */
|
|
47
52
|
rendered: string;
|