Skip to content

Commit 1c3f5ca

Browse files
committed
fix(webapp): isolate runTableV2Status from its poller under test; qualify publication probe by schema
Code-review follow-ups on the v2 hardening: - runTableV2Status no longer starts its background poller under vitest (NODE_ENV=test). The module is imported by the mint/read sites, so the import-time poll plus setInterval was firing live DB queries against the test database and leaking a timer, and the async refresh could race tests that drive the cached status directly. Tests exercise the gates by mutating the cached state, so the poller only gets in the way. - The publication-readiness probe now filters pg_publication_tables on schemaname = "public", so a same-named table in another published schema cannot satisfy the check.
1 parent 2bc70be commit 1c3f5ca

2 files changed

Lines changed: 14 additions & 3 deletions

File tree

apps/webapp/app/v3/runTableV2Status.server.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,15 @@ const status = singleton("runTableV2Status", initialize);
3838
function initialize(): RunTableV2Status {
3939
const state: RunTableV2Status = { published: false, hasRows: false };
4040

41+
// No background poller under vitest: this module is imported by the mint/read
42+
// sites, so a live DB poll + setInterval at import time would query the test
43+
// database and leak a timer for the test run, and the async refresh could race
44+
// tests that drive the cached status directly. Tests exercise the gates by
45+
// mutating the cached state, so the poller would only get in the way.
46+
if (env.NODE_ENV === "test") {
47+
return state;
48+
}
49+
4150
// The publication only exists when runs replication is configured. Without it
4251
// no v2 run can be captured by ClickHouse, so leave published=false: minting
4352
// stays on legacy regardless of org flags.
@@ -51,6 +60,7 @@ function initialize(): RunTableV2Status {
5160
SELECT EXISTS (
5261
SELECT 1 FROM pg_publication_tables
5362
WHERE pubname = ${env.RUN_REPLICATION_PUBLICATION_NAME}
63+
AND schemaname = 'public'
5464
AND tablename = 'task_run_v2'
5565
) AS present`;
5666
state.published = published[0]?.present ?? false;

apps/webapp/test/runTableV2Status.test.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,10 @@ import { describe, expect, it } from "vitest";
22
import { canMintV2Run, v2RunsMayExist } from "~/v3/runTableV2Status.server";
33

44
// The module caches its status in a globalThis singleton ("runTableV2Status").
5-
// In the unit-test env runs replication is unconfigured, so it initializes to
6-
// { published:false, hasRows:false } with no background poller. Mutate that
7-
// cached object to exercise the gates deterministically.
5+
// Under vitest (NODE_ENV=test) it skips the background poller entirely and
6+
// initializes to { published:false, hasRows:false } — so no live DB query, no
7+
// leaked interval, and nothing races these assertions. Mutate that cached
8+
// object to exercise the gates deterministically.
89
function setStatus(published: boolean, hasRows: boolean) {
910
const singletons = (globalThis as any).__trigger_singletons;
1011
// Force module init (the singleton is created on first getter call/import).

0 commit comments

Comments
 (0)