Skip to content

Commit 1834c50

Browse files
test(add_labels): add edge-case tests for blocked patterns, removal prevention, and label truncation (#28848)
1 parent 115b573 commit 1834c50

1 file changed

Lines changed: 64 additions & 0 deletions

File tree

actions/setup/js/add_labels.test.cjs

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -681,5 +681,69 @@ describe("add_labels", () => {
681681
expect(mockCore.infos.some(msg => msg.includes("Blocked patterns:"))).toBe(false);
682682
expect(mockCore.infos.some(msg => msg.includes("max=5"))).toBe(true);
683683
});
684+
685+
it("should succeed with empty labelsAdded when all labels are blocked by patterns", async () => {
686+
const handler = await main({
687+
max: 10,
688+
blocked: ["*"],
689+
});
690+
691+
const addLabelsCalls = [];
692+
mockGithub.rest.issues.addLabels = async params => {
693+
addLabelsCalls.push(params);
694+
return {};
695+
};
696+
697+
const result = await handler(
698+
{
699+
item_number: 100,
700+
labels: ["bug", "enhancement"],
701+
},
702+
{}
703+
);
704+
705+
// All labels blocked → treated as "no valid labels"
706+
expect(result.success).toBe(true);
707+
expect(result.labelsAdded).toEqual([]);
708+
expect(result.message).toContain("No valid labels");
709+
expect(addLabelsCalls.length).toBe(0);
710+
});
711+
712+
it("should reject labels starting with '-' (removal attempt)", async () => {
713+
const handler = await main({ max: 10 });
714+
715+
const result = await handler(
716+
{
717+
item_number: 100,
718+
labels: ["-bug"],
719+
},
720+
{}
721+
);
722+
723+
expect(result.success).toBe(false);
724+
expect(result.error).toContain("Label removal is not permitted");
725+
});
726+
727+
it("should truncate labels longer than 64 characters", async () => {
728+
const handler = await main({ max: 10 });
729+
const addLabelsCalls = [];
730+
731+
mockGithub.rest.issues.addLabels = async params => {
732+
addLabelsCalls.push(params);
733+
return {};
734+
};
735+
736+
const longLabel = "a".repeat(80);
737+
const result = await handler(
738+
{
739+
item_number: 100,
740+
labels: [longLabel],
741+
},
742+
{}
743+
);
744+
745+
expect(result.success).toBe(true);
746+
expect(result.labelsAdded[0].length).toBe(64);
747+
});
684748
});
685749
});

0 commit comments

Comments
 (0)