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
8 changes: 7 additions & 1 deletion CLAUDE.md
Original file line number Diff line number Diff line change
Expand Up @@ -414,12 +414,13 @@ in `docs/adr/0001-event-bus-and-alerts.md`.
- `integration_disabled`: its type is off in the environment (Slack without `SLACK_CLIENT_ID`/`SECRET`), or the
organization disconnected it (e.g., last Slack workspace was removed)
- `unavailable`: no transport registered

It is computed, never stored. When an organization removes its last Slack workspace (`removeSlackWorkspace()`),
`disableForIntegration()` disables all enabled Slack channels with `disabledReason: 'integration'`; when Slack
is installed again, `restoreForIntegration()` enables only those back (ones manually disabled or failed stay
as they are). `deliver()` only sends to `connected` channels, the views (`toView()`, alert channel options)
carry it, and the settings list badges `integration_disabled`.

- Paused alerts and delivery status: `alertDelivery()` (`#lib/alerts/delivery.ts`, shared with the
client) says whether an alert is `live`: it has email recipients or at least one connected
channel. It computes `disconnectedTypes` (types of the alert's disconnected channels without repeats,
Expand Down Expand Up @@ -628,6 +629,11 @@ Making an event alertable:
monitors, monitors/new, monitors/[id], monitors/[id]/edit}`, thin routes over
`#lib/server/monitoring/page.ts`; components in `#lib/components/monitoring/`; the Code Report
service page shows its monitors (`service-monitors.ts`).
- Public API (`/api/monitoring/{monitors,monitors/[id],monitors/[id]/test,status}`, ADR 0005, logic in
`#lib/server/monitoring/api.ts`): permission-first (404 unreadable project/monitor, 403 no action,
409 `module_disabled`). Responses only carry `headerNames`/`hasHeaders`/`hasBody`, never header
values or the body, and URLs are the display URL. An `mcp` key sending `headers` or `body` on create
gets 400 `mcp_monitor_secrets_not_allowed`; other keys and sessions are unchanged.

## CVE feed

Expand Down
96 changes: 96 additions & 0 deletions e2e/specs/monitoring-api.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
import http from 'node:http';
import type { AddressInfo } from 'node:net';
import { test, expect } from '@playwright/test';
import { getSeed } from '../fixtures/auth';

const seed = getSeed();
const bearer = (token: string) => ({ Authorization: `Bearer ${token}` });

// a local target (the e2e server runs with MONITORING_ALLOW_PRIVATE_TARGETS=true)
let target: http.Server;
let targetUrl = '';

test.beforeAll(async () => {
target = http.createServer((_req, res) => res.writeHead(200).end('ok'));
await new Promise<void>((resolve) => target.listen(0, '127.0.0.1', resolve));
targetUrl = `http://127.0.0.1:${(target.address() as AddressInfo).port}`;
});

test.afterAll(() => {
target.closeAllConnections();
target.close();
});

test.describe('monitoring API', () => {
test('a key with create permission adds a monitor that shows up in the list', async ({
request,
}) => {
const name = `API monitor ${Date.now()}`;
const created = await request.post('/api/monitoring/monitors', {
headers: bearer(seed.apiKeys.write),
data: {
projectId: seed.primaryProjectId,
name,
url: `${targetUrl}/health?token=abc`,
headers: [{ name: 'Authorization', value: 'Bearer e2e-secret-value' }],
},
});
expect(created.status()).toBe(201);
const monitor = await created.json();
expect(monitor).toMatchObject({ name, hasHeaders: true, headerNames: ['Authorization'] });
expect(JSON.stringify(monitor)).not.toContain('e2e-secret-value');
expect(monitor.url).toBe(`${targetUrl}/health`);

const listed = await request.get(
`/api/monitoring/monitors?projectId=${seed.primaryProjectId}`,
{ headers: bearer(seed.apiKeys.readOnly) },
);
expect(listed.status()).toBe(200);
const items = (await listed.json()).items as { id: string; name: string }[];
expect(items.some((item) => item.id === monitor.id && item.name === name)).toBe(true);

const detail = await request.get(`/api/monitoring/monitors/${monitor.id}`, {
headers: bearer(seed.apiKeys.readOnly),
});
expect(detail.status()).toBe(200);

const status = await request.get(`/api/monitoring/status?projectId=${seed.primaryProjectId}`, {
headers: bearer(seed.apiKeys.readOnly),
});
expect((await status.json()).total).toBeGreaterThan(0);
});

test('validation errors come back per field', async ({ request }) => {
const response = await request.post('/api/monitoring/monitors', {
headers: bearer(seed.apiKeys.write),
data: { projectId: seed.primaryProjectId, name: '', url: 'nope' },
});
expect(response.status()).toBe(400);
expect(await response.json()).toMatchObject({
code: 'validation_failed',
errors: { name: 'monitoring.errors.required', url: 'monitoring.errors.invalid_url' },
});
});

test('a read-only key cannot create (403) and a key of another project sees nothing (404)', async ({
request,
}) => {
const data = { projectId: seed.primaryProjectId, name: 'Nope', url: targetUrl };
const readOnly = await request.post('/api/monitoring/monitors', {
headers: bearer(seed.apiKeys.readOnly),
data,
});
expect(readOnly.status()).toBe(403);

const outsider = await request.get(
`/api/monitoring/monitors?projectId=${seed.primaryProjectId}`,
{ headers: bearer(seed.apiKeys.outsiderProject) },
);
expect(outsider.status()).toBe(404);

const anonymous = await request.get(
`/api/monitoring/monitors?projectId=${seed.primaryProjectId}`,
);
expect(anonymous.status()).toBe(401);
});
});
Loading
Loading