@@ -1683,6 +1683,81 @@ describe("SessionProjector", () => {
16831683 } ) ,
16841684 )
16851685
1686+ it . effect ( "forks retain instruction notices as history but supersede them when they inherit a baseline" , ( ) =>
1687+ Effect . gen ( function * ( ) {
1688+ const db = yield * seedSession ( )
1689+ const bus = yield * Bus . Service
1690+ const store = yield * SessionStore . Service
1691+ const boundary = SessionMessage . ID . make ( "msg_fork_boundary" )
1692+ const messages = [
1693+ ...[
1694+ { text : "Legacy tool compatibility notice" } ,
1695+ { text : "Other system notice" , metadata : { notice : "legacy-tools" } } ,
1696+ { text : "Superseded instruction update" , metadata : { notice : "instructions" } } ,
1697+ ] . map ( ( message , index ) =>
1698+ SessionMessage . System . make ( {
1699+ ...message ,
1700+ id : SessionMessage . ID . make ( `msg_system_${ index } ` ) ,
1701+ type : "system" ,
1702+ time : { created } ,
1703+ } ) ,
1704+ ) ,
1705+ SessionMessage . User . make ( {
1706+ id : boundary ,
1707+ type : "user" ,
1708+ text : "Continue" ,
1709+ time : { created } ,
1710+ } ) ,
1711+ ]
1712+ yield * db
1713+ . insert ( SessionMessageTable )
1714+ . values (
1715+ messages . map ( ( message , seq ) => {
1716+ const { id, type, ...data } = encodeMessage ( message )
1717+ return { id : SessionMessage . ID . make ( id ) , session_id : sessionID , type, seq, time_created : 0 , data }
1718+ } ) ,
1719+ )
1720+ . run ( )
1721+ . pipe ( Effect . orDie )
1722+
1723+ for ( const inherited of [ false , true ] ) {
1724+ const childID = Session . ID . make ( `ses_instruction_fork_${ inherited } ` )
1725+ yield * bus . publish ( SessionEvent . Forked , {
1726+ sessionID : childID ,
1727+ parentID : sessionID ,
1728+ boundary : { type : "through" , messageID : boundary } ,
1729+ ...( inherited ? { instructions : { } } : { } ) ,
1730+ } )
1731+ const copied = yield * store . messages ( { sessionID : childID , order : "asc" } )
1732+ expect ( copied ) . toMatchObject ( [
1733+ { type : "system" , text : "Legacy tool compatibility notice" } ,
1734+ { type : "system" , text : "Other system notice" , metadata : { notice : "legacy-tools" } } ,
1735+ { type : "system" , text : "Superseded instruction update" , metadata : { notice : "instructions" } } ,
1736+ { type : "user" , text : "Continue" } ,
1737+ ] )
1738+ expect ( copied [ 2 ] . metadata ?. instructionSuperseded ) . toBe ( inherited ? true : undefined )
1739+ expect ( yield * store . context ( childID ) ) . toMatchObject ( [
1740+ { type : "system" , text : "Legacy tool compatibility notice" } ,
1741+ { type : "system" , text : "Other system notice" , metadata : { notice : "legacy-tools" } } ,
1742+ ...( inherited ? [ ] : [ { type : "system" , text : "Superseded instruction update" } ] ) ,
1743+ { type : "user" , text : "Continue" } ,
1744+ ] )
1745+ const grandchildID = Session . ID . make ( `ses_instruction_grandfork_${ inherited } ` )
1746+ yield * bus . publish ( SessionEvent . Forked , {
1747+ sessionID : grandchildID ,
1748+ parentID : childID ,
1749+ boundary : { type : "before" , messageID : copied [ 2 ] . id } ,
1750+ instructions : { } ,
1751+ } )
1752+ expect ( yield * store . messages ( { sessionID : grandchildID , order : "asc" } ) ) . toMatchObject ( [
1753+ { type : "system" , text : "Legacy tool compatibility notice" } ,
1754+ { type : "system" , text : "Other system notice" } ,
1755+ ] )
1756+ }
1757+ expect ( withoutIDs ( yield * store . messages ( { sessionID, order : "asc" } ) ) ) . toEqual ( withoutIDs ( messages ) )
1758+ } ) ,
1759+ )
1760+
16861761 it . effect ( "forks a settled message whose parts are in session_part with its content" , ( ) =>
16871762 Effect . gen ( function * ( ) {
16881763 const db = yield * seedSession ( )
0 commit comments