1+ import * as Cause from "effect/Cause" ;
12import { scopedThreadKey , scopeThreadRef } from "@t3tools/client-runtime/environment" ;
23import { EnvironmentId , ThreadId } from "@t3tools/contracts" ;
34import { expect , it , vi } from "vite-plus/test" ;
@@ -20,7 +21,7 @@ vi.mock(import("../../state/use-atom-command"), async (importOriginal) => ({
2021
2122vi . mock ( import ( "../../state/use-orchestration-command" ) , async ( importOriginal ) => ( {
2223 ...( await importOriginal ( ) ) ,
23- useOrchestrationCommand : ( ( ) => async ( ) => ( { _tag : "Success" , value : undefined } ) ) as never ,
24+ useOrchestrationCommand : ( ( ) => ( input : unknown ) => state . switchRef ( input ) ) as never ,
2425} ) ) ;
2526
2627vi . mock ( import ( "../../hooks/useThreadActions" ) , async ( importOriginal ) => ( {
@@ -77,7 +78,7 @@ function RestoreBranchHarness(props: {
7778 serverConfig : null ,
7879 runtimeMode : "full-access" as never ,
7980 isWorking : false ,
80- pendingBackgroundTasks : [ ] ,
81+ pendingBackgroundTasks : [ { taskId : "background-command" , kind : "command" } ] as never ,
8182 turnItems : [ ] ,
8283 activePendingApproval : null as never ,
8384 activePendingUserInput : null as never ,
@@ -95,13 +96,16 @@ function RestoreBranchHarness(props: {
9596 persistThreadSettingsForNextTurn : async ( ) => ( { _tag : "Success" , value : undefined } ) as never ,
9697 } ) ;
9798 return (
98- < button
99- type = "button"
100- disabled = { lifecycle . isRestoringThreadBranch }
101- onClick = { lifecycle . handleSwitchCheckoutToThreadStable }
102- >
103- { lifecycle . isRestoringThreadBranch ? "Restoring..." : "Restore branch" }
104- </ button >
99+ < >
100+ { lifecycle . workNow ?. actions }
101+ < button
102+ type = "button"
103+ disabled = { lifecycle . isRestoringThreadBranch }
104+ onClick = { lifecycle . handleSwitchCheckoutToThreadStable }
105+ >
106+ { lifecycle . isRestoringThreadBranch ? "Restoring..." : "Restore branch" }
107+ </ button >
108+ </ >
105109 ) ;
106110}
107111
@@ -181,3 +185,44 @@ it.each(["a", "b", "navigation"] as const)(
181185 expect ( focusComposer ) . toHaveBeenCalledTimes ( scenario === "navigation" ? 0 : 1 ) ;
182186 } ,
183187) ;
188+
189+ it . each ( [ "Success" , "Failure" ] as const ) (
190+ "keeps background stop requests per thread after %s" ,
191+ async ( outcome ) => {
192+ setup ( ) ;
193+ const completions : Array < ( result : unknown ) => void > = [ ] ;
194+ state . switchRef = vi . fn ( ( ) => new Promise ( ( resolve ) => completions . push ( resolve ) ) ) ;
195+ const threadA = threadInput ( "thread:a" , "feature-a" ) ;
196+ const threadB = threadInput ( "thread:b" , "feature-b" ) ;
197+ const currentRouteThreadKeyRef = { current : threadA . routeThreadKey } ;
198+ const harness = ( thread : ThreadInput ) => (
199+ < RestoreBranchHarness
200+ thread = { thread }
201+ currentRouteThreadKeyRef = { currentRouteThreadKeyRef }
202+ refreshGitStatus = { ( ) => undefined }
203+ focusComposer = { ( ) => undefined }
204+ />
205+ ) ;
206+ await using screen = await render ( harness ( threadA ) ) ;
207+ await page . getByRole ( "button" , { name : "Stop" , exact : true } ) . click ( ) ;
208+ await expect . element ( page . getByRole ( "button" , { name : "Stopping..." } ) ) . toBeDisabled ( ) ;
209+ await screen . rerender ( harness ( threadB ) ) ;
210+ await page . getByRole ( "button" , { name : "Stop" , exact : true } ) . click ( ) ;
211+ await screen . rerender ( harness ( threadA ) ) ;
212+ await expect . element ( page . getByRole ( "button" , { name : "Stopping..." } ) ) . toBeDisabled ( ) ;
213+ completions [ 0 ] ! (
214+ outcome === "Success"
215+ ? { _tag : "Success" , value : undefined }
216+ : { _tag : "Failure" , cause : Cause . fail ( new Error ( "stop failed" ) ) } ,
217+ ) ;
218+ if ( outcome === "Success" ) {
219+ await expect . element ( page . getByRole ( "button" , { name : "Stopping..." } ) ) . toBeDisabled ( ) ;
220+ } else {
221+ await expect . element ( page . getByRole ( "button" , { name : "Stop" , exact : true } ) ) . toBeEnabled ( ) ;
222+ }
223+ await screen . rerender ( harness ( threadB ) ) ;
224+ await expect . element ( page . getByRole ( "button" , { name : "Stopping..." } ) ) . toBeDisabled ( ) ;
225+ expect ( state . switchRef ) . toHaveBeenCalledTimes ( 2 ) ;
226+ completions [ 1 ] ! ( { _tag : "Success" , value : undefined } ) ;
227+ } ,
228+ ) ;
0 commit comments