Skip to content

Commit 83b2fb9

Browse files
cliffhallclaude
andcommitted
Name the version actually checked when an alert target is unverified, and stop advertising it in the title
Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: cliffhall <[email protected]>
1 parent 5090add commit 83b2fb9

2 files changed

Lines changed: 92 additions & 7 deletions

File tree

‎scripts/dependabot-alerts.mjs‎

Lines changed: 36 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -424,23 +424,48 @@ export function pickTarget(ecosystem, advisories, installed = []) {
424424
advisories.map((a) => a.fixedIn),
425425
),
426426
verified: false,
427+
reason: "older",
428+
checked: floor,
427429
stillOpen: covers(floor).map((a) => a.ghsa),
428430
};
429431
}
430432

431433
for (const candidate of candidates) {
432434
if (covers(candidate).length === 0) {
433-
return { fixedIn: candidate, verified: true, stillOpen: [] };
435+
return {
436+
fixedIn: candidate,
437+
verified: true,
438+
reason: null,
439+
checked: candidate,
440+
stillOpen: [],
441+
};
434442
}
435443
}
436444
const highest = candidates.at(-1);
437445
return {
438446
fixedIn: highest,
439447
verified: false,
448+
reason: "in-range",
449+
checked: highest,
440450
stillOpen: covers(highest).map((a) => a.ghsa),
441451
};
442452
}
443453

454+
/**
455+
* Why an unverified target is not safe, naming the version that was actually
456+
* checked: the listed fix itself, or the newest affected copy when every
457+
* listed fix is older than it.
458+
*
459+
* @param {{fixedIn: string, targetReason?: string | null, targetChecked?: string, targetStillOpen?: string[]}} group
460+
* @returns {string}
461+
*/
462+
export function unverifiedReason(group) {
463+
const open = (group.targetStillOpen ?? []).map((g) => `\`${g}\``).join(", ");
464+
return group.targetReason === "older"
465+
? `every listed patched version is older than the installed \`${group.targetChecked}\`, which is still in range of ${open}`
466+
: `\`${group.fixedIn}\`, the highest listed patched version, is still in range of ${open}`;
467+
}
468+
444469
/** One advisory as it applies to one manifest. */
445470
export function advisoryKey(pkg, manifestPath, ghsa) {
446471
return JSON.stringify([pkg, manifestPath, ghsa]);
@@ -551,9 +576,11 @@ export function narrowToApplicable(group, entries) {
551576
advisories,
552577
ghsas: advisories.map((a) => a.ghsa),
553578
severity,
554-
...(({ fixedIn, verified, stillOpen }) => ({
579+
...(({ fixedIn, verified, reason, checked, stillOpen }) => ({
555580
fixedIn,
556581
targetVerified: verified,
582+
targetReason: reason,
583+
targetChecked: checked,
557584
targetStillOpen: stillOpen,
558585
}))(
559586
pickTarget(
@@ -570,6 +597,11 @@ export function narrowToApplicable(group, entries) {
570597
/** @param {ReturnType<typeof groupAlerts>[number]} group */
571598
export function buildIssueTitle(group) {
572599
const n = group.advisories.length;
600+
// An unverified target is not advertised as the version to move to: a title
601+
// is often all a notification shows.
602+
if (group.targetVerified === false) {
603+
return `chore(deps): find a safe release of \`${group.package}\` in \`${group.manifestPath}\` (${n} ${n === 1 ? "advisory" : "advisories"}, no listed fix clears them)`;
604+
}
573605
return `chore(deps): bump \`${group.package}\` to \`${group.fixedIn}\` in \`${group.manifestPath}\` (${n} ${n === 1 ? "advisory" : "advisories"})`;
574606
}
575607

@@ -691,7 +723,7 @@ export function buildIssueBody(
691723
const steps =
692724
group.targetVerified === false
693725
? [
694-
`**Choose a target first.** No patched version these advisories list is outside every range below (\`${group.fixedIn}\` is still in range of ${(group.targetStillOpen ?? []).map((g) => `\`${g}\``).join(", ")}). Find a release of \`${group.package}\` that no listed range covers, then make the edit this repo uses for it: raise the declared range, or pin it with ${group.ecosystem === "pip" ? "`uv lock --upgrade-package` or `constraint-dependencies`" : "an `overrides` entry"}.`,
726+
`**Choose a target first.** No patched version these advisories list is a safe target: ${unverifiedReason(group)}. Find a release of \`${group.package}\` that no listed range covers, then make the edit this repo uses for it: raise the declared range, or pin it with ${group.ecosystem === "pip" ? "`uv lock --upgrade-package` or `constraint-dependencies`" : "an `overrides` entry"}.`,
695727
]
696728
: group.ecosystem === "pip"
697729
? pipFix(group, { declaredSpec })
@@ -720,7 +752,7 @@ export function buildIssueBody(
720752
`| Manifest | \`${cell(group.manifestPath)}\` |`,
721753
`| Vulnerable on \`${TARGET_BRANCH}\` | ${[...new Set(affected.map((e) => e.version))].map((v) => `\`${cell(v)}\``).join(", ") || "—"} |`,
722754
group.targetVerified === false
723-
? `| 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 |`
755+
? `| Bump to | ⚠️ none found: ${cell(unverifiedReason(group))}. Pick a release outside every range listed |`
724756
: `| Bump to | \`${cell(group.fixedIn)}\`, the lowest patched version below that is outside every range listed |`,
725757
`| Scope | ${cell(group.scope)} |`,
726758
`| Highest severity | ${cell(group.severity)} |`,

‎scripts/dependabot-alerts.test.mjs‎

Lines changed: 56 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ import {
3535
parseCommentMarker,
3636
parseMarker,
3737
pickTarget,
38+
unverifiedReason,
3839
scopedOverrideExample,
3940
splitOwner,
4041
toSemverRange,
@@ -363,6 +364,8 @@ test("pickTarget names the lowest patched version outside every range", () => {
363364
assert.deepEqual(tricky, {
364365
fixedIn: "2.0.0",
365366
verified: false,
367+
reason: "in-range",
368+
checked: "2.0.0",
366369
stillOpen: ["A"],
367370
});
368371

@@ -372,7 +375,13 @@ test("pickTarget names the lowest patched version outside every range", () => {
372375
{ ghsa: "A", range: "<= 3.1.59", fixedIn: "3.1.60" },
373376
{ ghsa: "B", range: "<= 3.1.61", fixedIn: "3.1.62" },
374377
]),
375-
{ fixedIn: "3.1.62", verified: true, stillOpen: [] },
378+
{
379+
fixedIn: "3.1.62",
380+
verified: true,
381+
reason: null,
382+
checked: "3.1.62",
383+
stillOpen: [],
384+
},
376385
);
377386

378387
// Disjoint lines: a lower fix can clear everything.
@@ -381,7 +390,13 @@ test("pickTarget names the lowest patched version outside every range", () => {
381390
{ ghsa: "A", range: "< 1.4.0", fixedIn: "1.4.0" },
382391
{ ghsa: "B", range: ">= 2.0.0, < 2.1.0", fixedIn: "2.1.0" },
383392
]),
384-
{ fixedIn: "1.4.0", verified: true, stillOpen: [] },
393+
{
394+
fixedIn: "1.4.0",
395+
verified: true,
396+
reason: null,
397+
checked: "1.4.0",
398+
stillOpen: [],
399+
},
385400
);
386401

387402
// An unreadable range cannot vouch for anything.
@@ -402,6 +417,8 @@ test("pickTarget never targets below an affected copy", () => {
402417
assert.deepEqual(pickTarget("npm", advisories, ["1.3.0", "2.0.5"]), {
403418
fixedIn: "2.1.0",
404419
verified: true,
420+
reason: null,
421+
checked: "2.1.0",
405422
stillOpen: [],
406423
});
407424
// Every listed fix is older than an affected copy: unverified, naming the
@@ -412,7 +429,38 @@ test("pickTarget never targets below an affected copy", () => {
412429
[{ ghsa: "A", range: "< 1.4.0 || >= 3.0.0, < 3.2.0", fixedIn: "1.4.0" }],
413430
["3.0.5"],
414431
),
415-
{ fixedIn: "1.4.0", verified: false, stillOpen: ["A"] },
432+
{
433+
fixedIn: "1.4.0",
434+
verified: false,
435+
reason: "older",
436+
checked: "3.0.5",
437+
stillOpen: ["A"],
438+
},
439+
);
440+
});
441+
442+
test("an unverified target names the version it actually checked", () => {
443+
// Every fix is older than the installed copy: the body blames the copy,
444+
// not the fix, which no listed range covers.
445+
const older = unverifiedReason({
446+
fixedIn: "1.4.0",
447+
targetReason: "older",
448+
targetChecked: "3.0.5",
449+
targetStillOpen: ["A"],
450+
});
451+
assert.match(
452+
older,
453+
/older than the installed `3\.0\.5`, which is still in range of `A`/,
454+
);
455+
assert.ok(!older.includes("`1.4.0`"));
456+
assert.match(
457+
unverifiedReason({
458+
fixedIn: "2.0.0",
459+
targetReason: "in-range",
460+
targetChecked: "2.0.0",
461+
targetStillOpen: ["A"],
462+
}),
463+
/`2\.0\.0`, the highest listed patched version, is still in range of `A`/,
416464
);
417465
});
418466

@@ -432,6 +480,11 @@ test("an unverified target is flagged in the body and the comment", () => {
432480
assert.equal(narrowed.targetVerified, false);
433481
const body = buildIssueBody(narrowed, { affected, declarers: [] });
434482
assert.match(body, /still in range of `GHSA-a`/);
483+
// The title does not advertise the unsafe version either.
484+
assert.equal(
485+
buildIssueTitle(narrowed),
486+
"chore(deps): find a safe release of `x` in `package-lock.json` (2 advisories, no listed fix clears them)",
487+
);
435488
// No concrete edit to a version known to stay vulnerable.
436489
assert.match(body, /\*\*Choose a target first\.\*\*/);
437490
assert.ok(!body.includes("Raise the declared range**"));

0 commit comments

Comments
 (0)