11import { expect , sourceURL , story } from "../../storybook/playwright/story"
2+ import type { ParentProps } from "solid-js"
3+ import type { Command } from "@opencode/gui-extensions/sdk"
4+ import type { Item } from "../src/runtime/extension/host"
25
36const source = ( path : string ) => sourceURL ( new URL ( path , import . meta. url ) )
47
@@ -9,21 +12,49 @@ const modules = {
912 language : source ( "../src/runtime/i18n/language.tsx" ) ,
1013 browser : source ( "../../gui-extensions/src/browser/index.ts" ) ,
1114 browserRenderer : source ( "../../gui-extensions/src/browser/renderer.tsx" ) ,
15+ browserPanel : source ( "../../gui-extensions/src/browser/panel.tsx" ) ,
1216 file : source ( "../../gui-extensions/src/file/index.ts" ) ,
1317 fileRenderer : source ( "../../gui-extensions/src/file/renderer.tsx" ) ,
18+ commands : source ( "../src/shell/commands/command.tsx" ) ,
19+ sdk : source ( "../../gui-extensions/src/sdk/index.ts" ) ,
20+ render : source ( "../src/runtime/extension/render.tsx" ) ,
21+ settings : source ( "../src/settings/model.tsx" ) ,
22+ platform : source ( "../src/runtime/platform/platform.tsx" ) ,
23+ solid : source ( "./extension-host.fixture.tsx" ) ,
1424}
1525
1626story . beforeEach ( async ( { mount, page } ) => {
1727 // Any story loads the app styles; the fixture mounts the real side region and extensions beside it.
1828 await mount ( "ui-line-comment--editor" )
1929 await page . evaluate ( async ( modules ) => {
20- const [ { mountBrowserRegion } , host , panels , language , browser , file ] = await Promise . all ( [
30+ const [
31+ { mountBrowserRegion } ,
32+ host ,
33+ panels ,
34+ language ,
35+ browser ,
36+ file ,
37+ commands ,
38+ sdk ,
39+ renderer ,
40+ settings ,
41+ platform ,
42+ solid ,
43+ ] = await Promise . all ( [
2144 import ( modules . fixture ) ,
2245 import ( modules . host ) ,
2346 import ( modules . panels ) ,
2447 import ( modules . language ) ,
2548 import ( modules . browser ) ,
2649 import ( modules . file ) ,
50+ import ( modules . commands ) ,
51+ import ( modules . sdk ) ,
52+ import ( modules . render ) ,
53+ import ( modules . settings ) ,
54+ import ( modules . platform ) ,
55+ import ( modules . solid ) ,
56+ // Load the pane before mounting: Vite must not reload the page to optimize its dependencies mid-fixture.
57+ import ( modules . browserPanel ) ,
2758 ] )
2859
2960 mountBrowserRegion ( {
@@ -35,10 +66,87 @@ story.beforeEach(async ({ mount, page }) => {
3566 { ...browser . default , renderer : ( ) => import ( modules . browserRenderer ) } ,
3667 { ...file . default , renderer : ( ) => import ( modules . fileRenderer ) } ,
3768 ] ,
69+ Shell : ( props : ParentProps ) =>
70+ solid . createComponent ( platform . PlatformProvider , {
71+ value : { platform : "web" , openExternal ( ) { } , restart : async ( ) => undefined , notify : async ( ) => undefined } ,
72+ get children ( ) {
73+ return solid . createComponent ( settings . SettingsProvider , {
74+ get children ( ) {
75+ return solid . createComponent ( commands . CommandProvider , {
76+ get children ( ) {
77+ return props . children
78+ } ,
79+ } )
80+ } ,
81+ } )
82+ } ,
83+ } ) ,
84+ Commands : ( props : { close : ( ) => void } ) => {
85+ const command = commands . useCommand ( )
86+ const extensions = host . useExtensionHost ( )
87+ command . register ( "fixture-session" , ( ) => [
88+ {
89+ id : "tab.close" ,
90+ title : "Close session tab" ,
91+ keybind : "mod+w" ,
92+ onSelect : props . close ,
93+ } ,
94+ ] )
95+ // Storybook aliases the app's command hook to a no-op. Bridge the real extension contributions
96+ // to the real dispatcher imported by source URL, so the shortcut runs rather than its alias.
97+ command . register ( "fixture-extensions" , ( ) =>
98+ extensions . items ( sdk . Command ) . map ( ( item : Item < Command > ) => {
99+ const scope = item . value . scope
100+
101+ return {
102+ id : `${ item . extension } .${ item . value . id } ` ,
103+ title : item . value . title ,
104+ keybind : item . value . bind ,
105+ disabled : item . value . enabled === false ,
106+ hidden : item . value . hidden ,
107+ editable : item . value . editable ,
108+ when : scope
109+ ? ( event : KeyboardEvent ) => event . target instanceof Element && ! ! event . target . closest ( scope )
110+ : undefined ,
111+ onSelect : ( ) => item . value . run ( ) ,
112+ }
113+ } ) ,
114+ )
115+
116+ return null
117+ } ,
118+ Contribution : renderer . Contribution ,
38119 } )
39120 } , modules )
40121} )
41122
123+ story ( "closes a blank browser tab from its address field without closing the session" , async ( { page } ) => {
124+ const root = page . getByTestId ( "browser-region-fixture" )
125+ const outside = root . getByRole ( "button" , { name : "Beta" , exact : true } )
126+ await expect ( root . getByText ( "Registrations: 1" , { exact : true } ) ) . toBeVisible ( )
127+ await outside . click ( )
128+ await expect ( root . getByText ( "Registrations: 2" , { exact : true } ) ) . toBeVisible ( )
129+ await root . getByRole ( "button" , { name : "Blank page" , exact : true } ) . click ( )
130+ await expect ( root . getByRole ( "tab" , { name : "New tab" , exact : true } ) ) . toHaveAttribute ( "aria-selected" , "true" )
131+
132+ // Prove the scope while browser.close is still registered.
133+ await outside . focus ( )
134+ await outside . press ( "ControlOrMeta+w" )
135+ await expect ( root . getByTestId ( "session-state" ) ) . toHaveText ( "closed" )
136+ await expect ( root . getByTestId ( "browser-closes" ) ) . toHaveText ( "[]" )
137+ await expect ( root . getByRole ( "tab" , { name : "New tab" , exact : true } ) ) . toBeVisible ( )
138+ await outside . click ( )
139+ await expect ( root . getByTestId ( "session-state" ) ) . toHaveText ( "open" )
140+
141+ const address = root . getByRole ( "combobox" , { name : "Browser address" , exact : true } )
142+ await address . fill ( "example.com" )
143+ await expect ( address ) . toBeFocused ( )
144+ await address . press ( "ControlOrMeta+w" )
145+ await expect ( root . getByRole ( "tab" , { name : "New tab" , exact : true } ) ) . toHaveCount ( 0 )
146+ await expect ( root . getByTestId ( "browser-closes" ) ) . toHaveText ( '["tab_33333333-3333-3333-3333-333333333333"]' )
147+ await expect ( root . getByTestId ( "session-state" ) ) . toHaveText ( "open" )
148+ } )
149+
42150story ( "keeps a restored browser tab selected and undrawn until the desktop's first inventory" , async ( { page } ) => {
43151 const root = page . getByTestId ( "browser-region-fixture" )
44152 const tabs = root . getByRole ( "tab" )
0 commit comments