@@ -474,4 +474,83 @@ describe("run-ops split — read-after-write reads the OWNING store's WRITER, no
474474 expect ( hits ( ) ) . toEqual ( { ...none , newWriter : true , legacyWriter : true } ) ;
475475 }
476476 ) ;
477+
478+ // Catches: a dropped field list, a client with no field list reading a replica, or a branded replica reaching a writer.
479+ heteroRunOpsPostgresTest (
480+ "findRunOrThrow with a caller client keeps the field list or reads the whole row, and a branded replica fans out over the replicas" ,
481+ async ( { prisma14, prisma17 } ) => {
482+ const dedicated = seedEnvironmentDedicated ( "ort_rows_new" ) ;
483+ const legacy = await seedEnvironmentLegacy ( prisma14 , "ort_rows_leg" ) ;
484+ const newRunId = `run_${ NEW_ID_26 } ` ;
485+ const legacyRunId = `run_${ CUID_25 } ` ;
486+ await prisma17 . taskRun . create ( {
487+ data : taskRunData ( {
488+ id : newRunId ,
489+ friendlyId : "run_rows_new" ,
490+ organizationId : dedicated . organization . id ,
491+ projectId : dedicated . project . id ,
492+ runtimeEnvironmentId : dedicated . environment . id ,
493+ } ) ,
494+ } ) ;
495+ await prisma14 . taskRun . create ( {
496+ data : {
497+ ...taskRunData ( {
498+ id : legacyRunId ,
499+ friendlyId : "run_rows_leg" ,
500+ organizationId : legacy . organization . id ,
501+ projectId : legacy . project . id ,
502+ runtimeEnvironmentId : legacy . environment . id ,
503+ } ) ,
504+ spanId : "span_rows_legacy" ,
505+ } ,
506+ } ) ;
507+
508+ // 1. Run id with a field list → only the selected field (plus `id`, which the run-ops
509+ // schema's select always keeps), from the NEW writer.
510+ const selected = makeLaggingRouter ( prisma14 , prisma17 ) ;
511+ expect (
512+ await selected . router . findRunOrThrow (
513+ { id : newRunId } ,
514+ { select : { friendlyId : true } } ,
515+ prisma14
516+ )
517+ ) . toEqual ( { friendlyId : "run_rows_new" , id : newRunId } ) ;
518+ expect ( selected . hits ( ) ) . toEqual ( { ...none , newWriter : true } ) ;
519+
520+ // 2. Run id, client and no field list → the whole row, from the NEW writer.
521+ const wholeRow = makeLaggingRouter ( prisma14 , prisma17 ) ;
522+ const row = await wholeRow . router . findRunOrThrow ( { id : newRunId } , prisma14 ) ;
523+ expect ( row ) . toMatchObject ( { friendlyId : "run_rows_new" , taskIdentifier : "my-task" } ) ;
524+ expect ( wholeRow . hits ( ) ) . toEqual ( { ...none , newWriter : true } ) ;
525+
526+ // 3. No run id with a field list → only the selected field, from the LEGACY writer.
527+ const fanSelected = makeLaggingRouter ( prisma14 , prisma17 ) ;
528+ expect (
529+ await fanSelected . router . findRunOrThrow (
530+ { spanId : "span_rows_legacy" } ,
531+ { select : { id : true } } ,
532+ prisma14
533+ )
534+ ) . toEqual ( { id : legacyRunId } ) ;
535+ expect ( fanSelected . hits ( ) ) . toEqual ( { ...none , newWriter : true , legacyWriter : true } ) ;
536+
537+ // 4. No run id, client and no field list, every database misses → P2025 from the LEGACY writer.
538+ const fanMissing = makeLaggingRouter ( prisma14 , prisma17 ) ;
539+ await expect (
540+ fanMissing . router . findRunOrThrow ( { spanId : "span_rows_nowhere" } , prisma14 )
541+ ) . rejects . toMatchObject ( notFound ) ;
542+ expect ( fanMissing . hits ( ) ) . toEqual ( { ...none , newWriter : true , legacyWriter : true } ) ;
543+
544+ // 5. No run id and a branded replica → both replicas, no writer.
545+ const fanReplica = makeLaggingRouter ( prisma14 , prisma17 ) ;
546+ await expect (
547+ fanReplica . router . findRunOrThrow (
548+ { spanId : "span_rows_legacy" } ,
549+ { select : { id : true } } ,
550+ markReadReplicaClient ( { } ) as never
551+ )
552+ ) . rejects . toThrow ( "lagging replica" ) ;
553+ expect ( fanReplica . hits ( ) ) . toEqual ( { ...none , newReplica : true , legacyReplica : true } ) ;
554+ }
555+ ) ;
477556} ) ;
0 commit comments