@@ -14,19 +14,9 @@ vi.setConfig({ testTimeout: 60_000 });
1414// real implementation. Dependency injection of a real store over a real container — not a mock.
1515class CountingPostgresRunStore extends PostgresRunStore {
1616 public readonly counts = {
17- findWaitpoint : 0 ,
1817 createWaitpoint : 0 ,
1918 } ;
2019
21- // The read client passed into the most recent findWaitpoint call (args[1]).
22- public lastFindWaitpointClient : unknown = undefined ;
23-
24- override findWaitpoint ( ...args : Parameters < PostgresRunStore [ "findWaitpoint" ] > ) {
25- this . counts . findWaitpoint ++ ;
26- this . lastFindWaitpointClient = args [ 1 ] ;
27- return super . findWaitpoint ( ...args ) ;
28- }
29-
3020 override createWaitpoint ( ...args : Parameters < PostgresRunStore [ "createWaitpoint" ] > ) {
3121 this . counts . createWaitpoint ++ ;
3222 return super . createWaitpoint ( ...args ) ;
@@ -123,62 +113,6 @@ async function createBatch(prisma: any, environment: any) {
123113}
124114
125115describe ( "RunEngine public waitpoint router" , ( ) => {
126- // getWaitpoint routes its read through the store seam, preserving the env-mismatch guard.
127- containerTest ( "getWaitpoint reads through the store" , async ( { prisma, redisOptions } ) => {
128- const environment = await setupAuthenticatedEnvironment ( prisma , "PRODUCTION" ) ;
129- const store = new CountingPostgresRunStore ( {
130- prisma,
131- readOnlyPrisma : prisma ,
132- } ) ;
133- const engine = new RunEngine ( engineOptions ( redisOptions , prisma , { store } ) ) ;
134-
135- try {
136- const { waitpoint } = await engine . createManualWaitpoint ( {
137- environmentId : environment . id ,
138- projectId : environment . project . id ,
139- } ) ;
140-
141- const before = store . counts . findWaitpoint ;
142- const found = await engine . getWaitpoint ( {
143- waitpointId : waitpoint . id ,
144- environmentId : environment . id ,
145- projectId : environment . project . id ,
146- } ) ;
147-
148- // routed through the store exactly once
149- expect ( store . counts . findWaitpoint ) . toBe ( before + 1 ) ;
150- assertNonNullable ( found ) ;
151- expect ( found . id ) . toBe ( waitpoint . id ) ;
152- // the include shape is preserved (blockingTaskRuns is present, even if empty)
153- expect ( ( found as any ) . blockingTaskRuns ) . toBeDefined ( ) ;
154- expect ( Array . isArray ( ( found as any ) . blockingTaskRuns ) ) . toBe ( true ) ;
155-
156- // the read is pinned to the PRIMARY client, not defaulted to the replica
157- expect ( store . lastFindWaitpointClient ) . toBe ( prisma ) ;
158-
159- // env-mismatch guard still returns null
160- const mismatch = await engine . getWaitpoint ( {
161- waitpointId : waitpoint . id ,
162- environmentId : "env_does_not_exist" ,
163- projectId : environment . project . id ,
164- } ) ;
165- expect ( mismatch ) . toBeNull ( ) ;
166-
167- // a non-existent waitpointId drives the `if (!waitpoint) return null` branch
168- const beforeMissing = store . counts . findWaitpoint ;
169- const missing = await engine . getWaitpoint ( {
170- waitpointId : "waitpoint_does_not_exist" ,
171- environmentId : environment . id ,
172- projectId : environment . project . id ,
173- } ) ;
174- expect ( missing ) . toBeNull ( ) ;
175- // not-found was reached THROUGH the store (not short-circuited)
176- expect ( store . counts . findWaitpoint ) . toBe ( beforeMissing + 1 ) ;
177- } finally {
178- await engine . quit ( ) ;
179- }
180- } ) ;
181-
182116 // blockRunWithCreatedBatch routes its BATCH waitpoint create through the store (non-tx path),
183117 // links the run, and preserves the P2002 duplicate-idempotency-key -> null path.
184118 containerTest (
@@ -424,12 +358,11 @@ describe("RunEngine public waitpoint router", () => {
424358 } ) ;
425359 assertNonNullable ( waitpoint ) ;
426360
427- // getWaitpoint reads back the row it wrote (with the include shape)
428- const fetched = await engine . getWaitpoint ( {
429- waitpointId : waitpoint . id ,
430- environmentId : environment . id ,
431- projectId : environment . project . id ,
432- } ) ;
361+ // the store reads back the row it wrote
362+ const fetched = await engine . runStore . findWaitpoint (
363+ { where : { id : waitpoint . id } } ,
364+ engine . prisma
365+ ) ;
433366 assertNonNullable ( fetched ) ;
434367 expect ( fetched . id ) . toBe ( waitpoint . id ) ;
435368 expect ( fetched . type ) . toBe ( "BATCH" ) ;
0 commit comments