@@ -8,8 +8,13 @@ const directory = "C:/OpenCode/SubagentNavigation"
88const projectID = "proj_subagent_navigation"
99const parentID = "ses_subagent_parent"
1010const childID = "ses_subagent_child"
11+ const grandchildID = "ses_subagent_grandchild"
12+ const greatGrandchildID = "ses_subagent_great_grandchild"
1113const parentTitle = "Parent session"
1214const childTitle = "Subagent child session"
15+ const grandchildTitle = "Nested subagent session"
16+ const greatGrandchildTitle =
17+ "Deep research subagent session investigating a very long chain of agent registry failures and navigation breadcrumbs"
1318// Child session pages derive their heading from the task part that spawned them.
1419const taskDescription = "Inspect child navigation"
1520
@@ -25,6 +30,60 @@ test("navigates to a subagent child session missing from the session list", asyn
2530 await expect ( page . getByRole ( "button" , { name : "Toggle review" , exact : true } ) ) . toBeVisible ( )
2631} )
2732
33+ test ( "opens a directly linked nested subagent in its root session tab" , async ( { page } ) => {
34+ await setup ( page , undefined , 1 )
35+ await page . goto ( sessionHref ( grandchildID ) , { waitUntil : "domcontentloaded" } )
36+
37+ await expect ( page . locator ( '[data-slot="session-title-parent"]' ) ) . toHaveText ( childTitle )
38+ await expect ( page . locator ( '[data-slot="session-title-child"]' ) ) . toHaveText ( grandchildTitle )
39+ const tabs = page . locator ( '[data-slot="titlebar-tabs"] [data-titlebar-tab-slot]' )
40+ await expect ( tabs . locator ( `a[href="${ sessionHref ( grandchildID ) } "]` ) ) . toHaveCount ( 1 )
41+ await expect ( tabs ) . toHaveCount ( 1 )
42+ await expect ( tabs . locator ( '[data-slot="tab-title"]' ) ) . toHaveText ( parentTitle )
43+ } )
44+
45+ test ( "shows the full ancestor path and navigates to an earlier subagent" , async ( { page } ) => {
46+ await setup ( page , undefined , 2 )
47+ await page . goto ( sessionHref ( greatGrandchildID ) , { waitUntil : "domcontentloaded" } )
48+
49+ await expect ( page . locator ( "[data-timeline-virtual-content]" ) ) . toBeAttached ( )
50+ const header = page . locator ( "[data-session-title]" )
51+ await expect ( header . locator ( '[data-slot="session-title-ancestor"]' ) ) . toHaveText ( [ parentTitle , childTitle ] )
52+ await expect ( header . locator ( '[data-slot="session-title-parent"]' ) ) . toHaveText ( grandchildTitle )
53+ await expect ( header . getByRole ( "heading" , { name : greatGrandchildTitle } ) ) . toBeVisible ( )
54+
55+ await header . getByRole ( "button" , { name : childTitle , exact : true } ) . click ( )
56+ await expect ( page ) . toHaveURL ( sessionHref ( childID ) )
57+ await expect ( page . locator ( "[data-session-title]" ) . getByRole ( "heading" , { name : childTitle } ) ) . toBeVisible ( )
58+ await expect ( page . locator ( '[data-slot="titlebar-tabs"] [data-titlebar-tab-slot]' ) ) . toHaveCount ( 1 )
59+ } )
60+
61+ test ( "keeps the active nested session visible in a narrow desktop header" , async ( { page } ) => {
62+ await page . setViewportSize ( { width : 820 , height : 720 } )
63+ await setup ( page , undefined , 2 )
64+ await page . goto ( sessionHref ( greatGrandchildID ) , { waitUntil : "domcontentloaded" } )
65+
66+ const header = page . locator ( "[data-session-title]" )
67+ const heading = header . getByRole ( "heading" , { name : greatGrandchildTitle } )
68+ const separator = header . locator ( '[data-slot="session-title-ancestors"] + [data-slot="session-title-separator"]' )
69+ await expect ( header . locator ( '[data-slot="session-title-ancestor"]' ) ) . toHaveText ( [ parentTitle , childTitle ] )
70+ await expect ( heading ) . toBeInViewport ( )
71+ await expect ( separator ) . toBeInViewport ( )
72+ const bounds = await heading . boundingBox ( )
73+ expect ( bounds ) . not . toBeNull ( )
74+ expect ( bounds ! . x + bounds ! . width ) . toBeLessThanOrEqual ( 820 )
75+
76+ await page . evaluate ( ( ) => document . documentElement . setAttribute ( "dir" , "rtl" ) )
77+ await expect ( heading ) . toBeInViewport ( )
78+ await expect ( separator ) . toBeInViewport ( )
79+
80+ const root = header . locator ( `[data-slot="session-title-ancestor"][data-session-id="${ parentID } "]` )
81+ await root . focus ( )
82+ await expect ( root ) . toBeFocused ( )
83+ await root . press ( "Enter" )
84+ await expect ( page ) . toHaveURL ( sessionHref ( parentID ) )
85+ } )
86+
2887test ( "returns to the parent session with Escape" , async ( { page } ) => {
2988 await setup ( page )
3089 await openChildFromParent ( page )
@@ -144,7 +203,7 @@ test("shows the not found fallback when the viewed session is deleted", async ({
144203 await expect ( page . getByRole ( "heading" , { name : taskDescription } ) ) . toHaveCount ( 0 )
145204} )
146205
147- async function setup ( page : Page , events ?: ( ) => OpenCodeEvent [ ] ) {
206+ async function setup ( page : Page , events ?: ( ) => OpenCodeEvent [ ] , nestedDepth : 0 | 1 | 2 = 0 ) {
148207 await mockOpenCodeServer ( page , {
149208 directory,
150209 project : {
@@ -168,7 +227,14 @@ async function setup(page: Page, events?: () => OpenCodeEvent[]) {
168227 connected : [ "opencode" ] ,
169228 default : { providerID : "opencode" , modelID : "claude-opus-4-6" } ,
170229 } ,
171- sessions : [ session ( parentID , parentTitle , 1700000000000 ) , childSession ( ) ] ,
230+ sessions : [
231+ session ( parentID , parentTitle , 1700000000000 ) ,
232+ childSession ( ) ,
233+ ...( nestedDepth >= 1 ? [ session ( grandchildID , grandchildTitle , 1700000002000 , { parentID : childID } ) ] : [ ] ) ,
234+ ...( nestedDepth >= 2
235+ ? [ session ( greatGrandchildID , greatGrandchildTitle , 1700000003000 , { parentID : grandchildID } ) ]
236+ : [ ] ) ,
237+ ] ,
172238 pageMessages : ( sessionID ) => ( { items : sessionID === parentID ? parentMessages ( ) : [ ] } ) ,
173239 events,
174240 eventRetry : events ? 16 : undefined ,
0 commit comments