@@ -10,6 +10,11 @@ import * as Cause from "effect/Cause";
1010import { AsyncResult } from "effect/reactivity" ;
1111import { beforeEach , describe , expect , it , vi } from "vite-plus/test" ;
1212
13+ import { scopedThreadKey } from "@t3tools/client-runtime/environment" ;
14+ import { useDiffPanelStore } from "../diffPanelStore" ;
15+ import { browserMiniPlayerSource , usePreviewMiniPlayerStore } from "../previewMiniPlayerStore" ;
16+ import { useRightPanelStore } from "../rightPanelStore" ;
17+
1318function deferred < T > ( ) {
1419 let resolve ! : ( value : T ) => void ;
1520 const promise = new Promise < T > ( ( complete ) => {
@@ -163,6 +168,23 @@ vi.mock("./useSettings", () => ({
163168
164169import { useThreadActions } from "./useThreadActions" ;
165170
171+ function seedThreadPanelState ( ref : ScopedThreadRef ) {
172+ useRightPanelStore . getState ( ) . show ( ref ) ;
173+ useDiffPanelStore . getState ( ) . selectGitScope ( ref , "branch" ) ;
174+ usePreviewMiniPlayerStore . getState ( ) . open ( ref , browserMiniPlayerSource ( "tab" ) ) ;
175+ }
176+
177+ function threadPanelStatePresence ( ref : ScopedThreadRef ) {
178+ const key = scopedThreadKey ( ref ) ;
179+ return {
180+ rightPanel : key in useRightPanelStore . getState ( ) . byThreadKey ,
181+ diffPanel : key in useDiffPanelStore . getState ( ) . byThreadKey ,
182+ miniPlayer : key in usePreviewMiniPlayerStore . getState ( ) . byThreadKey ,
183+ } ;
184+ }
185+ const panelStateKept = { rightPanel : true , diffPanel : true , miniPlayer : true } ;
186+ const panelStateCleared = { rightPanel : false , diffPanel : false , miniPlayer : false } ;
187+
166188const primary = EnvironmentId . make ( "primary" ) ;
167189const secondary = EnvironmentId . make ( "secondary" ) ;
168190const target = { environmentId : secondary , threadId : ThreadId . make ( "thread" ) } ;
@@ -226,6 +248,9 @@ beforeEach(() => {
226248 state . toasts = [ ] ;
227249 state . afterRequest = undefined ;
228250 state . sessionLookupFails = false ;
251+ useRightPanelStore . setState ( useRightPanelStore . getInitialState ( ) , true ) ;
252+ useDiffPanelStore . setState ( useDiffPanelStore . getInitialState ( ) , true ) ;
253+ usePreviewMiniPlayerStore . setState ( usePreviewMiniPlayerStore . getInitialState ( ) , true ) ;
229254} ) ;
230255
231256describe ( "thread action permissions" , ( ) => {
@@ -284,23 +309,28 @@ describe("thread action permissions", () => {
284309
285310 it ( "deletes an archived thread only with its own environment's grant" , async ( ) => {
286311 state . threads = [ ] ;
312+ seedThreadPanelState ( target ) ;
287313 const actions = useThreadActions ( ) ;
288314 await actions . deleteThread ( target ) ;
289315 expect ( state . requests ) . toEqual ( [ ] ) ;
316+ expect ( threadPanelStatePresence ( target ) ) . toEqual ( panelStateKept ) ;
290317 state . scopes . get ( secondary ) ! . add ( AuthOrchestrationOperateScope ) ;
291318 expect ( ( await actions . deleteThread ( target ) ) . _tag ) . toBe ( "Success" ) ;
292319 expect ( state . requests ) . toEqual ( [
293320 expect . objectContaining ( { action : "delete" , environmentId : secondary } ) ,
294321 ] ) ;
322+ expect ( threadPanelStatePresence ( target ) ) . toEqual ( panelStateCleared ) ;
295323 } ) ;
296324
297325 it ( "stops before delete and local cleanup when permission is revoked during session stop" , async ( ) => {
298326 state . scopes . get ( secondary ) ! . add ( AuthOrchestrationOperateScope ) ;
299327 state . threads [ 0 ] ! . session = { status : "ready" } ;
300328 state . afterRequest = ( ) => state . scopes . get ( secondary ) ! . clear ( ) ;
329+ seedThreadPanelState ( target ) ;
301330 expect ( ( await useThreadActions ( ) . deleteThread ( target ) ) . _tag ) . toBe ( "Failure" ) ;
302331 expect ( state . requests . map ( ( request ) => request . action ) ) . toEqual ( [ "stopSession" ] ) ;
303332 expect ( state . localEffects ) . toEqual ( [ ] ) ;
333+ expect ( threadPanelStatePresence ( target ) ) . toEqual ( panelStateKept ) ;
304334 } ) ;
305335
306336 it . each ( [
@@ -310,10 +340,12 @@ describe("thread action permissions", () => {
310340 state . scopes . get ( secondary ) ! . add ( AuthOrchestrationOperateScope ) ;
311341 state . threads [ 0 ] ! . worktreePath = "/worktrees/thread" ;
312342 state . sessionLookupFails = sessionLookupFails ;
343+ seedThreadPanelState ( target ) ;
313344 expect ( ( await useThreadActions ( ) . deleteThread ( target ) ) . _tag ) . toBe ( "Success" ) ;
314345 expect ( state . confirm ) . not . toHaveBeenCalled ( ) ;
315346 expect ( state . requests . map ( ( request ) => request . action ) ) . toEqual ( [ "stopSession" , "delete" ] ) ;
316347 expect ( state . localEffects ) . toContain ( "clear-terminal-ui" ) ;
348+ expect ( threadPanelStatePresence ( target ) ) . toEqual ( panelStateCleared ) ;
317349 } ) ;
318350
319351 it ( "does not request worktree removal after its grant is revoked during delete" , async ( ) => {
0 commit comments