From 278327c54dd5ad627e76b728a872c3eecdab42e8 Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" <41898282+github-actions[bot]@users.noreply.github.com> Date: Tue, 28 Apr 2026 04:56:29 +0000 Subject: [PATCH] test(add_labels): add edge-case tests for blocked patterns, removal prevention, and label truncation MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Add test: all labels blocked by patterns → success with empty labelsAdded - Add test: labels starting with '-' rejected as removal attempts - Add test: labels longer than 64 characters are truncated Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> --- actions/setup/js/add_labels.test.cjs | 64 ++++++++++++++++++++++++++++ 1 file changed, 64 insertions(+) diff --git a/actions/setup/js/add_labels.test.cjs b/actions/setup/js/add_labels.test.cjs index 0e65a513f04..38c5ae2f380 100644 --- a/actions/setup/js/add_labels.test.cjs +++ b/actions/setup/js/add_labels.test.cjs @@ -681,5 +681,69 @@ describe("add_labels", () => { expect(mockCore.infos.some(msg => msg.includes("Blocked patterns:"))).toBe(false); expect(mockCore.infos.some(msg => msg.includes("max=5"))).toBe(true); }); + + it("should succeed with empty labelsAdded when all labels are blocked by patterns", async () => { + const handler = await main({ + max: 10, + blocked: ["*"], + }); + + const addLabelsCalls = []; + mockGithub.rest.issues.addLabels = async params => { + addLabelsCalls.push(params); + return {}; + }; + + const result = await handler( + { + item_number: 100, + labels: ["bug", "enhancement"], + }, + {} + ); + + // All labels blocked → treated as "no valid labels" + expect(result.success).toBe(true); + expect(result.labelsAdded).toEqual([]); + expect(result.message).toContain("No valid labels"); + expect(addLabelsCalls.length).toBe(0); + }); + + it("should reject labels starting with '-' (removal attempt)", async () => { + const handler = await main({ max: 10 }); + + const result = await handler( + { + item_number: 100, + labels: ["-bug"], + }, + {} + ); + + expect(result.success).toBe(false); + expect(result.error).toContain("Label removal is not permitted"); + }); + + it("should truncate labels longer than 64 characters", async () => { + const handler = await main({ max: 10 }); + const addLabelsCalls = []; + + mockGithub.rest.issues.addLabels = async params => { + addLabelsCalls.push(params); + return {}; + }; + + const longLabel = "a".repeat(80); + const result = await handler( + { + item_number: 100, + labels: [longLabel], + }, + {} + ); + + expect(result.success).toBe(true); + expect(result.labelsAdded[0].length).toBe(64); + }); }); });