From 0fb3e351de9dedaa6ec75bc8fff21684a7e8bb8f Mon Sep 17 00:00:00 2001 From: Cursor Agent Date: Mon, 10 Aug 2026 14:06:35 +0000 Subject: [PATCH] Show production commit on status page with GitHub link MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Probe commitSha from production GET /health each minute, persist the last known value in the status Durable Object, and render it in the page footer linked to github.com/kentcdodds/kody/commit/…. Co-authored-by: Kent C. Dodds --- packages/status/probes.node.test.ts | 19 +++++---- packages/status/probes.ts | 50 ++++++++++++++++++------ packages/status/status-page.node.test.ts | 10 ++++- packages/status/status-page.ts | 16 +++++++- packages/status/status-store.ts | 8 +++- packages/status/status-types.ts | 3 +- 6 files changed, 81 insertions(+), 25 deletions(-) diff --git a/packages/status/probes.node.test.ts b/packages/status/probes.node.test.ts index eee2e6a42b..16c8f6536b 100644 --- a/packages/status/probes.node.test.ts +++ b/packages/status/probes.node.test.ts @@ -27,7 +27,9 @@ const packageAppOrigin = 'https://kodyapps.dev' function healthyRoutes(): Record { return { - [`${primaryOrigin}/health`]: { body: { ok: true, commitSha: 'abc' } }, + [`${primaryOrigin}/health`]: { + body: { ok: true, commitSha: 'abc123def4567890abcdef1234567890abcdef12' }, + }, [`${primaryOrigin}/mcp`]: { status: 401, headers: { 'WWW-Authenticate': 'Bearer resource_metadata="..."' }, @@ -56,21 +58,24 @@ async function probe(routes: Record) { } function outcome( - outcomes: Awaited>, + result: Awaited>, component: string, ) { - return outcomes.find((entry) => entry.component === component) + return result.outcomes.find((entry) => entry.component === component) } test('a fully healthy pass reports every component ok', async () => { - const outcomes = await probe(healthyRoutes()) - expect(outcomes.map((entry) => entry.component).toSorted()).toEqual( + const result = await probe(healthyRoutes()) + expect(result.outcomes.map((entry) => entry.component).toSorted()).toEqual( [...statusComponentIds].toSorted(), ) - for (const entry of outcomes) { + for (const entry of result.outcomes) { expect(entry.ok, `${entry.component} should be ok`).toBe(true) } - expect(outcome(outcomes, 'app_db')?.latencyMs).toBe(4) + expect(outcome(result, 'app_db')?.latencyMs).toBe(4) + expect(result.productionCommitSha).toBe( + 'abc123def4567890abcdef1234567890abcdef12', + ) }) test('probe failures isolate to the affected component and map error details', async () => { diff --git a/packages/status/probes.ts b/packages/status/probes.ts index 1ffee47022..80d534c44a 100644 --- a/packages/status/probes.ts +++ b/packages/status/probes.ts @@ -65,32 +65,51 @@ async function timedFetch( } } +type AppHealthBody = { + ok?: boolean + commitSha?: string +} + +function readProductionCommitSha(body: AppHealthBody | null): string | null { + const commitSha = body?.commitSha?.trim() + if (!commitSha || !/^[0-9a-f]{7,40}$/i.test(commitSha)) return null + return commitSha.toLowerCase() +} + async function probeApp( fetcher: typeof fetch, primaryOrigin: string, -): Promise { +): Promise<{ outcome: ProbeOutcome; productionCommitSha: string | null }> { const result = await timedFetch(fetcher, `${primaryOrigin}/health`) if (!result.response) { return { - component: 'app', - ok: false, - latencyMs: result.latencyMs, - detail: result.error, + outcome: { + component: 'app', + ok: false, + latencyMs: result.latencyMs, + detail: result.error, + }, + productionCommitSha: null, } } + let body: AppHealthBody | null = null let bodyOk = false try { - const body = (await result.response.json()) as { ok?: boolean } + body = (await result.response.json()) as AppHealthBody bodyOk = body.ok === true } catch { + body = null bodyOk = false } const ok = result.response.ok && bodyOk return { - component: 'app', - ok, - latencyMs: result.latencyMs, - detail: ok ? null : `HTTP ${result.response.status}`, + outcome: { + component: 'app', + ok, + latencyMs: result.latencyMs, + detail: ok ? null : `HTTP ${result.response.status}`, + }, + productionCommitSha: readProductionCommitSha(body), } } @@ -184,9 +203,14 @@ async function probeStorageComponents( }) } +export type ProbeRunResult = { + outcomes: Array + productionCommitSha: string | null +} + export async function runAllProbes( config: ProbeConfig, -): Promise> { +): Promise { const fetcher = config.fetcher ?? fetch const [app, mcp, packageApps, storage] = await Promise.all([ probeApp(fetcher, config.primaryOrigin), @@ -194,7 +218,7 @@ export async function runAllProbes( probePackageApps(fetcher, config.packageAppOrigin), probeStorageComponents(fetcher, config.primaryOrigin), ]) - const outcomes = [app, mcp, packageApps, ...storage] + const outcomes = [app.outcome, mcp, packageApps, ...storage] const covered = new Set(outcomes.map((outcome) => outcome.component)) for (const component of statusComponentIds) { if (!covered.has(component)) { @@ -206,5 +230,5 @@ export async function runAllProbes( }) } } - return outcomes + return { outcomes, productionCommitSha: app.productionCommitSha } } diff --git a/packages/status/status-page.node.test.ts b/packages/status/status-page.node.test.ts index 84330cc795..0b64c6141b 100644 --- a/packages/status/status-page.node.test.ts +++ b/packages/status/status-page.node.test.ts @@ -33,7 +33,7 @@ function snapshot(overrides: Partial = {}): StatusSnapshot { openIncidents: [], recentIncidents: [], providerIncidents: null, - buildCommit: 'abc123', + productionCommit: 'abc123def4567890abcdef1234567890abcdef12', ...overrides, } } @@ -44,6 +44,11 @@ test('status page renders components, incidents, unknown state, and escapes deta expect(healthy).toContain(component.name.replaceAll('&', '&')) } expect(healthy).toContain('99.98% uptime') + expect(healthy).toContain('Production commit') + expect(healthy).toContain( + 'https://github.com/kentcdodds/kody/commit/abc123def4567890abcdef1234567890abcdef12', + ) + expect(healthy).toContain('>abc123d<') expect(healthy).toContain('http-equiv="refresh"') expect(healthy).toMatch(/operational|All systems/i) @@ -133,6 +138,9 @@ test('status page renders provider incidents separately and omits them when abse expect(withProvider).toContain('for context only') expect(withProvider).toContain('All systems operational') + const withoutCommit = renderStatusPage(snapshot({ productionCommit: null })) + expect(withoutCommit).not.toContain('Production commit') + const unsafeLink = renderStatusPage( snapshot({ providerIncidents: [ diff --git a/packages/status/status-page.ts b/packages/status/status-page.ts index a50cb1f459..d33d749a35 100644 --- a/packages/status/status-page.ts +++ b/packages/status/status-page.ts @@ -221,6 +221,20 @@ function renderProviderIncident(incident: ProviderIncident): string { ` } +/** Public GitHub repository for the main kody worker (production deploys). */ +const productionRepo = 'kentcdodds/kody' + +function productionCommitLink(commitSha: string): string { + const shortSha = commitSha.slice(0, 7) + const href = `https://github.com/${productionRepo}/commit/${escapeHtml(commitSha)}` + return `${escapeHtml(shortSha)}` +} + +function renderProductionCommit(commitSha: string | null): string { + if (!commitSha) return '' + return `Production commit ${productionCommitLink(commitSha)} · ` +} + function renderProviderIncidentsSection( incidents: Array | null | undefined, ): string { @@ -267,7 +281,7 @@ export function renderStatusPage(snapshot: StatusSnapshot): string { ${providerIncidents} ${recentIncidents}
- Probes run every minute from an independently deployed worker. + ${renderProductionCommit(snapshot.productionCommit)}Probes run every minute from an independently deployed worker. heykody.app · JSON
diff --git a/packages/status/status-store.ts b/packages/status/status-store.ts index 8d376a7a00..75935f9e87 100644 --- a/packages/status/status-store.ts +++ b/packages/status/status-store.ts @@ -31,6 +31,7 @@ import { } from './status-types.ts' const providerIncidentsMetaKey = 'provider_incidents_cache' +const productionCommitMetaKey = 'production_commit_sha' export type StatusWorkerEnv = { STATUS_STORE: DurableObjectNamespace @@ -385,11 +386,14 @@ export class StatusStore extends DurableObject { } async runProbes(): Promise { - const outcomes = await runAllProbes({ + const { outcomes, productionCommitSha } = await runAllProbes({ primaryOrigin: this.env.PRIMARY_ORIGIN, packageAppOrigin: this.env.PACKAGE_APP_ORIGIN, }) const now = Date.now() + if (productionCommitSha) { + this.setMeta(productionCommitMetaKey, productionCommitSha) + } for (const outcome of outcomes) { this.recordOutcome(outcome, now) } @@ -417,7 +421,7 @@ export class StatusStore extends DurableObject { openIncidents: this.listIncidents('open'), recentIncidents: this.listIncidents('resolved'), providerIncidents: this.readProviderIncidents(now), - buildCommit: this.env.BUILD_COMMIT ?? null, + productionCommit: this.getMeta(productionCommitMetaKey), } } diff --git a/packages/status/status-types.ts b/packages/status/status-types.ts index 95c8e68524..930b2435ba 100644 --- a/packages/status/status-types.ts +++ b/packages/status/status-types.ts @@ -73,5 +73,6 @@ export type StatusSnapshot = { * omits the provider section in that case (fail-soft). */ providerIncidents: Array | null - buildCommit: string | null + /** Latest `commitSha` reported by production `GET /health` (main worker). */ + productionCommit: string | null }