@@ -75,6 +75,13 @@ function createMockHostClient() {
7575 latestSnapshot = snapshot . state ;
7676 } ,
7777 } as unknown as HunkSessionBrokerClient ,
78+ dispatchCommand : async ( message : HunkSessionServerMessage ) => {
79+ if ( ! bridge ) {
80+ throw new Error ( "Expected App to register a bridge before running the test command." ) ;
81+ }
82+
83+ return bridge . dispatchCommand ( message ) ;
84+ } ,
7885 getBridge : ( ) => bridge ,
7986 getLatestSnapshot : ( ) => latestSnapshot ,
8087 navigateToHunk : async (
@@ -1113,6 +1120,90 @@ describe("App interactions", () => {
11131120 }
11141121 } ) ;
11151122
1123+ test ( "session reload preserves live comments while refreshing the file diff" , async ( ) => {
1124+ const dir = mkdtempSync ( join ( tmpdir ( ) , "hunk-session-reload-" ) ) ;
1125+ const left = join ( dir , "before.ts" ) ;
1126+ const right = join ( dir , "after.ts" ) ;
1127+ const reviewNote = "Keep this daemon review note" ;
1128+
1129+ writeFileSync ( left , "export const answer = 41;\n" ) ;
1130+ writeFileSync ( right , "export const answer = 42;\n" ) ;
1131+
1132+ const bootstrap = await loadAppBootstrap ( {
1133+ kind : "diff" ,
1134+ left,
1135+ right,
1136+ options : {
1137+ mode : "split" ,
1138+ } ,
1139+ } ) ;
1140+ const { dispatchCommand, hostClient } = createMockHostClient ( ) ;
1141+
1142+ const setup = await testRender ( < AppHost bootstrap = { bootstrap } hostClient = { hostClient } /> , {
1143+ width : 220 ,
1144+ height : 20 ,
1145+ } ) ;
1146+
1147+ try {
1148+ await flush ( setup ) ;
1149+
1150+ await act ( async ( ) => {
1151+ await dispatchCommand ( {
1152+ type : "command" ,
1153+ requestId : "comment-1" ,
1154+ command : "comment" ,
1155+ input : {
1156+ sessionId : "session-1" ,
1157+ filePath : "after.ts" ,
1158+ side : "new" ,
1159+ line : 1 ,
1160+ summary : reviewNote ,
1161+ reveal : true ,
1162+ } ,
1163+ } ) ;
1164+ } ) ;
1165+
1166+ let frame = await waitForFrame ( setup , ( currentFrame ) => currentFrame . includes ( reviewNote ) ) ;
1167+ expect ( frame ) . toContain ( reviewNote ) ;
1168+
1169+ writeFileSync ( right , "export const answer = 42;\nexport const added = true;\n" ) ;
1170+
1171+ await act ( async ( ) => {
1172+ await dispatchCommand ( {
1173+ type : "command" ,
1174+ requestId : "reload-1" ,
1175+ command : "reload_session" ,
1176+ input : {
1177+ sessionId : "session-1" ,
1178+ nextInput : {
1179+ kind : "diff" ,
1180+ left,
1181+ right,
1182+ options : {
1183+ mode : "split" ,
1184+ } ,
1185+ } ,
1186+ sourcePath : dir ,
1187+ } ,
1188+ } ) ;
1189+ } ) ;
1190+
1191+ frame = await waitForFrame (
1192+ setup ,
1193+ ( currentFrame ) => currentFrame . includes ( "export const added = true;" ) ,
1194+ 20 ,
1195+ ) ;
1196+
1197+ expect ( frame ) . toContain ( "export const added = true;" ) ;
1198+ expect ( frame ) . toContain ( reviewNote ) ;
1199+ } finally {
1200+ await act ( async ( ) => {
1201+ setup . renderer . destroy ( ) ;
1202+ } ) ;
1203+ rmSync ( dir , { force : true , recursive : true } ) ;
1204+ }
1205+ } ) ;
1206+
11161207 test ( "watch mode reloads the current file diff from disk" , async ( ) => {
11171208 const dir = mkdtempSync ( join ( tmpdir ( ) , "hunk-watch-" ) ) ;
11181209 const left = join ( dir , "before.ts" ) ;
0 commit comments