33// chat and settings routes, the sidebar and the right panel, through the same stores and
44// atoms the app reads. See renderScenarios.renders.tsx for the counting rules.
55import { createMemoryHistory } from "@tanstack/react-router" ;
6+ import { scopeThreadRef } from "@t3tools/client-runtime/environment" ;
67import type { ThreadId } from "@t3tools/contracts" ;
78import { DEFAULT_CLIENT_SETTINGS } from "@t3tools/contracts/settings" ;
89import type * as Context from "effect/Context" ;
@@ -13,11 +14,13 @@ import "~/index.css";
1314
1415import { AppRoot } from "~/AppRoot" ;
1516import { __setClientSettingsForTests } from "~/hooks/useSettings" ;
17+ import { useRightPanelStore } from "~/rightPanelStore" ;
1618import { getRouter , type AppRouter } from "~/router" ;
1719import {
1820 ENVIRONMENT_ID ,
1921 assistantItem ,
2022 emitThreadEvent ,
23+ emitVcsStatus ,
2124 installFakeEnvironment ,
2225 isThreadSubscribed ,
2326 runningRun ,
@@ -47,6 +50,7 @@ vi.mock(import("~/rpc/requestLatencyState"), async (original) => ({
4750 trackRpcRequestSent : ( ) => { } ,
4851} ) ) ;
4952
53+ const GIT_STATUS_UPDATES = 20 ;
5054const HISTORY_TURNS = 20 ;
5155const STREAM_DELTAS = 30 ;
5256const TYPED_TEXT = "fix the flaky tests!" ;
@@ -61,7 +65,9 @@ const [WARM, A, B, LIVE] = THREADS.map((thread) => thread.id) as [
6165 ThreadId ,
6266] ;
6367
64- installFakeEnvironment ( THREADS ) ;
68+ const SIDE_CHAT = { ...threadWithHistory ( "thread-side" , HISTORY_TURNS ) , sideChatOf : WARM } ;
69+
70+ installFakeEnvironment ( [ ...THREADS , SIDE_CHAT ] ) ;
6571// Desktop-sized, so the sidebar, composer and right panel lay out as they do in the app.
6672await page . viewport ( 1400 , 900 ) ;
6773// A returning user: the first-run gate would otherwise wait on onboarding evidence.
@@ -287,3 +293,33 @@ it("app-switch-settings-section", async () => {
287293 await measure ( openSettings ( router , "/settings/appearance" ) ) ,
288294 ] ) ;
289295} ) ;
296+
297+ // ChatView re-renders for any git status change; the composer and side chat timeline should not.
298+ it ( "app-git-status-updates-with-side-chat" , async ( ) => {
299+ using _clock = frozenClock ( ) ;
300+ useRightPanelStore . getState ( ) . openSideChat ( scopeThreadRef ( ENVIRONMENT_ID , WARM ) , SIDE_CHAT . id ) ;
301+ await using _app = ( await openThread ( WARM ) ) . screen ;
302+ await expect . element ( lastAnswer ( SIDE_CHAT . id ) ) . toBeVisible ( ) ;
303+ const local = ( insertions : number ) => ( {
304+ isRepo : true ,
305+ hasPrimaryRemote : true ,
306+ isDefaultRef : true ,
307+ refName : "main" ,
308+ hasWorkingTreeChanges : true ,
309+ workingTree : {
310+ files : [ { path : "src/app.ts" , insertions, deletions : 0 } ] ,
311+ insertions,
312+ deletions : 0 ,
313+ } ,
314+ } ) ;
315+ await act ( ( ) => emitVcsStatus ( { _tag : "snapshot" , local : local ( 0 ) , remote : null } ) ) ;
316+ const counted = await measure ( async ( ) => {
317+ for ( let update = 1 ; update <= GIT_STATUS_UPDATES ; update ++ ) {
318+ await act ( ( ) => emitVcsStatus ( { _tag : "localUpdated" , local : local ( update ) } ) ) ;
319+ }
320+ } ) ;
321+ expect ( counted . components . ChatView ) . toBe ( GIT_STATUS_UPDATES * 2 ) ;
322+ expect ( counted . components . ChatComposer ) . toBeUndefined ( ) ;
323+ expect ( counted . components . ConversationTimeline ) . toBeUndefined ( ) ;
324+ await report ( "app-git-status-updates-with-side-chat" , [ counted ] ) ;
325+ } ) ;
0 commit comments