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
32 changes: 32 additions & 0 deletions packages/cli/test/lib/api/alerts.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -604,6 +604,38 @@ describe("createMetricAlertRule", () => {
]);
});

test("drops empty trigger actions from detector conditions", async () => {
let sentBody: Record<string, unknown> = {};
globalThis.fetch = mockFetch(async (input, init) => {
sentBody = (await new Request(input!, init).json()) as Record<
string,
unknown
>;
return Response.json(metricDetector({ id: "1" }), { status: 201 });
});

await createMetricAlertRule("test-org", {
name: "Error spike",
query: "is:unresolved",
aggregate: "count()",
dataset: "errors",
timeWindow: 5,
triggers: [
{ label: "critical", alertThreshold: 11, actions: [] },
{ label: "warning", alertThreshold: 5, actions: [] },
],
projects: ["backend"],
});

expect(
(sentBody.conditionGroup as Record<string, unknown>).conditions,
).toEqual([
{ type: "gt", comparison: 11, conditionResult: 75 },
{ type: "gt", comparison: 5, conditionResult: 50 },
{ type: "lte", comparison: 11, conditionResult: 0 },
]);
});

test("passes native detector conditions through unchanged", async () => {
let sentBody: Record<string, unknown> = {};
globalThis.fetch = mockFetch(async (input, init) => {
Expand Down
14 changes: 14 additions & 0 deletions packages/cli/test/types/metric-alert.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,20 @@ describe("parseMetricTriggers", () => {
).not.toThrow();
});

// Older CLI releases required a non-empty `actions` array on each trigger
// (CLI-20K). Callers still send `actions: []`; it must parse, not fail.
test("passes threshold triggers with an empty actions array", () => {
expect(
parseMetricTriggers([
{ label: "critical", alertThreshold: 11, actions: [] },
{ label: "warning", alertThreshold: 5, actions: [] },
]),
).toEqual([
{ label: "critical", alertThreshold: 11, actions: [] },
{ label: "warning", alertThreshold: 5, actions: [] },
]);
});

test("rejects trigger actions, pointing at --workflow", () => {
expect(() =>
parseMetricTriggers([
Expand Down
Loading