@diffci.com/diffci 0.3.32 → 0.3.33
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/README.md +23 -0
- package/dist-client/src/client/check-plan-junit.d.ts +25 -0
- package/dist-client/src/client/check-plan-junit.js +215 -0
- package/dist-client/src/client/check-plan.d.ts +42 -0
- package/dist-client/src/client/check-plan.js +143 -0
- package/dist-client/src/client/cli.js +212 -7
- package/dist-client/src/client/command-batches.d.ts +1 -0
- package/dist-client/src/client/command-batches.js +3 -1
- package/dist-client/src/client/enforce-misses-collect.js +6 -1
- package/dist-client/src/client/enforce-misses.d.ts +3 -2
- package/dist-client/src/client/enforce-misses.js +19 -59
- package/dist-client/src/client/failure-baseline.js +0 -0
- package/dist-client/src/client/full-command.d.ts +8 -0
- package/dist-client/src/client/full-command.js +31 -0
- package/dist-client/src/client/job-summary.js +1 -1
- package/dist-client/src/client/observe.d.ts +4 -0
- package/dist-client/src/client/observe.js +31 -2
- package/dist-client/src/client/report.d.ts +4 -0
- package/dist-client/src/client/test-results.js +7 -0
- package/dist-client/src/client/verify.d.ts +18 -0
- package/dist-client/src/client/verify.js +39 -10
- package/dist-client/src/client/watch.d.ts +36 -0
- package/dist-client/src/client/watch.js +76 -0
- package/node_modules/@diffci.com/core/README.md +36 -5
- 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 +3 -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.d.ts +12 -0
- package/node_modules/@diffci.com/core/dist/git/git-diff.js +86 -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 +8 -0
- package/node_modules/@diffci.com/core/dist/planner/test-command.js +16 -0
- package/node_modules/@diffci.com/core/dist/planner/test-command.js.map +1 -1
- package/node_modules/@diffci.com/core/dist/repo/adapters/index.js +2 -1
- package/node_modules/@diffci.com/core/dist/repo/adapters/index.js.map +1 -1
- package/node_modules/@diffci.com/core/dist/repo/adapters/python.d.ts +32 -0
- package/node_modules/@diffci.com/core/dist/repo/adapters/python.js +273 -0
- package/node_modules/@diffci.com/core/dist/repo/adapters/python.js.map +1 -0
- package/node_modules/@diffci.com/core/dist/repo/adapters/types.d.ts +2 -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.js +21 -0
- package/node_modules/@diffci.com/core/dist/repo/file-references.js.map +1 -1
- package/node_modules/@diffci.com/core/dist/repo/graph.d.ts +4 -0
- package/node_modules/@diffci.com/core/dist/repo/graph.js +182 -21
- package/node_modules/@diffci.com/core/dist/repo/graph.js.map +1 -1
- package/node_modules/@diffci.com/core/dist/repo/impact.d.ts +1 -0
- package/node_modules/@diffci.com/core/dist/repo/impact.js +29 -4
- package/node_modules/@diffci.com/core/dist/repo/impact.js.map +1 -1
- package/node_modules/@diffci.com/core/dist/repo/types.d.ts +5 -0
- package/node_modules/@diffci.com/core/src/cache/graph-cache.ts +3 -1
- package/node_modules/@diffci.com/core/src/git/git-diff.ts +72 -0
- package/node_modules/@diffci.com/core/src/git/types.ts +5 -0
- package/node_modules/@diffci.com/core/src/planner/test-command.ts +14 -0
- package/node_modules/@diffci.com/core/src/repo/adapters/index.ts +2 -1
- package/node_modules/@diffci.com/core/src/repo/adapters/python.ts +252 -0
- package/node_modules/@diffci.com/core/src/repo/adapters/types.ts +2 -0
- package/node_modules/@diffci.com/core/src/repo/file-references.ts +19 -0
- package/node_modules/@diffci.com/core/src/repo/graph.ts +154 -20
- package/node_modules/@diffci.com/core/src/repo/impact.ts +27 -4
- package/node_modules/@diffci.com/core/src/repo/types.ts +5 -0
- package/package.json +3 -2
|
@@ -122,6 +122,8 @@ export interface ObservationGraph {
|
|
|
122
122
|
confidence: string;
|
|
123
123
|
/** Confidence after reachability narrowing for this delta - the value that drove the verdict. */
|
|
124
124
|
effectiveConfidence?: string;
|
|
125
|
+
/** Why `confidence` is below COMPLETE, in counts only; absent when it is COMPLETE. */
|
|
126
|
+
confidenceReasons?: string[];
|
|
125
127
|
durationMs: number;
|
|
126
128
|
phasesMs?: Record<string, number>;
|
|
127
129
|
typescriptProgram?: TypeScriptProgramMetrics;
|
|
@@ -186,6 +188,8 @@ export interface ObservationResult {
|
|
|
186
188
|
* subset of the full suite; verification runs them with `outsideSuiteCommands`. */
|
|
187
189
|
testsOutsideFullSuite?: string[];
|
|
188
190
|
outsideSuiteCommands?: string[];
|
|
191
|
+
/** Why `outsideSuiteCommands` is empty when the plan for those tests was refused. */
|
|
192
|
+
outsideSuiteRefusalReason?: string;
|
|
189
193
|
/** Phases of the test script, verbatim (`node scripts/test-security.js`), that a selective run must
|
|
190
194
|
* also execute: the selection covers some changed files only through them. Present only when the
|
|
191
195
|
* observation was asked for them (ObserveOptions.selectTestPhases). Like `proposedCommands`, these
|
|
@@ -40,6 +40,13 @@ export function parseTestFileResults(output) {
|
|
|
40
40
|
if (jest) {
|
|
41
41
|
const ms = duration(jest[3], "s");
|
|
42
42
|
results.set(jest[2], { file: jest[2], status: jest[1] === "FAIL" ? "failed" : "passed", ...(ms !== undefined ? { ms } : {}) });
|
|
43
|
+
continue;
|
|
44
|
+
}
|
|
45
|
+
// pytest progress: `tests/test_a.py ..F. [ 50%]`; F or E marks a failure (2026-11-06).
|
|
46
|
+
const pytest = /^(\S+\.py) ([.FEsxXp]+)\s*(?:\[\s*\d+%\])?\s*$/.exec(line);
|
|
47
|
+
if (pytest) {
|
|
48
|
+
const failed = /[FE]/.test(pytest[2]) || results.get(pytest[1])?.status === "failed";
|
|
49
|
+
results.set(pytest[1], { file: pytest[1], status: failed ? "failed" : "passed" });
|
|
43
50
|
}
|
|
44
51
|
}
|
|
45
52
|
return [...results.values()].sort((a, b) => a.file.localeCompare(b.file));
|
|
@@ -68,6 +68,8 @@ export interface VerificationReport {
|
|
|
68
68
|
/** The graph's own confidence and the confidence after narrowing to this change. */
|
|
69
69
|
graph_confidence?: string;
|
|
70
70
|
effective_graph_confidence?: string;
|
|
71
|
+
/** Why graph_confidence is below COMPLETE, in counts only. */
|
|
72
|
+
graph_confidence_reasons?: string[];
|
|
71
73
|
};
|
|
72
74
|
required_actions: string[];
|
|
73
75
|
/** Present when a failed verification was rerun at the base commit (`--baseline-on-failure`). */
|
|
@@ -88,6 +90,12 @@ export interface VerificationReport {
|
|
|
88
90
|
total: number;
|
|
89
91
|
timings: "file" | "equal";
|
|
90
92
|
};
|
|
93
|
+
/** A full run that first ran the tests the dependency graph found affected (firstPassParts). */
|
|
94
|
+
first_pass?: {
|
|
95
|
+
tests: number;
|
|
96
|
+
commands: string[];
|
|
97
|
+
stopped_full_suite: boolean;
|
|
98
|
+
};
|
|
91
99
|
/** Tests the coverage map added to the selection (coverage-map.ts), when it added any. */
|
|
92
100
|
coverage_added?: string[];
|
|
93
101
|
}
|
|
@@ -129,6 +137,16 @@ export declare function verifyChanged(options: VerifyChangedOptions): Promise<Ve
|
|
|
129
137
|
export declare function verifyRange(options: VerifyRangeOptions): Promise<VerificationReport>;
|
|
130
138
|
export declare function verificationExitCode(report: VerificationReport): number;
|
|
131
139
|
export declare function formatVerificationSummary(report: VerificationReport): string;
|
|
140
|
+
/**
|
|
141
|
+
* The commands that run a FULL observation's affected tests on their own, before the full suite: the
|
|
142
|
+
* tests the dependency graph did find, which a fallback elsewhere in the change does not make less
|
|
143
|
+
* likely to fail. Only when they are under half the suite, so the extra pass stays small, and only when
|
|
144
|
+
* the planner can run every one of them (paths are not redacted).
|
|
145
|
+
*/
|
|
146
|
+
export declare function firstPassParts(repoPath: string, result: NonNullable<ObservationReport["result"]>): {
|
|
147
|
+
parts: string[];
|
|
148
|
+
tests: number;
|
|
149
|
+
} | undefined;
|
|
132
150
|
/** The order to run selected tests in, and under --fail-fast the ones to run first (test-ranking.ts). */
|
|
133
151
|
export interface SelectedOrdering {
|
|
134
152
|
order: readonly string[];
|
|
@@ -5,7 +5,7 @@ import { appendToCommand, batchCommand, measureCommands, orderCommand, splitComm
|
|
|
5
5
|
import { coverageAdditions, readCoverageMap } from "./coverage-map.js";
|
|
6
6
|
import { checkAtBaseline, compareWithBaseline } from "./failure-baseline.js";
|
|
7
7
|
import { collectEnforcementContext, evaluateEnforcement } from "./enforce-policy.js";
|
|
8
|
-
import { inferFullCommand, inferSelectedCommand, inferSelectedCommands } from "./full-command.js";
|
|
8
|
+
import { inferFullCommand, inferPlannedCommands, inferSelectedCommand, inferSelectedCommands } from "./full-command.js";
|
|
9
9
|
import { plannedChecks, runChecks } from "./gate-checks.js";
|
|
10
10
|
import { makeGitRunner, observe } from "./observe.js";
|
|
11
11
|
import { selectedNodeTests, traceNodeTestFiles, unmatchedNodeTests, unstartedNodeTests } from "./selected-coverage.js";
|
|
@@ -86,7 +86,7 @@ async function executeWithPolicy(options, scope, before, observation, enforcemen
|
|
|
86
86
|
fallback_reasons: result?.fallbackReasons ?? [],
|
|
87
87
|
error: observation.reason,
|
|
88
88
|
...(observation.timings?.totalMs !== undefined ? { duration_ms: observation.timings.totalMs } : {}),
|
|
89
|
-
...(result?.graph ? { graph_confidence: result.graph.confidence, effective_graph_confidence: result.graph.effectiveConfidence } : {}),
|
|
89
|
+
...(result?.graph ? { graph_confidence: result.graph.confidence, effective_graph_confidence: result.graph.effectiveConfidence, ...(result.graph.confidenceReasons?.length ? { graph_confidence_reasons: result.graph.confidenceReasons } : {}) } : {}),
|
|
90
90
|
};
|
|
91
91
|
if ((observation.status !== "OBSERVED" || !result) && !enforcedFull) {
|
|
92
92
|
return blocked(before, scope, observation.reason ?? "DiffCI analysis did not produce a verification plan", analysis, counts, boundRange);
|
|
@@ -144,6 +144,10 @@ async function executeWithPolicy(options, scope, before, observation, enforcemen
|
|
|
144
144
|
? fullSelection(options.repoPath, `enforce fallback (${enforcement?.fired_fallback}): ${enforcement?.detail}`)
|
|
145
145
|
: executableSelection(options.repoPath, result, rankedOrdering(options, result), shard && shardTests ? { tests: new Set(shardTests), first: shard.index === 1 } : undefined);
|
|
146
146
|
const { selection, command, commands, outsideSuite } = executable;
|
|
147
|
+
// A full run first runs the tests the graph did find, and stops if one fails (2026-11-06 LobeHub catch
|
|
148
|
+
// study: both test-only failures were lost when the full suite reached the time limit first).
|
|
149
|
+
const firstPass = selection === "full" && !enforcedFull && !shard && !options.redactPaths && result ? firstPassParts(options.repoPath, result) : undefined;
|
|
150
|
+
const runCommands = firstPass ? [...firstPass.parts, ...commands] : commands;
|
|
147
151
|
const reason = coverageAdded.length && selection === "selected"
|
|
148
152
|
? `${executable.reason}; the coverage map added ${coverageAdded.length} test file(s) the dependency graph did not select (${coverageAdded.slice(0, 3).join(", ")})`
|
|
149
153
|
: executable.reason;
|
|
@@ -237,7 +241,7 @@ async function executeWithPolicy(options, scope, before, observation, enforcemen
|
|
|
237
241
|
try {
|
|
238
242
|
execution = checkRun?.failure
|
|
239
243
|
? checkRun.failure.measurement
|
|
240
|
-
: measureCommands(
|
|
244
|
+
: measureCommands(runCommands, { cwd: options.repoPath, timeoutMs: Math.max(options.timeoutMs - (checkRun?.wallMs ?? 0), 0), tailBytes: options.tailBytes, env: trace?.env, stopOnFailure: options.failFast, stopOnFailureWithin: firstPass?.parts.length });
|
|
241
245
|
startedNodeTests = trace?.read();
|
|
242
246
|
const nodeResults = trace?.results() ?? [];
|
|
243
247
|
if (nodeResults.length)
|
|
@@ -246,9 +250,12 @@ async function executeWithPolicy(options, scope, before, observation, enforcemen
|
|
|
246
250
|
finally {
|
|
247
251
|
trace?.dispose();
|
|
248
252
|
}
|
|
249
|
-
const
|
|
250
|
-
|
|
251
|
-
|
|
253
|
+
const stoppedInFirstPass = firstPass && execution.partsNotRun !== undefined && runCommands.length - execution.partsNotRun <= firstPass.parts.length;
|
|
254
|
+
const failFastNote = stoppedInFirstPass
|
|
255
|
+
? `; ${firstPass.tests} test file(s) the dependency graph found affected ran before the full suite and failed, so the full suite was not run`
|
|
256
|
+
: execution.partsNotRun
|
|
257
|
+
? `; --fail-fast stopped at the first failing part, so ${execution.partsNotRun} later part(s) of the selection did not run`
|
|
258
|
+
: "";
|
|
252
259
|
const preexistingNote = checksNote + failFastNote;
|
|
253
260
|
let after;
|
|
254
261
|
try {
|
|
@@ -309,7 +316,8 @@ async function executeWithPolicy(options, scope, before, observation, enforcemen
|
|
|
309
316
|
: `verification command failed with exit code ${String(execution.exitCode)}${preexistingNote}`;
|
|
310
317
|
const baselineSha = scope === "commit-range" ? range?.baseSha : before.baseSha;
|
|
311
318
|
const failureBaseline = verification === "failed" && !failedCheck && !execution.timedOut && options.baselineOnFailure && baselineSha
|
|
312
|
-
|
|
319
|
+
// The base reruns only the parts that ran here: a first-pass failure is compared without the full suite.
|
|
320
|
+
? 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 })
|
|
313
321
|
: undefined;
|
|
314
322
|
const baselineNote = failureBaseline && failureBaseline.status !== "unknown"
|
|
315
323
|
? `; ${failureBaseline.reason} (${failureBaseline.base_sha.slice(0, 12)})`
|
|
@@ -326,8 +334,9 @@ async function executeWithPolicy(options, scope, before, observation, enforcemen
|
|
|
326
334
|
selection,
|
|
327
335
|
...(selection === "selected" && result ? { selected_tests: result.selectedTests } : {}),
|
|
328
336
|
...(selection === "selected" && result?.selectionReasons ? { selection_reasons: result.selectionReasons } : {}),
|
|
329
|
-
command,
|
|
330
|
-
...(
|
|
337
|
+
command: firstPass ? runCommands.join(" && ") : command,
|
|
338
|
+
...(runCommands.length > 1 ? { commands: runCommands } : {}),
|
|
339
|
+
...(firstPass ? { first_pass: { tests: firstPass.tests, commands: firstPass.parts, stopped_full_suite: Boolean(stoppedInFirstPass) } } : {}),
|
|
331
340
|
execution,
|
|
332
341
|
...(checks ? { checks } : {}),
|
|
333
342
|
snapshot: {
|
|
@@ -500,6 +509,26 @@ function fullSelection(repoPath, reason) {
|
|
|
500
509
|
const command = inferFullCommand(repoPath).command;
|
|
501
510
|
return { selection: "full", command, commands: command ? [command] : [], reason, outsideSuite: 0 };
|
|
502
511
|
}
|
|
512
|
+
/**
|
|
513
|
+
* The commands that run a FULL observation's affected tests on their own, before the full suite: the
|
|
514
|
+
* tests the dependency graph did find, which a fallback elsewhere in the change does not make less
|
|
515
|
+
* likely to fail. Only when they are under half the suite, so the extra pass stays small, and only when
|
|
516
|
+
* the planner can run every one of them (paths are not redacted).
|
|
517
|
+
*/
|
|
518
|
+
export function firstPassParts(repoPath, result) {
|
|
519
|
+
const tests = result.selectedTests;
|
|
520
|
+
if (result.mode !== "FULL" || tests.length === 0 || !(tests.length * 2 < result.totalTestCount))
|
|
521
|
+
return undefined;
|
|
522
|
+
const planned = inferPlannedCommands(repoPath, tests);
|
|
523
|
+
if (!planned)
|
|
524
|
+
return undefined;
|
|
525
|
+
if ("commands" in planned)
|
|
526
|
+
return { parts: planned.commands, tests: tests.length };
|
|
527
|
+
// A selected file the runner's glob would not match never runs (as executableSelection checks).
|
|
528
|
+
if (unmatchedNodeTests(planned.single, tests).length)
|
|
529
|
+
return undefined;
|
|
530
|
+
return { parts: batchCommand(planned.single, tests), tests: tests.length };
|
|
531
|
+
}
|
|
503
532
|
/** Ranks the selected tests by the outcome log's history, or undefined when nothing in it says any is
|
|
504
533
|
* likelier to fail than another, so a repository without history runs its selection exactly as before. */
|
|
505
534
|
function rankedOrdering(options, result) {
|
|
@@ -602,7 +631,7 @@ export function executableSelection(repoPath, result, ordering, shard) {
|
|
|
602
631
|
reason = `${reason}; also ran ${outside.length} affected test file(s) the full test command does not run`;
|
|
603
632
|
}
|
|
604
633
|
else {
|
|
605
|
-
reason = `${reason}; ${outside.length} affected test file(s) outside the full test command were not run (${auxiliary?.reason ?? "no single command covers them"})`;
|
|
634
|
+
reason = `${reason}; ${outside.length} affected test file(s) outside the full test command were not run (${auxiliary?.reason ?? result.outsideSuiteRefusalReason ?? "no single command covers them"})`;
|
|
606
635
|
}
|
|
607
636
|
}
|
|
608
637
|
// Under --shard each selected command keeps only the shard's files, and the test-script phases and the
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `diffci watch` (2026-11-06), the idea of `jest --watch` with DiffCI's selection.
|
|
3
|
+
*
|
|
4
|
+
* WHY. A person working beside an agent, or in a `node --test` repository whose own watch mode reruns
|
|
5
|
+
* everything, wants the "what did I just break" answer on every save without typing a command. It is also
|
|
6
|
+
* the plainest way to see what DiffCI does: the selection changes as the files do.
|
|
7
|
+
*
|
|
8
|
+
* WHAT. Watches the repository recursively and, after a quiet period (debounce), runs one verification of
|
|
9
|
+
* the uncommitted changes: the same `verify --changed` an agent runs, so the selection, reuse, ranking and
|
|
10
|
+
* coverage map all apply. Changes inside `.git` and `node_modules` are ignored. Saves during a run start
|
|
11
|
+
* one more run after it, never two at once. Events that leave the tree as the last run left it start
|
|
12
|
+
* nothing, so files a test writes during a run do not trigger the next one.
|
|
13
|
+
* Each run is a fresh analysis; re-parsing only the changed files is not done yet.
|
|
14
|
+
*/
|
|
15
|
+
export interface WatchRun {
|
|
16
|
+
/** The tree as the run left it (files it wrote included), so its own writes start nothing new. */
|
|
17
|
+
treeSha: string;
|
|
18
|
+
}
|
|
19
|
+
export interface WatchOptions {
|
|
20
|
+
repoPath: string;
|
|
21
|
+
/** Runs one verification and reports it; resolves with the verified tree. */
|
|
22
|
+
run: () => Promise<WatchRun>;
|
|
23
|
+
debounceMs?: number;
|
|
24
|
+
/** Injected in tests; defaults to a recursive fs.watch. Calls `onChange` with a repository-relative path. */
|
|
25
|
+
watch?: (repoPath: string, onChange: (path: string) => void) => {
|
|
26
|
+
close(): void;
|
|
27
|
+
};
|
|
28
|
+
/** The tree as it is now, to tell a save from the run's own writes; undefined means "assume changed". */
|
|
29
|
+
currentTree?: () => string | undefined;
|
|
30
|
+
}
|
|
31
|
+
export declare function ignoredWatchPath(path: string): boolean;
|
|
32
|
+
/** Starts watching and runs once at start. `idle()` resolves when no run is pending or in progress. */
|
|
33
|
+
export declare function startWatch(options: WatchOptions): {
|
|
34
|
+
stop(): void;
|
|
35
|
+
idle(): Promise<void>;
|
|
36
|
+
};
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
import { realpathSync, watch as fsWatch } from "node:fs";
|
|
2
|
+
export function ignoredWatchPath(path) {
|
|
3
|
+
return path.split(/[\\/]/).some((part) => part === ".git" || part === "node_modules");
|
|
4
|
+
}
|
|
5
|
+
function defaultWatch(repoPath, onChange) {
|
|
6
|
+
// Windows: watching a short 8.3 path (C:\Users\SWATIK~1\...) aborts the process inside libuv, whose
|
|
7
|
+
// events carry long names; the real path is long.
|
|
8
|
+
let root = repoPath;
|
|
9
|
+
try {
|
|
10
|
+
root = realpathSync.native(repoPath);
|
|
11
|
+
}
|
|
12
|
+
catch { }
|
|
13
|
+
const watcher = fsWatch(root, { recursive: true }, (_event, name) => onChange(name ? String(name) : ""));
|
|
14
|
+
return { close: () => watcher.close() };
|
|
15
|
+
}
|
|
16
|
+
/** Starts watching and runs once at start. `idle()` resolves when no run is pending or in progress. */
|
|
17
|
+
export function startWatch(options) {
|
|
18
|
+
const debounceMs = options.debounceMs ?? 300;
|
|
19
|
+
let timer;
|
|
20
|
+
let running;
|
|
21
|
+
let pending = false;
|
|
22
|
+
let stopped = false;
|
|
23
|
+
let lastTree;
|
|
24
|
+
// A save during a run is part of the tree that run leaves, so the run queued for it always goes ahead;
|
|
25
|
+
// only an event after a run compares trees, which is what filters out the run's own writes.
|
|
26
|
+
const runOnce = async (force = false) => {
|
|
27
|
+
if (stopped)
|
|
28
|
+
return;
|
|
29
|
+
if (running) {
|
|
30
|
+
pending = true;
|
|
31
|
+
return;
|
|
32
|
+
}
|
|
33
|
+
const tree = options.currentTree?.();
|
|
34
|
+
if (!force && tree !== undefined && tree === lastTree)
|
|
35
|
+
return;
|
|
36
|
+
running = (async () => {
|
|
37
|
+
try {
|
|
38
|
+
lastTree = (await options.run()).treeSha;
|
|
39
|
+
}
|
|
40
|
+
catch {
|
|
41
|
+
lastTree = undefined;
|
|
42
|
+
}
|
|
43
|
+
})();
|
|
44
|
+
await running;
|
|
45
|
+
running = undefined;
|
|
46
|
+
if (pending && !stopped) {
|
|
47
|
+
pending = false;
|
|
48
|
+
await runOnce(true);
|
|
49
|
+
}
|
|
50
|
+
};
|
|
51
|
+
const schedule = (path) => {
|
|
52
|
+
if (stopped || ignoredWatchPath(path))
|
|
53
|
+
return;
|
|
54
|
+
if (timer)
|
|
55
|
+
clearTimeout(timer);
|
|
56
|
+
timer = setTimeout(() => { timer = undefined; void runOnce(); }, debounceMs);
|
|
57
|
+
};
|
|
58
|
+
const watcher = (options.watch ?? defaultWatch)(options.repoPath, schedule);
|
|
59
|
+
void runOnce();
|
|
60
|
+
return {
|
|
61
|
+
stop() {
|
|
62
|
+
stopped = true;
|
|
63
|
+
if (timer)
|
|
64
|
+
clearTimeout(timer);
|
|
65
|
+
watcher.close();
|
|
66
|
+
},
|
|
67
|
+
async idle() {
|
|
68
|
+
while (timer || running) {
|
|
69
|
+
if (running)
|
|
70
|
+
await running;
|
|
71
|
+
else
|
|
72
|
+
await new Promise((resolve) => setTimeout(resolve, debounceMs + 10));
|
|
73
|
+
}
|
|
74
|
+
},
|
|
75
|
+
};
|
|
76
|
+
}
|
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
# DiffCI Core
|
|
2
2
|
|
|
3
|
-
[](https://www.npmjs.com/package/@diffci.com/diffci)
|
|
4
|
+
[](https://github.com/marketplace/actions/diffci-change-impact)
|
|
5
|
+
[](LICENSE)
|
|
4
6
|
[](https://scorecard.dev/viewer/?uri=github.com/DiffCI/core)
|
|
5
7
|
|
|
6
8
|
**Affected checks before push, for AI coding agents.** DiffCI tells Claude Code, Codex, Cursor (or you) which tests and checks a change affects, so they run before the push instead of failing at the full CI gate afterwards. MIT licensed, runs locally, sends nothing by default, and falls back to the full suite whenever the evidence is incomplete.
|
|
@@ -11,6 +13,17 @@ npx "@diffci.com/diffci@latest" check
|
|
|
11
13
|
|
|
12
14
|
Run it in any Git checkout with Node.js 22.5+. [What the output means](docs/using-diffci.md).
|
|
13
15
|
|
|
16
|
+
**On every pull request**, add one job beside your existing CI. Its job summary shows which tests the change affects and why, or that the full suite is needed and why. It runs no tests and skips or changes nothing:
|
|
17
|
+
|
|
18
|
+
```yaml
|
|
19
|
+
- uses: actions/checkout@v7
|
|
20
|
+
with:
|
|
21
|
+
fetch-depth: 0 # DiffCI needs the base commit
|
|
22
|
+
- uses: DiffCI/core@v0.3.32
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
[Full workflow](examples/github-actions-observer.yml) · [GitLab CI/CD component](integrations/gitlab/README.md)
|
|
26
|
+
|
|
14
27
|
[](https://www.youtube.com/watch?v=ychCnVVRQq0)
|
|
15
28
|
|
|
16
29
|
▶ [Watch the demo on YouTube](https://www.youtube.com/watch?v=ychCnVVRQq0)
|
|
@@ -55,12 +68,19 @@ into `CLAUDE.md` or `AGENTS.md` so it runs DiffCI before pushing.
|
|
|
55
68
|
|
|
56
69
|
## GitHub Action
|
|
57
70
|
|
|
58
|
-
The public [`action.yml`](action.yml)
|
|
59
|
-
|
|
60
|
-
|
|
71
|
+
The public [`action.yml`](action.yml) ("DiffCI change impact") shows, in the
|
|
72
|
+
job summary of every pull request, which tests the change affects and why, or
|
|
73
|
+
that the full suite is needed and why. It is observation only: it runs the
|
|
74
|
+
pinned published DiffCI CLI outside the observed checkout, retains existing CI
|
|
75
|
+
jobs, skips nothing, and uploads the report as an artifact. See the
|
|
61
76
|
[observer Action guide](docs/github-action-observer.md) and
|
|
62
77
|
[workflow example](examples/github-actions-observer.yml).
|
|
63
78
|
|
|
79
|
+
Set `comment: "true"` (with `pull-requests: write`) to also keep one comment on
|
|
80
|
+
the pull request up to date with the answer, where reviewers see it. Outputs
|
|
81
|
+
such as `full-suite-required` and `affected-tests` let a workflow act on the
|
|
82
|
+
answer; see [outputs](docs/github-action-observer.md#outputs).
|
|
83
|
+
|
|
64
84
|
The [v0.3.10 corresponding source](https://github.com/DiffCI/core/tree/4c76be14cec37d94eb7df93922f3c29d202f4e65/packages/diffci-cli)
|
|
65
85
|
remains publicly available at tagged Core commit `4c76be14` (`cli-v0.3.10-source`)
|
|
66
86
|
while distribution migrates to the Core-native CLI package.
|
|
@@ -74,7 +94,7 @@ while distribution migrates to the Core-native CLI package.
|
|
|
74
94
|
[Star Core](https://github.com/DiffCI/core) · [Volunteer a pilot repository](https://diffci.com/#pilot) · [Find a first contribution](https://github.com/DiffCI/core/issues?q=is%3Aopen+label%3A%22good+first+issue%22).
|
|
75
95
|
Watch → Custom → Releases and Discussions for benchmark results and support updates. [Public roadmap](docs/roadmap.md).
|
|
76
96
|
|
|
77
|
-
This is the standalone Core engine. It analyzes local JavaScript/TypeScript repositories, supported Vue components, root Go modules
|
|
97
|
+
This is the standalone Core engine. It analyzes local JavaScript/TypeScript repositories, supported Vue components, root Go modules, conventional Maven reactors and Python projects tested with pytest, traces dependency impact, infers GitHub Actions structure and proposes test selections with evidence and full-run fallbacks. It works without a DiffCI account, hosted service or API key. See [the release boundary](docs/release-boundary.md) for support limits.
|
|
78
98
|
|
|
79
99
|
**Want to try DiffCI in an existing repository?** Use the published CLI: `npx @diffci.com/diffci@latest check`. See [the CLI quickstart](docs/using-diffci.md) for a no-execution analysis option, prerequisites, and result interpretation. The commands below build the standalone engine from source.
|
|
80
100
|
|
|
@@ -179,6 +199,17 @@ What stays in Core, and never moves to Cloud, is set out in [STEWARDSHIP.md](STE
|
|
|
179
199
|
|
|
180
200
|
Most open work is teaching DiffCI to narrow changes it currently treats as "run everything": config files, `package.json` edits and lockfiles. Each case is small and comes with a synthetic fixture, so you don't need to learn the whole engine. Python and Rust support are next and split into one-PR steps: see the [Python](https://github.com/DiffCI/core/issues/61) and [Rust](https://github.com/DiffCI/core/issues/62) tracking issues. Pick a [good first issue](https://github.com/DiffCI/core/issues?q=is%3Aopen+label%3A%22good+first+issue%22) and see [CONTRIBUTING.md](CONTRIBUTING.md); a dev container is included.
|
|
181
201
|
|
|
202
|
+
### Contributors
|
|
203
|
+
|
|
204
|
+
Thank you to everyone who has improved DiffCI:
|
|
205
|
+
|
|
206
|
+
- <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)).
|
|
207
|
+
- <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)**: 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)).
|
|
208
|
+
- <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)).
|
|
209
|
+
- <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)).
|
|
210
|
+
|
|
211
|
+
Every merged contribution is credited in the release notes, here, and next to the feature in the docs.
|
|
212
|
+
|
|
182
213
|
## License
|
|
183
214
|
|
|
184
215
|
See [LICENSE](LICENSE), [NOTICE](NOTICE) and [CONTRIBUTING.md](CONTRIBUTING.md). Releases before the MIT switch were published under AGPL-3.0-only and are now also available under MIT; see [LICENSE-HISTORY.md](LICENSE-HISTORY.md). Grant eligibility depends on the particular grant agreement. No eligibility or legal separation is guaranteed by this repository layout.
|
|
@@ -5,7 +5,9 @@ import { resolve } from "node:path";
|
|
|
5
5
|
// 4: bounded computed loads have edges, and results carry runtimeTestSelection (2026-11-03).
|
|
6
6
|
// 5: inline type-only imports are type edges and vi.mock/jest.mock targets are edges (2026-11-04).
|
|
7
7
|
// 6: the profile's diffciConfig carries declared `inputs` (2026-11-05).
|
|
8
|
-
|
|
8
|
+
// 7: folded computed specifiers and root-absolute Vite globs have edges (2026-11-06).
|
|
9
|
+
// 8: Python projects have a graph, and the profile carries pythonSources/pythonTests (2026-11-06).
|
|
10
|
+
export const GRAPH_CACHE_SCHEMA_VERSION = "8";
|
|
9
11
|
export function buildGraphCacheKey(inputs) {
|
|
10
12
|
const payload = JSON.stringify({
|
|
11
13
|
schema: GRAPH_CACHE_SCHEMA_VERSION,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"graph-cache.js","sourceRoot":"","sources":["../../src/cache/graph-cache.ts"],"names":[],"mappings":"AAAA,+BAA+B;AAC/B,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AACzC,OAAO,EAAE,UAAU,EAAE,SAAS,EAAE,YAAY,EAAE,aAAa,EAAE,MAAM,SAAS,CAAC;AAC7E,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAGpC,6FAA6F;AAC7F,mGAAmG;AACnG,wEAAwE;AACxE,MAAM,CAAC,MAAM,0BAA0B,GAAG,GAAG,CAAC;AAa9C,MAAM,UAAU,kBAAkB,CAAC,MAA2B;IAC5D,MAAM,OAAO,GAAG,IAAI,CAAC,SAAS,CAAC;QAC7B,MAAM,EAAE,0BAA0B;QAClC,MAAM,EAAE,MAAM,CAAC,SAAS;QACxB,QAAQ,EAAE,MAAM,CAAC,YAA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AE,MAAM,CAAC,CAAC;QACnC,CAAC;QAAC,MAAM,CAAC;YACP,OAAO,SAAS,CAAC;QACnB,CAAC;QAED,IAAI,MAAgG,CAAC;QACrG,IAAI,CAAC;YACH,MAAM,GAAG,IAAI,CAAC,KAAK,CAAC,GAAG,CAA+E,CAAC;QACzG,CAAC;QAAC,MAAM,CAAC;YACP,OAAO,SAAS,CAAC;QACnB,CAAC;QAED,IAAI,CAAC,MAAM,IAAI,MAAM,CAAC,kBAAkB,KAAK,0BAA0B;YAAE,OAAO,SAAS,CAAC;QAC1F,IAAI,OAAO,MAAM,CAAC,QAAQ,KAAK,QAAQ,IAAI,MAAM,CAAC,QAAQ,KAAK,GAAG;YAAE,OAAO,SAAS,CAAC;QACrF,OAAO,MAAM,CAAC;IAChB,CAAC;IAED,IAAI,CAAC,GAAW,EAAE,MAA6B;QAC7C,IAAI,CAAC,SAAS,EAAE,CAAC;QACjB,MAAM,OAAO,GAAG,IAAI,CAAC,SAAS,CAAC,EAAE,GAAG,MAAM,EAAE,kBAAkB,EAAE,0BAA0B,EAAE,EAAE,IAAI,EAAE,CAAC,CAAC,CAAC;QACvG,aAAa,CAAC,IAAI,CAAC,SAAS,CAAC,GAAG,CAAC,EAAE,OAAO,CAAC,CAAC;IAC9C,CAAC;IAED,UAAU,CAAC,GAAW;QACpB,MAAM,IAAI,GAAG,IAAI,CAAC,SAAS,CAAC,GAAG,CAAC,CAAC;QACjC,IAAI,UAAU,CAAC,IAAI,CAAC,EAAE,CAAC;YACrB,kFAAkF;YAClF,aAAa,CAAC,IAAI,EAAE,IAAI,CAAC,SAAS,CAAC,EAAE,WAAW,EAAE,IAAI,EAAE,CAAC,CAAC,CAAC;QAC7D,CAAC;IACH,CAAC;CACF"}
|
|
@@ -59,6 +59,18 @@ export interface PackageJsonChange {
|
|
|
59
59
|
* workspaces and unparseable JSON.
|
|
60
60
|
*/
|
|
61
61
|
export declare function packageJsonChange(oldContent: string | undefined, newContent: string | undefined): PackageJsonChange;
|
|
62
|
+
/**
|
|
63
|
+
* The files a package.json edit remaps through `exports`, when that is its only behavioral change
|
|
64
|
+
* (2026-11-06: LobeHub's model-bank moved `./qwen` from `./src/aiModels/qwen.ts` to
|
|
65
|
+
* `./src/aiModels/qwen/index.ts` and ran the full suite). An importer of a remapped subpath resolves to
|
|
66
|
+
* one of these targets at one side of the change, so the targets' dependents bound it. Returns the
|
|
67
|
+
* `./`-relative targets of every changed subpath on both sides, or undefined when anything else
|
|
68
|
+
* changed, a subpath or target is a pattern (`*`), or a target is not a `./` path.
|
|
69
|
+
*/
|
|
70
|
+
export declare function exportsRemapTargets(oldContent: string | undefined, newContent: string | undefined): {
|
|
71
|
+
targets: string[];
|
|
72
|
+
dataChanged: boolean;
|
|
73
|
+
} | undefined;
|
|
62
74
|
/** packageJsonChange's kind, with a dependency change reported as behavioral. */
|
|
63
75
|
export declare function packageJsonChangeKind(oldContent: string | undefined, newContent: string | undefined): "metadata" | "data" | "behavioral";
|
|
64
76
|
/** `isCiConfig` defaults to names alone; analyzeGitDelta also passes what GitLab `include` reaches. */
|
|
@@ -170,6 +170,16 @@ const CONFIG_PATTERNS = [
|
|
|
170
170
|
/^pnpm-lock\.yaml$/,
|
|
171
171
|
/^bun\.lockb$/,
|
|
172
172
|
/^(npm|pnpm|yarn)-lock\./,
|
|
173
|
+
// Python projects (2026-11-06): what pytest, the interpreter and the installed packages are.
|
|
174
|
+
/^pyproject\.toml$/,
|
|
175
|
+
/^setup\.(?:py|cfg)$/,
|
|
176
|
+
/^pytest\.ini$/,
|
|
177
|
+
/^tox\.ini$/,
|
|
178
|
+
/^noxfile\.py$/,
|
|
179
|
+
/^requirements[^/]*\.(?:txt|in)$/,
|
|
180
|
+
/^Pipfile(?:\.lock)?$/,
|
|
181
|
+
/^(?:poetry|uv|pdm)\.lock$/,
|
|
182
|
+
/^\.python-version$/,
|
|
173
183
|
];
|
|
174
184
|
// Stage 1B fix (2026-08-21, docs/research/2026-08-21-stage1b-*.md): root-caused in Stage 1A's fallback-
|
|
175
185
|
// composition analysis - dependencyManifestChanged previously fired on ANY change to the root
|
|
@@ -389,6 +399,74 @@ export function packageJsonChange(oldContent, newContent) {
|
|
|
389
399
|
? result("dependencies", [...added].sort(), [...dependencies].sort(), specifiersOnly)
|
|
390
400
|
: result("data", [...added].sort());
|
|
391
401
|
}
|
|
402
|
+
/**
|
|
403
|
+
* The files a package.json edit remaps through `exports`, when that is its only behavioral change
|
|
404
|
+
* (2026-11-06: LobeHub's model-bank moved `./qwen` from `./src/aiModels/qwen.ts` to
|
|
405
|
+
* `./src/aiModels/qwen/index.ts` and ran the full suite). An importer of a remapped subpath resolves to
|
|
406
|
+
* one of these targets at one side of the change, so the targets' dependents bound it. Returns the
|
|
407
|
+
* `./`-relative targets of every changed subpath on both sides, or undefined when anything else
|
|
408
|
+
* changed, a subpath or target is a pattern (`*`), or a target is not a `./` path.
|
|
409
|
+
*/
|
|
410
|
+
export function exportsRemapTargets(oldContent, newContent) {
|
|
411
|
+
let oldJson;
|
|
412
|
+
let newJson;
|
|
413
|
+
try {
|
|
414
|
+
oldJson = JSON.parse(oldContent ?? "");
|
|
415
|
+
newJson = JSON.parse(newContent ?? "");
|
|
416
|
+
}
|
|
417
|
+
catch {
|
|
418
|
+
return undefined;
|
|
419
|
+
}
|
|
420
|
+
const isRecord = (value) => !!value && typeof value === "object" && !Array.isArray(value);
|
|
421
|
+
if (!isRecord(oldJson) || !isRecord(newJson))
|
|
422
|
+
return undefined;
|
|
423
|
+
if (JSON.stringify(oldJson.exports) === JSON.stringify(newJson.exports))
|
|
424
|
+
return undefined;
|
|
425
|
+
const without = (json) => JSON.stringify({ ...json, exports: undefined });
|
|
426
|
+
const rest = packageJsonChange(without(oldJson), without(newJson));
|
|
427
|
+
if (rest.kind !== "metadata" && rest.kind !== "data")
|
|
428
|
+
return undefined;
|
|
429
|
+
if (JSON.stringify(parsePackageScripts(oldContent)) !== JSON.stringify(parsePackageScripts(newContent)))
|
|
430
|
+
return undefined;
|
|
431
|
+
// A string, an array or an object of conditions at the top level is the "." export.
|
|
432
|
+
const subpaths = (value) => {
|
|
433
|
+
if (value === undefined)
|
|
434
|
+
return {};
|
|
435
|
+
if (typeof value === "string" || Array.isArray(value))
|
|
436
|
+
return { ".": value };
|
|
437
|
+
if (!isRecord(value))
|
|
438
|
+
return undefined;
|
|
439
|
+
const keys = Object.keys(value);
|
|
440
|
+
if (keys.every((key) => key.startsWith(".")))
|
|
441
|
+
return value;
|
|
442
|
+
return keys.some((key) => key.startsWith(".")) ? undefined : { ".": value };
|
|
443
|
+
};
|
|
444
|
+
const before = subpaths(oldJson.exports);
|
|
445
|
+
const after = subpaths(newJson.exports);
|
|
446
|
+
if (!before || !after)
|
|
447
|
+
return undefined;
|
|
448
|
+
const targets = new Set();
|
|
449
|
+
const collect = (value) => {
|
|
450
|
+
if (value === null)
|
|
451
|
+
return true;
|
|
452
|
+
if (typeof value === "string") {
|
|
453
|
+
if (!value.startsWith("./") || value.includes("*"))
|
|
454
|
+
return false;
|
|
455
|
+
targets.add(value);
|
|
456
|
+
return true;
|
|
457
|
+
}
|
|
458
|
+
if (Array.isArray(value))
|
|
459
|
+
return value.every(collect);
|
|
460
|
+
return isRecord(value) && Object.values(value).every(collect);
|
|
461
|
+
};
|
|
462
|
+
for (const key of new Set([...Object.keys(before), ...Object.keys(after)])) {
|
|
463
|
+
if (JSON.stringify(before[key]) === JSON.stringify(after[key]))
|
|
464
|
+
continue;
|
|
465
|
+
if (key.includes("*") || !collect(before[key]) || !collect(after[key]))
|
|
466
|
+
return undefined;
|
|
467
|
+
}
|
|
468
|
+
return { targets: [...targets].sort(), dataChanged: rest.kind === "data" };
|
|
469
|
+
}
|
|
392
470
|
/** packageJsonChange's kind, with a dependency change reported as behavioral. */
|
|
393
471
|
export function packageJsonChangeKind(oldContent, newContent) {
|
|
394
472
|
const { kind } = packageJsonChange(oldContent, newContent);
|
|
@@ -785,6 +863,14 @@ export async function analyzeGitDelta(options = {}) {
|
|
|
785
863
|
const before = readFileAtSha(baseSha, file.path, repoPath);
|
|
786
864
|
const after = readFileAtSha(headSha, file.path, repoPath);
|
|
787
865
|
const change = packageJsonChange(before, after);
|
|
866
|
+
const remap = change.kind === "behavioral" ? exportsRemapTargets(before, after) : undefined;
|
|
867
|
+
if (remap) {
|
|
868
|
+
// Readers of the file are resolved like a data edit, and ImpactAnalyzer treats each target as changed.
|
|
869
|
+
const dir = posix.dirname(file.path);
|
|
870
|
+
(analysis.exportsRemaps ??= {})[file.path] = { targets: remap.targets.map((target) => posix.normalize(posix.join(dir, target))), dataChanged: remap.dataChanged };
|
|
871
|
+
referenceResolvedPaths.push(file.path);
|
|
872
|
+
continue;
|
|
873
|
+
}
|
|
788
874
|
if (change.kind !== "metadata" && change.kind !== "data")
|
|
789
875
|
continue;
|
|
790
876
|
if (JSON.stringify(parsePackageScripts(before)) !== JSON.stringify(parsePackageScripts(after)))
|