Skip to content

Commit fac1521

Browse files
committed
Merge remote-tracking branch 'origin/dev' into merge953
# Conflicts: # tests/responses-compaction-routing.test.ts
2 parents 9664abd + d086a54 commit fac1521

179 files changed

Lines changed: 23953 additions & 1035 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

‎.github/PULL_REQUEST_TEMPLATE.md‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
## Verification
66

77
- List the commands or checks you ran.
8+
- If this PR changes the GUI, include a screenshot of the UI change in the description.
89

910
## Checklist
1011

‎.github/scripts/enforce-pr-target.test.cjs‎

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -48,11 +48,17 @@ describe("enforce-pr-target workflow", () => {
4848
assert.match(workflow, /synchronize/);
4949
});
5050

51-
it("checks out trusted default-branch scripts only (never PR head)", () => {
52-
assert.match(workflow, /actions\/checkout@[0-9a-f]{40}/);
53-
assert.match(workflow, /ref:\s*\$\{\{\s*github\.event\.repository\.default_branch\s*\}\}/);
54-
assert.match(workflow, /sparse-checkout:\s*\.github\/scripts/);
55-
assert.match(workflow, /persist-credentials:\s*false/);
51+
it("checks out trusted base-branch scripts only (never PR head)", () => {
52+
// Scope the assertions to the checkout step itself, so a stray `ref:` on
53+
// another step cannot satisfy the pin while the checkout stays mutable.
54+
const checkoutStep = workflow
55+
.split("- name: Checkout trusted PR-quality scripts")[1]
56+
.split(/\n {6}- name:/)[0];
57+
assert.match(checkoutStep, /actions\/checkout@[0-9a-f]{40}/);
58+
assert.match(checkoutStep, /ref:\s*\$\{\{\s*github\.event\.pull_request\.base\.sha\s*\}\}/);
59+
// The readiness ping reads MAINTAINERS.md from the same trusted checkout.
60+
assert.match(checkoutStep, /sparse-checkout:\s*\|\s*\n\s*\.github\/scripts\n\s*MAINTAINERS\.md/);
61+
assert.match(checkoutStep, /persist-credentials:\s*false/);
5662
assert.doesNotMatch(workflow, /ref:\s*\$\{\{\s*github\.event\.pull_request\.head/);
5763
});
5864

@@ -75,9 +81,9 @@ describe("enforce-pr-target workflow", () => {
7581

7682
it("strips stale WRONG BRANCH prefix on failure when base is corrected", () => {
7783
const failureBlock = workflow.match(
78-
/if \(failures\.length > 0\) \{([\s\S]*?)core\.setFailed\(/,
84+
/if \(mustDraft\) \{([\s\S]*?)core\.setFailed\(/,
7985
);
80-
assert.ok(failureBlock, "workflow must have a failure path");
86+
assert.ok(failureBlock, "workflow must have a draft path");
8187
const failurePath = failureBlock[1];
8288
assert.match(failurePath, /shouldStripTitlePrefix/);
8389
assert.match(failurePath, /!hasWrongBase/);

‎.github/scripts/pr-labeler.cjs‎

Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,35 @@ function detectTypeLabelFromTitle(title) {
5555
return null;
5656
}
5757

58+
/**
59+
* Type from the PR's own commits, for titles the title matcher cannot classify.
60+
*
61+
* A PR titled `stack 3/5: carry six contributor bug fixes` fails the
62+
* conventional regex (the `3/5` sits between the word and the colon) and then
63+
* reaches the sentence-case fallback, which extracts `stack`. That has no entry
64+
* in PREFIX_TO_LABEL, so the sync skips — and a skip is not a failure, so the
65+
* `label` check stays green while the PR carries no type label at all. The
66+
* commits underneath are conventional (`fix(codex): ...`), so they can answer
67+
* the question the title cannot.
68+
*
69+
* `chore` is supporting, not competing. `test:`, `ci:`, `chore:`, `style:`,
70+
* `refactor:`, and `build:` all map to it, and none of them says what a PR is
71+
* FOR. Requiring unanimity would abstain on almost every real PR: #955 is four
72+
* `fix(codex):` commits plus one `test(codex):`, and it is a bug fix.
73+
*
74+
* Anything still ambiguous after that (`fix:` alongside `feat:`) stays
75+
* unlabeled rather than guessed.
76+
*/
77+
function detectTypeLabelFromCommits(messages) {
78+
const types = new Set();
79+
for (const message of Array.isArray(messages) ? messages : []) {
80+
const detected = detectTypeLabelFromTitle(String(message || "").split("\n")[0]);
81+
if (detected) types.add(detected);
82+
}
83+
if (types.size > 1) types.delete("chore");
84+
return types.size === 1 ? [...types][0] : null;
85+
}
86+
5887
/**
5988
* True when a human (any non-bot actor) has ever labeled or unlabeled a managed
6089
* type label on this PR. Mirrors issue-quality's sticky maintainerOverride:
@@ -105,7 +134,11 @@ function planTypeLabelSync(input) {
105134
return { skip: true, reason: "human-override" };
106135
}
107136

108-
const detected = detectTypeLabelFromTitle(title);
137+
// The title is authoritative when it classifies. The commits only answer for
138+
// titles it cannot (`stack 3/5: ...`), so a well-formed title is never
139+
// overridden by what happens to be committed under it.
140+
const detected =
141+
detectTypeLabelFromTitle(title) ?? detectTypeLabelFromCommits(input?.commitMessages);
109142
if (!detected) {
110143
return { skip: true, reason: "no-prefix" };
111144
}
@@ -121,6 +154,7 @@ module.exports = {
121154
TYPE_LABELS,
122155
BOT_ACTORS,
123156
detectTypeLabelFromTitle,
157+
detectTypeLabelFromCommits,
124158
hasHumanTypeLabelOverride,
125159
planTypeLabelSync,
126160
};

‎.github/scripts/pr-labeler.test.cjs‎

Lines changed: 110 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ const { describe, it } = require("node:test");
66
const assert = require("node:assert/strict");
77
const {
88
detectTypeLabelFromTitle,
9+
detectTypeLabelFromCommits,
910
hasHumanTypeLabelOverride,
1011
planTypeLabelSync,
1112
TYPE_LABELS,
@@ -145,6 +146,115 @@ describe("planTypeLabelSync", () => {
145146
});
146147
});
147148

149+
describe("detectTypeLabelFromCommits", () => {
150+
it("reads the type from unanimous commits", () => {
151+
assert.equal(
152+
detectTypeLabelFromCommits([
153+
"fix(usage): price long-context requests at the published long rate",
154+
]),
155+
"bug",
156+
);
157+
});
158+
159+
it("treats chore as supporting, not competing (PR #955 shape)", () => {
160+
// Four `fix(codex):` commits plus one `test(codex):`. Requiring unanimity
161+
// would abstain here, and on almost every real PR — nearly every
162+
// substantial change carries a test or chore commit alongside its fix.
163+
assert.equal(
164+
detectTypeLabelFromCommits([
165+
"fix(codex): probe reset-derived cooldowns without waiting to be selected",
166+
"fix(codex): fail closed on an unrecognized plan",
167+
"fix(codex): classify prolite as a weekly plan",
168+
"fix(codex): share one window rule instead of a plan allowlist",
169+
"test(codex): assert the window rule in literals",
170+
]),
171+
"bug",
172+
);
173+
});
174+
175+
it("keeps chore when nothing else competes", () => {
176+
assert.equal(
177+
detectTypeLabelFromCommits(["ci: pin an action", "test: add a case"]),
178+
"chore",
179+
);
180+
});
181+
182+
it("abstains on a genuine mix of fix and feat", () => {
183+
assert.equal(
184+
detectTypeLabelFromCommits(["fix(a): repair x", "feat(b): add y"]),
185+
null,
186+
);
187+
});
188+
189+
it("reads only the first line of a multi-line commit message", () => {
190+
// A body line starting with `feat:` must not vote.
191+
assert.equal(
192+
detectTypeLabelFromCommits([
193+
"fix(a): repair x\n\nfeat: this is prose in the body, not a type",
194+
]),
195+
"bug",
196+
);
197+
});
198+
199+
it("returns null for absent or unusable input", () => {
200+
assert.equal(detectTypeLabelFromCommits([]), null);
201+
assert.equal(detectTypeLabelFromCommits(undefined), null);
202+
assert.equal(detectTypeLabelFromCommits(["", null]), null);
203+
});
204+
});
205+
206+
describe("planTypeLabelSync commit fallback", () => {
207+
it("labels a stack PR whose title carries no type", () => {
208+
// `stack 3/5:` fails the conventional regex (the `3/5` sits between the
209+
// word and the colon), reaches the sentence-case fallback, which extracts
210+
// `stack` — a word with no PREFIX_TO_LABEL entry. The sync used to skip
211+
// here, and a skip is not a failure, so the `label` check stayed green
212+
// while all four stack PRs carried no type label.
213+
const plan = planTypeLabelSync({
214+
title: "stack 3/5: carry six contributor bug fixes with authorship intact",
215+
currentLabels: [],
216+
events: [],
217+
commitMessages: [
218+
"fix(kiro): round-trip the redactedContent reasoning blob",
219+
"fix(responses): close passthrough streams at terminal events",
220+
],
221+
});
222+
assert.deepEqual(plan, { skip: false, detected: "bug", add: "bug", remove: [] });
223+
});
224+
225+
it("does not let commits override a title that already classifies", () => {
226+
const plan = planTypeLabelSync({
227+
title: "feat(providers): add a preset",
228+
currentLabels: [],
229+
events: [],
230+
commitMessages: ["fix(a): repair x", "fix(b): repair y"],
231+
});
232+
assert.equal(plan.detected, "enhancement");
233+
});
234+
235+
it("still skips when neither the title nor the commits classify", () => {
236+
const plan = planTypeLabelSync({
237+
title: "stack 1/5: triage the open issue surface",
238+
currentLabels: [],
239+
events: [],
240+
commitMessages: ["wip", "more wip"],
241+
});
242+
assert.deepEqual(plan, { skip: true, reason: "no-prefix" });
243+
});
244+
245+
it("still honours a human override before consulting commits", () => {
246+
const plan = planTypeLabelSync({
247+
title: "stack 2/5: price long-context requests",
248+
currentLabels: ["enhancement"],
249+
events: [
250+
{ event: "labeled", label: { name: "enhancement" }, actor: { login: "a-human" } },
251+
],
252+
commitMessages: ["fix(usage): price long-context requests"],
253+
});
254+
assert.deepEqual(plan, { skip: true, reason: "human-override" });
255+
});
256+
});
257+
148258
describe("pr-labeler workflow", () => {
149259
const workflowPath = path.join(__dirname, "../workflows/pr-labeler.yml");
150260
const workflow = fs.readFileSync(workflowPath, "utf8");

0 commit comments

Comments
 (0)