Skip to content

Commit 129a0a0

Browse files
cliffhallclaude
andcommitted
Verify an alert issue's target against every applicable range; scope SDK labels to servers behind; qualify the milestone and issue-flow wording
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Signed-off-by: cliffhall <cliff@futurescale.com>
1 parent 1b5f6ae commit 129a0a0

6 files changed

Lines changed: 156 additions & 24 deletions

File tree

‎AGENTS.md‎

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -219,8 +219,10 @@ its reasoning; these are the rules.
219219
that closes it.
220220
- **Sweeps do not write the board.** `GITHUB_TOKEN` cannot hold `organization
221221
projects: write`. A sweep issue arrives labeled `v2` + `chore` +
222-
`dependencies` (+ a `server-<name>` scope where it concerns one server) and
223-
milestoned, and `issue-triage` pass 1 boards it in `Todo`. Boarding from the
222+
`dependencies` (+ a `server-<name>` scope for each server it concerns) and
223+
carries the open milestone with the nearest due date, so `issue-triage` pass
224+
1 boards it in `Todo`. With no dated milestone open it is filed unmilestoned
225+
and boarded in `Incoming`, like any unapproved issue. Boarding from the
224226
workflows waits on a GitHub App credential (#5061); do not add board-write
225227
code that reads a secret that does not exist.
226228
- **A sweep's marker counts only on an issue the automation wrote**: authored

‎docs/ai-software-factory.md‎

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,12 @@ work was tracked as #4858.
2727
It is not a tool bolted onto the repository. It is the repository's own
2828
contribution process, `AGENTS.md` plus the skills, loaded automatically by
2929
Claude Code, versioned and tested like code.
30-
- **Nothing happens without an issue.** Every PR closes one, every issue is on
31-
the board, and the one thing that used to open PRs without an issue,
32-
Dependabot, now files issues instead.
30+
- **Nothing happens without an issue.** In the ordinary flow every PR closes
31+
one and every issue reaches the board, through `issue-create` or a triage
32+
pass. The few exceptions are named in `AGENTS.md`: a security advisory's fix
33+
(tracked by a private draft card), the milestone merge PR and the version PRs
34+
(tied to their release issue). The one thing that used to open PRs with no
35+
issue at all, Dependabot, now files issues instead.
3336
- **A gate strict enough to trust.** `npm run local:gate` runs every check CI
3437
runs, for both languages, before anything is pushed.
3538

‎scripts/dependabot-alerts.mjs‎

Lines changed: 60 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -366,14 +366,57 @@ export function groupKey(pkg, manifestPath) {
366366
* @returns {string}
367367
*/
368368
export function highestVersion(ecosystem, versions) {
369-
const compare =
370-
ecosystem === "pip"
371-
? pep440Compare
372-
: (a, b) =>
373-
semver.valid(a) && semver.valid(b)
374-
? semver.compare(a, b)
375-
: a.localeCompare(b);
376-
return [...versions].sort(compare).at(-1);
369+
return [...versions].sort(versionCompare(ecosystem)).at(-1);
370+
}
371+
372+
/** The ecosystem's own ordering. */
373+
function versionCompare(ecosystem) {
374+
return ecosystem === "pip"
375+
? pep440Compare
376+
: (a, b) =>
377+
semver.valid(a) && semver.valid(b)
378+
? semver.compare(a, b)
379+
: a.localeCompare(b);
380+
}
381+
382+
/**
383+
* The version a grouped issue asks for: the LOWEST of the advisories' patched
384+
* versions that falls outside every applicable range. The highest patched
385+
* version is not enough on its own: one advisory's range can still cover
386+
* another's fix (`<1.5.0 || >=2.0.0 <2.2.0` patched at 1.5.0, beside `<2.0.0`
387+
* patched at 2.0.0, leaves 2.0.0 vulnerable). When no listed patched version
388+
* clears them all, the highest is named and `verified` is false, and the body
389+
* says so rather than claiming one bump clears everything.
390+
*
391+
* @param {string} ecosystem
392+
* @param {Array<{fixedIn: string, range: string}>} advisories
393+
* @returns {{fixedIn: string, verified: boolean, stillOpen: string[]}}
394+
* `stillOpen` names the advisories whose range still covers the target
395+
*/
396+
export function pickTarget(ecosystem, advisories) {
397+
const covers = (version) =>
398+
advisories.filter((a) => {
399+
try {
400+
return inRange(ecosystem, version, a.range);
401+
} catch {
402+
// A range that cannot be read cannot vouch for the target.
403+
return true;
404+
}
405+
});
406+
const candidates = [...new Set(advisories.map((a) => a.fixedIn))].sort(
407+
versionCompare(ecosystem),
408+
);
409+
for (const candidate of candidates) {
410+
if (covers(candidate).length === 0) {
411+
return { fixedIn: candidate, verified: true, stillOpen: [] };
412+
}
413+
}
414+
const highest = candidates.at(-1);
415+
return {
416+
fixedIn: highest,
417+
verified: false,
418+
stillOpen: covers(highest).map((a) => a.ghsa),
419+
};
377420
}
378421

379422
/** One advisory as it applies to one manifest. */
@@ -485,10 +528,11 @@ export function narrowToApplicable(group, entries) {
485528
advisories,
486529
ghsas: advisories.map((a) => a.ghsa),
487530
severity,
488-
fixedIn: highestVersion(
489-
group.ecosystem,
490-
advisories.map((a) => a.fixedIn),
491-
),
531+
...(({ fixedIn, verified, stillOpen }) => ({
532+
fixedIn,
533+
targetVerified: verified,
534+
targetStillOpen: stillOpen,
535+
}))(pickTarget(group.ecosystem, advisories)),
492536
},
493537
affected,
494538
};
@@ -616,7 +660,9 @@ export function buildIssueBody(
616660
`| Package | \`${cell(group.package)}\` (${group.ecosystem}) |`,
617661
`| Manifest | \`${cell(group.manifestPath)}\` |`,
618662
`| Vulnerable on \`${TARGET_BRANCH}\` | ${[...new Set(affected.map((e) => e.version))].map((v) => `\`${cell(v)}\``).join(", ") || "—"} |`,
619-
`| Bump to | \`${cell(group.fixedIn)}\`, the highest patched version below |`,
663+
group.targetVerified === false
664+
? `| Bump to | \`${cell(group.fixedIn)}\` is the highest patched version below, but ⚠️ it is still in range of ${(group.targetStillOpen ?? []).map((g) => `\`${cell(g)}\``).join(", ")}: pick a release outside every range listed |`
665+
: `| Bump to | \`${cell(group.fixedIn)}\`, the lowest patched version below that is outside every range listed |`,
620666
`| Scope | ${cell(group.scope)} |`,
621667
`| Highest severity | ${cell(group.severity)} |`,
622668
"",
@@ -690,7 +736,7 @@ export function buildNewAdvisoryComment(group, added) {
690736
.join("\n");
691737
return [
692738
buildCommentMarker(added),
693-
`${added.length} new Dependabot ${added.length === 1 ? "advisory" : "advisories"} for \`${group.package}\`. The bump this issue asks for is now to \`${group.fixedIn}\`, which clears ${added.length === 1 ? "it" : "them"} along with the rest.`,
739+
`${added.length} new Dependabot ${added.length === 1 ? "advisory" : "advisories"} for \`${group.package}\`. The bump this issue asks for is now to \`${group.fixedIn}\`${group.targetVerified === false ? "; see the issue body, since no single listed patched version clears every advisory" : `, which clears ${added.length === 1 ? "it" : "them"} along with the rest`}.`,
694740
"",
695741
"| GHSA | Severity | Summary |",
696742
"| --- | --- | --- |",

‎scripts/dependabot-alerts.test.mjs‎

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ import {
3434
parseClearedDate,
3535
parseCommentMarker,
3636
parseMarker,
37+
pickTarget,
3738
scopedOverrideExample,
3839
splitOwner,
3940
toSemverRange,
@@ -352,6 +353,67 @@ test("narrowToApplicable keeps only advisories in range, and retargets", () => {
352353
);
353354
});
354355

356+
test("pickTarget names the lowest patched version outside every range", () => {
357+
// Copilot's example: 2.0.0 is the highest fix, but the first range still
358+
// covers it, and no listed fix clears both.
359+
const tricky = pickTarget("npm", [
360+
{ ghsa: "A", range: "< 1.5.0 || >= 2.0.0, < 2.2.0", fixedIn: "1.5.0" },
361+
{ ghsa: "B", range: "< 2.0.0", fixedIn: "2.0.0" },
362+
]);
363+
assert.deepEqual(tricky, {
364+
fixedIn: "2.0.0",
365+
verified: false,
366+
stillOpen: ["A"],
367+
});
368+
369+
// Nested ranges: the highest fix is the lowest safe one.
370+
assert.deepEqual(
371+
pickTarget("pip", [
372+
{ ghsa: "A", range: "<= 3.1.59", fixedIn: "3.1.60" },
373+
{ ghsa: "B", range: "<= 3.1.61", fixedIn: "3.1.62" },
374+
]),
375+
{ fixedIn: "3.1.62", verified: true, stillOpen: [] },
376+
);
377+
378+
// Disjoint lines: a lower fix can clear everything.
379+
assert.deepEqual(
380+
pickTarget("npm", [
381+
{ ghsa: "A", range: "< 1.4.0", fixedIn: "1.4.0" },
382+
{ ghsa: "B", range: ">= 2.0.0, < 2.1.0", fixedIn: "2.1.0" },
383+
]),
384+
{ fixedIn: "1.4.0", verified: true, stillOpen: [] },
385+
);
386+
387+
// An unreadable range cannot vouch for anything.
388+
assert.equal(
389+
pickTarget("npm", [{ ghsa: "A", range: "whenever", fixedIn: "1.0.0" }])
390+
.verified,
391+
false,
392+
);
393+
});
394+
395+
test("an unverified target is flagged in the body and the comment", () => {
396+
const [group] = groupAlerts([
397+
alert({
398+
name: "x",
399+
range: "< 1.5.0 || >= 2.0.0, < 2.2.0",
400+
fixed: "1.5.0",
401+
ghsa: "GHSA-a",
402+
}),
403+
alert({ name: "x", range: "< 2.0.0", fixed: "2.0.0", ghsa: "GHSA-b" }),
404+
]);
405+
const { group: narrowed, affected } = narrowToApplicable(group, [
406+
{ path: "node_modules/x", version: "1.0.0", topLevel: true },
407+
]);
408+
assert.equal(narrowed.targetVerified, false);
409+
const body = buildIssueBody(narrowed, { affected, declarers: [] });
410+
assert.match(body, /still in range of `GHSA-a`/);
411+
assert.match(
412+
buildNewAdvisoryComment(narrowed, ["GHSA-b"]),
413+
/no single listed patched version/,
414+
);
415+
});
416+
355417
test("titles and labels name the bump and the server", () => {
356418
const group = {
357419
package: "pyjwt",

‎scripts/sdk-watch.mjs‎

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -271,15 +271,19 @@ export function buildIssueTitle(state) {
271271
}
272272

273273
/**
274-
* Labels: the sweep's, plus each server a row is in, unless the rows reach
275-
* every server (then the issue is repository-wide and takes none).
274+
* Labels: the sweep's, plus each server with a copy that is BEHIND (a server
275+
* already at the target has no work here), unless that is every server (then
276+
* the issue is repository-wide and takes none).
276277
*
277278
* @param {NonNullable<ReturnType<typeof groupState>>} state
278279
*/
279280
export function issueLabels(state) {
280281
const scopes = [
281282
...new Set(
282-
state.rows.map((r) => scopeLabel(`${r.where}/`)).filter(Boolean),
283+
state.rows
284+
.filter((r) => r.behind)
285+
.map((r) => scopeLabel(`${r.where}/`))
286+
.filter(Boolean),
283287
),
284288
].sort();
285289
return scopes.length === SERVERS.length

‎scripts/sdk-watch.test.mjs‎

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -220,13 +220,28 @@ test("titles, labels and bodies", () => {
220220
"fetch",
221221
"git",
222222
"time",
223-
].map((s) => ({ where: `src/${s}` })),
223+
].map((s) => ({ where: `src/${s}`, behind: true })),
224224
};
225225
assert.deepEqual(issueLabels(everywhere), ["v2", "chore", "dependencies"]);
226+
// Only servers that are behind are labeled.
227+
const partly = groupState(
228+
group("python-sdk"),
229+
[
230+
row("mcp", "src/fetch", "", "2.3.0"),
231+
row("mcp", "src/time", "", "1.29.0"),
232+
],
233+
{ mcp: "2.3.0" },
234+
);
235+
assert.deepEqual(issueLabels(partly), [
236+
"v2",
237+
"chore",
238+
"dependencies",
239+
"server-time",
240+
]);
226241
assert.deepEqual(
227242
issueLabels({
228243
group: group("typescript-sdk-v1"),
229-
rows: [{ where: "root" }],
244+
rows: [{ where: "root", behind: true }],
230245
}),
231246
["v2", "chore", "dependencies"],
232247
);

0 commit comments

Comments
 (0)