@@ -17,6 +17,8 @@ import { useHandleNewThread } from "../hooks/useHandleNewThread";
1717import { __setClientSettingsForTests , getClientSettings } from "../hooks/useSettings" ;
1818import { useThreadRouteTarget } from "../hooks/useThreadRouteTarget" ;
1919import { useProjects , useQuietThreadShells } from "../state/entities" ;
20+ import { readEnvironmentScope , useEnvironmentScope } from "../state/session" ;
21+ import { useOrchestrationCommand } from "../state/use-orchestration-command" ;
2022import { useTerminalUiStateStore } from "../terminalUiStateStore" ;
2123import type { Project } from "../types" ;
2224import Sidebar from "./Sidebar" ;
@@ -28,6 +30,8 @@ vi.mock("../state/entities", { spy: true });
2830vi . mock ( "../hooks/useHandleNewThread" , { spy : true } ) ;
2931vi . mock ( "../hooks/useThreadRouteTarget" , { spy : true } ) ;
3032vi . mock ( "./sidebar/SidebarThreadRow" , { spy : true } ) ;
33+ vi . mock ( "../state/session" , { spy : true } ) ;
34+ vi . mock ( "../state/use-orchestration-command" , { spy : true } ) ;
3135vi . mock ( import ( "../state/server" ) , async ( original ) => {
3236 const { Atom } = await import ( "effect/reactivity" ) ;
3337 const { compileResolvedKeybindingsConfig } = await import ( "@t3tools/shared/keybindings" ) ;
@@ -190,3 +194,56 @@ describe("sidebar render isolation", () => {
190194 expect ( jumpLabelsSince ( beforeRelease ) ) . toEqual ( [ ] ) ;
191195 } ) ;
192196} ) ;
197+
198+ describe ( "sidebar thread rename" , ( ) => {
199+ // regression: #35151 an untouched rename wrote back the title it opened with over a newer one
200+ it . each ( [ "{Enter}" , "{Tab}" ] ) (
201+ "ending an untouched rename with %s keeps a title that arrived while it was open" ,
202+ async ( finish ) => {
203+ const activeProject = project ( "active" ) ;
204+ const routeThreadRef : ScopedThreadRef = {
205+ environmentId : activeProject . environmentId ,
206+ threadId : ThreadId . make ( "thread-0" ) ,
207+ } ;
208+ const shellTitled = ( title : string ) => ( { ...threadShell ( activeProject . id , 0 ) , title } ) ;
209+ const updateMetadata = vi . fn ( ) . mockResolvedValue ( { _tag : "Success" } ) ;
210+ vi . mocked ( useOrchestrationCommand ) . mockReturnValue ( updateMetadata ) ;
211+ vi . mocked ( readEnvironmentScope ) . mockReturnValue ( true ) ;
212+ vi . mocked ( useEnvironmentScope ) . mockReturnValue ( true ) ;
213+ vi . mocked ( useProjects ) . mockReturnValue ( [ activeProject ] ) ;
214+ vi . mocked ( useQuietThreadShells ) . mockReturnValue ( [ shellTitled ( "Fix the login redirect" ) ] ) ;
215+ vi . mocked ( useThreadRouteTarget ) . mockReturnValue ( {
216+ kind : "server" ,
217+ threadRef : routeThreadRef ,
218+ } ) ;
219+ vi . mocked ( useHandleNewThread ) . mockReturnValue ( {
220+ activeDraftThread : null ,
221+ activeThread : null ,
222+ defaultProjectRef : {
223+ environmentId : activeProject . environmentId ,
224+ projectId : activeProject . id ,
225+ } ,
226+ defaultProjectFallbackReady : true ,
227+ handleNewThread : vi . fn ( ) . mockResolvedValue ( null ) ,
228+ routeDraftId : null ,
229+ routeThreadRef,
230+ } ) ;
231+ const tree = ( ) => (
232+ < SidebarProvider >
233+ < Sidebar routeReveal = { { observedKey : null , pendingKey : null } } />
234+ </ SidebarProvider >
235+ ) ;
236+ await using screen = await render ( tree ( ) ) ;
237+ await userEvent . dblClick ( screen . getByText ( "Fix the login redirect" ) . first ( ) ) ;
238+ const input = screen . getByRole ( "textbox" , { name : "Thread title" } ) ;
239+ await expect . element ( input ) . toHaveValue ( "Fix the login redirect" ) ;
240+
241+ vi . mocked ( useQuietThreadShells ) . mockReturnValue ( [ shellTitled ( "Generated title" ) ] ) ;
242+ await screen . rerender ( tree ( ) ) ;
243+ await userEvent . keyboard ( finish ) ;
244+
245+ await expect . element ( input ) . not . toBeInTheDocument ( ) ;
246+ expect ( updateMetadata ) . not . toHaveBeenCalled ( ) ;
247+ } ,
248+ ) ;
249+ } ) ;
0 commit comments