@@ -1541,20 +1541,14 @@ describe("createTransform protected tail", () => {
15411541 expect ( createSession ) . not . toHaveBeenCalled ( ) ;
15421542 } ) ;
15431543
1544- it ( "clears stale compartmentInProgress and still applies pending ops in the same pass " , async ( ) => {
1545- //#given
1544+ it ( "clears stale compartmentInProgress when no eligible history exists " , async ( ) => {
1545+ //#given — stale compartmentInProgress with no raw history to resume
15461546 useTempDataHome ( "transform-protected-tail-pending-" ) ;
1547- createOpenCodeDbForTransform ( "ses-pt-pending" , [
1548- { id : "m-raw-1" , role : "user" , text : "recent 1" } ,
1549- { id : "m-raw-2" , role : "user" , text : "recent 2" } ,
1550- { id : "m-raw-3" , role : "user" , text : "recent 3" } ,
1551- ] ) ;
1552- const shouldExecute = mock < Scheduler [ "shouldExecute" ] > ( ( ) => "defer" ) ;
1553- const scheduler : Scheduler = { shouldExecute } ;
1547+ createOpenCodeDbForTransform ( "ses-pt-pending" , [ ] ) ;
15541548 const db = openDatabase ( ) ;
15551549 const transform = createTransform ( {
15561550 tagger : createTagger ( ) ,
1557- scheduler,
1551+ scheduler : { shouldExecute : ( ) => "defer" } ,
15581552 contextUsageMap : new Map ( [
15591553 [
15601554 "ses-pt-pending" ,
@@ -1567,7 +1561,7 @@ describe("createTransform protected tail", () => {
15671561 flushedSessions : new Set < string > ( ) ,
15681562 lastHeuristicsTurnId : new Map < string , string > ( ) ,
15691563 clearReasoningAge : 50 ,
1570- protectedTags : 0 ,
1564+ protectedTags : 10 ,
15711565 autoDropToolAge : 1000 ,
15721566 client : {
15731567 session : {
@@ -1581,41 +1575,26 @@ describe("createTransform protected tail", () => {
15811575 directory : "/tmp" ,
15821576 } ) ;
15831577
1584- const firstPass : TestMessage [ ] = [
1578+ const messages : TestMessage [ ] = [
15851579 {
15861580 info : { id : "m-user" , role : "user" , sessionID : "ses-pt-pending" } ,
1587- parts : [ { type : "text" , text : "keep me " } ] ,
1581+ parts : [ { type : "text" , text : "hello " } ] ,
15881582 } ,
15891583 {
15901584 info : { id : "m-assistant" , role : "assistant" } ,
1591- parts : [ { type : "text" , text : "assistant " } ] ,
1585+ parts : [ { type : "text" , text : "world " } ] ,
15921586 } ,
15931587 ] ;
1594- await transform ( { } , { messages : firstPass } ) ;
15951588
1596- queuePendingOp ( db , "ses-pt-pending" , 1 , "drop" ) ;
1589+ //#when — first pass initializes session, then set stale flag
1590+ await transform ( { } , { messages } ) ;
15971591 updateSessionMeta ( db , "ses-pt-pending" , { compartmentInProgress : true } ) ;
1598- shouldExecute . mockImplementation ( ( ) => "execute" ) ;
1599-
1600- const secondPass : TestMessage [ ] = [
1601- {
1602- info : { id : "m-user" , role : "user" , sessionID : "ses-pt-pending" } ,
1603- parts : [ { type : "text" , text : "keep me" } ] ,
1604- } ,
1605- {
1606- info : { id : "m-assistant" , role : "assistant" } ,
1607- parts : [ { type : "text" , text : "assistant" } ] ,
1608- } ,
1609- ] ;
1592+ expect ( getOrCreateSessionMeta ( db , "ses-pt-pending" ) . compartmentInProgress ) . toBe ( true ) ;
16101593
1611- //#when
1612- await transform ( { } , { messages : secondPass } ) ;
1594+ //#when — second pass detects stale flag, clears it (no eligible history to resume)
1595+ await transform ( { } , { messages } ) ;
16131596
16141597 //#then
1615- expect ( secondPass ) . toHaveLength ( 1 ) ;
1616- expect ( text ( secondPass [ 0 ] , 0 ) ) . toContain ( "assistant" ) ;
1617- expect ( getTagById ( db , "ses-pt-pending" , 1 ) ?. status ) . toBe ( "dropped" ) ;
1618- expect ( getPendingOps ( db , "ses-pt-pending" ) ) . toHaveLength ( 0 ) ;
16191598 expect ( getOrCreateSessionMeta ( db , "ses-pt-pending" ) . compartmentInProgress ) . toBe ( false ) ;
16201599 } ) ;
16211600} ) ;
0 commit comments