diff --git a/actions/setup/js/update_discussion.cjs b/actions/setup/js/update_discussion.cjs index 01ad842c415..5a0d63a1161 100644 --- a/actions/setup/js/update_discussion.cjs +++ b/actions/setup/js/update_discussion.cjs @@ -292,7 +292,7 @@ function buildDiscussionUpdateData(item, config) { } const allowedLabels = config.allowed_labels || []; - const labelsResult = validateLabels(item.labels, allowedLabels.length > 0 ? allowedLabels : undefined); + const labelsResult = validateLabels(item.labels, allowedLabels.length > 0 ? allowedLabels : undefined, MAX_LABELS); if (!labelsResult.valid) { return { success: false, error: labelsResult.error ?? "Invalid labels" }; } diff --git a/actions/setup/js/update_discussion.test.cjs b/actions/setup/js/update_discussion.test.cjs index 9e7357ca697..69770dad0b3 100644 --- a/actions/setup/js/update_discussion.test.cjs +++ b/actions/setup/js/update_discussion.test.cjs @@ -36,6 +36,13 @@ describe("update_discussion", () => { { id: "LA_kwDO2", name: "Label2" }, { id: "LA_kwDO3", name: "Label3" }, { id: "LA_kwDO4", name: "Label4" }, + { id: "LA_kwDO5", name: "Label5" }, + { id: "LA_kwDO6", name: "Label6" }, + { id: "LA_kwDO7", name: "Label7" }, + { id: "LA_kwDO8", name: "Label8" }, + { id: "LA_kwDO9", name: "Label9" }, + { id: "LA_kwDO10", name: "Label10" }, + { id: "LA_kwDO11", name: "Label11" }, { id: "LA_kwDO_bug", name: "bug" }, { id: "LA_kwDO_feature", name: "feature" }, ]; @@ -282,6 +289,50 @@ describe("update_discussion", () => { // Label1 has id "LA_kwDO1" expect(addCalls[0].variables.labelIds).toEqual(["LA_kwDO1"]); }); + + it("should allow up to MAX_LABELS (10) labels, not just 3 (issue: discussion labels limited to 3 per item)", async () => { + const handler = await main({ + target: "*", + allow_labels: true, + }); + + // Agent requests 5 labels - previously this would truncate to 3 + const result = await handler({ type: "update_discussion", labels: ["Label1", "Label2", "Label3", "Label4", "Label5"], discussion_number: 42 }, {}); + expect(result.success).toBe(true); + + // Must not call updateDiscussion mutation (labels-only update) + expect(getUpdateDiscussionMutations()).toHaveLength(0); + + // All 5 labels should be applied, not truncated to 3 + const addCalls = getAddLabelsCalls(); + expect(addCalls).toHaveLength(1); + expect(addCalls[0].variables.labelIds).toEqual(["LA_kwDO1", "LA_kwDO2", "LA_kwDO3", "LA_kwDO4", "LA_kwDO5"]); + }); + + it("should reject when more than MAX_LABELS (10) labels are requested", async () => { + const handler = await main({ + target: "*", + allow_labels: true, + }); + + // Agent requests 11 labels — exceeds MAX_LABELS limit + const result = await handler( + { + type: "update_discussion", + labels: ["Label1", "Label2", "Label3", "Label4", "Label5", "Label6", "Label7", "Label8", "Label9", "Label10", "Label11"], + discussion_number: 42, + }, + {} + ); + + expect(result.success).toBe(false); + expect(result.error).toContain("E003"); + expect(result.error).toContain("10"); + + // No label mutations should have been called + expect(getAddLabelsCalls()).toHaveLength(0); + expect(getRemoveLabelsCalls()).toHaveLength(0); + }); }); describe("title-only update", () => {