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
81 changes: 81 additions & 0 deletions actions/setup/js/add_labels.test.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -569,5 +569,86 @@ describe("add_labels", () => {
expect(result.number).toBe(99);
expect(addLabelsCalls[0].issue_number).toBe(99);
});

it("should preview labels in staged mode without calling API", async () => {
const handler = await main({ max: 10, staged: true });
const addLabelsCalls = [];

mockGithub.rest.issues.addLabels = async params => {
addLabelsCalls.push(params);
return {};
};

const result = await handler(
{
item_number: 100,
labels: ["bug", "enhancement"],
},
{}
);

expect(result.success).toBe(true);
expect(result.staged).toBe(true);
expect(result.previewInfo).toBeDefined();
expect(result.previewInfo.number).toBe(100);
expect(result.previewInfo.labels).toEqual(["bug", "enhancement"]);
expect(addLabelsCalls.length).toBe(0);
});

it("should count staged calls toward processedCount", async () => {
const handler = await main({ max: 1, staged: true });

const result1 = await handler({ item_number: 1, labels: ["bug"] }, {});
expect(result1.success).toBe(true);
expect(result1.staged).toBe(true);

const result2 = await handler({ item_number: 2, labels: ["enhancement"] }, {});
expect(result2.success).toBe(false);
expect(result2.error).toContain("Max count");
});

it("should filter out labels matching blocked patterns", async () => {
const handler = await main({
max: 10,
blocked: ["internal-*", "~*"],
});
const addLabelsCalls = [];

mockGithub.rest.issues.addLabels = async params => {
addLabelsCalls.push(params);
return {};
};

const result = await handler(
{
item_number: 100,
labels: ["bug", "internal-only", "~secret", "enhancement"],
},
{}
);

expect(result.success).toBe(true);
expect(result.labelsAdded).toEqual(["bug", "enhancement"]);
Copy link

Copilot AI Mar 23, 2026

Choose a reason for hiding this comment

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

This test assumes the GitHub API is called exactly once, but it never asserts the call count. Adding an explicit assertion (e.g., that addLabelsCalls has length 1) would prevent the test from passing if the handler accidentally performs multiple addLabels calls.

Suggested change
expect(result.labelsAdded).toEqual(["bug", "enhancement"]);
expect(result.labelsAdded).toEqual(["bug", "enhancement"]);
expect(addLabelsCalls).toHaveLength(1);

Copilot uses AI. Check for mistakes.
expect(addLabelsCalls[0].labels).toEqual(["bug", "enhancement"]);
});

it("should succeed with empty labelsAdded when all labels filtered by allowed list", async () => {
const handler = await main({
max: 10,
allowed: ["bug", "enhancement"],
});

const result = await handler(
{
item_number: 100,
labels: ["documentation", "invalid-label"],
},
{}
);

expect(result.success).toBe(true);
expect(result.labelsAdded).toEqual([]);
expect(result.message).toContain("No valid labels");
});
Comment on lines +649 to +652
Copy link

Copilot AI Mar 23, 2026

Choose a reason for hiding this comment

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

This test doesn’t verify that the handler avoids calling github.rest.issues.addLabels when no valid labels remain after filtering. Consider stubbing addLabels (as in other tests) and asserting it was not called, so the behavior remains protected against regressions.

Copilot uses AI. Check for mistakes.
});
});
4 changes: 2 additions & 2 deletions pkg/workflow/label_trigger_integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,8 +88,8 @@ func TestLabelTriggerIntegrationSimple(t *testing.T) {
}

required, ok := itemNumber["required"].(bool)
if !ok || !required {
t.Errorf("item_number.required = %v, want true", required)
if !ok || required {
t.Errorf("item_number.required = %v, want false", required)
}
}

Expand Down
Loading