feat: realtime test status with polling backstop#27
Merged
Conversation
Logged-in (bearer) users now get near-instant run status via a Supabase Realtime subscription on the `results` table, layered over the existing poll loop as a latency optimisation rather than a rewrite: a realtime change "pokes" the loop to fetch immediately, reusing all existing render/terminal/artifact logic. - AuthContext exposes accessToken + env for bearer sessions so realtime can authenticate the socket under RLS (no DB migration needed — we only read the `new` row). - RealtimeResultsGateway: subscribes to postgres_changes on `results` filtered by org_id; any failure degrades silently to pure polling. - Backstop cadence: 60s for bearer (realtime carries the fast path), 20s for api-key users (no realtime). Inter-poll wait is interruptible and latches pokes that land mid-fetch so events are never dropped. - api-key users get a dim `dcd login` tip, suppressed in CI / json / quiet. - New isCI() helper + unit tests. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Code reviewNo issues found. Checked for bugs and CLAUDE.md compliance. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What & why
The CLI learned test-run status only by HTTP polling (
GET /results/{uploadId}every 10s). The backend already writes status to the Postgresresultstable, that table is in thesupabase_realtimepublication, and the frontend already consumes it live. This PR gives logged-in users near-instant status by reusing that same channel, while keeping polling as the resilience backstop.Approach
Realtime is a latency optimisation layered over the existing poll loop, not a rewrite. A realtime change "pokes" the loop to fetch immediately, so all existing render / terminal-state / artifact-download logic is reused unchanged. If realtime can't connect (network blocks WebSockets, or the user is on an api-key), the loop just keeps polling.
AuthContextnow carriesaccessToken+envfor bearer (logged-in) sessions, so the realtime socket can authenticate under RLS. No DB migration needed — we only read thenewrow (status,test_upload_id), which Postgres always ships on INSERT/UPDATE.RealtimeResultsGateway(new) — subscribes topostgres_changesonresultsfiltered byorg_id,setAuths the JWT, firesonChangewhen a row for this upload changes. Construction never throws; any failure degrades silently to pure polling.dcd logintip, suppressed in CI /--json/--quietvia a new dependency-freeisCI()helper.Known limitations (documented in code)
Verification
pnpm typecheck— cleanpnpm lint— 0 errorspnpm test— 147 passing (142 + 5 newisCIunit tests)exec(non-TTY).Manual (not yet run against a live env): logged-in run with
--debugshould show the channelSUBSCRIBEDand status updating between the 60s polls; api-key run should show 20s polling + the tip, with the tip gone underCI=1.🤖 Generated with Claude Code