Something went wrong. Try again.
[READ-ONLY] Mirror of https://github.com/openstatusHQ/openstatus. ๐ซ Status page with uptime monitoring & API monitoring as code ๐ซ openstatus.dev
bun drizzle-orm monitoring monitoring-as-code nextjs observability on-call open-source shadcn-ui status-page statuspage synthetic-monitoring tinybird turso uptime uptime-checker uptime-monitor
Something went wrong. Try again.
2.5 kB ยท 85 lines
TypeScript
at incident-api
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586import { expect } from "@std/expect";import { beforeAll, describe, test } from "@std/testing/bdd";
import { createWorkspaceFixture, makeUserCtx, withTestTransaction,} from "../../../test/helpers";import type { Workspace } from "../../types";import { addIncidentNoteTool, agentTools, declareIncidentTool, getIncidentTool, isAgentToolAvailable, listIncidentsTool, resolveIncidentTool, updateIncidentTool,} from "../index";
let workspace: Workspace;let userId: number;
beforeAll(async () => { const fixture = await createWorkspaceFixture("team"); workspace = fixture.workspace; userId = fixture.userId;});
describe("incident agent tools", () => { test("declare defaults the commander to the requester, then the full loop", async () => { await withTestTransaction(async (tx) => { const ctx = { ...makeUserCtx(workspace, { userId }), db: tx }; const declared = await declareIncidentTool.run({ ctx, input: declareIncidentTool.inputSchema.parse({ title: "Checkout failing", severity: "critical", }), }); await updateIncidentTool.run({ ctx, input: { id: declared.id, severity: "major" }, }); await addIncidentNoteTool.run({ ctx, input: { id: declared.id, message: "Rolled back" }, }); const resolved = await resolveIncidentTool.run({ ctx, input: { id: declared.id, note: "Fixed" }, }); expect(resolved.status).toBe("resolved");
const list = await listIncidentsTool.run({ ctx, input: listIncidentsTool.inputSchema.parse({}), }); expect(list.items.map((i) => i.id)).toContain(declared.id);
const detail = await getIncidentTool.run({ ctx, input: { id: declared.id }, }); expect(detail.commander?.id).toBe(userId); expect(detail.severity).toBe("major"); expect(detail.events.map((e) => e.type)).toEqual([ "resolved", "note", "severity_changed", "declared", ]); expect(getIncidentTool.outputSchema.parse(detail)).toBeDefined(); }); });
test("every incident tool is feature-gated, the rest are not", () => { for (const tool of Object.values(agentTools)) { const isIncident = tool.name.includes("incident") || tool.name.includes("postmortem"); expect(tool.feature === "incident-management").toBe(isIncident); } expect(isAgentToolAvailable(listIncidentsTool, { id: 1 })).toBe(true); });});