1
0
Fork 0

fix(bot): read open-ended changelog ranges in the newest direction

CHANGELOG.md is newest-first, but resolveChangelogRange treated its two
range ends as a closed min/max index pair. A range with only a starting
version ("0.6.0..") therefore resolved to the oldest entries through
0.6.0 instead of 0.6.0 and everything newer, so the release-notes command
announced the wrong set of releases.

Resolve each open end toward the direction it opens: "X.." runs from the
newest entry down to X, "..X" runs from X to the oldest entry, and a
closed range still normalizes to min/max. Adds a regression test against
the shipped file.
This commit is contained in:
Jason Fraley 2026-10-13 11:18:24 -04:00
parent e1cfdd3329
commit 8d5aa081ba
2 changed files with 39 additions and 10 deletions

View file

@ -284,14 +284,33 @@ export function resolveChangelogRange(
if (!from && !to) return { found: false, versions: [], messages: [] };
const idxFrom = from ? entries.findIndex((entry) => entry.version === from) : 0;
const idxTo = to ? entries.findIndex((entry) => entry.version === to) : entries.length - 1;
if (idxFrom === -1 || idxTo === -1) {
return { found: false, versions: [], messages: [] };
const indexOf = (version: string): number =>
entries.findIndex((entry) => entry.version === version);
// The file is newest-first, so a LOWER index is a NEWER version. "from.." opens
// toward the newest (index 0); "..to" opens toward the oldest (the last index).
let start: number;
let end: number;
if (from && to) {
const a = indexOf(from);
const b = indexOf(to);
if (a === -1 || b === -1) return { found: false, versions: [], messages: [] };
start = Math.min(a, b);
end = Math.max(a, b);
} else if (from) {
// "a.." = a and everything newer, up to the newest entry.
const a = indexOf(from);
if (a === -1) return { found: false, versions: [], messages: [] };
start = 0;
end = a;
} else {
// "..b" = the oldest entry through b.
const b = indexOf(to as string);
if (b === -1) return { found: false, versions: [], messages: [] };
start = b;
end = entries.length - 1;
}
const start = Math.min(idxFrom, idxTo);
const end = Math.max(idxFrom, idxTo);
const slice = entries
.slice(start, end + 1)
.sort((a, b) => compareVersions(a.version, b.version));

View file

@ -96,14 +96,14 @@ describe("resolveChangelogRange", () => {
expect(batch.messages).toHaveLength(3);
});
it("opens the top end (from here to the latest)", () => {
it("opens the top end: 'X..' is X and everything newer", () => {
const batch = resolveChangelogRange(DESC_CONTENT, "0.3.0", undefined);
expect(batch.versions).toEqual(["0.1.0", "0.2.0", "0.3.0"]);
expect(batch.versions).toEqual(["0.3.0", "0.4.0", "0.5.0"]);
});
it("opens the bottom end (from the oldest to here)", () => {
it("opens the bottom end: '..X' is the oldest through X", () => {
const batch = resolveChangelogRange(DESC_CONTENT, undefined, "0.4.0");
expect(batch.versions).toEqual(["0.4.0", "0.5.0"]);
expect(batch.versions).toEqual(["0.1.0", "0.2.0", "0.3.0", "0.4.0"]);
});
it("normalizes a reversed range", () => {
@ -260,4 +260,14 @@ describe("real CHANGELOG.md", () => {
messages.forEach((message) => expect(message.length).toBeLessThanOrEqual(4000));
});
});
it("treats 'X..' as X and newer on the shipped file (reported bug)", () => {
const content = readFileSync(CHANGELOG_PATH, "utf8");
const newest = parseChangelog(content)[0].version;
const batch = resolveChangelogRange(content, "0.6.0", undefined);
expect(batch.found).toBe(true);
expect(batch.versions[0]).toBe("0.6.0");
expect(batch.versions[batch.versions.length - 1]).toBe(newest);
expect(batch.versions.every((version) => compareVersions(version, "0.6.0") >= 0)).toBe(true);
});
});