@@ -395,34 +395,36 @@ describe("StandardMetadataManager", () => {
395395 const update = metadataUpdates [ 0 ] ! ;
396396 const operations = update . operations ! ;
397397
398- // Should have: 1 collapsed increment, 1 collapsed set, 2 appends
399- // (delete operations on non-existent keys are not queued)
400- expect ( operations ) . toHaveLength ( 4 ) ;
401-
402- // Find each operation type
403- const incrementOp = operations . find ( ( op ) => op . type === "increment" ) ;
404- const setOp = operations . find ( ( op ) => op . type === "set" ) ;
405- const appendOps = operations . filter ( ( op ) => op . type === "append" ) ;
398+ // With order-preserving collapse, expect 6 operations:
399+ // increment(counter, 5), set(status, processing), append(logs, ...), increment(counter, 3), set(status, completed), append(logs, ...)
400+ expect ( operations ) . toHaveLength ( 6 ) ;
406401
407- expect ( incrementOp ) . toEqual ( {
402+ expect ( operations [ 0 ] ) . toEqual ( {
408403 type : "increment" ,
409404 key : "counter" ,
410- value : 8 , // 5 + 3
405+ value : 5 ,
411406 } ) ;
412-
413- expect ( setOp ) . toEqual ( {
407+ expect ( operations [ 1 ] ) . toEqual ( {
414408 type : "set" ,
415409 key : "status" ,
416- value : "completed" , // Last set value
410+ value : "processing" ,
417411 } ) ;
418-
419- expect ( appendOps ) . toHaveLength ( 2 ) ;
420- expect ( appendOps [ 0 ] ) . toEqual ( {
412+ expect ( operations [ 2 ] ) . toEqual ( {
421413 type : "append" ,
422414 key : "logs" ,
423415 value : "Started processing" ,
424416 } ) ;
425- expect ( appendOps [ 1 ] ) . toEqual ( {
417+ expect ( operations [ 3 ] ) . toEqual ( {
418+ type : "increment" ,
419+ key : "counter" ,
420+ value : 3 ,
421+ } ) ;
422+ expect ( operations [ 4 ] ) . toEqual ( {
423+ type : "set" ,
424+ key : "status" ,
425+ value : "completed" ,
426+ } ) ;
427+ expect ( operations [ 5 ] ) . toEqual ( {
426428 type : "append" ,
427429 key : "logs" ,
428430 value : "Processing completed" ,
@@ -454,42 +456,48 @@ describe("StandardMetadataManager", () => {
454456 const update = metadataUpdates [ 1 ] ! ;
455457 const operations = update . operations ! ;
456458
457- // Should have: 1 collapsed increment, 1 collapsed set, 2 appends, 2 collapsed deletes
458- expect ( operations ) . toHaveLength ( 6 ) ;
459-
460- // Find each operation type
461- const incrementOp = operations . find ( ( op ) => op . type === "increment" ) ;
462- const setOp = operations . find ( ( op ) => op . type === "set" ) ;
463- const appendOps = operations . filter ( ( op ) => op . type === "append" ) ;
464- const deleteOps = operations . filter ( ( op ) => op . type === "delete" ) ;
459+ // With order-preserving collapse, expect 8 operations:
460+ // increment(counter, 5), set(status, processing), append(logs, ...), increment(counter, 3), set(status, completed), append(logs, ...), delete(tempData1), delete(tempData2)
461+ expect ( operations ) . toHaveLength ( 8 ) ;
465462
466- expect ( incrementOp ) . toEqual ( {
463+ expect ( operations [ 0 ] ) . toEqual ( {
467464 type : "increment" ,
468465 key : "counter" ,
469- value : 8 , // 5 + 3
466+ value : 5 ,
470467 } ) ;
471-
472- expect ( setOp ) . toEqual ( {
468+ expect ( operations [ 1 ] ) . toEqual ( {
473469 type : "set" ,
474470 key : "status" ,
475- value : "completed" , // Last set value
471+ value : "processing" ,
476472 } ) ;
477-
478- expect ( appendOps ) . toHaveLength ( 2 ) ;
479- expect ( appendOps [ 0 ] ) . toEqual ( {
473+ expect ( operations [ 2 ] ) . toEqual ( {
480474 type : "append" ,
481475 key : "logs" ,
482476 value : "Started processing" ,
483477 } ) ;
484- expect ( appendOps [ 1 ] ) . toEqual ( {
478+ expect ( operations [ 3 ] ) . toEqual ( {
479+ type : "increment" ,
480+ key : "counter" ,
481+ value : 3 ,
482+ } ) ;
483+ expect ( operations [ 4 ] ) . toEqual ( {
484+ type : "set" ,
485+ key : "status" ,
486+ value : "completed" ,
487+ } ) ;
488+ expect ( operations [ 5 ] ) . toEqual ( {
485489 type : "append" ,
486490 key : "logs" ,
487491 value : "Processing completed" ,
488492 } ) ;
489-
490- expect ( deleteOps ) . toHaveLength ( 2 ) ;
491- const deleteKeys = deleteOps . map ( ( op ) => ( op as any ) . key ) . sort ( ) ;
492- expect ( deleteKeys ) . toEqual ( [ "tempData1" , "tempData2" ] ) ;
493+ expect ( operations [ 6 ] ) . toEqual ( {
494+ type : "delete" ,
495+ key : "tempData1" ,
496+ } ) ;
497+ expect ( operations [ 7 ] ) . toEqual ( {
498+ type : "delete" ,
499+ key : "tempData2" ,
500+ } ) ;
493501 } ) ;
494502
495503 test ( "should collapse operations across different keys independently" , async ( ) => {
@@ -504,26 +512,30 @@ describe("StandardMetadataManager", () => {
504512 expect ( metadataUpdates ) . toHaveLength ( 1 ) ;
505513
506514 const update = metadataUpdates [ 0 ] ! ;
507- expect ( update . operations ) . toHaveLength ( 2 ) ;
508-
509- // Should have separate collapsed increments for each key
510- const filesOp = update . operations ! . find (
511- ( op ) => op . type === "increment" && ( op as any ) . key === "filesProcessed"
512- ) ;
513- const errorsOp = update . operations ! . find (
514- ( op ) => op . type === "increment" && ( op as any ) . key === "errorsCount"
515- ) ;
515+ const operations = update . operations ! ;
516516
517- expect ( filesOp ) . toEqual ( {
517+ // With order-preserving collapse, expect 4 operations:
518+ // increment(filesProcessed, 10), increment(errorsCount, 1), increment(filesProcessed, 5), increment(errorsCount, 2)
519+ expect ( operations ) . toHaveLength ( 4 ) ;
520+ expect ( operations [ 0 ] ) . toEqual ( {
518521 type : "increment" ,
519522 key : "filesProcessed" ,
520- value : 15 , // 10 + 5
523+ value : 10 ,
521524 } ) ;
522-
523- expect ( errorsOp ) . toEqual ( {
525+ expect ( operations [ 1 ] ) . toEqual ( {
526+ type : "increment" ,
527+ key : "errorsCount" ,
528+ value : 1 ,
529+ } ) ;
530+ expect ( operations [ 2 ] ) . toEqual ( {
531+ type : "increment" ,
532+ key : "filesProcessed" ,
533+ value : 5 ,
534+ } ) ;
535+ expect ( operations [ 3 ] ) . toEqual ( {
524536 type : "increment" ,
525537 key : "errorsCount" ,
526- value : 3 , // 1 + 2
538+ value : 2 ,
527539 } ) ;
528540 } ) ;
529541
0 commit comments