@@ -8,8 +8,10 @@ import {
88 pathForMemoryTab ,
99 pathForAgentPanel ,
1010 pathForPluginsHubTab ,
11+ pathForWorkboardBoard ,
1112 pluginsHubTabFromPath ,
1213 routeIdFromPath ,
14+ type RouteId ,
1315 type MemoryRouteTab ,
1416 type PluginsHubRouteTab ,
1517} from "./app-route-paths.ts" ;
@@ -27,6 +29,167 @@ const AGENT_PANEL_CASES = [
2729 "memory" ,
2830] as const satisfies readonly AgentsPanel [ ] ;
2931
32+ const DYNAMIC_STARTUP_CASES = [
33+ {
34+ label : "agent panel" ,
35+ routeId : "agents" ,
36+ location : {
37+ pathname : pathForAgentPanel ( "team.writer" , "tools" ) ,
38+ search : "?probe=1" ,
39+ hash : "#catalog" ,
40+ } ,
41+ } ,
42+ {
43+ label : "chat session" ,
44+ routeId : "chat" ,
45+ location : {
46+ pathname : "/chat/main/01JSESSIONA" ,
47+ search : "?probe=1" ,
48+ hash : "#message" ,
49+ } ,
50+ } ,
51+ {
52+ label : "dashboard session" ,
53+ routeId : "dashboard" ,
54+ location : {
55+ pathname : "/dashboard/main/01JSESSIONA" ,
56+ search : "?probe=1" ,
57+ hash : "#dashboard" ,
58+ } ,
59+ } ,
60+ {
61+ label : "workboard board" ,
62+ routeId : "workboard" ,
63+ location : {
64+ pathname : pathForWorkboardBoard ( "ops.v2" ) ,
65+ search : "?agent=main" ,
66+ hash : "#queue" ,
67+ } ,
68+ } ,
69+ {
70+ label : "Memory tab" ,
71+ routeId : "memory" ,
72+ location : {
73+ pathname : pathForMemoryTab ( "settings" ) ,
74+ search : "?probe=1" ,
75+ hash : "#memory-backend" ,
76+ } ,
77+ } ,
78+ {
79+ label : "Plugins tab" ,
80+ routeId : "plugins" ,
81+ location : {
82+ pathname : pathForPluginsHubTab ( "discover" ) ,
83+ search : "?query=calendar" ,
84+ hash : "#featured" ,
85+ } ,
86+ } ,
87+ ] as const satisfies readonly {
88+ label : string ;
89+ routeId : RouteId ;
90+ location : RouteLocation ;
91+ } [ ] ;
92+
93+ describe ( "Dynamic route startup bridge" , ( ) => {
94+ it . each ( DYNAMIC_STARTUP_CASES ) (
95+ "loads the $label once while publishing its real location" ,
96+ async ( { routeId, location : initialLocation } ) => {
97+ let location : RouteLocation = { ...initialLocation } ;
98+ const history : RouterHistory = {
99+ location : ( ) => location ,
100+ push : vi . fn ( ( next : RouteLocation ) => {
101+ location = next ;
102+ } ) ,
103+ replace : vi . fn ( ( next : RouteLocation ) => {
104+ location = next ;
105+ } ) ,
106+ listen : ( ) => ( ) => undefined ,
107+ } ;
108+ const router = createApplicationRouter ( ) ;
109+ const route = router . getRoute ( routeId ) ;
110+ if ( ! route ) {
111+ throw new Error ( `Route missing: ${ routeId } ` ) ;
112+ }
113+ const loader = vi . fn ( async ( ) => ( { routeId } ) ) ;
114+ const originalLoader = route . loader ;
115+ const originalComponent = route . component ;
116+ try {
117+ route . loader = loader ;
118+ route . component = async ( ) => ( { render : ( ) => null } ) ;
119+
120+ await startApplicationRouter ( router , history , "" , {
121+ basePath : "" ,
122+ } as unknown as ApplicationContext ) ;
123+
124+ expect ( loader ) . toHaveBeenCalledOnce ( ) ;
125+ expect ( router . getState ( ) . location ) . toEqual ( initialLocation ) ;
126+ expect ( router . getState ( ) . matches [ 0 ] ?. location ) . toEqual ( initialLocation ) ;
127+ } finally {
128+ router . stop ( ) ;
129+ route . loader = originalLoader ;
130+ route . component = originalComponent ;
131+ }
132+ } ,
133+ ) ;
134+
135+ it ( "loads a later dynamic history destination exactly once" , async ( ) => {
136+ let location : RouteLocation = {
137+ pathname : "/chat/main/01JSESSIONA" ,
138+ search : "" ,
139+ hash : "#first" ,
140+ } ;
141+ let historyListener : ( ( next : RouteLocation ) => void ) | undefined ;
142+ const history : RouterHistory = {
143+ location : ( ) => location ,
144+ push : vi . fn ( ( next : RouteLocation ) => {
145+ location = next ;
146+ } ) ,
147+ replace : vi . fn ( ( next : RouteLocation ) => {
148+ location = next ;
149+ } ) ,
150+ listen : ( listener ) => {
151+ historyListener = listener ;
152+ return ( ) => {
153+ historyListener = undefined ;
154+ } ;
155+ } ,
156+ } ;
157+ const router = createApplicationRouter ( ) ;
158+ const route = router . getRoute ( "chat" ) ;
159+ if ( ! route ) {
160+ throw new Error ( "Chat route missing" ) ;
161+ }
162+ const loader = vi . fn ( async ( ) => ( { } ) ) ;
163+ const originalLoader = route . loader ;
164+ const originalComponent = route . component ;
165+ try {
166+ route . loader = loader ;
167+ route . component = async ( ) => ( { render : ( ) => null } ) ;
168+
169+ await startApplicationRouter ( router , history , "" , {
170+ basePath : "" ,
171+ } as unknown as ApplicationContext ) ;
172+ expect ( loader ) . toHaveBeenCalledOnce ( ) ;
173+
174+ location = {
175+ pathname : "/chat/main/01JSESSIONB" ,
176+ search : "?probe=1" ,
177+ hash : "#second" ,
178+ } ;
179+ historyListener ?.( location ) ;
180+
181+ await vi . waitFor ( ( ) => {
182+ expect ( loader ) . toHaveBeenCalledTimes ( 2 ) ;
183+ expect ( router . getState ( ) . location ) . toEqual ( location ) ;
184+ } ) ;
185+ } finally {
186+ router . stop ( ) ;
187+ route . loader = originalLoader ;
188+ route . component = originalComponent ;
189+ }
190+ } ) ;
191+ } ) ;
192+
30193describe ( "Agent panel route paths" , ( ) => {
31194 it . each ( AGENT_PANEL_CASES ) ( "round-trips the %s panel with an encoded agent id" , ( panel ) => {
32195 const pathname = pathForAgentPanel ( "team.writer" , panel ) ;
0 commit comments