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 {
@@ -108,7 +108,7 @@ describe("rightPanelStore", () => {
108108 } ,
109109 ) ;
110110
111- const completedDiff = { id : "diff" , kind : "diff" } as const ;
111+ const completedDiff = { kind : "diff" , turnId : RunId . make ( "turn-1" ) } as const ;
112112 const linkedPullRequest = pullRequestSurface ( {
113113 projectId : "project-a" ,
114114 repository : "pingdotgg/t3code" ,
@@ -181,9 +181,15 @@ describe("rightPanelStore", () => {
181181 expect (
182182 store . openProactive ( refA , { id : "pull-requests" , kind : "pull-requests" } , revision ) ,
183183 ) . toBe ( false ) ;
184- expect ( selectThreadRightPanelState ( useRightPanelStore . getState ( ) . byThreadKey , refA ) ) . toBe (
185- chosen ,
184+ const { isOpen, activeSurfaceId, surfaces } = selectThreadRightPanelState (
185+ useRightPanelStore . getState ( ) . byThreadKey ,
186+ refA ,
186187 ) ;
188+ expect ( { isOpen, activeSurfaceId, surfaces } ) . toEqual ( {
189+ isOpen : chosen . isOpen ,
190+ activeSurfaceId : chosen . activeSurfaceId ,
191+ surfaces : chosen . surfaces ,
192+ } ) ;
187193 } ) ;
188194
189195 it ( "allows automatic panels for a later turn after a manual choice" , ( ) => {
@@ -193,10 +199,73 @@ describe("rightPanelStore", () => {
193199 expect ( store . openProactive ( refA , completedDiff , firstTurnRevision ) ) . toBe ( false ) ;
194200
195201 const nextTurnRevision = store . getUserActionRevision ( refA ) ;
196- expect ( store . openProactive ( refA , completedDiff , nextTurnRevision ) ) . toBe ( true ) ;
202+ expect (
203+ store . openProactive (
204+ refA ,
205+ { ...completedDiff , turnId : RunId . make ( "turn-2" ) } ,
206+ nextTurnRevision ,
207+ ) ,
208+ ) . toBe ( true ) ;
197209 expect ( selectActiveRightPanel ( useRightPanelStore . getState ( ) . byThreadKey , refA ) ) . toBe ( "diff" ) ;
198210 } ) ;
199211
212+ it . each ( [
213+ { dismissal : "hide" , dismiss : ( ) => useRightPanelStore . getState ( ) . close ( refA ) } ,
214+ {
215+ dismissal : "close tab" ,
216+ dismiss : ( ) => useRightPanelStore . getState ( ) . closeSurface ( refA , "diff" ) ,
217+ } ,
218+ ] ) ( "offers each turn's diff once after $dismissal and reload" , ( { dismiss } ) => {
219+ const store = useRightPanelStore . getState ( ) ;
220+ expect ( store . openProactive ( refA , completedDiff , store . getUserActionRevision ( refA ) ) ) . toBe ( true ) ;
221+ dismiss ( ) ;
222+ const persisted = JSON . parse (
223+ JSON . stringify ( { byThreadKey : useRightPanelStore . getState ( ) . byThreadKey } ) ,
224+ ) ;
225+ useRightPanelStore . setState ( migratePersistedRightPanelState ( persisted ) ) ;
226+
227+ expect ( store . openProactive ( refA , completedDiff , store . getUserActionRevision ( refA ) ) ) . toBe ( false ) ;
228+ expect ( selectActiveRightPanel ( useRightPanelStore . getState ( ) . byThreadKey , refA ) ) . toBeNull ( ) ;
229+
230+ const nextTurn = { ...completedDiff , turnId : RunId . make ( "turn-2" ) } ;
231+ expect ( store . openProactive ( refA , nextTurn , store . getUserActionRevision ( refA ) ) ) . toBe ( true ) ;
232+ expect ( selectActiveRightPanel ( useRightPanelStore . getState ( ) . byThreadKey , refA ) ) . toBe ( "diff" ) ;
233+ } ) ;
234+
235+ it . each ( [
236+ { action : "open file" , act : ( ) => useRightPanelStore . getState ( ) . openFile ( refA , "src/app.ts" ) } ,
237+ { action : "open files" , act : ( ) => useRightPanelStore . getState ( ) . open ( refA , "files" ) } ,
238+ {
239+ action : "open pull request" ,
240+ act : ( ) => useRightPanelStore . getState ( ) . openPullRequest ( refA , linkedPullRequest ) ,
241+ } ,
242+ ] ) ( "keeps the offered turn after dismissing, then $action, then reload" , ( { act } ) => {
243+ const store = useRightPanelStore . getState ( ) ;
244+ expect ( store . openProactive ( refA , completedDiff , store . getUserActionRevision ( refA ) ) ) . toBe ( true ) ;
245+ store . close ( refA ) ;
246+ act ( ) ;
247+ const persisted = JSON . parse (
248+ JSON . stringify ( { byThreadKey : useRightPanelStore . getState ( ) . byThreadKey } ) ,
249+ ) ;
250+ useRightPanelStore . setState ( migratePersistedRightPanelState ( persisted ) ) ;
251+ const before = selectThreadRightPanelState ( useRightPanelStore . getState ( ) . byThreadKey , refA ) ;
252+
253+ expect ( store . openProactive ( refA , completedDiff , store . getUserActionRevision ( refA ) ) ) . toBe ( false ) ;
254+ expect ( selectThreadRightPanelState ( useRightPanelStore . getState ( ) . byThreadKey , refA ) ) . toBe (
255+ before ,
256+ ) ;
257+ } ) ;
258+
259+ it ( "does not retry a diff offer the user already declined" , ( ) => {
260+ const store = useRightPanelStore . getState ( ) ;
261+ const revision = store . getUserActionRevision ( refA ) ;
262+ store . openFile ( refA , "src/app.ts" ) ;
263+ expect ( store . openProactive ( refA , completedDiff , revision ) ) . toBe ( false ) ;
264+
265+ expect ( store . openProactive ( refA , completedDiff , store . getUserActionRevision ( refA ) ) ) . toBe ( false ) ;
266+ expect ( selectActiveRightPanel ( useRightPanelStore . getState ( ) . byThreadKey , refA ) ) . toBe ( "file" ) ;
267+ } ) ;
268+
200269 it ( "keeps manual choices scoped to their thread and environment" , ( ) => {
201270 const otherEnvironment = scopeThreadRef ( "env-2" as EnvironmentId , refA . threadId ) ;
202271 const store = useRightPanelStore . getState ( ) ;
0 commit comments