File tree Expand file tree Collapse file tree
internal-packages/run-store/src Expand file tree Collapse file tree Original file line number Diff line number Diff line change 33 diffLatest ,
44 diffSince ,
55 normalizeFromRedis ,
6+ normalizeFromPg ,
67 SnapshotComparator ,
78 type DivergenceClass ,
89 type NormalizedSnapshot ,
@@ -154,6 +155,39 @@ describe("diffLatest", () => {
154155 ) ;
155156 expect ( d . some ( ( x ) => x . field === "toString" && x . class === "unknownField" ) ) . toBe ( true ) ;
156157 } ) ;
158+
159+ it ( "normalizeFromPg's waitpointIdSet is index-bearing only, matching the Redis read surface" , ( ) => {
160+ // A non-indexed completed waitpoint is in the relation but not in completedWaitpointOrder; Redis's
161+ // distinctIds (dedupe of order) does not expose it, so the PG side must not either.
162+ const row = {
163+ id : "s1" ,
164+ engine : "V2" ,
165+ executionStatus : "EXECUTING" ,
166+ description : "d" ,
167+ isValid : true ,
168+ error : null ,
169+ previousSnapshotId : null ,
170+ runId : "r1" ,
171+ runStatus : "EXECUTING" ,
172+ batchId : null ,
173+ attemptNumber : null ,
174+ environmentId : "env" ,
175+ environmentType : "DEVELOPMENT" ,
176+ projectId : "p" ,
177+ organizationId : "o" ,
178+ checkpointId : null ,
179+ workerId : null ,
180+ runnerId : null ,
181+ createdAt : new Date ( 1000 ) ,
182+ updatedAt : new Date ( 1000 ) ,
183+ metadata : null ,
184+ completedWaitpointOrder : [ "w_indexed" ] ,
185+ completedWaitpoints : [ { id : "w_indexed" } , { id : "w_nonindexed" } ] ,
186+ } ;
187+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
188+ const n = normalizeFromPg ( row as any ) ;
189+ expect ( n . waitpointIdSet ) . toEqual ( [ "w_indexed" ] ) ;
190+ } ) ;
157191} ) ;
158192
159193describe ( "diffSince" , ( ) => {
Original file line number Diff line number Diff line change @@ -101,7 +101,6 @@ function canonicalJson(v: unknown): string {
101101export function normalizeFromPg (
102102 row : Prisma . TaskRunExecutionSnapshotGetPayload < { include : { completedWaitpoints : true } } >
103103) : NormalizedSnapshot {
104- const wps = ( row . completedWaitpoints ?? [ ] ) as Array < { id : string } > ;
105104 const n : NormalizedSnapshot = {
106105 id : row . id ,
107106 engine : row . engine ,
@@ -125,7 +124,10 @@ export function normalizeFromPg(
125124 updatedAt : row . updatedAt . getTime ( ) ,
126125 metadata : row . metadata ?? null ,
127126 completedWaitpointOrder : [ ...( row . completedWaitpointOrder ?? [ ] ) ] ,
128- waitpointIdSet : [ ...wps . map ( ( w ) => w . id ) ] . sort ( ) ,
127+ // Index-bearing distinct set, from completedWaitpointOrder, to match the Redis read surface
128+ // (distinctIds = dedupe of `order`). The full relation holds non-indexed ids Redis does not
129+ // expose here (payload-layer, out of scope), so comparing it would fire a spurious divergence.
130+ waitpointIdSet : [ ...new Set ( row . completedWaitpointOrder ?? [ ] ) ] . sort ( ) ,
129131 } ;
130132 carryUnknownKeys ( n , row as unknown as Record < string , unknown > ) ;
131133 return n ;
You can’t perform that action at this time.
0 commit comments