Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
87 commits
Select commit Hold shift + click to select a range
5551306
fix(alerts): five ways a page was lost or left open
Makisuo Nov 24, 2026
16ff264
wip(on-call): gaps, departed members and chain tiers
Makisuo Nov 24, 2026
dd837a1
Merge branch 'alerts/lost-pages' into alerts/oncall-gaps
Makisuo Nov 24, 2026
dcb5e52
fix(alerts): close the gaps a review found in the lost-page fixes
Makisuo Nov 24, 2026
2fc74cd
fix(on-call): a step that reaches nobody no longer goes unnoticed
Makisuo Nov 24, 2026
c7882c1
feat(web): warn about coverage gaps and departed people on on-call sc…
Makisuo Nov 24, 2026
4d2c6f2
fix(slo): burn alerts that hold through an outage and do not fire on …
Makisuo Nov 24, 2026
fa3074e
Merge branch 'alerts/lost-pages' into alerts/oncall-gaps
Makisuo Nov 24, 2026
53f50c4
Merge remote-tracking branch 'origin/main' into alerts/lost-pages
Makisuo Nov 24, 2026
6878c1d
fix(on-call): review fixes for gap handling
Makisuo Nov 24, 2026
6e20154
Merge branch 'alerts/oncall-gaps-ui' into alerts/oncall-gaps
Makisuo Nov 24, 2026
d0cf95b
style(on-call): format the member notifier
Makisuo Nov 24, 2026
b66923d
Merge branch 'alerts/oncall-gaps' into slo/alert-correctness
Makisuo Nov 24, 2026
b6e28fb
wip(alerts): manual resolve and time to acknowledge
Makisuo Nov 24, 2026
9606c97
fix(slo): review fixes for the burn and budget alerts
Makisuo Nov 24, 2026
10224cc
Merge branch 'slo/alert-correctness' into alerts/incident-actions
Makisuo Nov 24, 2026
3c2ac87
feat(mcp): resolve_alert_incident resolves an open incident by hand
Makisuo Nov 24, 2026
47fa2ac
feat(web): SLO pages show capped tiers, the spent budget alert and SL…
Makisuo Nov 24, 2026
d9b69e8
Merge branch 'slo/alert-correctness-ui' into slo/alert-correctness
Makisuo Nov 24, 2026
d59ac62
fix(web): tier readings count recorded spans, as the evaluator does
Makisuo Nov 24, 2026
0ea2bf2
Merge remote-tracking branch 'origin/main' into alerts/lost-pages
Makisuo Nov 24, 2026
31ab3d2
fix(alerts): all-clears on rule delete cover every paged destination …
Makisuo Nov 24, 2026
9b5fe37
Merge branch 'alerts/lost-pages' into alerts/oncall-gaps
Makisuo Nov 24, 2026
294bf0c
fix(on-call): review fixes for chains that reach nobody
Makisuo Nov 24, 2026
62f53d0
Merge branch 'alerts/oncall-gaps' into slo/alert-correctness
Makisuo Nov 24, 2026
bde33d7
style(alerts): format after the merge
Makisuo Nov 24, 2026
a28c54b
Merge branch 'slo/alert-correctness' into alerts/incident-actions
Makisuo Nov 24, 2026
4ab0b4b
feat(alerts): resolve an incident by hand from the dashboard, and sho…
Makisuo Nov 24, 2026
96645b0
fix(alerts): review fixes for the resolve by hand
Makisuo Nov 24, 2026
a198643
Merge remote-tracking branch 'origin/main' into alerts/lost-pages
Makisuo Nov 24, 2026
7bdf929
test(browser): wire goldens follow the SDK version
Makisuo Nov 24, 2026
443b627
ci: size the ai test lanes at 1.5s per file
Makisuo Nov 24, 2026
04fbd34
Merge branch 'alerts/lost-pages' into alerts/oncall-gaps
Makisuo Nov 24, 2026
e2ee2c0
Merge branch 'alerts/oncall-gaps' into slo/alert-correctness
Makisuo Nov 24, 2026
30842bd
test(slo): record the new SLO SQL and check the recorded span count a…
Makisuo Nov 24, 2026
fd675ab
Merge branch 'slo/alert-correctness' into alerts/incident-actions
Makisuo Nov 24, 2026
2e2868e
feat(on-call): a private calendar feed per schedule
Makisuo Nov 24, 2026
18c432a
test(domain): the v2 incident contract fixture carries first_acknowle…
Makisuo Nov 24, 2026
841bb01
Merge branch 'alerts/incident-actions' into oncall/calendar-feed
Makisuo Nov 24, 2026
6f2e730
feat(web): the schedule page makes, replaces and turns off its calend…
Makisuo Nov 24, 2026
e848ac9
docs(alerting): on-call schedules and escalation chains
Makisuo Nov 24, 2026
ed9e402
fix(on-call): review fixes for the calendar feed
Makisuo Nov 24, 2026
79284af
Merge remote-tracking branch 'origin/fix/browser-wire-golden-version'…
Makisuo Nov 24, 2026
65189b8
Merge branch 'alerts/lost-pages' into alerts/oncall-gaps
Makisuo Nov 24, 2026
1629cf9
Merge branch 'alerts/oncall-gaps' into slo/alert-correctness
Makisuo Nov 24, 2026
c1cd272
Merge branch 'slo/alert-correctness' into alerts/incident-actions
Makisuo Nov 24, 2026
af24040
Merge branch 'alerts/incident-actions' into oncall/calendar-feed
Makisuo Nov 24, 2026
7562fd3
fix(alerts): second round of review fixes for lost pages
Makisuo Nov 24, 2026
afe24b5
Merge branch 'alerts/lost-pages' into alerts/oncall-gaps
Makisuo Nov 24, 2026
682a4de
fix(on-call): say that a departed person's shifts go uncovered when n…
Makisuo Nov 24, 2026
fe6ce9c
Merge branch 'alerts/oncall-gaps' into slo/alert-correctness
Makisuo Nov 24, 2026
4d2eade
fix(slo): review fixes for budget recovery, incident thresholds and s…
Makisuo Nov 24, 2026
f329c2d
Merge branch 'slo/alert-correctness' into alerts/incident-actions
Makisuo Nov 24, 2026
b0ac455
Merge branch 'alerts/incident-actions' into oncall/calendar-feed
Makisuo Nov 24, 2026
9902564
fix(alerts): review fixes for resolve by hand
Makisuo Nov 24, 2026
76cfa39
fix(on-call): review fixes for the calendar feed
Makisuo Nov 24, 2026
b01a24b
Merge branch 'alerts/lost-pages' into alerts/oncall-gaps
Makisuo Nov 24, 2026
e0c7c20
Merge branch 'alerts/oncall-gaps' into slo/alert-correctness
Makisuo Nov 24, 2026
5c1845d
Merge remote-tracking branch 'origin/main' into alerts/lost-pages
Makisuo Nov 24, 2026
351b5a2
Merge branch 'slo/alert-correctness' into alerts/incident-actions
Makisuo Nov 24, 2026
e11c5a6
Merge branch 'alerts/incident-actions' into oncall/calendar-feed
Makisuo Nov 24, 2026
3e3f024
fix(mcp): the coverage warning names the gap window the server report…
Makisuo Nov 24, 2026
720bcae
Merge branch 'alerts/oncall-gaps' into slo/alert-correctness
Makisuo Nov 24, 2026
5b9f480
Merge branch 'slo/alert-correctness' into alerts/incident-actions
Makisuo Nov 24, 2026
dc16334
Merge branch 'alerts/incident-actions' into oncall/calendar-feed
Makisuo Nov 24, 2026
6864371
fix(alerts): a skipped post earns no all-clear on rule deletion, and …
Makisuo Nov 24, 2026
dc2e03d
Merge branch 'alerts/lost-pages' into alerts/oncall-gaps
Makisuo Nov 24, 2026
17e9b68
Merge branch 'alerts/oncall-gaps' into slo/alert-correctness
Makisuo Nov 24, 2026
8c3cefa
Merge branch 'slo/alert-correctness' into alerts/incident-actions
Makisuo Nov 24, 2026
20ba262
Merge branch 'alerts/incident-actions' into oncall/calendar-feed
Makisuo Nov 24, 2026
90b70b8
fix(alerts): relink an all-clear that outlives its rule while in flig…
Makisuo Nov 24, 2026
f200c3d
Merge branch 'alerts/lost-pages' into alerts/oncall-gaps
Makisuo Nov 24, 2026
7f6e404
Merge branch 'alerts/oncall-gaps' into slo/alert-correctness
Makisuo Nov 24, 2026
5be044e
fix(slo): a held tier says it has no events or too few to judge, and …
Makisuo Nov 24, 2026
247ed8d
Merge branch 'slo/alert-correctness' into alerts/incident-actions
Makisuo Nov 24, 2026
4f38875
Merge branch 'alerts/incident-actions' into oncall/calendar-feed
Makisuo Nov 24, 2026
bb67f9c
fix(slo): a budget incident names no group, though it is stored with …
Makisuo Nov 24, 2026
ad35090
Merge branch 'slo/alert-correctness' into alerts/incident-actions
Makisuo Nov 24, 2026
9afebef
Merge branch 'alerts/incident-actions' into oncall/calendar-feed
Makisuo Nov 24, 2026
07e6937
fix(on-call): a calendar link someone else turned off stops showing a…
Makisuo Nov 24, 2026
b2a2041
test(on-call): leaving the calendar feed question sends nothing, and …
Makisuo Nov 24, 2026
8e578e2
Merge main after #3013 was squash-merged
Makisuo Nov 24, 2026
4f208e8
Merge remote-tracking branch 'origin/main' into slo/alert-correctness
Makisuo Nov 24, 2026
0059290
Merge branch 'slo/alert-correctness' into alerts/incident-actions
Makisuo Nov 24, 2026
16b682a
Merge main after #3017 was squash-merged
Makisuo Nov 24, 2026
4b8b434
Merge branch 'alerts/incident-actions' into oncall/calendar-feed
Makisuo Nov 24, 2026
4d8d519
Merge main after #3018 was squash-merged
Makisuo Nov 24, 2026
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
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,7 @@ const layer = (seen: Seen) =>
onCallNow: null,
coverageGaps: [],
departedUserIds: [],
calendarFeedCreatedAt: null,
chainIds: [CHAIN_ID],
createdAt: NOW,
updatedAt: NOW,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ const scheduleDoc = (overrides: Partial<typeof OnCallScheduleDocument.Encoded> =
},
coverageGaps: [],
departedUserIds: [],
calendarFeedCreatedAt: null,
chainIds: [],
createdAt: NOW,
updatedAt: NOW,
Expand Down
23 changes: 22 additions & 1 deletion apps/api/src/http/api-observability.test.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { describe, expect, it } from "vitest"
import { Effect } from "effect"
import { HttpMiddleware, HttpServerRequest, UrlParams } from "effect/http"
import { ApiObservabilityLive } from "./api-observability"
import { ApiObservabilityLive, loggablePath } from "./api-observability"

const tracedFor = (url: string, method = "GET") =>
Effect.gen(function* () {
Expand All @@ -23,6 +23,27 @@ describe("ApiObservabilityLive", () => {
expect(tracedFor("/hb/abc123secret/fail", "PUT")).toBe(false)
})

// The feed's link is its only credential, and a calendar app polls it for months.
it("records no server span for an on-call calendar feed, whatever follows the prefix", () => {
expect(tracedFor("/calendar/oncall/mcal_abc123secret.ics")).toBe(false)
expect(tracedFor("/calendar/oncall/mcal_abc123secret.ics?x=1")).toBe(false)
expect(tracedFor("/calendar/oncall/mcal_abc123secret/typo", "POST")).toBe(false)
expect(tracedFor("/calendar/oncallers")).toBe(true)
// Spellings the router still routes to the feed.
expect(tracedFor("/Calendar/OnCall/mcal_abc123secret.ics")).toBe(false)
expect(tracedFor("//calendar/oncall/mcal_abc123secret.ics")).toBe(false)
expect(tracedFor("/calendar//oncall/mcal_abc123secret.ics")).toBe(false)
})

it("writes a request path to the logs without the credential it holds", () => {
expect(loggablePath("/calendar/oncall/mcal_abc123secret.ics")).toBe("/calendar/oncall/[redacted]")
expect(loggablePath("/Calendar//oncall/mcal_abc123secret.ics?x=1")).toBe(
"/Calendar//oncall/[redacted]?x=1",
)
expect(loggablePath("/hb/abc123secret/fail")).toBe("/hb/[redacted]/fail")
expect(loggablePath("/v2/alerts/rules")).toBe("/v2/alerts/rules")
})

// The audit log is filtered by a member's email. The span of that request is kept for weeks
// and read by people who cannot open the audit log.
it("keeps an audit actor filter out of the URL a server span records", () => {
Expand Down
15 changes: 14 additions & 1 deletion apps/api/src/http/api-observability.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Layer } from "effect"
import { Layer, String as Str } from "effect"
import { Headers, HttpMiddleware, UrlParams } from "effect/http"
import { VCS_SYNC_BATCH_PATH } from "../worker/vcs-sync-dispatch"

Expand Down Expand Up @@ -31,6 +31,18 @@ const isUnroutedHeartbeat = (request: { url: string; method: string }) =>
HEARTBEAT_PATH.test(request.url) &&
!(HEARTBEAT_PING_ROUTE.test(request.url) && (request.method === "GET" || request.method === "POST"))

// An on-call calendar feed's path holds the feed's token, the only credential it has, and calendar
// apps poll it for as long as the link lives. The server span would keep that token in telemetry,
// so it is suppressed for the whole prefix; `OnCallCalendarRouter` carries its own span without it.
// The router matches without regard to case and collapses repeated slashes, so the filter does too.
const ONCALL_CALENDAR_PATH = /^\/+calendar\/+oncall(?:\/|$)/i

// Paths whose next segment is a credential: an on-call calendar link and a heartbeat ping. What
// logs a request path outside a span (a route graph that failed to build, a cause that escaped it)
// writes this form of it.
const CREDENTIAL_SEGMENT = /^(\/+(?:calendar\/+oncall|hb)\/+)[^/?#]+/i
export const loggablePath = (path: string): string => Str.replace(CREDENTIAL_SEGMENT, "$1[redacted]")(path)

// The `TracerDisabledWhen` filter and the header-redaction list — both
// references `HttpMiddleware.tracer` reads regardless of which Tracer is
// active. The Worker registers this layer with alchemy's `Telemetry.layer`, so
Expand All @@ -48,6 +60,7 @@ export const ApiObservabilityLive = Layer.mergeAll(
OAUTH_CALLBACK_PATH.test(request.url) ||
EMAIL_UNSUBSCRIBE_PATH.test(request.url) ||
isUnroutedHeartbeat(request) ||
ONCALL_CALENDAR_PATH.test(request.url) ||
/\.(png|ico|jpg|jpeg|gif|css|js|svg|webp|woff2?)(\?.*)?$/i.test(request.url),
),
// Spans record only the allowlisted headers (`MapleHttpTracingLive`), none of
Expand Down
93 changes: 93 additions & 0 deletions apps/api/src/routes/oncall-calendar.http.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
import { afterAll, describe, expect, it } from "@effect/vitest"
import { AlertMemberDirectoryUnavailableError, AlertPersistenceError } from "@maple/domain/http"
import { Effect, Layer, Option } from "effect"
import { HttpRouter } from "effect/http"
import { OnCallSchedulesService } from "@maple/backend/services/alerts/OnCallSchedulesService"
import { ShareRateLimiter } from "@maple/backend/services/auth/ShareRateLimiter"
import { onCallCalendarFeedUrl, OnCallCalendarRouter } from "./oncall-calendar.http"

const TOKEN = "mcal_known"
const CALENDAR = "BEGIN:VCALENDAR\r\nVERSION:2.0\r\nEND:VCALENDAR\r\n"
const asked: Array<string> = []

/** One feed exists, behind `TOKEN`; `mcal_down` and `mcal_nodir` stand for two things being down. */
const schedules = Layer.mock(OnCallSchedulesService)({
calendarFeed: (token) => {
asked.push(token)
if (token === "mcal_down")
return Effect.fail(new AlertPersistenceError({ message: "Alert persistence failed" }))
if (token === "mcal_nodir")
return Effect.fail(
new AlertMemberDirectoryUnavailableError({ message: "No answer", cause: "timeout" }),
)
return Effect.succeed(token === TOKEN ? Option.some(CALENDAR) : Option.none())
},
})

const limited = { now: false }
const checked: Array<{ readonly tokenHashPrefix: string; readonly ip: string | undefined }> = []
const rateLimiter = Layer.succeed(ShareRateLimiter, {
check: (input) => {
checked.push(input)
return Effect.succeed(limited.now ? ("limited" as const) : ("allowed" as const))
},
})

const { handler, dispose } = HttpRouter.toWebHandler(
OnCallCalendarRouter.pipe(Layer.provide(Layer.merge(schedules, rateLimiter))),
{ disableLogger: true },
)
afterAll(() => dispose())

const get = (path: string, method = "GET") =>
handler(new Request(`https://api.maple.test${path}`, { method }))

describe("OnCallCalendarRouter", () => {
it("serves the calendar behind a known link as text/calendar, kept out of shared caches and indexes", async () => {
const response = await get(new URL(onCallCalendarFeedUrl("https://api.maple.test", TOKEN)).pathname)
expect(response.status).toBe(200)
expect(response.headers.get("content-type")).toBe("text/calendar; charset=utf-8")
expect(response.headers.get("cache-control")).toBe("private, max-age=300")
expect(response.headers.get("x-robots-tag")).toBe("noindex")
expect(await response.text()).toBe(CALENDAR)
})

it("answers an unknown link, and a path without the .ics ending, with the same bare 404", async () => {
const unknown = await get("/calendar/oncall/mcal_guess.ics")
expect(unknown.status).toBe(404)
expect(await unknown.text()).toBe("Not found")
expect(unknown.headers.get("cache-control")).toBe("no-store")
const before = asked.length
const noSuffix = await get(`/calendar/oncall/${TOKEN}`)
expect(noSuffix.status).toBe(404)
// Not a feed path at all: the service is never asked.
expect(asked).toHaveLength(before)
})

it("says to come back later when the database cannot be read, without saying why", async () => {
const response = await get("/calendar/oncall/mcal_down.ics")
expect(response.status).toBe(503)
expect(response.headers.get("retry-after")).toBe("60")
expect(await response.text()).toBe("Temporarily unavailable")
})

it("answers 503, not a feed without names, when the member directory is down", async () => {
const response = await get("/calendar/oncall/mcal_nodir.ics")
expect(response.status).toBe(503)
expect(response.headers.get("retry-after")).toBe("300")
expect(response.headers.get("content-type")).not.toContain("text/calendar")
})

it("refuses a link polled too fast before reading anything, keyed by a hash of the link", async () => {
limited.now = true
const before = asked.length
const response = await get(`/calendar/oncall/${TOKEN}.ics`)
limited.now = false
expect(response.status).toBe(429)
expect(response.headers.get("retry-after")).toBe("60")
expect(asked).toHaveLength(before)
const key = checked[checked.length - 1]?.tokenHashPrefix ?? ""
expect(key).toMatch(/^[0-9a-f]{24}$/)
expect(key).not.toContain(TOKEN)
})
})
102 changes: 102 additions & 0 deletions apps/api/src/routes/oncall-calendar.http.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
import { createHash } from "node:crypto"
import { Effect, Option, String as Str } from "effect"
import { HttpRouter, HttpServerRequest, HttpServerResponse } from "effect/http"
import { OnCallSchedulesService } from "@maple/backend/services/alerts/OnCallSchedulesService"
import { ShareRateLimiter } from "@maple/backend/services/auth/ShareRateLimiter"

/**
* `GET /calendar/oncall/{token}.ics`: a schedule's shifts as an iCalendar feed, for a calendar app
* to subscribe to. No session and no API key: the link is the credential, so the response says
* nothing a caller without it could use, and an unknown link is the same bare 404 as a wrong path.
*/

export const ONCALL_CALENDAR_PATH = "/calendar/oncall"
const ICS_SUFFIX = ".ics"

/** The link a schedule's feed is fetched by. */
export const onCallCalendarFeedUrl = (apiOrigin: string, token: string): string =>
`${apiOrigin}${ONCALL_CALENDAR_PATH}/${token}${ICS_SUFFIX}`

// Private: the body names people. A calendar app refetches on its own clock, so a short
// lifetime only spares a burst of repeat requests.
const FEED_HEADERS = {
"cache-control": "private, max-age=300",
"x-robots-tag": "noindex",
"content-disposition": 'inline; filename="on-call.ics"',
}

const notFound = HttpServerResponse.text("Not found", {
status: 404,
headers: { "cache-control": "no-store", "x-robots-tag": "noindex" },
})

const comeBackLater = (seconds: number) =>
HttpServerResponse.text("Temporarily unavailable", {
status: 503,
headers: { "cache-control": "no-store", "retry-after": String(seconds) },
})

const tooManyRequests = HttpServerResponse.text("Too many requests", {
status: 429,
headers: { "cache-control": "no-store", "retry-after": "60" },
})

export const OnCallCalendarRouter = HttpRouter.use((router) =>
Effect.gen(function* () {
const schedules = yield* OnCallSchedulesService
const rateLimiter = yield* ShareRateLimiter
yield* router.add(
"GET",
`${ONCALL_CALENDAR_PATH}/:file`,
Effect.gen(function* () {
const params = yield* HttpRouter.params
const file = params.file ?? ""
if (!Str.endsWith(ICS_SUFFIX)(file)) return notFound
const token = Str.slice(0, -ICS_SUFFIX.length)(file)
// The same two buckets as a shared dashboard link: per caller, and per link, so a
// leaked link cannot be polled without bound. Keyed by a hash, never the token.
const request = yield* HttpServerRequest.HttpServerRequest
const outcome = yield* rateLimiter.check({
tokenHashPrefix: Str.slice(
0,
24,
)(createHash("sha256").update(token, "utf8").digest("hex")),
ip: request.headers["cf-connecting-ip"],
})
if (outcome === "limited") return tooManyRequests
const body = yield* schedules.calendarFeed(token)
return Option.match(body, {
onNone: () => notFound,
onSome: (calendar) =>
HttpServerResponse.text(calendar, {
status: 200,
contentType: "text/calendar; charset=utf-8",
headers: FEED_HEADERS,
}),
})
}).pipe(
Effect.tap((response) =>
Effect.annotateCurrentSpan("http.response.status_code", response.status),
),
Effect.tapError(() => Effect.annotateCurrentSpan("http.response.status_code", 503)),
// The request's only server span, since the automatic one is suppressed for this
// prefix. The token must not reach a trace: it carries the route, not the path.
Effect.withSpan("OnCallCalendar.feed", {
kind: "server",
attributes: {
"http.route": `${ONCALL_CALENDAR_PATH}/:file`,
"http.request.method": "GET",
},
}),
Comment thread
Makisuo marked this conversation as resolved.
Resolved
// A calendar app keeps its last good copy on a 503, which beats a feed without names.
Effect.catchTags({
"@maple/http/errors/AlertPersistenceError": () => Effect.succeed(comeBackLater(60)),
"@maple/http/errors/AlertMemberDirectoryUnavailableError": () =>
Effect.succeed(comeBackLater(300)),
}),
),
// The server span is suppressed for this prefix; this covers a span recorded anyway.
{ redactedParams: ["file"] },
)
}),
)
49 changes: 49 additions & 0 deletions apps/api/src/routes/v2/alerts.http.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1942,6 +1942,55 @@ describe("v2 alerts over HTTP", () => {
],
}

it("makes, replaces and turns off a schedule's calendar link", async () => {
const harness = makeHarness()
const key = await harness.bootstrapKey(["alerts:write"])
const readOnly = await harness.bootstrapKey(["alerts:read"])
const created = await harness.request(
"POST",
"/v2/alerts/oncall_schedules",
key.secret,
weeklySchedule,
)
expect(created.body.calendar_feed_created_at).toBeNull()
const base = `/v2/alerts/oncall_schedules/${created.body.id}`

const refused = await harness.request("POST", `${base}/calendar_feed`, readOnly.secret)
expect(refused.status).toBe(403)

const feed = await harness.request("POST", `${base}/calendar_feed`, key.secret)
expect(feed.status, JSON.stringify(feed.body)).toBe(200)
expect(feed.body).toMatchObject({ object: "oncall_calendar_feed", schedule_id: created.body.id })
expect(feed.body.url).toMatch(/\/calendar\/oncall\/mcal_[A-Za-z0-9_-]{43}\.ics$/)
const read = await harness.request("GET", base, readOnly.secret)
// The schedule says the feed is on and since when, never the link.
expect(read.body.calendar_feed_created_at).toBe(feed.body.created_at)
expect(JSON.stringify(read.body)).not.toContain("mcal_")

// A second create is refused, so a link calendars use is not ended by accident.
const again = await harness.request("POST", `${base}/calendar_feed`, key.secret)
expect([again.status, again.body.error.code]).toEqual([409, "oncall_calendar_feed_exists"])
const replaced = await harness.request("POST", `${base}/calendar_feed?replace=true`, key.secret)
expect(replaced.body.url).not.toBe(feed.body.url)

const off = await harness.request("DELETE", `${base}/calendar_feed`, key.secret)
expect(off.body).toEqual({
object: "oncall_calendar_feed",
schedule_id: created.body.id,
deleted: true,
})
expect((await harness.request("GET", base, key.secret)).body.calendar_feed_created_at).toBeNull()

const missing = await harness.request(
"POST",
"/v2/alerts/oncall_schedules/onc_tC4d9V79DCDzgbGKhAnff9/calendar_feed",
key.secret,
)
expect(missing.status).toBe(404)

await harness.dispose()
})

it("runs on-call schedule CRUD, answers who is on call and renders shifts around an override", async () => {
const harness = makeHarness()
const key = await harness.bootstrapKey(["alerts:write"])
Expand Down
Loading
Loading