Skip to content

Commit bb51aed

Browse files
korthoutclaude
andcommitted
test: tighten and reorganize comment-formatter tests
Three small fixes from a self-review of the test suite: - Move five tests that exercise formatRunComment out of the formatInitialComment describe block into the formatRunComment describe where they belong. The misplacement made test reports misleading (formatInitialComment appeared to have six cases when it has one). - Add a multiple-targets case to comment_style: legacy. The pre-existing test claimed to verify "per-target comments" but only ran with a single label, so the per-target multiplicity was never actually exercised. The new case asserts two comments for two targets and zero updates. - Drop the unused branchname parameter from the failed() test helper. Nothing reads result.branchname (the formatter reads error.branch), so the param was dead. The underlying field on TargetResult.failed is also dead state — flagged for a separate follow-up. Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
1 parent e24e1e6 commit bb51aed

2 files changed

Lines changed: 29 additions & 13 deletions

File tree

‎src/test/backport.integration.test.ts‎

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -650,7 +650,7 @@ describe("Backport.run() orchestration", () => {
650650
});
651651

652652
describe("comment_style: legacy (default)", () => {
653-
it("posts per-target comments and never updates", async () => {
653+
it("single target: posts one comment and never updates", async () => {
654654
const github = new FakeGithub();
655655
const git = createMockGit();
656656
const config = makeConfig();
@@ -661,6 +661,23 @@ describe("Backport.run() orchestration", () => {
661661
expect(github.comments[0].body).toContain("Successfully created");
662662
expect(github.updatedComments).toHaveLength(0);
663663
});
664+
665+
it("multiple targets: posts one comment per target and never updates", async () => {
666+
const github = new FakeGithub({
667+
sourcePr: {
668+
labels: [{ name: "backport main" }, { name: "backport release" }],
669+
},
670+
});
671+
const git = createMockGit();
672+
const config = makeConfig();
673+
const backport = new Backport(github, config, git);
674+
await backport.run();
675+
676+
expect(github.comments).toHaveLength(2);
677+
expect(github.comments[0].body).toContain("Successfully created");
678+
expect(github.comments[1].body).toContain("Successfully created");
679+
expect(github.updatedComments).toHaveLength(0);
680+
});
664681
});
665682

666683
describe("comment_style: summary", () => {

‎src/test/comments.test.ts‎

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,8 @@ const context: CommentContext = {
2323
function failed(
2424
targetBranch: string,
2525
error: Error,
26-
branchname?: string,
2726
): Extract<TargetResult, { status: "failed" }> {
28-
return { status: "failed", targetBranch, error, branchname };
27+
return { status: "failed", targetBranch, error };
2928
}
3029

3130
describe("formatSingleTargetComment", () => {
@@ -316,16 +315,6 @@ describe("formatRunComment", () => {
316315
expect(out).not.toContain("is backporting");
317316
expect(out).not.toContain("| Target |");
318317
});
319-
});
320-
321-
describe("formatInitialComment", () => {
322-
it("renders the early-run placeholder", () => {
323-
const out = formatInitialComment(context);
324-
325-
expect(out).toContain("is backporting this pull request");
326-
expect(out).toContain("workflow run 12345");
327-
expect(out).not.toContain("| Target |");
328-
});
329318

330319
it("error with empty pendingTargets: intro + error message, no table", () => {
331320
const out = formatRunComment(
@@ -384,3 +373,13 @@ describe("formatInitialComment", () => {
384373
expect(out).not.toContain("<details>");
385374
});
386375
});
376+
377+
describe("formatInitialComment", () => {
378+
it("renders the early-run placeholder", () => {
379+
const out = formatInitialComment(context);
380+
381+
expect(out).toContain("is backporting this pull request");
382+
expect(out).toContain("workflow run 12345");
383+
expect(out).not.toContain("| Target |");
384+
});
385+
});

0 commit comments

Comments
 (0)