Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions scripts/changelog-history-guard.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,9 +62,15 @@ describe("compareHistory", () => {
expect(violation?.removed).toEqual(["0.12.11"]);
});

test("ignores a file absent on either side", () => {
test("ignores a file absent at the base", () => {
expect(compareHistory("packages/x/CHANGELOG.md", undefined, FULL)).toBeUndefined();
expect(compareHistory("packages/x/CHANGELOG.md", FULL, undefined)).toBeUndefined();
});

test("catches a changelog deleted at the head", () => {
const violation = compareHistory("packages/x/CHANGELOG.md", FULL, undefined);
expect(violation?.removed).toEqual(["0.12.12", "0.12.11"]);
expect(violation?.baseHeadingCount).toBe(2);
expect(violation?.headHeadingCount).toBe(0);
});

test("does not flag reordering or rewording that keeps every version", () => {
Expand Down
12 changes: 8 additions & 4 deletions scripts/changelog-history-guard.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,17 +61,21 @@ export function releaseHeadings(text: string): string[] {
/**
* Compare one changelog across a range.
*
* A file that did not exist at the base cannot have lost history, and a file
* deleted at the head is a different review conversation (and is visible in the
* diff as a deletion), so both return no violation here.
* A file that did not exist at the base cannot have lost history. A file that
* existed at the base but is deleted at the head has lost every released
* section, so deletion fails closed through the same violation contract.
*/
export function compareHistory(
file: string,
baseText: string | undefined,
headText: string | undefined,
): ChangelogHistoryViolation | undefined {
if (baseText === undefined || headText === undefined) return undefined;
if (baseText === undefined) return undefined;
const before = releaseHeadings(baseText);
if (headText === undefined) {
if (before.length === 0) return undefined;
return { file, removed: before, baseHeadingCount: before.length, headHeadingCount: 0 };
Comment on lines +75 to +77

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Disable rename detection while enumerating changelogs

When a package changelog is moved and edited but remains similar enough for Git to classify it as a rename, this deletion branch is never reached. In the dev-ci.yml guard, Git 2.43 reports such a change as R072 packages/a/CHANGELOG.md packages/b/CHANGELOG.md, while the current git diff --name-only returns only the destination; collectViolations then finds no file at that destination in the base and exempts it, allowing removed released headings to pass CI. Enumerate with --no-renames or process both sides of rename records so the source deletion is checked.

AGENTS.md reference: AGENTS.md:L178-L178

Useful? React with 👍 / 👎.

}
const after = new Set(releaseHeadings(headText));
const removed = before.filter(version => !after.has(version));
if (removed.length === 0) return undefined;
Expand Down
Loading