caelum0x 5ccd834941 feat(watch): uptime checks with a public status page per app and owner email through Rally Send (PY2.2)
RYP-E4, dispatch 4.2 PY2.2 (Railyard side):
- lib/watch: checks (public https app addresses only; IPs, private names and
  our own hosts refused), 20 per org, a status page slug each. The box 1
  agent reads GET /api/v1/watch/agent/checks (ids and URLs only, bearer
  WATCH_AGENT_TOKEN) and posts results to /api/v1/watch/agent/results.
  Two failures in a row turn a check red; each change emails the owner once
  through Rally Send (product railyard, from status@, idempotency key per
  change; a failed send is retried on the next result). Older, unknown and
  future results change nothing.
- /status/<slug>: live results only (state, share of the last checks, bars),
  the check's name and never its address or any host or vendor name.
- The Watch screen: add by address, pause or resume, open the status page.
- Bridge route uptime (contract cases, uptime_check_keys): a check for the
  given address, or the app's latest live deploy; the first result is the
  slot's proof (check_result).
- Gated on RAILYARD_WATCH_LIVE (denylist rule railyard-slot-watch): off, no
  check runs, the pages 404, the nav has no Watch item and the slot answers
  arriving. The copy test lints each gated surface with the flag and proves it
  checks the flag first.
- Migration 0006 (watch_checks, watch_status; https only, history capped at
  90, cascades with the org).

Tests: watch 10/10, bridge 25/25, contract 3/3, migration 7/7 (0006 twice on a
scratch cluster), watch copy 7/7, console 108/108 with the bundle build,
tsc clean, SDK 7/7.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-09-30 00:24:06 +03:00

43 lines
1.4 KiB
TypeScript

// Alert email through Rally Send (Wave E contract 5.2): our own transactional
// sender, product "railyard". RALLY_TX_URL and RALLY_TX_KEY on the console.
export interface Mailer {
send(msg: { to: string; subject: string; text: string; html: string; idempotencyKey: string; project: string }): Promise<boolean>;
}
type Fetch = typeof fetch;
export function rallySend(opts: { url: string; key: string; fetchImpl?: Fetch }): Mailer {
return {
async send(msg) {
const res = await (opts.fetchImpl ?? fetch)(opts.url, {
method: "POST",
headers: { "content-type": "application/json", authorization: `Bearer ${opts.key}` },
body: JSON.stringify({
product: "railyard",
project: msg.project,
to: msg.to,
from_local: "status",
from_name: "Railyard status",
subject: msg.subject,
text: msg.text,
html: msg.html,
idempotency_key: msg.idempotencyKey,
tags: ["watch"],
}),
});
if (res.status === 202) return true;
console.error(`watch alert not sent: Rally Send answered ${res.status}`);
return false;
},
};
}
/** No sender configured: alerts are logged, never lost silently. */
export const noMailer: Mailer = {
async send(msg) {
console.error(`watch alert not sent (no RALLY_TX_URL): ${msg.subject}`);
return false;
},
};