@diffci.com/diffci 0.3.21 → 0.3.22
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-identity.d.ts +26 -0
- package/dist-client/src/client/agent-identity.js +62 -0
- package/dist-client/src/client/agent-selection.d.ts +55 -0
- package/dist-client/src/client/cli.d.ts +2 -0
- package/dist-client/src/client/cli.js +68 -3
- package/dist-client/src/client/command-batches.d.ts +26 -0
- package/dist-client/src/client/command-batches.js +7 -1
- package/dist-client/src/client/context.d.ts +47 -0
- package/dist-client/src/client/delivery-warning.d.ts +1 -0
- package/dist-client/src/client/economics.d.ts +17 -0
- package/dist-client/src/client/enforce-misses-collect.d.ts +49 -0
- package/dist-client/src/client/enforce-misses.d.ts +124 -0
- package/dist-client/src/client/enforce-policy.d.ts +33 -0
- package/dist-client/src/client/failure-baseline.d.ts +67 -0
- package/dist-client/src/client/failure-baseline.js +43 -19
- package/dist-client/src/client/feedback-prompt.d.ts +6 -0
- package/dist-client/src/client/full-command.d.ts +16 -0
- package/dist-client/src/client/gate-checks.d.ts +54 -0
- package/dist-client/src/client/gate-checks.js +16 -4
- package/dist-client/src/client/gate.d.ts +154 -0
- package/dist-client/src/client/hook.d.ts +27 -0
- package/dist-client/src/client/install.d.ts +19 -0
- package/dist-client/src/client/mcp.d.ts +2 -0
- package/dist-client/src/client/observe.d.ts +52 -0
- package/dist-client/src/client/observe.js +25 -3
- package/dist-client/src/client/package-identity.d.ts +14 -0
- package/dist-client/src/client/pilot-packet.d.ts +6 -0
- package/dist-client/src/client/report.d.ts +265 -0
- package/dist-client/src/client/selected-coverage.d.ts +19 -0
- package/dist-client/src/client/selected-coverage.js +86 -0
- package/dist-client/src/client/shared-graph-cache.d.ts +113 -0
- package/dist-client/src/client/shared-graph-cache.js +347 -0
- package/dist-client/src/client/spec-conflicts.d.ts +19 -0
- package/dist-client/src/client/submit.d.ts +61 -0
- package/dist-client/src/client/telemetry.d.ts +13 -0
- package/dist-client/src/client/usage-signal.d.ts +19 -0
- package/dist-client/src/client/verify-savings.d.ts +186 -0
- package/dist-client/src/client/verify-savings.js +3 -0
- package/dist-client/src/client/verify.d.ts +113 -0
- package/dist-client/src/client/verify.js +37 -13
- package/dist-client/src/client/workflow-guard.d.ts +59 -0
- package/dist-client/src/client/workflow-guard.js +253 -0
- package/dist-client/src/client/workflow-templates.d.ts +8 -0
- package/dist-client/src/client/working-tree.d.ts +26 -0
- package/dist-client/src/preflight/fingerprint.d.ts +29 -0
- package/dist-client/src/preflight/taxonomy.d.ts +10 -0
- package/node_modules/@diffci.com/core/README.md +4 -0
- package/node_modules/@diffci.com/core/dist/git/git-diff.js +17 -2
- package/node_modules/@diffci.com/core/dist/git/git-diff.js.map +1 -1
- package/node_modules/@diffci.com/core/dist/planner/test-command.d.ts +2 -0
- package/node_modules/@diffci.com/core/dist/planner/test-command.js +46 -1
- package/node_modules/@diffci.com/core/dist/planner/test-command.js.map +1 -1
- package/node_modules/@diffci.com/core/src/git/git-diff.ts +17 -2
- package/node_modules/@diffci.com/core/src/planner/test-command.ts +45 -1
- package/package.json +9 -2
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Did this change introduce the failures, or were they already there? (2026-10-21.)
|
|
3
|
+
*
|
|
4
|
+
* WHY. 44 of DentalPresence's 124 verification receipts failed, and about 31 of those were one
|
|
5
|
+
* route-list assertion failing on commit after commit. Each receipt told the agent "verification
|
|
6
|
+
* failed" with nothing to separate a regression it caused from a suite that was already red.
|
|
7
|
+
*
|
|
8
|
+
* WHAT. On request, the failing command is rerun against the base commit, exported with `git archive`
|
|
9
|
+
* into a temporary directory (the repository, its index and its .git are never written), and the
|
|
10
|
+
* failing test names on both sides are compared. The verdict never changes: a red suite stays
|
|
11
|
+
* `failed` and `safe_to_continue` stays false, because required CI fails either way. Only the
|
|
12
|
+
* explanation changes.
|
|
13
|
+
*
|
|
14
|
+
* WHEN IT DECLINES. No identifiable failing test names, a dependency manifest or lockfile that differs
|
|
15
|
+
* between base and head (the base would run against the wrong installed dependencies), no installed
|
|
16
|
+
* node_modules to share, or an export or run that fails to start: the status is `unknown`, with why.
|
|
17
|
+
*/
|
|
18
|
+
export interface FailureBaseline {
|
|
19
|
+
status: "preexisting" | "introduced" | "mixed" | "unknown";
|
|
20
|
+
base_sha: string;
|
|
21
|
+
reason: string;
|
|
22
|
+
failing_at_head: number;
|
|
23
|
+
failing_at_base?: number;
|
|
24
|
+
/** Failing test names found on both sides, at most 20. */
|
|
25
|
+
preexisting: string[];
|
|
26
|
+
/** Failing test names found only at head, at most 20. */
|
|
27
|
+
introduced: string[];
|
|
28
|
+
base_execution?: {
|
|
29
|
+
exit_code: number | null;
|
|
30
|
+
wall_ms: number;
|
|
31
|
+
timed_out: boolean;
|
|
32
|
+
};
|
|
33
|
+
}
|
|
34
|
+
/** Test names a runner reported as failing: node:test spec and TAP, Vitest and Jest. */
|
|
35
|
+
export declare function failingTestNames(output: string): string[];
|
|
36
|
+
export declare function compareWithBaseline(input: {
|
|
37
|
+
repoPath: string;
|
|
38
|
+
baseSha: string;
|
|
39
|
+
/** The commit (or snapshot commit) that was verified. */
|
|
40
|
+
headSha: string;
|
|
41
|
+
commands: readonly string[];
|
|
42
|
+
headFailures: readonly string[];
|
|
43
|
+
timeoutMs: number;
|
|
44
|
+
}): FailureBaseline;
|
|
45
|
+
/**
|
|
46
|
+
* A gate check that failed at head, rerun at the base (2026-10-31). The CI replay found 5 introduced
|
|
47
|
+
* breakages hidden behind a check that was already red at the base (DentalPresence `validate:aws`):
|
|
48
|
+
* verify stopped at that check and never reached the change's own failure. A check is all or nothing,
|
|
49
|
+
* so the comparison is its exit status, not test names.
|
|
50
|
+
*/
|
|
51
|
+
export interface CheckBaseline {
|
|
52
|
+
status: "preexisting" | "introduced" | "unknown";
|
|
53
|
+
base_sha: string;
|
|
54
|
+
reason: string;
|
|
55
|
+
base_execution?: {
|
|
56
|
+
exit_code: number | null;
|
|
57
|
+
wall_ms: number;
|
|
58
|
+
timed_out: boolean;
|
|
59
|
+
};
|
|
60
|
+
}
|
|
61
|
+
export declare function checkAtBaseline(input: {
|
|
62
|
+
repoPath: string;
|
|
63
|
+
baseSha: string;
|
|
64
|
+
headSha: string;
|
|
65
|
+
command: string;
|
|
66
|
+
timeoutMs: number;
|
|
67
|
+
}): CheckBaseline;
|
|
@@ -37,24 +37,7 @@ export function compareWithBaseline(input) {
|
|
|
37
37
|
});
|
|
38
38
|
if (input.headFailures.length === 0)
|
|
39
39
|
return report("unknown", "no failing test names could be identified in the verification output");
|
|
40
|
-
const
|
|
41
|
-
if (changedDependencies.status !== 0)
|
|
42
|
-
return report("unknown", "dependency manifests or lockfiles differ between base and head");
|
|
43
|
-
const modules = join(input.repoPath, "node_modules");
|
|
44
|
-
if (declaresDependencies(input.repoPath) && !existsSync(modules)) {
|
|
45
|
-
return report("unknown", "no installed node_modules to run the base commit with");
|
|
46
|
-
}
|
|
47
|
-
const directory = mkdtempSync(join(tmpdir(), "diffci-baseline-"));
|
|
48
|
-
const link = join(directory, "node_modules");
|
|
49
|
-
try {
|
|
50
|
-
const archive = git(input.repoPath, ["archive", "--format=tar", input.baseSha]);
|
|
51
|
-
if (archive.status !== 0)
|
|
52
|
-
return report("unknown", "the base commit could not be exported");
|
|
53
|
-
const extract = spawnSync("tar", ["-x", "-f", "-", "-C", directory], { input: archive.stdout, maxBuffer: 64 * 1024 * 1024 });
|
|
54
|
-
if (extract.status !== 0)
|
|
55
|
-
return report("unknown", "the base commit could not be extracted");
|
|
56
|
-
if (existsSync(modules))
|
|
57
|
-
symlinkSync(modules, link, process.platform === "win32" ? "junction" : "dir");
|
|
40
|
+
const run = withBaseTree(input, (directory) => {
|
|
58
41
|
const execution = measureCommands(input.commands, { cwd: directory, timeoutMs: input.timeoutMs, tailBytes: 0 });
|
|
59
42
|
const baseExecution = { exit_code: execution.exitCode, wall_ms: execution.wallMs, timed_out: execution.timedOut };
|
|
60
43
|
if (execution.timedOut)
|
|
@@ -72,9 +55,50 @@ export function compareWithBaseline(input) {
|
|
|
72
55
|
? `none of the ${introduced.length} failing test(s) fail at the base commit`
|
|
73
56
|
: `${introduced.length} failing test(s) are new; ${preexisting.length} also fail at the base commit`;
|
|
74
57
|
return report(status, reason, { failing_at_base: atBase.size, preexisting: preexisting.slice(0, 20), introduced: introduced.slice(0, 20), base_execution: baseExecution });
|
|
58
|
+
});
|
|
59
|
+
return run.ok ? run.value : report("unknown", run.reason);
|
|
60
|
+
}
|
|
61
|
+
export function checkAtBaseline(input) {
|
|
62
|
+
const report = (status, reason, extra = {}) => ({ status, base_sha: input.baseSha, reason, ...extra });
|
|
63
|
+
const run = withBaseTree(input, (directory) => {
|
|
64
|
+
const execution = measureCommands([input.command], { cwd: directory, timeoutMs: input.timeoutMs, tailBytes: 0 });
|
|
65
|
+
const baseExecution = { exit_code: execution.exitCode, wall_ms: execution.wallMs, timed_out: execution.timedOut };
|
|
66
|
+
if (execution.timedOut)
|
|
67
|
+
return report("unknown", "the base run timed out", { base_execution: baseExecution });
|
|
68
|
+
return execution.exitCode === 0
|
|
69
|
+
? report("introduced", "the same check passes at the base commit", { base_execution: baseExecution })
|
|
70
|
+
: report("preexisting", "the same check also fails at the base commit", { base_execution: baseExecution });
|
|
71
|
+
});
|
|
72
|
+
return run.ok ? run.value : report("unknown", run.reason);
|
|
73
|
+
}
|
|
74
|
+
/**
|
|
75
|
+
* Runs `use` in the base commit, exported with `git archive` into a temporary directory with the
|
|
76
|
+
* repository's installed node_modules linked in. The same declines apply to tests and checks: the
|
|
77
|
+
* dependency manifests differ, or nothing is installed. The repository itself is never written.
|
|
78
|
+
*/
|
|
79
|
+
function withBaseTree(input, use) {
|
|
80
|
+
const changedDependencies = git(input.repoPath, ["diff", "--quiet", input.baseSha, input.headSha, "--", ...DEPENDENCY_FILES]);
|
|
81
|
+
if (changedDependencies.status !== 0)
|
|
82
|
+
return { ok: false, reason: "dependency manifests or lockfiles differ between base and head" };
|
|
83
|
+
const modules = join(input.repoPath, "node_modules");
|
|
84
|
+
if (declaresDependencies(input.repoPath) && !existsSync(modules)) {
|
|
85
|
+
return { ok: false, reason: "no installed node_modules to run the base commit with" };
|
|
86
|
+
}
|
|
87
|
+
const directory = mkdtempSync(join(tmpdir(), "diffci-baseline-"));
|
|
88
|
+
const link = join(directory, "node_modules");
|
|
89
|
+
try {
|
|
90
|
+
const archive = git(input.repoPath, ["archive", "--format=tar", input.baseSha]);
|
|
91
|
+
if (archive.status !== 0)
|
|
92
|
+
return { ok: false, reason: "the base commit could not be exported" };
|
|
93
|
+
const extract = spawnSync("tar", ["-x", "-f", "-", "-C", directory], { input: archive.stdout, maxBuffer: 64 * 1024 * 1024 });
|
|
94
|
+
if (extract.status !== 0)
|
|
95
|
+
return { ok: false, reason: "the base commit could not be extracted" };
|
|
96
|
+
if (existsSync(modules))
|
|
97
|
+
symlinkSync(modules, link, process.platform === "win32" ? "junction" : "dir");
|
|
98
|
+
return { ok: true, value: use(directory) };
|
|
75
99
|
}
|
|
76
100
|
catch (error) {
|
|
77
|
-
return
|
|
101
|
+
return { ok: false, reason: `the base run could not be prepared: ${error instanceof Error ? error.message : String(error)}` };
|
|
78
102
|
}
|
|
79
103
|
finally {
|
|
80
104
|
// Remove the dependency link itself first, so cleanup can never descend into the real node_modules.
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { type TelemetryMode } from "./telemetry.js";
|
|
2
|
+
type Flags = Record<string, string | boolean>;
|
|
3
|
+
export declare function shouldShowFeedbackPrompt(flags: Flags, env: NodeJS.ProcessEnv, interactive: boolean, now?: number): boolean;
|
|
4
|
+
export declare function formatFeedbackPrompt(telemetry: TelemetryMode): string;
|
|
5
|
+
export declare function markFeedbackPromptShown(env: NodeJS.ProcessEnv, now?: number): void;
|
|
6
|
+
export {};
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/** Rebuild the complete plan locally; never join arbitrary report commands. */
|
|
2
|
+
export declare function inferWorkspaceComparison(repoPath: string, proposed: readonly string[], selectedTests: readonly string[]): {
|
|
3
|
+
full?: string;
|
|
4
|
+
selected?: string;
|
|
5
|
+
reason: string;
|
|
6
|
+
};
|
|
7
|
+
export interface FullCommandDecision {
|
|
8
|
+
command?: string;
|
|
9
|
+
reason: string;
|
|
10
|
+
}
|
|
11
|
+
/** Automatic timing must retain the non-selected phases of the declared test script. */
|
|
12
|
+
export declare function inferComparableSelectedCommand(repoPath: string, proposed: string, selectedTests: readonly string[]): FullCommandDecision;
|
|
13
|
+
/** Preserve the repository's TypeScript test loader for selected node:test files. */
|
|
14
|
+
export declare function inferSelectedCommand(repoPath: string, proposed: string, selectedTests: readonly string[]): FullCommandDecision;
|
|
15
|
+
/** Choose the repository's conventional full test command without executing anything. */
|
|
16
|
+
export declare function inferFullCommand(repoPath: string): FullCommandDecision;
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import { type GateCheckKind } from "@diffci.com/core/planner/pipeline-steps";
|
|
2
|
+
import type { CheckBaseline } from "./failure-baseline.js";
|
|
3
|
+
import { measureCommand } from "./verify-savings.js";
|
|
4
|
+
/** One leaf of the repository's gate (`npm run check`), as an agent or verify runs it. */
|
|
5
|
+
export interface PlannedCheck {
|
|
6
|
+
id: string;
|
|
7
|
+
kind: GateCheckKind;
|
|
8
|
+
/** RUN as written, NARROWED to the changed files, or SKIP for this change (never run). */
|
|
9
|
+
decision: "RUN" | "NARROWED" | "SKIP";
|
|
10
|
+
command: string;
|
|
11
|
+
reason: string;
|
|
12
|
+
}
|
|
13
|
+
export interface CheckResult extends PlannedCheck {
|
|
14
|
+
status: "passed" | "failed" | "timed_out" | "not_run" | "skipped";
|
|
15
|
+
exit_code?: number | null;
|
|
16
|
+
wall_ms?: number;
|
|
17
|
+
/** Present when a failed check was rerun at the base commit (`--baseline-on-failure`). */
|
|
18
|
+
baseline?: CheckBaseline;
|
|
19
|
+
}
|
|
20
|
+
/** The commits a change runs between; without one every check runs as written. */
|
|
21
|
+
export interface CheckChange {
|
|
22
|
+
baseSha: string;
|
|
23
|
+
headSha: string;
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* The checks the repository's gate runs besides its tests (2026-10-29, docs/design/pipeline-impact.md).
|
|
27
|
+
* Agents ran the tests DiffCI selected and then failed `npm run check` after push; these are the rest of
|
|
28
|
+
* the gate. With a change, per-file lint and format checks are narrowed to its files or skipped
|
|
29
|
+
* (check-narrowing.ts); if the change cannot be read, every check runs. No package.json, or one that
|
|
30
|
+
* cannot be read, has none. `extraRoots` replaces the scripts CI workflows add to the gate, for a caller
|
|
31
|
+
* that knows exactly which scripts its build runs (`diffci gate --script`).
|
|
32
|
+
*/
|
|
33
|
+
export declare function plannedChecks(repoPath: string, change?: CheckChange, options?: {
|
|
34
|
+
extraRoots?: readonly string[];
|
|
35
|
+
}): PlannedCheck[];
|
|
36
|
+
/** Runs checks in order and stops at the first failure, as the gate's `&&` chain would. SKIP checks
|
|
37
|
+
* are recorded as skipped and not run. `baseline` reruns a failed check at the base commit; one that
|
|
38
|
+
* fails there too is recorded in `preexisting` and the run goes on, so a check that was already red
|
|
39
|
+
* cannot hide what the change itself broke. */
|
|
40
|
+
export declare function runChecks(checks: readonly PlannedCheck[], options: {
|
|
41
|
+
cwd: string;
|
|
42
|
+
timeoutMs: number;
|
|
43
|
+
tailBytes: number;
|
|
44
|
+
baseline?: (check: PlannedCheck, remainingMs: number) => CheckBaseline;
|
|
45
|
+
}): {
|
|
46
|
+
results: CheckResult[];
|
|
47
|
+
failure: {
|
|
48
|
+
check: CheckResult;
|
|
49
|
+
measurement: ReturnType<typeof measureCommand>;
|
|
50
|
+
} | undefined;
|
|
51
|
+
preexisting: CheckResult[];
|
|
52
|
+
outOfTime: boolean;
|
|
53
|
+
wallMs: number;
|
|
54
|
+
};
|
|
@@ -95,10 +95,13 @@ export function plannedChecks(repoPath, change, options = {}) {
|
|
|
95
95
|
}));
|
|
96
96
|
}
|
|
97
97
|
/** Runs checks in order and stops at the first failure, as the gate's `&&` chain would. SKIP checks
|
|
98
|
-
* are recorded as skipped and not run.
|
|
98
|
+
* are recorded as skipped and not run. `baseline` reruns a failed check at the base commit; one that
|
|
99
|
+
* fails there too is recorded in `preexisting` and the run goes on, so a check that was already red
|
|
100
|
+
* cannot hide what the change itself broke. */
|
|
99
101
|
export function runChecks(checks, options) {
|
|
100
102
|
const started = Date.now();
|
|
101
103
|
const results = [];
|
|
104
|
+
const preexisting = [];
|
|
102
105
|
let failure;
|
|
103
106
|
for (const check of checks) {
|
|
104
107
|
if (check.decision === "SKIP") {
|
|
@@ -114,9 +117,18 @@ export function runChecks(checks, options) {
|
|
|
114
117
|
const status = measurement.timedOut ? "timed_out" : measurement.exitCode === 0 && measurement.signal === null ? "passed" : "failed";
|
|
115
118
|
const result = { ...check, status, exit_code: measurement.exitCode, wall_ms: measurement.wallMs };
|
|
116
119
|
results.push(result);
|
|
117
|
-
if (status
|
|
118
|
-
|
|
120
|
+
if (status === "passed")
|
|
121
|
+
continue;
|
|
122
|
+
// Only a check run as written is comparable at the base: a NARROWED one names files the base may not have.
|
|
123
|
+
if (status === "failed" && check.decision === "RUN" && options.baseline) {
|
|
124
|
+
result.baseline = options.baseline(check, options.timeoutMs - (Date.now() - started));
|
|
125
|
+
if (result.baseline.status === "preexisting") {
|
|
126
|
+
preexisting.push(result);
|
|
127
|
+
continue;
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
failure = { check: result, measurement };
|
|
119
131
|
}
|
|
120
132
|
const outOfTime = !failure && results.some((result) => result.status === "not_run");
|
|
121
|
-
return { results, failure, outOfTime, wallMs: Date.now() - started };
|
|
133
|
+
return { results, failure, preexisting, outOfTime, wallMs: Date.now() - started };
|
|
122
134
|
}
|
|
@@ -0,0 +1,154 @@
|
|
|
1
|
+
import { type PlannedCheck } from "./gate-checks.js";
|
|
2
|
+
import { observe } from "./observe.js";
|
|
3
|
+
import type { ObservationReport } from "./report.js";
|
|
4
|
+
import { type CommandMeasurement } from "./verify-savings.js";
|
|
5
|
+
/**
|
|
6
|
+
* `diffci gate` in observe mode (2026-10-30, docs/design/pipeline-impact.md, phase 2).
|
|
7
|
+
*
|
|
8
|
+
* WHY. Builds that run a script instead of workflow jobs (DentalPresence's Cloudflare Sandbox build runs
|
|
9
|
+
* `npm run check` and its whole test suite on every staging build, about 19 of 44 build-hours) cannot use
|
|
10
|
+
* per-job `if:` conditions. `diffci gate` replaces that script. Before anything is skipped in a build, the
|
|
11
|
+
* miss rate has to be measured on real builds, so this mode changes nothing about what runs.
|
|
12
|
+
*
|
|
13
|
+
* WHAT IT DOES. Runs every leaf of the gate and the full test command, exactly as the build would, and
|
|
14
|
+
* exits with their result. Alongside, it records what DiffCI would have done for the same commit range:
|
|
15
|
+
* each check's RUN/NARROWED/SKIP decision and the test selection. A miss is a step DiffCI would have
|
|
16
|
+
* skipped or narrowed that failed in full while DiffCI's version passed; those are only rerun when the full
|
|
17
|
+
* step failed, so a passing build pays for nothing but the analysis. `--measure-selected` also runs the
|
|
18
|
+
* narrowed checks and selected tests on passing builds, to measure rather than estimate the saving.
|
|
19
|
+
*
|
|
20
|
+
* DiffCI never decides the build's outcome here: an analysis that fails still runs and reports the full gate.
|
|
21
|
+
*/
|
|
22
|
+
export declare const GATE_SCHEMA: "diffci.gate.v1";
|
|
23
|
+
export type StepStatus = "passed" | "failed" | "timed_out" | "not_run";
|
|
24
|
+
export interface StepRun {
|
|
25
|
+
status: StepStatus;
|
|
26
|
+
wall_ms?: number;
|
|
27
|
+
exit_code?: number | null;
|
|
28
|
+
}
|
|
29
|
+
export interface GateCheckReport {
|
|
30
|
+
id: string;
|
|
31
|
+
kind: PlannedCheck["kind"];
|
|
32
|
+
/** What DiffCI would have done; UNPLANNED when the change could not be analysed. */
|
|
33
|
+
decision: PlannedCheck["decision"] | "UNPLANNED";
|
|
34
|
+
reason: string;
|
|
35
|
+
command: string;
|
|
36
|
+
narrowed_command?: string;
|
|
37
|
+
full: StepRun;
|
|
38
|
+
narrowed?: StepRun;
|
|
39
|
+
/** The full step failed and DiffCI would have skipped it, or its narrowed run passed. */
|
|
40
|
+
missed?: boolean;
|
|
41
|
+
}
|
|
42
|
+
export interface GateTestReport {
|
|
43
|
+
command: string;
|
|
44
|
+
full: StepRun & {
|
|
45
|
+
failing_tests?: string[];
|
|
46
|
+
};
|
|
47
|
+
selection: "selected" | "full" | "unavailable";
|
|
48
|
+
reason: string;
|
|
49
|
+
tests_selected: number;
|
|
50
|
+
tests_available: number;
|
|
51
|
+
selected_commands?: string[];
|
|
52
|
+
selected?: StepRun;
|
|
53
|
+
missed?: boolean;
|
|
54
|
+
}
|
|
55
|
+
export interface GateReport {
|
|
56
|
+
schema: typeof GATE_SCHEMA;
|
|
57
|
+
schema_version: "1";
|
|
58
|
+
produced_at: string;
|
|
59
|
+
diffci_version: string;
|
|
60
|
+
mode: "observe";
|
|
61
|
+
/** Present when the build runs its checks and tests as separate stages (`--only`). */
|
|
62
|
+
only?: "checks" | "tests";
|
|
63
|
+
/** Present when a plan was supplied (`--plan`): whether it was used. Analysis time then belongs to the
|
|
64
|
+
* planning step, not this report. */
|
|
65
|
+
plan?: "supplied" | "unusable";
|
|
66
|
+
range?: {
|
|
67
|
+
base_sha: string;
|
|
68
|
+
head_sha: string;
|
|
69
|
+
source: string;
|
|
70
|
+
};
|
|
71
|
+
analysis: {
|
|
72
|
+
status: string;
|
|
73
|
+
reason?: string;
|
|
74
|
+
mode?: string;
|
|
75
|
+
fallback_reasons: string[];
|
|
76
|
+
duration_ms?: number;
|
|
77
|
+
};
|
|
78
|
+
gate: {
|
|
79
|
+
status: "passed" | "failed";
|
|
80
|
+
wall_ms: number;
|
|
81
|
+
reason: string;
|
|
82
|
+
};
|
|
83
|
+
checks: GateCheckReport[];
|
|
84
|
+
tests?: GateTestReport;
|
|
85
|
+
summary: {
|
|
86
|
+
/** Every gate step run one after another, as observed. */
|
|
87
|
+
full_ms: number;
|
|
88
|
+
/** Analysis plus the steps DiffCI would have run. */
|
|
89
|
+
diffci_ms: number;
|
|
90
|
+
saved_ms: number;
|
|
91
|
+
/** `measured` when every step DiffCI would have run was timed; `estimated` when narrowed checks count at
|
|
92
|
+
* their full time and selected tests in proportion to the files selected. */
|
|
93
|
+
basis: "measured" | "estimated";
|
|
94
|
+
misses: string[];
|
|
95
|
+
};
|
|
96
|
+
}
|
|
97
|
+
export interface GateOptions {
|
|
98
|
+
repoPath: string;
|
|
99
|
+
env: Record<string, string | undefined>;
|
|
100
|
+
version: string;
|
|
101
|
+
engineSha?: string;
|
|
102
|
+
baseOverride?: string;
|
|
103
|
+
headOverride?: string;
|
|
104
|
+
/** The build's full test command; defaults to the repository's conventional one (`npm test`). */
|
|
105
|
+
tests?: string;
|
|
106
|
+
/** The build's gate scripts beyond `check`; replaces the scripts CI workflows add. */
|
|
107
|
+
scripts?: readonly string[];
|
|
108
|
+
measureSelected?: boolean;
|
|
109
|
+
/** Run one half of the gate, for builds that run checks and tests as separate stages (DentalPresence
|
|
110
|
+
* runs `npm run check` on the host and its tests in a container, because together they exhausted the
|
|
111
|
+
* builder's memory). */
|
|
112
|
+
only?: "checks" | "tests";
|
|
113
|
+
timeoutMs: number;
|
|
114
|
+
tailBytes: number;
|
|
115
|
+
/** A plan from `gate --plan-out`, used instead of analysing here (no git history needed). */
|
|
116
|
+
plan?: unknown;
|
|
117
|
+
/** The commit being gated; a plan for another commit is not used. */
|
|
118
|
+
expectHead?: string;
|
|
119
|
+
/** Injected for tests. */
|
|
120
|
+
run?: (command: string, options: {
|
|
121
|
+
cwd: string;
|
|
122
|
+
timeoutMs: number;
|
|
123
|
+
tailBytes: number;
|
|
124
|
+
}) => CommandMeasurement;
|
|
125
|
+
analyse?: (options: Parameters<typeof observe>[0]) => Promise<ObservationReport>;
|
|
126
|
+
}
|
|
127
|
+
export declare const GATE_PLAN_SCHEMA: "diffci.gate-plan.v1";
|
|
128
|
+
/**
|
|
129
|
+
* DiffCI's decisions for a range, without running anything. A build whose gate runs where there is no git
|
|
130
|
+
* history (DentalPresence's Sandbox receives a `git archive` of one commit) plans where the checkout is
|
|
131
|
+
* (`gate --plan-out`) and ships the plan to the stage that runs the gate (`gate --plan`).
|
|
132
|
+
*/
|
|
133
|
+
export interface GatePlan {
|
|
134
|
+
schema: typeof GATE_PLAN_SCHEMA;
|
|
135
|
+
diffci_version: string;
|
|
136
|
+
range?: {
|
|
137
|
+
base_sha: string;
|
|
138
|
+
head_sha: string;
|
|
139
|
+
source: string;
|
|
140
|
+
};
|
|
141
|
+
analysis: GateReport["analysis"];
|
|
142
|
+
checks: PlannedCheck[];
|
|
143
|
+
tests: {
|
|
144
|
+
selection: "selected" | "full" | "unavailable";
|
|
145
|
+
reason: string;
|
|
146
|
+
tests_selected: number;
|
|
147
|
+
tests_available: number;
|
|
148
|
+
selected_commands?: string[];
|
|
149
|
+
};
|
|
150
|
+
}
|
|
151
|
+
export declare function planGate(options: Omit<GateOptions, "plan" | "expectHead" | "run" | "timeoutMs" | "tailBytes" | "measureSelected" | "only" | "tests">): Promise<GatePlan>;
|
|
152
|
+
export declare function runGate(options: GateOptions): Promise<GateReport>;
|
|
153
|
+
export declare function gateExitCode(report: GateReport): number;
|
|
154
|
+
export declare function formatGateSummary(report: GateReport): string;
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The pre-push hook `diffci init --hook` installs (2026-10-28).
|
|
3
|
+
*
|
|
4
|
+
* WHY. In 449 agent sessions on DentalPresence, agents ran DiffCI in 24 of over 1,500 test commands:
|
|
5
|
+
* they picked test files themselves (928) or ran the whole suite (282), and 104 pushes then failed the
|
|
6
|
+
* repository gates in CI. Instructions alone did not make DiffCI the default. A hook does: every push,
|
|
7
|
+
* by an agent or a person, verifies the commits being pushed before they leave the machine.
|
|
8
|
+
*
|
|
9
|
+
* BEHAVIOUR. For each pushed ref that is the checked-out HEAD, the hook runs
|
|
10
|
+
* `diffci verify --base <remote sha> --head <local sha>` (a new branch uses its merge base with the
|
|
11
|
+
* remote's default branch). Failing verification (exit 1) blocks the push. When DiffCI cannot verify
|
|
12
|
+
* (exit 2: dirty checkout, unknown base, analysis refused) it says why and lets the push through,
|
|
13
|
+
* because required CI still runs; `DIFFCI_HOOK_STRICT=1` blocks instead. `git push --no-verify` skips it.
|
|
14
|
+
*
|
|
15
|
+
* REPORTING (2026-10-29). When DIFFCI_API_URL and DIFFCI_TOKEN are set, the hook also sends an
|
|
16
|
+
* observation report for the pushed range, the same report the GitHub Action sends. A dogfood repository
|
|
17
|
+
* whose GitHub Actions minutes ran out sent nothing for two weeks while its builds moved to another CI;
|
|
18
|
+
* reporting from the push keeps that data. It runs after verification and can never block the push.
|
|
19
|
+
*/
|
|
20
|
+
export declare const HOOK_MARKER = "# diffci:managed pre-push hook";
|
|
21
|
+
export declare function prePushHook(command: string): string;
|
|
22
|
+
/** The command the hook runs: the installed binary when the repository has DiffCI as a dependency,
|
|
23
|
+
* otherwise a pinned npx invocation, so the hook never floats to a newer release. */
|
|
24
|
+
export declare function hookCommand(manager: "npm" | "pnpm" | "yarn" | "bun" | undefined, version: string): string;
|
|
25
|
+
/** Writes the hook into the directory Git actually runs hooks from (`core.hooksPath` included, such as
|
|
26
|
+
* `.husky`). An existing hook DiffCI did not write is kept unless `force` is set. */
|
|
27
|
+
export declare function installPrePushHook(repoPath: string, command: string, force: boolean): string;
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { spawnSync, type SpawnSyncReturns } from "node:child_process";
|
|
2
|
+
export type SupportedPackageManager = "npm" | "pnpm" | "yarn" | "bun";
|
|
3
|
+
export interface InstallPlan {
|
|
4
|
+
manager: SupportedPackageManager;
|
|
5
|
+
command: string;
|
|
6
|
+
args: string[];
|
|
7
|
+
packageSpec: string;
|
|
8
|
+
}
|
|
9
|
+
export interface PackageScriptResult {
|
|
10
|
+
added: string[];
|
|
11
|
+
kept: string[];
|
|
12
|
+
}
|
|
13
|
+
export declare function detectPackageManager(repoPath: string): SupportedPackageManager;
|
|
14
|
+
export declare function installPlan(repoPath: string, version: string, platform?: NodeJS.Platform): InstallPlan;
|
|
15
|
+
export declare function installDiffci(repoPath: string, version: string, run?: typeof spawnSync, packageSpecOverride?: string): {
|
|
16
|
+
plan: InstallPlan;
|
|
17
|
+
result: SpawnSyncReturns<string>;
|
|
18
|
+
};
|
|
19
|
+
export declare function addDiffciPackageScripts(repoPath: string): PackageScriptResult;
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import type { ObservationAgent } from "./agent-identity.js";
|
|
2
|
+
import { type GitRunner, type ObservationEnvironment } from "./context.js";
|
|
3
|
+
import { type ObservationReport } from "./report.js";
|
|
4
|
+
import type { DependencyGraphResult } from "@diffci.com/core/repo/types";
|
|
5
|
+
export interface ObserveOptions {
|
|
6
|
+
/** The checked-out repository to observe. Never written to. */
|
|
7
|
+
repoPath: string;
|
|
8
|
+
env: ObservationEnvironment;
|
|
9
|
+
/** DiffCI's own version string, recorded in the report. */
|
|
10
|
+
version: string;
|
|
11
|
+
/** The DiffCI commit that produced this report, when it can be determined. */
|
|
12
|
+
engineSha?: string;
|
|
13
|
+
baseOverride?: string;
|
|
14
|
+
headOverride?: string;
|
|
15
|
+
/** Replace every path in the report with a stable 12-character digest. */
|
|
16
|
+
redactPaths?: boolean;
|
|
17
|
+
/** Where the report will be written, so the report can state whether that is inside the checkout. */
|
|
18
|
+
reportPath?: string;
|
|
19
|
+
/** Injected for tests. Defaults to a real git in `repoPath`. */
|
|
20
|
+
git?: GitRunner;
|
|
21
|
+
/** Optional external CI timing history. It can only bypass to full validation. */
|
|
22
|
+
economicsHistory?: unknown;
|
|
23
|
+
economicsJobKey?: string;
|
|
24
|
+
forceAnalysis?: boolean;
|
|
25
|
+
/** Optional cache outside the checkout; graph resolution and selection remain fresh. */
|
|
26
|
+
vueAnalysisCacheDir?: string;
|
|
27
|
+
/** Let the engine cover a file the test script runs directly by naming that phase
|
|
28
|
+
* (`result.testPhases`) instead of falling back. Only for callers that execute the phases with the
|
|
29
|
+
* selection - verification does; check, observe and enforce do not, so they keep the fallback. */
|
|
30
|
+
selectTestPhases?: boolean;
|
|
31
|
+
/**
|
|
32
|
+
* Opt-in dependency-graph cache (local and/or DiffCI Cloud, src/client/shared-graph-cache.ts). Used only
|
|
33
|
+
* for a clean checkout; any failure is a miss, and a hit yields the same graph a build would.
|
|
34
|
+
*/
|
|
35
|
+
graphCache?: {
|
|
36
|
+
load(key: string): Promise<{
|
|
37
|
+
result: DependencyGraphResult;
|
|
38
|
+
} | undefined>;
|
|
39
|
+
save(key: string, result: DependencyGraphResult): void;
|
|
40
|
+
};
|
|
41
|
+
/** Opt-in agent identity (src/client/agent-identity.ts); absent means the report carries none. */
|
|
42
|
+
agent?: ObservationAgent;
|
|
43
|
+
}
|
|
44
|
+
export declare function makeGitRunner(repoPath: string): GitRunner;
|
|
45
|
+
/**
|
|
46
|
+
* True when the report would land inside the observed checkout. That is not a style preference: an
|
|
47
|
+
* untracked file in the working tree changes `git status`, and CI jobs that assert a clean tree (a
|
|
48
|
+
* generated-code check, a lockfile check, `git diff --exit-code`) would start failing because DiffCI
|
|
49
|
+
* was installed. The report is written outside the repository by default for exactly that reason.
|
|
50
|
+
*/
|
|
51
|
+
export declare function isInsideRepository(repoPath: string, candidate: string): boolean;
|
|
52
|
+
export declare function observe(options: ObserveOptions): Promise<ObservationReport>;
|
|
@@ -26,6 +26,7 @@ import { economicsContext, evaluateEconomics } from "./economics.js";
|
|
|
26
26
|
import { readCiEnvironment, resolveCommitRange, } from "./context.js";
|
|
27
27
|
import { OBSERVATION_SCHEMA, readTypeScriptProgramMetrics, redactPath, } from "./report.js";
|
|
28
28
|
import { auditWorkflows } from "./workflow-guard.js";
|
|
29
|
+
import { deriveSharedGraphCacheKey } from "./shared-graph-cache.js";
|
|
29
30
|
/** Build output and dependencies are never sources of truth about a repository's own structure. */
|
|
30
31
|
const EXCLUDE_DIRS = ["node_modules", ".next", "dist", "build"];
|
|
31
32
|
export function makeGitRunner(repoPath) {
|
|
@@ -128,6 +129,7 @@ export async function observe(options) {
|
|
|
128
129
|
reason: extra.reason,
|
|
129
130
|
result: extra.result,
|
|
130
131
|
economics,
|
|
132
|
+
...(options.agent ? { agent: options.agent } : {}),
|
|
131
133
|
payload: {
|
|
132
134
|
includesFilePaths: options.redactPaths !== true,
|
|
133
135
|
includesFileContents: false,
|
|
@@ -163,7 +165,7 @@ export async function observe(options) {
|
|
|
163
165
|
if (economics.decision === "BYPASS_FULL")
|
|
164
166
|
return finish("REFUSED", "eligibility", { reason: `ECONOMICS_FULL_BYPASS: ${economics.reason}. No selective command is authorized.` });
|
|
165
167
|
}
|
|
166
|
-
const [{ analyzeGitDelta }, { classifyRepositoryProject, buildDependencyGraph }, { ImpactAnalyzer }, { runPathBaseline }, { commandSpecToString, planSelectiveTestCommands }, { repositoryFileReader }] = await Promise.all([
|
|
168
|
+
const [{ analyzeGitDelta }, { classifyRepositoryProject, buildDependencyGraph, hydrateDependencyGraph }, { ImpactAnalyzer }, { runPathBaseline }, { commandSpecToString, planSelectiveTestCommands }, { repositoryFileReader }] = await Promise.all([
|
|
167
169
|
import("@diffci.com/core/git/git-diff"), import("@diffci.com/core/repo/graph"), import("@diffci.com/core/repo/impact"), import("@diffci.com/core/planner/path-baseline"), import("@diffci.com/core/planner/test-command"), import("@diffci.com/core/repo/file-references"),
|
|
168
170
|
]);
|
|
169
171
|
markPhase("engineLoad");
|
|
@@ -182,8 +184,28 @@ export async function observe(options) {
|
|
|
182
184
|
}
|
|
183
185
|
const delta = deltaResult.delta;
|
|
184
186
|
markPhase("delta");
|
|
185
|
-
const
|
|
186
|
-
|
|
187
|
+
const graphCacheKey = options.graphCache
|
|
188
|
+
? deriveSharedGraphCacheKey({ repoPath, git, version: options.version, engineSha: options.engineSha, excludeDirs: EXCLUDE_DIRS })
|
|
189
|
+
: undefined;
|
|
190
|
+
let cachedGraph;
|
|
191
|
+
if (options.graphCache && graphCacheKey) {
|
|
192
|
+
try {
|
|
193
|
+
const hit = await options.graphCache.load(graphCacheKey);
|
|
194
|
+
if (hit)
|
|
195
|
+
cachedGraph = { ...hit.result, graph: hydrateDependencyGraph(hit.result.graph, repoPath, hit.result.profile?.testPatterns) };
|
|
196
|
+
}
|
|
197
|
+
catch {
|
|
198
|
+
cachedGraph = undefined;
|
|
199
|
+
}
|
|
200
|
+
}
|
|
201
|
+
const graphResult = cachedGraph ?? await buildDependencyGraph({ repoPath, excludeDirs: EXCLUDE_DIRS, vueAnalysisCache: options.vueAnalysisCacheDir ? { directory: options.vueAnalysisCacheDir, version: `${options.version}:${options.engineSha ?? ""}` } : undefined });
|
|
202
|
+
if (!cachedGraph && options.graphCache && graphCacheKey) {
|
|
203
|
+
try {
|
|
204
|
+
options.graphCache.save(graphCacheKey, graphResult);
|
|
205
|
+
}
|
|
206
|
+
catch { /* caching never fails an observation */ }
|
|
207
|
+
}
|
|
208
|
+
markPhase(cachedGraph ? "graphCached" : "graph");
|
|
187
209
|
if (graphResult.graph.nodes.length === 0) {
|
|
188
210
|
return finish("REFUSED", "graph", {
|
|
189
211
|
reason: "the dependency graph came back empty - DiffCI will not propose a selection from a graph that sees none of this repository" +
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
export interface DiffciPackageIdentity {
|
|
2
|
+
version: string;
|
|
3
|
+
root?: string;
|
|
4
|
+
sha?: string;
|
|
5
|
+
}
|
|
6
|
+
/**
|
|
7
|
+
* Find package metadata without assuming whether this code is running from
|
|
8
|
+
* source, a build directory, or an installed npm tarball.
|
|
9
|
+
*/
|
|
10
|
+
export declare function findDiffciPackageIdentity(): DiffciPackageIdentity | undefined;
|
|
11
|
+
/** Preserve the CLI's historical unknown-version fallback for diagnostics. */
|
|
12
|
+
export declare function observerIdentity(): DiffciPackageIdentity;
|
|
13
|
+
/** MCP negotiation must never advertise an invented release version. */
|
|
14
|
+
export declare function requireDiffciPackageIdentity(): DiffciPackageIdentity;
|