@@ -14,7 +14,17 @@ import { afterEach, beforeEach, describe, expect, it, vi } from "vite-plus/test"
1414import type { Thread , ThreadShell , TurnDiffSummary } from "../types" ;
1515import { deriveProviderInstanceEntries , NO_PROVIDER_MODEL_SELECTION } from "../providerInstances" ;
1616import type { CodexArtifactTemplate } from "@t3tools/client-runtime/codex-artifact-templates" ;
17- import type { RightPanelSurface } from "../rightPanelStore" ;
17+ import { scopeThreadRef } from "@t3tools/client-runtime/environment" ;
18+ import {
19+ type RightPanelSurface ,
20+ pullRequestSurface ,
21+ selectActiveRightPanelSurface ,
22+ useRightPanelStore ,
23+ } from "../rightPanelStore" ;
24+ import {
25+ selectThreadPreviewMiniPlayer ,
26+ usePreviewMiniPlayerStore ,
27+ } from "../previewMiniPlayerStore" ;
1828import {
1929 MAX_HIDDEN_MOUNTED_PREVIEW_THREADS ,
2030 MAX_HIDDEN_MOUNTED_TERMINAL_THREADS ,
@@ -39,6 +49,7 @@ import {
3949 resolveComposerInteractionMode ,
4050 resolveComposerProviderSelection ,
4151 resolveDraftPromotionNavigationTarget ,
52+ observeProactivePanelUserChoice ,
4253 resolveProactiveTurnDiffAction ,
4354 resolveThreadMetadataUpdateForNextTurn ,
4455 resolveSendEnvMode ,
@@ -95,6 +106,37 @@ describe("agent browser close confirmation", () => {
95106} ) ;
96107
97108describe ( "floating browser preview" , ( ) => {
109+ it ( "keeps agent preview intent when a user selects its browser tab and then switches away" , ( ) => {
110+ useRightPanelStore . setState ( { byThreadKey : { } , userActionRevisionByThreadKey : { } } ) ;
111+ usePreviewMiniPlayerStore . setState ( { byThreadKey : { } } ) ;
112+ const ref = scopeThreadRef ( EnvironmentId . make ( "env-1" ) , ThreadId . make ( "thread-1" ) ) ;
113+ const panels = useRightPanelStore . getState ( ) ;
114+ const revision = panels . getUserActionRevision ( ref ) ;
115+ usePreviewMiniPlayerStore . getState ( ) . open ( ref , "agent-tab" ) ;
116+ panels . reconcileBrowserSurfaces ( ref , [ "agent-tab" ] ) ;
117+ const intent = selectThreadPreviewMiniPlayer (
118+ usePreviewMiniPlayerStore . getState ( ) . byThreadKey ,
119+ ref ,
120+ ) ;
121+ const isFloating = ( ) =>
122+ shouldRenderPreviewMiniPlayer (
123+ selectThreadPreviewMiniPlayer ( usePreviewMiniPlayerStore . getState ( ) . byThreadKey , ref )
124+ ?. tabId ?? null ,
125+ selectActiveRightPanelSurface ( useRightPanelStore . getState ( ) . byThreadKey , ref ) ,
126+ ) ;
127+
128+ panels . openProactive ( ref , { id : "diff" , kind : "diff" } , revision ) ;
129+ expect ( isFloating ( ) ) . toBe ( true ) ;
130+ panels . activateSurface ( ref , "browser:agent-tab" ) ;
131+ expect ( isFloating ( ) ) . toBe ( false ) ;
132+ expect ( panels . openProactive ( ref , { id : "diff" , kind : "diff" } , revision ) ) . toBe ( false ) ;
133+ panels . open ( ref , "diff" ) ;
134+ expect ( isFloating ( ) ) . toBe ( true ) ;
135+ expect (
136+ selectThreadPreviewMiniPlayer ( usePreviewMiniPlayerStore . getState ( ) . byThreadKey , ref ) ,
137+ ) . toBe ( intent ) ;
138+ } ) ;
139+
98140 it ( "only hides the duplicate while the same browser is rendered in the panel" , ( ) => {
99141 expect ( shouldRenderPreviewMiniPlayer ( null , null ) ) . toBe ( false ) ;
100142 expect (
@@ -116,6 +158,90 @@ describe("floating browser preview", () => {
116158} ) ;
117159
118160describe ( "proactive panels" , ( ) => {
161+ it ( "keeps a manual PR selection made after following a replacement while loading" , ( ) => {
162+ useRightPanelStore . setState ( { byThreadKey : { } , userActionRevisionByThreadKey : { } } ) ;
163+ const ref = scopeThreadRef ( EnvironmentId . make ( "env-1" ) , ThreadId . make ( "thread-1" ) ) ;
164+ const panels = useRightPanelStore . getState ( ) ;
165+ const oldPr = pullRequestSurface ( {
166+ projectId : "project-1" ,
167+ repository : "owner/repo" ,
168+ number : 1 ,
169+ } ) ;
170+ const replacement = pullRequestSurface ( { ...oldPr , number : 2 } ) ;
171+ const turnId = TurnId . make ( "turn-1" ) ;
172+ panels . openPullRequest ( ref , oldPr ) ;
173+ const loading = observeProactivePanelUserChoice ( null , {
174+ threadKey : "env-1:thread-1" ,
175+ runningTurnId : turnId ,
176+ userActionRevision : panels . getUserActionRevision ( ref ) ,
177+ } ) ;
178+ expect ( panels . openProactive ( ref , replacement , loading . userActionRevision ) ) . toBe ( true ) ;
179+
180+ panels . activateSurface ( ref , oldPr . id ) ;
181+ const loaded = observeProactivePanelUserChoice ( loading , {
182+ threadKey : loading . threadKey ,
183+ runningTurnId : turnId ,
184+ userActionRevision : panels . getUserActionRevision ( ref ) ,
185+ } ) ;
186+ expect ( panels . openProactive ( ref , replacement , loaded . userActionRevision ) ) . toBe ( false ) ;
187+ expect ( selectActiveRightPanelSurface ( useRightPanelStore . getState ( ) . byThreadKey , ref ) ) . toEqual (
188+ oldPr ,
189+ ) ;
190+ expect ( shouldOpenProactivePullRequest ( loaded . targetKey , "owner/repo:2" ) ) . toBe ( false ) ;
191+ expect (
192+ shouldOpenProactiveTurnDiff ( {
193+ previousRunningTurnId : loaded . runningTurnId ,
194+ runningTurnId : null ,
195+ settledTurnId : turnId ,
196+ turnCompleted : true ,
197+ } ) ,
198+ ) . toBe ( false ) ;
199+ } ) ;
200+
201+ it . each ( [ "idle" , "loading" , "observed" ] as const ) (
202+ "captures a new turn's choice once with initial state %s" ,
203+ ( initialState ) => {
204+ useRightPanelStore . setState ( { byThreadKey : { } , userActionRevisionByThreadKey : { } } ) ;
205+ const ref = scopeThreadRef ( EnvironmentId . make ( "env-1" ) , ThreadId . make ( "thread-1" ) ) ;
206+ const panels = useRightPanelStore . getState ( ) ;
207+ const firstTurn = TurnId . make ( "turn-1" ) ;
208+ const nextTurn = TurnId . make ( "turn-2" ) ;
209+ const initial = observeProactivePanelUserChoice ( null , {
210+ threadKey : "env-1:thread-1" ,
211+ runningTurnId : initialState === "idle" ? null : firstTurn ,
212+ userActionRevision : panels . getUserActionRevision ( ref ) ,
213+ } ) ;
214+ panels . openFile ( ref , "src/first.ts" ) ;
215+ const loadingNextTurn = observeProactivePanelUserChoice (
216+ {
217+ ...initial ,
218+ ...( initialState === "observed" ? { runningTurnId : firstTurn , targetKey : null } : { } ) ,
219+ } ,
220+ {
221+ threadKey : initial . threadKey ,
222+ runningTurnId : nextTurn ,
223+ userActionRevision : panels . getUserActionRevision ( ref ) ,
224+ } ,
225+ ) ;
226+ expect (
227+ panels . openProactive ( ref , { id : "diff" , kind : "diff" } , loadingNextTurn . userActionRevision ) ,
228+ ) . toBe ( true ) ;
229+
230+ panels . openFile ( ref , "src/second.ts" ) ;
231+ const loaded = observeProactivePanelUserChoice ( loadingNextTurn , {
232+ threadKey : initial . threadKey ,
233+ runningTurnId : nextTurn ,
234+ userActionRevision : panels . getUserActionRevision ( ref ) ,
235+ } ) ;
236+ expect (
237+ panels . openProactive ( ref , { id : "diff" , kind : "diff" } , loaded . userActionRevision ) ,
238+ ) . toBe ( false ) ;
239+ expect (
240+ selectActiveRightPanelSurface ( useRightPanelStore . getState ( ) . byThreadKey , ref ) ?. id ,
241+ ) . toBe ( "file:src/second.ts" ) ;
242+ } ,
243+ ) ;
244+
119245 it ( "opens a pull request only after a newly observed link appears" , ( ) => {
120246 expect ( shouldOpenProactivePullRequest ( undefined , "project:repo:42" ) ) . toBe ( false ) ;
121247 expect ( shouldOpenProactivePullRequest ( null , "project:repo:42" ) ) . toBe ( true ) ;
@@ -173,14 +299,12 @@ describe("proactive panels", () => {
173299 resolveProactiveTurnDiffAction ( {
174300 checkpoint : changedCheckpoint ,
175301 isGitRepo : true ,
176- activeSurfaceKind : null ,
177302 } ) ,
178303 ) . toBe ( "open" ) ;
179304 expect (
180305 resolveProactiveTurnDiffAction ( {
181306 checkpoint : unchangedCheckpoint ,
182307 isGitRepo : true ,
183- activeSurfaceKind : null ,
184308 } ) ,
185309 ) . toBe ( "ignore" ) ;
186310 } ) ;
@@ -199,39 +323,21 @@ describe("proactive panels", () => {
199323 resolveProactiveTurnDiffAction ( {
200324 checkpoint : undefined ,
201325 isGitRepo : true ,
202- activeSurfaceKind : null ,
203326 } ) ,
204327 ) . toBe ( "defer" ) ;
205328 expect (
206329 resolveProactiveTurnDiffAction ( {
207330 checkpoint : missingCheckpoint ,
208331 isGitRepo : true ,
209- activeSurfaceKind : null ,
210332 } ) ,
211333 ) . toBe ( "defer" ) ;
212334 expect (
213335 resolveProactiveTurnDiffAction ( {
214336 checkpoint : changedCheckpoint ,
215337 isGitRepo : undefined ,
216- activeSurfaceKind : null ,
217338 } ) ,
218339 ) . toBe ( "defer" ) ;
219340 } ) ;
220-
221- it ( "keeps an active pull request above a completed turn diff" , ( ) => {
222- const changedCheckpoint = {
223- status : "ready" ,
224- files : [ { path : "src/app.ts" , kind : "modified" , additions : 1 , deletions : 0 } ] ,
225- } satisfies Pick < TurnDiffSummary , "status" | "files" > ;
226-
227- expect (
228- resolveProactiveTurnDiffAction ( {
229- checkpoint : changedCheckpoint ,
230- isGitRepo : true ,
231- activeSurfaceKind : "pull-request" ,
232- } ) ,
233- ) . toBe ( "ignore" ) ;
234- } ) ;
235341} ) ;
236342
237343describe ( "toolGroupConsumesUpwardNavigation" , ( ) => {
0 commit comments