11import { scopeThreadRef } from "@t3tools/client-runtime/environment" ;
2- import { type EnvironmentId , ThreadId } from "@t3tools/contracts" ;
2+ import { type EnvironmentId , RunId , ThreadId } from "@t3tools/contracts" ;
33import { beforeEach , describe , expect , it } from "vite-plus/test" ;
44
55import { useClosedViewStore } from "./closedViewStore" ;
@@ -208,7 +208,7 @@ describe("rightPanelStore", () => {
208208 } ,
209209 ) ;
210210
211- const completedDiff = { id : "diff" , kind : "diff" } as const ;
211+ const completedDiff = { kind : "diff" , turnId : RunId . make ( "turn-1" ) } as const ;
212212 const linkedPullRequest = pullRequestSurface ( {
213213 projectId : "project-a" ,
214214 repository : "pingdotgg/t3code" ,
@@ -281,9 +281,15 @@ describe("rightPanelStore", () => {
281281 expect (
282282 store . openProactive ( refA , { id : "pull-requests" , kind : "pull-requests" } , revision ) ,
283283 ) . toBe ( false ) ;
284- expect ( selectThreadRightPanelState ( useRightPanelStore . getState ( ) . byThreadKey , refA ) ) . toBe (
285- chosen ,
284+ const { isOpen, activeSurfaceId, surfaces } = selectThreadRightPanelState (
285+ useRightPanelStore . getState ( ) . byThreadKey ,
286+ refA ,
286287 ) ;
288+ expect ( { isOpen, activeSurfaceId, surfaces } ) . toEqual ( {
289+ isOpen : chosen . isOpen ,
290+ activeSurfaceId : chosen . activeSurfaceId ,
291+ surfaces : chosen . surfaces ,
292+ } ) ;
287293 } ) ;
288294
289295 it ( "allows automatic panels for a later turn after a manual choice" , ( ) => {
@@ -293,10 +299,73 @@ describe("rightPanelStore", () => {
293299 expect ( store . openProactive ( refA , completedDiff , firstTurnRevision ) ) . toBe ( false ) ;
294300
295301 const nextTurnRevision = store . getUserActionRevision ( refA ) ;
296- expect ( store . openProactive ( refA , completedDiff , nextTurnRevision ) ) . toBe ( true ) ;
302+ expect (
303+ store . openProactive (
304+ refA ,
305+ { ...completedDiff , turnId : RunId . make ( "turn-2" ) } ,
306+ nextTurnRevision ,
307+ ) ,
308+ ) . toBe ( true ) ;
297309 expect ( selectActiveRightPanel ( useRightPanelStore . getState ( ) . byThreadKey , refA ) ) . toBe ( "diff" ) ;
298310 } ) ;
299311
312+ it . each ( [
313+ { dismissal : "hide" , dismiss : ( ) => useRightPanelStore . getState ( ) . close ( refA ) } ,
314+ {
315+ dismissal : "close tab" ,
316+ dismiss : ( ) => useRightPanelStore . getState ( ) . closeSurface ( refA , "diff" ) ,
317+ } ,
318+ ] ) ( "offers each turn's diff once after $dismissal and reload" , ( { dismiss } ) => {
319+ const store = useRightPanelStore . getState ( ) ;
320+ expect ( store . openProactive ( refA , completedDiff , store . getUserActionRevision ( refA ) ) ) . toBe ( true ) ;
321+ dismiss ( ) ;
322+ const persisted = JSON . parse (
323+ JSON . stringify ( { byThreadKey : useRightPanelStore . getState ( ) . byThreadKey } ) ,
324+ ) ;
325+ useRightPanelStore . setState ( migratePersistedRightPanelState ( persisted ) ) ;
326+
327+ expect ( store . openProactive ( refA , completedDiff , store . getUserActionRevision ( refA ) ) ) . toBe ( false ) ;
328+ expect ( selectActiveRightPanel ( useRightPanelStore . getState ( ) . byThreadKey , refA ) ) . toBeNull ( ) ;
329+
330+ const nextTurn = { ...completedDiff , turnId : RunId . make ( "turn-2" ) } ;
331+ expect ( store . openProactive ( refA , nextTurn , store . getUserActionRevision ( refA ) ) ) . toBe ( true ) ;
332+ expect ( selectActiveRightPanel ( useRightPanelStore . getState ( ) . byThreadKey , refA ) ) . toBe ( "diff" ) ;
333+ } ) ;
334+
335+ it . each ( [
336+ { action : "open file" , act : ( ) => useRightPanelStore . getState ( ) . openFile ( refA , "src/app.ts" ) } ,
337+ { action : "open files" , act : ( ) => useRightPanelStore . getState ( ) . open ( refA , "files" ) } ,
338+ {
339+ action : "open pull request" ,
340+ act : ( ) => useRightPanelStore . getState ( ) . openPullRequest ( refA , linkedPullRequest ) ,
341+ } ,
342+ ] ) ( "keeps the offered turn after dismissing, then $action, then reload" , ( { act } ) => {
343+ const store = useRightPanelStore . getState ( ) ;
344+ expect ( store . openProactive ( refA , completedDiff , store . getUserActionRevision ( refA ) ) ) . toBe ( true ) ;
345+ store . close ( refA ) ;
346+ act ( ) ;
347+ const persisted = JSON . parse (
348+ JSON . stringify ( { byThreadKey : useRightPanelStore . getState ( ) . byThreadKey } ) ,
349+ ) ;
350+ useRightPanelStore . setState ( migratePersistedRightPanelState ( persisted ) ) ;
351+ const before = selectThreadRightPanelState ( useRightPanelStore . getState ( ) . byThreadKey , refA ) ;
352+
353+ expect ( store . openProactive ( refA , completedDiff , store . getUserActionRevision ( refA ) ) ) . toBe ( false ) ;
354+ expect ( selectThreadRightPanelState ( useRightPanelStore . getState ( ) . byThreadKey , refA ) ) . toBe (
355+ before ,
356+ ) ;
357+ } ) ;
358+
359+ it ( "does not retry a diff offer the user already declined" , ( ) => {
360+ const store = useRightPanelStore . getState ( ) ;
361+ const revision = store . getUserActionRevision ( refA ) ;
362+ store . openFile ( refA , "src/app.ts" ) ;
363+ expect ( store . openProactive ( refA , completedDiff , revision ) ) . toBe ( false ) ;
364+
365+ expect ( store . openProactive ( refA , completedDiff , store . getUserActionRevision ( refA ) ) ) . toBe ( false ) ;
366+ expect ( selectActiveRightPanel ( useRightPanelStore . getState ( ) . byThreadKey , refA ) ) . toBe ( "file" ) ;
367+ } ) ;
368+
300369 it ( "keeps manual choices scoped to their thread and environment" , ( ) => {
301370 const otherEnvironment = scopeThreadRef ( "env-2" as EnvironmentId , refA . threadId ) ;
302371 const store = useRightPanelStore . getState ( ) ;
0 commit comments