@diffci.com/diffci 0.3.13 → 0.3.15
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/LICENSE +20 -661
- package/README.md +1 -1
- package/dist-client/src/client/agent-selection.js +4 -1
- package/dist-client/src/client/cli.js +143 -59
- package/dist-client/src/client/command-batches.js +80 -0
- package/dist-client/src/client/context.js +1 -1
- package/dist-client/src/client/enforce-misses-collect.js +157 -0
- package/dist-client/src/client/enforce-misses.js +229 -0
- package/dist-client/src/client/enforce-policy.js +169 -0
- package/dist-client/src/client/failure-baseline.js +99 -0
- package/dist-client/src/client/feedback-prompt.js +42 -0
- package/dist-client/src/client/mcp.js +1 -1
- package/dist-client/src/client/observe.js +12 -4
- package/dist-client/src/client/pilot-packet.js +0 -31
- package/dist-client/src/client/telemetry.js +46 -0
- package/dist-client/src/client/usage-signal.js +17 -10
- package/dist-client/src/client/verify-savings.js +12 -1
- package/dist-client/src/client/verify.js +81 -9
- package/dist-client/src/client/workflow-templates.js +80 -0
- package/node_modules/@diffci.com/core/README.md +13 -7
- package/node_modules/@diffci.com/core/dist/analyze.js +2 -1
- package/node_modules/@diffci.com/core/dist/analyze.js.map +1 -1
- 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 +1 -1
- package/node_modules/@diffci.com/core/dist/git/git-diff.d.ts +9 -0
- package/node_modules/@diffci.com/core/dist/git/git-diff.js +122 -19
- 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 +9 -0
- package/node_modules/@diffci.com/core/dist/planner/test-command.js +16 -3
- package/node_modules/@diffci.com/core/dist/planner/test-command.js.map +1 -1
- package/node_modules/@diffci.com/core/dist/repo/adapters/maven.js +99 -42
- package/node_modules/@diffci.com/core/dist/repo/adapters/maven.js.map +1 -1
- package/node_modules/@diffci.com/core/dist/repo/compiled-projects.d.ts +16 -0
- package/node_modules/@diffci.com/core/dist/repo/compiled-projects.js +101 -0
- package/node_modules/@diffci.com/core/dist/repo/compiled-projects.js.map +1 -0
- package/node_modules/@diffci.com/core/dist/repo/file-references.d.ts +68 -0
- package/node_modules/@diffci.com/core/dist/repo/file-references.js +278 -0
- package/node_modules/@diffci.com/core/dist/repo/file-references.js.map +1 -0
- package/node_modules/@diffci.com/core/dist/repo/graph.d.ts +4 -2
- package/node_modules/@diffci.com/core/dist/repo/graph.js +107 -31
- package/node_modules/@diffci.com/core/dist/repo/graph.js.map +1 -1
- package/node_modules/@diffci.com/core/dist/repo/impact-types.d.ts +7 -1
- package/node_modules/@diffci.com/core/dist/repo/impact.d.ts +32 -0
- package/node_modules/@diffci.com/core/dist/repo/impact.js +241 -20
- package/node_modules/@diffci.com/core/dist/repo/impact.js.map +1 -1
- package/node_modules/@diffci.com/core/dist/repo/runner-universe.js +9 -3
- package/node_modules/@diffci.com/core/dist/repo/runner-universe.js.map +1 -1
- package/node_modules/@diffci.com/core/dist/repo/script-universe.d.ts +16 -0
- package/node_modules/@diffci.com/core/dist/repo/script-universe.js +173 -0
- package/node_modules/@diffci.com/core/dist/repo/script-universe.js.map +1 -0
- package/node_modules/@diffci.com/core/dist/repo/test-discovery.d.ts +12 -0
- package/node_modules/@diffci.com/core/dist/repo/test-discovery.js +54 -7
- 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 +8 -0
- package/node_modules/@diffci.com/core/dist/repo/workflow-test-steps.d.ts +15 -0
- package/node_modules/@diffci.com/core/dist/repo/workflow-test-steps.js +157 -0
- package/node_modules/@diffci.com/core/dist/repo/workflow-test-steps.js.map +1 -0
- package/node_modules/@diffci.com/core/package.json +5 -0
- package/node_modules/@diffci.com/core/src/analyze.ts +2 -1
- package/node_modules/@diffci.com/core/src/cache/graph-cache.ts +1 -1
- package/node_modules/@diffci.com/core/src/git/git-diff.ts +106 -20
- package/node_modules/@diffci.com/core/src/git/types.ts +9 -0
- package/node_modules/@diffci.com/core/src/planner/test-command.ts +17 -3
- package/node_modules/@diffci.com/core/src/repo/adapters/maven.ts +120 -30
- package/node_modules/@diffci.com/core/src/repo/compiled-projects.ts +108 -0
- package/node_modules/@diffci.com/core/src/repo/file-references.ts +275 -0
- package/node_modules/@diffci.com/core/src/repo/graph.ts +104 -31
- package/node_modules/@diffci.com/core/src/repo/impact-types.ts +10 -0
- package/node_modules/@diffci.com/core/src/repo/impact.ts +243 -18
- package/node_modules/@diffci.com/core/src/repo/runner-universe.ts +6 -3
- package/node_modules/@diffci.com/core/src/repo/script-universe.ts +158 -0
- package/node_modules/@diffci.com/core/src/repo/test-discovery.ts +62 -7
- package/node_modules/@diffci.com/core/src/repo/types.ts +5 -0
- package/node_modules/@diffci.com/core/src/repo/workflow-test-steps.ts +117 -0
- package/package.json +6 -4
|
@@ -0,0 +1,229 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Enforce mode miss detection (docs/enforce-mode-01-plan.md, step 5).
|
|
3
|
+
*
|
|
4
|
+
* After a full run on `main`, every failing test is held against the enforce receipts of the pull
|
|
5
|
+
* requests merged since the last full run that was recorded. A MISS is a test that fails on `main`,
|
|
6
|
+
* fails again when re-run, was not failing before those pull requests merged, and was left out by a
|
|
7
|
+
* pull request whose receipt says `selection: "selected"`. That is exactly the failure enforce mode
|
|
8
|
+
* would have let through.
|
|
9
|
+
*
|
|
10
|
+
* Everything here is pure: parsing, classification and the report. GitHub, git and the re-run live in
|
|
11
|
+
* `enforce-misses-collect.ts`, so each classification can be tested without a repository or a token.
|
|
12
|
+
*
|
|
13
|
+
* Nothing here changes configuration. A miss produces the exact `enforce.openUnsafeMisses` entry for
|
|
14
|
+
* a human to add; re-enabling enforcement is never automatic.
|
|
15
|
+
*/
|
|
16
|
+
import { isAbsolute, relative, resolve } from "node:path";
|
|
17
|
+
export const MISS_REPORT_SCHEMA = "diffci.enforce-misses.v1";
|
|
18
|
+
// ---------------------------------------------------------------------------------------------------
|
|
19
|
+
// JUnit (node:test's `--test-reporter=junit`, which also matches the common Jest/Vitest shape)
|
|
20
|
+
function decodeEntities(text) {
|
|
21
|
+
return text.replace(/&(#x[0-9a-f]+|#\d+|amp|lt|gt|quot|apos);/gi, (_, entity) => {
|
|
22
|
+
const lower = entity.toLowerCase();
|
|
23
|
+
if (lower.startsWith("#x"))
|
|
24
|
+
return String.fromCodePoint(Number.parseInt(lower.slice(2), 16));
|
|
25
|
+
if (lower.startsWith("#"))
|
|
26
|
+
return String.fromCodePoint(Number.parseInt(lower.slice(1), 10));
|
|
27
|
+
return { amp: "&", lt: "<", gt: ">", quot: '"', apos: "'" }[lower];
|
|
28
|
+
});
|
|
29
|
+
}
|
|
30
|
+
function attributes(source) {
|
|
31
|
+
const result = {};
|
|
32
|
+
for (const match of source.matchAll(/([\w:.-]+)\s*=\s*"([^"]*)"/g))
|
|
33
|
+
result[match[1]] = decodeEntities(match[2]);
|
|
34
|
+
return result;
|
|
35
|
+
}
|
|
36
|
+
/** Repository-relative with forward slashes; paths outside the repository stay absolute. */
|
|
37
|
+
export function normalizeTestPath(path, repoRoot) {
|
|
38
|
+
const slashed = path.replace(/\\/g, "/").replace(/^\.\//, "");
|
|
39
|
+
if (!slashed)
|
|
40
|
+
return "";
|
|
41
|
+
if (!isAbsolute(path))
|
|
42
|
+
return slashed;
|
|
43
|
+
const inside = relative(resolve(repoRoot), resolve(path));
|
|
44
|
+
return inside && !inside.startsWith("..") && !isAbsolute(inside) ? inside.replace(/\\/g, "/") : slashed;
|
|
45
|
+
}
|
|
46
|
+
/** Testcases in document order, named by their enclosing suites. Repeated ids are merged: any failure wins. */
|
|
47
|
+
export function parseJunit(xml, repoRoot) {
|
|
48
|
+
const byId = new Map();
|
|
49
|
+
const suites = [];
|
|
50
|
+
let current;
|
|
51
|
+
const finish = () => {
|
|
52
|
+
if (!current)
|
|
53
|
+
return;
|
|
54
|
+
const seen = byId.get(current.id);
|
|
55
|
+
if (seen) {
|
|
56
|
+
seen.failed ||= current.failed;
|
|
57
|
+
seen.skipped &&= current.skipped;
|
|
58
|
+
}
|
|
59
|
+
else
|
|
60
|
+
byId.set(current.id, current);
|
|
61
|
+
current = undefined;
|
|
62
|
+
};
|
|
63
|
+
// Attribute values may hold a raw `>` (failure messages), so the tag body skips over quoted strings.
|
|
64
|
+
const tags = /<(\/?)(testsuite|testcase|failure|error|skipped)\b((?:[^>"]|"[^"]*")*?)(\/?)>/g;
|
|
65
|
+
for (const [, closing, tag, body, selfClosing] of xml.matchAll(tags)) {
|
|
66
|
+
if (tag === "testsuite") {
|
|
67
|
+
if (closing)
|
|
68
|
+
suites.pop();
|
|
69
|
+
else if (!selfClosing)
|
|
70
|
+
suites.push(attributes(body).name ?? "");
|
|
71
|
+
}
|
|
72
|
+
else if (tag === "testcase") {
|
|
73
|
+
if (closing) {
|
|
74
|
+
finish();
|
|
75
|
+
continue;
|
|
76
|
+
}
|
|
77
|
+
finish();
|
|
78
|
+
const attrs = attributes(body);
|
|
79
|
+
const file = normalizeTestPath(attrs.file ?? "", repoRoot);
|
|
80
|
+
const name = [...suites, attrs.name ?? ""].filter(Boolean).join(" > ");
|
|
81
|
+
current = { id: `${file} > ${name}`, file, name, failed: attrs.failure !== undefined, skipped: false };
|
|
82
|
+
if (selfClosing)
|
|
83
|
+
finish();
|
|
84
|
+
}
|
|
85
|
+
else if (current && !closing) {
|
|
86
|
+
if (tag === "skipped")
|
|
87
|
+
current.skipped = true;
|
|
88
|
+
else
|
|
89
|
+
current.failed = true;
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
finish();
|
|
93
|
+
return [...byId.values()];
|
|
94
|
+
}
|
|
95
|
+
// ---------------------------------------------------------------------------------------------------
|
|
96
|
+
// Receipts
|
|
97
|
+
const TEST_FILE = /\.(?:test|spec)\.[cm]?[jt]sx?$/;
|
|
98
|
+
function normalizeSelected(path) {
|
|
99
|
+
return path.replace(/\\/g, "/").replace(/^\.\//, "");
|
|
100
|
+
}
|
|
101
|
+
/**
|
|
102
|
+
* The test files a `selected` receipt ran. Receipts from before `selected_tests` existed fall back to the
|
|
103
|
+
* test-file arguments of the command. `undefined` means the receipt does not say.
|
|
104
|
+
*/
|
|
105
|
+
export function selectedFiles(report) {
|
|
106
|
+
if (Array.isArray(report.selected_tests))
|
|
107
|
+
return new Set(report.selected_tests.map(normalizeSelected));
|
|
108
|
+
const fromCommand = (report.command ?? "")
|
|
109
|
+
.split(/\s+/)
|
|
110
|
+
.map((token) => normalizeSelected(token.replace(/^["']|["']$/g, "")))
|
|
111
|
+
.filter((token) => TEST_FILE.test(token));
|
|
112
|
+
return fromCommand.length > 0 ? new Set(fromCommand) : undefined;
|
|
113
|
+
}
|
|
114
|
+
function verdict(pr, file) {
|
|
115
|
+
const report = pr.receipt?.report;
|
|
116
|
+
if (!report)
|
|
117
|
+
return "no-receipt";
|
|
118
|
+
if (report.selection === "full")
|
|
119
|
+
return "ran-full";
|
|
120
|
+
if (report.selection !== "selected")
|
|
121
|
+
return "no-tests-run";
|
|
122
|
+
const files = selectedFiles(report);
|
|
123
|
+
if (!files)
|
|
124
|
+
return "selection-unrecorded";
|
|
125
|
+
return files.has(file) ? "selected" : "missed";
|
|
126
|
+
}
|
|
127
|
+
export function classifyFailures(input) {
|
|
128
|
+
const rerun = new Map((input.rerun ?? []).map((outcome) => [outcome.id, outcome]));
|
|
129
|
+
const baseline = new Set(input.baseline);
|
|
130
|
+
return input.fullRun
|
|
131
|
+
.filter((outcome) => outcome.failed)
|
|
132
|
+
.map((outcome) => {
|
|
133
|
+
const base = { id: outcome.id, file: outcome.file, name: outcome.name };
|
|
134
|
+
const again = rerun.get(outcome.id);
|
|
135
|
+
if (again && !again.failed && !again.skipped) {
|
|
136
|
+
return { ...base, classification: "flaky", pull_requests: [], detail: "passed when re-run" };
|
|
137
|
+
}
|
|
138
|
+
// Not found in the re-run (or no re-run at all) is treated as deterministic: "cannot tell" must
|
|
139
|
+
// never be what keeps a miss from being counted.
|
|
140
|
+
const rerunNote = !input.rerun ? "not re-run" : again ? "failed again when re-run" : "absent from the re-run";
|
|
141
|
+
if (baseline.has(outcome.id)) {
|
|
142
|
+
return { ...base, classification: "pre-existing", pull_requests: [], detail: `already failing at the start of the window; ${rerunNote}` };
|
|
143
|
+
}
|
|
144
|
+
const pullRequests = input.pullRequests.map((pr) => ({
|
|
145
|
+
number: pr.number,
|
|
146
|
+
verdict: verdict(pr, outcome.file),
|
|
147
|
+
...(pr.receipt ? { artifact: pr.receipt.artifact } : {}),
|
|
148
|
+
}));
|
|
149
|
+
const skippedBy = pullRequests.filter((pr) => pr.verdict === "missed" || pr.verdict === "selection-unrecorded");
|
|
150
|
+
if (skippedBy.length > 0) {
|
|
151
|
+
return {
|
|
152
|
+
...base,
|
|
153
|
+
classification: "miss",
|
|
154
|
+
pull_requests: pullRequests,
|
|
155
|
+
detail: `${rerunNote}; not selected by ${skippedBy.map((pr) => `#${pr.number}`).join(", ")}`,
|
|
156
|
+
};
|
|
157
|
+
}
|
|
158
|
+
if (pullRequests.every((pr) => pr.verdict === "no-receipt" || pr.verdict === "no-tests-run")) {
|
|
159
|
+
return { ...base, classification: "unattributed", pull_requests: pullRequests, detail: `${rerunNote}; no merged pull request in the window ran or skipped it` };
|
|
160
|
+
}
|
|
161
|
+
return { ...base, classification: "covered", pull_requests: pullRequests, detail: `${rerunNote}; every pull request with a receipt ran it` };
|
|
162
|
+
});
|
|
163
|
+
}
|
|
164
|
+
export function unsafeMissEntries(failures, context) {
|
|
165
|
+
return failures
|
|
166
|
+
.filter((failure) => failure.classification === "miss")
|
|
167
|
+
.flatMap((failure) => failure.pull_requests
|
|
168
|
+
.filter((pr) => pr.verdict === "missed" || pr.verdict === "selection-unrecorded")
|
|
169
|
+
.map((pr) => ({
|
|
170
|
+
test: failure.id,
|
|
171
|
+
pullRequest: pr.number,
|
|
172
|
+
receipt: pr.artifact ?? null,
|
|
173
|
+
mainSha: context.headSha,
|
|
174
|
+
detectedAt: context.detectedAt,
|
|
175
|
+
...(context.runUrl ? { run: context.runUrl } : {}),
|
|
176
|
+
})));
|
|
177
|
+
}
|
|
178
|
+
export function buildMissReport(input) {
|
|
179
|
+
const failures = classifyFailures(input);
|
|
180
|
+
const open = unsafeMissEntries(failures, { headSha: input.headSha, detectedAt: input.producedAt, runUrl: input.runUrl });
|
|
181
|
+
return {
|
|
182
|
+
schema: MISS_REPORT_SCHEMA,
|
|
183
|
+
produced_at: input.producedAt,
|
|
184
|
+
head_sha: input.headSha,
|
|
185
|
+
...(input.runUrl ? { run_url: input.runUrl } : {}),
|
|
186
|
+
full_suite: input.fullRun.some((outcome) => outcome.failed) ? "failed" : "passed",
|
|
187
|
+
rerun: input.rerun ? "done" : "not-run",
|
|
188
|
+
window: input.window,
|
|
189
|
+
pull_requests: input.pullRequests.map((pr) => ({
|
|
190
|
+
number: pr.number,
|
|
191
|
+
merge_sha: pr.mergeSha,
|
|
192
|
+
head_sha: pr.headSha,
|
|
193
|
+
receipt: pr.receipt?.artifact ?? null,
|
|
194
|
+
selection: pr.receipt?.report.selection ?? null,
|
|
195
|
+
})),
|
|
196
|
+
deterministic_failures: failures.filter((failure) => failure.classification !== "flaky").map((failure) => failure.id),
|
|
197
|
+
failures,
|
|
198
|
+
misses: failures.filter((failure) => failure.classification === "miss").length,
|
|
199
|
+
open_unsafe_misses: open,
|
|
200
|
+
notes: input.notes ?? [],
|
|
201
|
+
};
|
|
202
|
+
}
|
|
203
|
+
const CLASS_ORDER = ["miss", "unattributed", "pre-existing", "covered", "flaky"];
|
|
204
|
+
export function formatMissReportMarkdown(report) {
|
|
205
|
+
const lines = [
|
|
206
|
+
report.misses > 0 ? `# DiffCI enforce: ${report.misses} unsafe miss(es) on main` : "# DiffCI enforce: no misses on main",
|
|
207
|
+
"",
|
|
208
|
+
`- main: \`${report.head_sha}\`${report.run_url ? ` ([run](${report.run_url}))` : ""}`,
|
|
209
|
+
`- full suite: ${report.full_suite}; re-run of failures: ${report.rerun}`,
|
|
210
|
+
`- window: ${report.window.from_sha ? `\`${report.window.from_sha.slice(0, 12)}..${report.head_sha.slice(0, 12)}\`` : "none found"} (${report.window.source})`,
|
|
211
|
+
`- merged pull requests: ${report.pull_requests.length === 0 ? "none" : report.pull_requests.map((pr) => `#${pr.number} (${pr.selection ?? "no receipt"})`).join(", ")}`,
|
|
212
|
+
];
|
|
213
|
+
for (const note of report.notes)
|
|
214
|
+
lines.push(`- note: ${note}`);
|
|
215
|
+
for (const classification of CLASS_ORDER) {
|
|
216
|
+
const group = report.failures.filter((failure) => failure.classification === classification);
|
|
217
|
+
if (group.length === 0)
|
|
218
|
+
continue;
|
|
219
|
+
lines.push("", `## ${classification} (${group.length})`, "");
|
|
220
|
+
for (const failure of group) {
|
|
221
|
+
const prs = failure.pull_requests.map((pr) => `#${pr.number}: ${pr.verdict}`).join(", ");
|
|
222
|
+
lines.push(`- \`${failure.id}\` - ${failure.detail}${prs ? ` [${prs}]` : ""}`);
|
|
223
|
+
}
|
|
224
|
+
}
|
|
225
|
+
if (report.open_unsafe_misses.length > 0) {
|
|
226
|
+
lines.push("", "## What to do", "", "Enforce mode must stop skipping tests until a human has looked at this. Add these entries to", "`enforce.openUnsafeMisses` in `diffci.config.json` (fallback 4 then forces the full suite), and turn", "the `DIFFCI_ENFORCE` repository variable off if enforcement is live. Nothing was changed automatically;", "clearing the entries is the deliberate step that re-enables enforcement.", "", "```json", JSON.stringify(report.open_unsafe_misses, null, 2), "```");
|
|
227
|
+
}
|
|
228
|
+
return `${lines.join("\n")}\n`;
|
|
229
|
+
}
|
|
@@ -0,0 +1,169 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Enforce mode, Level 1 (docs/enforce-mode-01-plan.md, step 1).
|
|
3
|
+
*
|
|
4
|
+
* Shadow mode only predicts. Enforce mode lets `diffci verify` run the selected tests INSTEAD of the
|
|
5
|
+
* full suite - so every way the selection could be wrong has to be answered here with "run FULL", never
|
|
6
|
+
* with "run less". The checks are ordered: repository-level conditions first (is enforcement on at all,
|
|
7
|
+
* approved, not demoted), then per-run conditions (is this range and this analysis trustworthy). The
|
|
8
|
+
* first one that fires is recorded in the receipt; nothing after it is evaluated.
|
|
9
|
+
*
|
|
10
|
+
* `evaluateEnforcement` is pure. Everything that touches git, the event payload or the environment is
|
|
11
|
+
* in `collectEnforcementContext`, so each fallback can be tested without a repository.
|
|
12
|
+
*/
|
|
13
|
+
import { extname } from "node:path";
|
|
14
|
+
import { readEventPayload } from "./context.js";
|
|
15
|
+
/** The only policy shape this CLI understands. A newer or older `enforce` block falls back to FULL. */
|
|
16
|
+
export const ENFORCE_POLICY_VERSION = 1;
|
|
17
|
+
export const FORCE_FULL_LABEL = "diffci:force-full";
|
|
18
|
+
export const ENFORCE_VARIABLE = "DIFFCI_ENFORCE";
|
|
19
|
+
/**
|
|
20
|
+
* Paths whose change can affect every test without appearing in the import graph. The analyzer already
|
|
21
|
+
* falls back for many of these; enforce mode lists them again because here a gap costs a missed failure,
|
|
22
|
+
* not a mis-scored prediction.
|
|
23
|
+
*/
|
|
24
|
+
const GLOBAL_RISK_PATTERNS = [
|
|
25
|
+
/^\.github\//,
|
|
26
|
+
/(?:^|\/)package\.json$/,
|
|
27
|
+
/(?:^|\/)(?:package-lock\.json|npm-shrinkwrap\.json|pnpm-lock\.yaml|pnpm-workspace\.yaml|yarn\.lock|bun\.lockb?)$/,
|
|
28
|
+
/(?:^|\/)\.(?:npmrc|nvmrc|node-version|tool-versions)$/,
|
|
29
|
+
/(?:^|\/)tsconfig(?:\.[^/]+)?\.json$/,
|
|
30
|
+
/(?:^|\/)(?:jest|vitest|vite|playwright|cypress|mocha|ava|karma|babel)\.config\.[^/]+$/,
|
|
31
|
+
/(?:^|\/)\.(?:mocharc|babelrc)(?:\.[^/]+)?$/,
|
|
32
|
+
/(?:^|\/)diffci(?:\.config)?\.json$/,
|
|
33
|
+
];
|
|
34
|
+
const DOC_DIRECTORIES = ["docs", "doc", "documentation"];
|
|
35
|
+
/** Same rule as RepositoryLayout.isDocumentationPath, without needing a repository profile. */
|
|
36
|
+
function isDocumentationPath(path) {
|
|
37
|
+
const ext = extname(path).toLowerCase();
|
|
38
|
+
if (ext === ".md" || ext === ".mdx")
|
|
39
|
+
return true;
|
|
40
|
+
const first = path.split("/")[0];
|
|
41
|
+
return first !== undefined && DOC_DIRECTORIES.includes(first.toLowerCase());
|
|
42
|
+
}
|
|
43
|
+
function policyProblem(policy) {
|
|
44
|
+
if (policy === undefined)
|
|
45
|
+
return "diffci.config.json at the range base has no `enforce` block";
|
|
46
|
+
if (policy === null || typeof policy !== "object" || Array.isArray(policy))
|
|
47
|
+
return "`enforce` must be an object";
|
|
48
|
+
const block = policy;
|
|
49
|
+
if (block.policyVersion !== ENFORCE_POLICY_VERSION) {
|
|
50
|
+
return `enforce.policyVersion is ${JSON.stringify(block.policyVersion)}; this DiffCI supports ${ENFORCE_POLICY_VERSION}`;
|
|
51
|
+
}
|
|
52
|
+
if (block.level !== 1)
|
|
53
|
+
return `enforce.level is ${JSON.stringify(block.level)}; only level 1 is implemented`;
|
|
54
|
+
if (typeof block.approvedBy !== "string" || block.approvedBy.trim() === "")
|
|
55
|
+
return "enforce.approvedBy is missing";
|
|
56
|
+
if (typeof block.approvedAt !== "string" || Number.isNaN(Date.parse(block.approvedAt)))
|
|
57
|
+
return "enforce.approvedAt is not a date";
|
|
58
|
+
if (block.openUnsafeMisses !== undefined && !Array.isArray(block.openUnsafeMisses))
|
|
59
|
+
return "enforce.openUnsafeMisses must be an array";
|
|
60
|
+
return undefined;
|
|
61
|
+
}
|
|
62
|
+
function openMisses(policy) {
|
|
63
|
+
const misses = policy.openUnsafeMisses;
|
|
64
|
+
return Array.isArray(misses) ? misses : [];
|
|
65
|
+
}
|
|
66
|
+
/** Matches a `DiffCI: full` trailer line anywhere in the head commit message. */
|
|
67
|
+
export function hasForceFullTrailer(message) {
|
|
68
|
+
return message !== undefined && /^diffci:\s*full\s*$/im.test(message);
|
|
69
|
+
}
|
|
70
|
+
export function evaluateEnforcement(context, observation) {
|
|
71
|
+
const decide = (fired, detail) => ({
|
|
72
|
+
policy: "enforce",
|
|
73
|
+
policy_version: ENFORCE_POLICY_VERSION,
|
|
74
|
+
fired_fallback: fired,
|
|
75
|
+
detail,
|
|
76
|
+
});
|
|
77
|
+
if (context.killSwitch !== "on")
|
|
78
|
+
return decide("kill-switch", `${ENFORCE_VARIABLE} is not "on"`);
|
|
79
|
+
if (context.pullRequestLabels.includes(FORCE_FULL_LABEL))
|
|
80
|
+
return decide("per-run-override", `pull request is labelled ${FORCE_FULL_LABEL}`);
|
|
81
|
+
if (hasForceFullTrailer(context.headCommitMessage))
|
|
82
|
+
return decide("per-run-override", "head commit carries a `DiffCI: full` trailer");
|
|
83
|
+
const problem = policyProblem(context.policy);
|
|
84
|
+
if (problem)
|
|
85
|
+
return decide("policy-not-approved", problem);
|
|
86
|
+
const misses = openMisses(context.policy);
|
|
87
|
+
if (misses.length > 0)
|
|
88
|
+
return decide("open-unsafe-miss", `${misses.length} unsafe miss(es) recorded and not yet cleared`);
|
|
89
|
+
if (!context.range.trusted)
|
|
90
|
+
return decide("untrusted-range", context.range.reason);
|
|
91
|
+
const result = observation.result;
|
|
92
|
+
if (observation.status !== "OBSERVED" || !result) {
|
|
93
|
+
return decide("analysis-failure", observation.reason ?? `analysis status ${observation.status}`);
|
|
94
|
+
}
|
|
95
|
+
const confidence = result.graph.effectiveConfidence ?? result.graph.confidence;
|
|
96
|
+
if (confidence !== "COMPLETE")
|
|
97
|
+
return decide("graph-confidence", `effective graph confidence is ${confidence}, not COMPLETE`);
|
|
98
|
+
if (context.pathsRedacted)
|
|
99
|
+
return decide("global-risk", "changed paths are redacted, so global-risk paths cannot be checked");
|
|
100
|
+
const critical = result.riskSignals.find((signal) => signal.level === "critical");
|
|
101
|
+
if (critical)
|
|
102
|
+
return decide("global-risk", `critical risk signal: ${critical.reason}`);
|
|
103
|
+
if (result.mode === "FULL")
|
|
104
|
+
return decide("global-risk", `analyzer required full validation: ${result.fallbackReasons[0] ?? "no reason given"}`);
|
|
105
|
+
const risky = result.changedFiles.find((path) => GLOBAL_RISK_PATTERNS.some((pattern) => pattern.test(path)));
|
|
106
|
+
if (risky)
|
|
107
|
+
return decide("global-risk", `global-risk path changed: ${risky}`);
|
|
108
|
+
if (result.selectedTests.length === 0 && result.changedFiles.some((path) => !isDocumentationPath(path))) {
|
|
109
|
+
return decide("empty-selection", "source files changed but no tests were selected");
|
|
110
|
+
}
|
|
111
|
+
return decide(null, "every enforce check passed");
|
|
112
|
+
}
|
|
113
|
+
function git(runner, args) {
|
|
114
|
+
const result = runner(args);
|
|
115
|
+
return result.ok ? result.stdout : undefined;
|
|
116
|
+
}
|
|
117
|
+
function rangeTrust(runner, range) {
|
|
118
|
+
if (!range)
|
|
119
|
+
return { trusted: false, reason: "no commit range was resolved" };
|
|
120
|
+
// A head-parent range covers one commit, not the whole push or branch it stands in for.
|
|
121
|
+
if (range.source === "head-parent")
|
|
122
|
+
return { trusted: false, reason: "range is the head commit's parent, not the full push" };
|
|
123
|
+
if (git(runner, ["rev-parse", "--is-shallow-repository"])?.trim() !== "false") {
|
|
124
|
+
return { trusted: false, reason: "checkout is shallow; use fetch-depth: 0" };
|
|
125
|
+
}
|
|
126
|
+
// Force-pushes leave `before` off the new history; a diff from it is not "what this push changed".
|
|
127
|
+
if (git(runner, ["merge-base", "--is-ancestor", range.baseSha, range.headSha]) === undefined) {
|
|
128
|
+
return { trusted: false, reason: `base ${range.baseSha.slice(0, 12)} is not an ancestor of head ${range.headSha.slice(0, 12)}` };
|
|
129
|
+
}
|
|
130
|
+
return { trusted: true };
|
|
131
|
+
}
|
|
132
|
+
function policyAtBase(runner, range) {
|
|
133
|
+
if (!range)
|
|
134
|
+
return undefined;
|
|
135
|
+
const text = git(runner, ["show", `${range.baseSha}:diffci.config.json`]);
|
|
136
|
+
if (text === undefined)
|
|
137
|
+
return undefined;
|
|
138
|
+
try {
|
|
139
|
+
const parsed = JSON.parse(text);
|
|
140
|
+
return parsed !== null && typeof parsed === "object" ? parsed.enforce : undefined;
|
|
141
|
+
}
|
|
142
|
+
catch {
|
|
143
|
+
return undefined;
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
function pullRequestLabels(env) {
|
|
147
|
+
const payload = readEventPayload(env);
|
|
148
|
+
const pullRequest = payload?.pull_request;
|
|
149
|
+
if (pullRequest === null || typeof pullRequest !== "object")
|
|
150
|
+
return [];
|
|
151
|
+
const labels = pullRequest.labels;
|
|
152
|
+
if (!Array.isArray(labels))
|
|
153
|
+
return [];
|
|
154
|
+
return labels.flatMap((label) => {
|
|
155
|
+
const name = label !== null && typeof label === "object" ? label.name : undefined;
|
|
156
|
+
return typeof name === "string" ? [name] : [];
|
|
157
|
+
});
|
|
158
|
+
}
|
|
159
|
+
export function collectEnforcementContext(runner, env, observation) {
|
|
160
|
+
const range = observation.commitRange;
|
|
161
|
+
return {
|
|
162
|
+
killSwitch: env[ENFORCE_VARIABLE],
|
|
163
|
+
pullRequestLabels: pullRequestLabels(env),
|
|
164
|
+
headCommitMessage: range ? git(runner, ["log", "-1", "--format=%B", range.headSha]) : undefined,
|
|
165
|
+
policy: policyAtBase(runner, range),
|
|
166
|
+
range: rangeTrust(runner, range),
|
|
167
|
+
pathsRedacted: observation.payload.pathRedaction !== undefined,
|
|
168
|
+
};
|
|
169
|
+
}
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
import { spawnSync } from "node:child_process";
|
|
2
|
+
import { existsSync, lstatSync, mkdtempSync, readFileSync, rmdirSync, rmSync, symlinkSync, unlinkSync } from "node:fs";
|
|
3
|
+
import { tmpdir } from "node:os";
|
|
4
|
+
import { join } from "node:path";
|
|
5
|
+
import { measureCommands } from "./command-batches.js";
|
|
6
|
+
const DEPENDENCY_FILES = ["package.json", "package-lock.json", "npm-shrinkwrap.json", "pnpm-lock.yaml", "yarn.lock", "bun.lock", "bun.lockb"];
|
|
7
|
+
/** Test names a runner reported as failing: node:test spec and TAP, Vitest and Jest. */
|
|
8
|
+
export function failingTestNames(output) {
|
|
9
|
+
const names = new Set();
|
|
10
|
+
for (const raw of output.split(/\r?\n/)) {
|
|
11
|
+
const line = raw.replace(/\x1b\[[0-9;]*m/g, "");
|
|
12
|
+
const spec = /^\s*✖\s+(.+?)\s+\(\d+(?:\.\d+)?m?s\)\s*$/.exec(line);
|
|
13
|
+
const tap = /^\s*not ok \d+ - (.+?)\s*(?:#.*)?$/.exec(line);
|
|
14
|
+
const vitest = /^\s*(?:FAIL|×)\s+(.+?)(?:\s+\d+(?:\.\d+)?m?s)?\s*$/.exec(line);
|
|
15
|
+
const jest = /^\s*●\s+(.+›.+?)\s*$/.exec(line);
|
|
16
|
+
const name = (spec ?? tap ?? vitest ?? jest)?.[1]?.trim();
|
|
17
|
+
if (name && !/^failing tests:?$/i.test(name))
|
|
18
|
+
names.add(name);
|
|
19
|
+
}
|
|
20
|
+
return [...names].sort();
|
|
21
|
+
}
|
|
22
|
+
function declaresDependencies(repoPath) {
|
|
23
|
+
try {
|
|
24
|
+
const pkg = JSON.parse(readFileSync(join(repoPath, "package.json"), "utf8"));
|
|
25
|
+
return ["dependencies", "devDependencies", "optionalDependencies"].some((field) => Object.keys(pkg[field] ?? {}).length > 0);
|
|
26
|
+
}
|
|
27
|
+
catch {
|
|
28
|
+
return existsSync(join(repoPath, "package.json"));
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
function git(repoPath, args) {
|
|
32
|
+
return spawnSync("git", args, { cwd: repoPath, encoding: "buffer", maxBuffer: 1024 * 1024 * 1024 });
|
|
33
|
+
}
|
|
34
|
+
export function compareWithBaseline(input) {
|
|
35
|
+
const report = (status, reason, extra = {}) => ({
|
|
36
|
+
status, base_sha: input.baseSha, reason, failing_at_head: input.headFailures.length, preexisting: [], introduced: [], ...extra,
|
|
37
|
+
});
|
|
38
|
+
if (input.headFailures.length === 0)
|
|
39
|
+
return report("unknown", "no failing test names could be identified in the verification output");
|
|
40
|
+
const changedDependencies = git(input.repoPath, ["diff", "--quiet", input.baseSha, input.headSha, "--", ...DEPENDENCY_FILES]);
|
|
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");
|
|
58
|
+
const execution = measureCommands(input.commands, { cwd: directory, timeoutMs: input.timeoutMs, tailBytes: 0 });
|
|
59
|
+
const baseExecution = { exit_code: execution.exitCode, wall_ms: execution.wallMs, timed_out: execution.timedOut };
|
|
60
|
+
if (execution.timedOut)
|
|
61
|
+
return report("unknown", "the base run timed out", { base_execution: baseExecution });
|
|
62
|
+
const atBase = new Set(execution.failingTests ?? []);
|
|
63
|
+
if (execution.exitCode === 0) {
|
|
64
|
+
return report("introduced", "the same command passes at the base commit", { failing_at_base: 0, introduced: input.headFailures.slice(0, 20), base_execution: baseExecution });
|
|
65
|
+
}
|
|
66
|
+
const preexisting = input.headFailures.filter((name) => atBase.has(name));
|
|
67
|
+
const introduced = input.headFailures.filter((name) => !atBase.has(name));
|
|
68
|
+
const status = introduced.length === 0 ? "preexisting" : preexisting.length === 0 ? "introduced" : "mixed";
|
|
69
|
+
const reason = status === "preexisting"
|
|
70
|
+
? `all ${preexisting.length} failing test(s) also fail at the base commit`
|
|
71
|
+
: status === "introduced"
|
|
72
|
+
? `none of the ${introduced.length} failing test(s) fail at the base commit`
|
|
73
|
+
: `${introduced.length} failing test(s) are new; ${preexisting.length} also fail at the base commit`;
|
|
74
|
+
return report(status, reason, { failing_at_base: atBase.size, preexisting: preexisting.slice(0, 20), introduced: introduced.slice(0, 20), base_execution: baseExecution });
|
|
75
|
+
}
|
|
76
|
+
catch (error) {
|
|
77
|
+
return report("unknown", `the base run could not be prepared: ${error instanceof Error ? error.message : String(error)}`);
|
|
78
|
+
}
|
|
79
|
+
finally {
|
|
80
|
+
// Remove the dependency link itself first, so cleanup can never descend into the real node_modules.
|
|
81
|
+
let linked = false;
|
|
82
|
+
try {
|
|
83
|
+
if (lstatSync(link, { throwIfNoEntry: false })) {
|
|
84
|
+
try {
|
|
85
|
+
unlinkSync(link);
|
|
86
|
+
}
|
|
87
|
+
catch {
|
|
88
|
+
rmdirSync(link);
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
catch {
|
|
93
|
+
linked = true;
|
|
94
|
+
}
|
|
95
|
+
// If the link could not be removed, leave the temporary directory rather than risk the real one.
|
|
96
|
+
if (!linked)
|
|
97
|
+
rmSync(directory, { recursive: true, force: true });
|
|
98
|
+
}
|
|
99
|
+
}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { mkdirSync, readFileSync, writeFileSync } from "node:fs";
|
|
2
|
+
import { dirname, join } from "node:path";
|
|
3
|
+
import { preferencePath } from "./telemetry.js";
|
|
4
|
+
/** Interactive runs only; CI, agents and machine-readable output never see it. At most once a week. */
|
|
5
|
+
const INTERVAL_MS = 7 * 24 * 60 * 60 * 1000;
|
|
6
|
+
function stampPath(env) {
|
|
7
|
+
return join(dirname(preferencePath(env)), "feedback-prompt.json");
|
|
8
|
+
}
|
|
9
|
+
export function shouldShowFeedbackPrompt(flags, env, interactive, now = Date.now()) {
|
|
10
|
+
if (!interactive || flags.json === true || flags.quiet === true)
|
|
11
|
+
return false;
|
|
12
|
+
if (env.CI || env.GITHUB_ACTIONS || env.DIFFCI_MCP === "1" || env.DIFFCI_NO_FEEDBACK_PROMPT === "1")
|
|
13
|
+
return false;
|
|
14
|
+
try {
|
|
15
|
+
const last = JSON.parse(readFileSync(stampPath(env), "utf8")).shownAt;
|
|
16
|
+
if (typeof last === "number" && now - last < INTERVAL_MS)
|
|
17
|
+
return false;
|
|
18
|
+
}
|
|
19
|
+
catch { /* Never shown, or unreadable: show it. */ }
|
|
20
|
+
return true;
|
|
21
|
+
}
|
|
22
|
+
export function formatFeedbackPrompt(telemetry) {
|
|
23
|
+
const lines = [
|
|
24
|
+
"",
|
|
25
|
+
"Using DiffCI on a real repository? We read every reply:",
|
|
26
|
+
" tell us how it went: https://github.com/DiffCI/core/discussions",
|
|
27
|
+
" volunteer a pilot: https://diffci.com/#pilot",
|
|
28
|
+
" star the engine: https://github.com/DiffCI/core",
|
|
29
|
+
];
|
|
30
|
+
if (telemetry === "off")
|
|
31
|
+
lines.push(" share anonymous run counts: diffci telemetry --mode anonymous (no repository content)");
|
|
32
|
+
lines.push("Shown at most weekly; DIFFCI_NO_FEEDBACK_PROMPT=1 hides it.");
|
|
33
|
+
return lines.join("\n");
|
|
34
|
+
}
|
|
35
|
+
export function markFeedbackPromptShown(env, now = Date.now()) {
|
|
36
|
+
try {
|
|
37
|
+
const path = stampPath(env);
|
|
38
|
+
mkdirSync(dirname(path), { recursive: true });
|
|
39
|
+
writeFileSync(path, `${JSON.stringify({ shownAt: now })}\n`, { encoding: "utf8", mode: 0o600 });
|
|
40
|
+
}
|
|
41
|
+
catch { /* A read-only home only means the prompt may repeat. */ }
|
|
42
|
+
}
|
|
@@ -53,7 +53,7 @@ const tools = [
|
|
|
53
53
|
},
|
|
54
54
|
{
|
|
55
55
|
name: "diffci_check",
|
|
56
|
-
description: "Analyze the repository, run inferred full and selected test commands when available, and report paired runtime.
|
|
56
|
+
description: "Analyze the repository, run inferred full and selected test commands when available, and report paired runtime. No report is uploaded. Optional aggregate telemetry follows the user's saved consent; DIFFCI_NO_SEND=1 overrides it.",
|
|
57
57
|
inputSchema: {
|
|
58
58
|
type: "object",
|
|
59
59
|
properties: {
|
|
@@ -28,7 +28,7 @@ import { OBSERVATION_SCHEMA, readTypeScriptProgramMetrics, redactPath, } from ".
|
|
|
28
28
|
import { auditWorkflows } from "./workflow-guard.js";
|
|
29
29
|
/** Build output and dependencies are never sources of truth about a repository's own structure. */
|
|
30
30
|
const EXCLUDE_DIRS = ["node_modules", ".next", "dist", "build"];
|
|
31
|
-
function makeGitRunner(repoPath) {
|
|
31
|
+
export function makeGitRunner(repoPath) {
|
|
32
32
|
return (args) => {
|
|
33
33
|
try {
|
|
34
34
|
const stdout = execFileSync("git", args, {
|
|
@@ -163,8 +163,8 @@ export async function observe(options) {
|
|
|
163
163
|
if (economics.decision === "BYPASS_FULL")
|
|
164
164
|
return finish("REFUSED", "eligibility", { reason: `ECONOMICS_FULL_BYPASS: ${economics.reason}. No selective command is authorized.` });
|
|
165
165
|
}
|
|
166
|
-
const [{ analyzeGitDelta }, { classifyRepositoryProject, buildDependencyGraph }, { ImpactAnalyzer }, { runPathBaseline }, { commandSpecToString, planSelectiveTestCommands }] = await Promise.all([
|
|
167
|
-
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"),
|
|
166
|
+
const [{ analyzeGitDelta }, { classifyRepositoryProject, buildDependencyGraph }, { ImpactAnalyzer }, { runPathBaseline }, { commandSpecToString, planSelectiveTestCommands }, { repositoryFileReader }] = await Promise.all([
|
|
167
|
+
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
168
|
]);
|
|
169
169
|
markPhase("engineLoad");
|
|
170
170
|
// The eligibility gate is asked of the graph builder itself (classifyRepositoryProject), not of a
|
|
@@ -193,6 +193,7 @@ export async function observe(options) {
|
|
|
193
193
|
const profile = graphResult.profile;
|
|
194
194
|
const impact = new ImpactAnalyzer().analyze(delta, graphResult, profile, {
|
|
195
195
|
repositoryFiles: deltaResult.inventory?.files,
|
|
196
|
+
readRepositoryFile: repositoryFileReader(repoPath),
|
|
196
197
|
});
|
|
197
198
|
const baseline = runPathBaseline(profile.testFilePaths, delta.files, profile);
|
|
198
199
|
const selectedTests = impact.affectedTests.map((test) => test.path).sort();
|
|
@@ -202,6 +203,8 @@ export async function observe(options) {
|
|
|
202
203
|
const commandPlan = impact.fallbackRequired
|
|
203
204
|
? undefined
|
|
204
205
|
: planSelectiveTestCommands(profile, selectedTests);
|
|
206
|
+
const outsideSuite = (impact.testsOutsideFullSuite ?? []).map((test) => test.path).sort();
|
|
207
|
+
const outsidePlan = outsideSuite.length ? planSelectiveTestCommands(profile, outsideSuite) : undefined;
|
|
205
208
|
markPhase("impactAndCommands");
|
|
206
209
|
return finish("OBSERVED", "complete", {
|
|
207
210
|
result: {
|
|
@@ -210,7 +213,12 @@ export async function observe(options) {
|
|
|
210
213
|
changedFiles: delta.files.map((file) => hashPath(file.path)),
|
|
211
214
|
affectedSourceFileCount: impact.affectedSourceFiles.length,
|
|
212
215
|
selectedTests: selectedTests.map(hashPath),
|
|
213
|
-
totalTestCount: profile.testFilePaths.length,
|
|
216
|
+
totalTestCount: impact.fullSuiteTestCount ?? profile.testFilePaths.length,
|
|
217
|
+
discoveredTestCount: profile.testFilePaths.length,
|
|
218
|
+
...(outsideSuite.length ? {
|
|
219
|
+
testsOutsideFullSuite: outsideSuite.map(hashPath),
|
|
220
|
+
outsideSuiteCommands: outsidePlan?.refusalReason ? [] : (outsidePlan?.commands ?? []).map(commandSpecToString),
|
|
221
|
+
} : {}),
|
|
214
222
|
fallbackReasons: impact.fallbackReasons,
|
|
215
223
|
proposedCommands: (commandPlan?.commands ?? []).map(commandSpecToString),
|
|
216
224
|
workspaceCommands: Boolean(profile.workspaceTestPackages?.length),
|
|
@@ -1,40 +1,9 @@
|
|
|
1
|
-
const CHECKOUT_SHA = "3d3c42e5aac5ba805825da76410c181273ba90b1";
|
|
2
|
-
const SETUP_NODE_SHA = "820762786026740c76f36085b0efc47a31fe5020";
|
|
3
|
-
const UPLOAD_ARTIFACT_SHA = "043fb46d1a93c77aae656e7c1c64a875d1fc6a0a";
|
|
4
1
|
function text(value) {
|
|
5
2
|
return value?.trim() || "not reported";
|
|
6
3
|
}
|
|
7
4
|
function bullets(values, empty) {
|
|
8
5
|
return values.length > 0 ? values.map((value) => `- ${value}`).join("\n") : `- ${empty}`;
|
|
9
6
|
}
|
|
10
|
-
export function buildPilotWorkflow(version) {
|
|
11
|
-
return `name: DiffCI pilot observation
|
|
12
|
-
on: [pull_request]
|
|
13
|
-
permissions:
|
|
14
|
-
contents: read
|
|
15
|
-
jobs:
|
|
16
|
-
diffci-pilot:
|
|
17
|
-
name: DiffCI pilot (non-blocking)
|
|
18
|
-
runs-on: ubuntu-24.04
|
|
19
|
-
continue-on-error: true
|
|
20
|
-
steps:
|
|
21
|
-
- uses: actions/checkout@${CHECKOUT_SHA} # immutable checkout pin
|
|
22
|
-
with:
|
|
23
|
-
fetch-depth: 0
|
|
24
|
-
- uses: actions/setup-node@${SETUP_NODE_SHA} # immutable setup-node pin
|
|
25
|
-
with:
|
|
26
|
-
node-version: 22
|
|
27
|
-
- name: Observe only
|
|
28
|
-
run: npx "@diffci.com/diffci@${version}" observe --no-send --out "$RUNNER_TEMP/diffci-observe.json"
|
|
29
|
-
- name: Upload local observation
|
|
30
|
-
if: always()
|
|
31
|
-
uses: actions/upload-artifact@${UPLOAD_ARTIFACT_SHA} # immutable upload-artifact v7 pin
|
|
32
|
-
with:
|
|
33
|
-
name: diffci-observation-\${{ github.run_id }}-\${{ github.run_attempt }}
|
|
34
|
-
path: \${{ runner.temp }}/diffci-observe.json
|
|
35
|
-
if-no-files-found: warn
|
|
36
|
-
`;
|
|
37
|
-
}
|
|
38
7
|
export function renderPilotPacket(report, options) {
|
|
39
8
|
const result = report.result;
|
|
40
9
|
const range = report.commitRange;
|