11/* @vitest -environment jsdom */
22
3- import { render } from "lit" ;
43import { afterEach , describe , expect , it , vi } from "vitest" ;
5- import type { ApplicationContext } from "../../app/context.ts" ;
64import type { BoardWidget } from "../../lib/board/types.ts" ;
75import { recordBoardWidgetTicketReceipt } from "../../lib/board/widget-ticket-lifetime.ts" ;
86import { BoardWidgetFrameLifecycle } from "./board-widget-frame.ts" ;
@@ -17,10 +15,6 @@ type LifecycleInternals = {
1715 frameFailureKey : string ;
1816 frameRefreshAttempts : number ;
1917 refreshFailedFrame : ( widget : BoardWidget ) => void ;
20- sandboxHostOptions : (
21- frame : HTMLIFrameElement ,
22- widget : BoardWidget ,
23- ) => { controlUiBaseUrl ?: string } | undefined ;
2418} ;
2519
2620function createTicketRefreshLifecycle (
@@ -49,72 +43,6 @@ afterEach(() => {
4943 vi . useRealTimers ( ) ;
5044} ) ;
5145
52- describe ( "board widget sandbox permissions" , ( ) => {
53- it ( "allows rendered widgets to open new tabs while approval placeholders stay strict" , ( ) => {
54- const renderSandbox = ( grantState : BoardWidget [ "grantState" ] ) => {
55- const widget = {
56- name : "links" ,
57- revision : 1 ,
58- grantState,
59- sandboxUrl : "/mcp-app-sandbox" ,
60- sandboxPort : 19124 ,
61- viewTicket : "ticket" ,
62- } as BoardWidget ;
63- const lifecycle = new BoardWidgetFrameLifecycle ( {
64- active : ( ) => true ,
65- connected : ( ) => true ,
66- context : ( ) =>
67- ( {
68- gateway : { connection : { gatewayUrl : "https://gateway.example" } } ,
69- } ) as ApplicationContext ,
70- refreshFrame : ( ) => undefined ,
71- reportContentHeight : ( ) => { } ,
72- requestUpdate : ( ) => { } ,
73- resolveFrameUrl : ( ) => ( ) => "/widget" ,
74- root : ( ) => document ,
75- widget : ( ) => widget ,
76- } ) ;
77- const container = document . createElement ( "div" ) ;
78- render ( lifecycle . render ( widget ) , container ) ;
79- return container . querySelector ( "iframe" ) ?. getAttribute ( "sandbox" ) ;
80- } ;
81-
82- const baseSandbox = "allow-scripts allow-same-origin allow-forms" ;
83- const linkSandbox = `${ baseSandbox } allow-popups allow-popups-to-escape-sandbox` ;
84- expect ( renderSandbox ( "pending" ) ) . toBe ( baseSandbox ) ;
85- expect ( renderSandbox ( "rejected" ) ) . toBe ( baseSandbox ) ;
86- expect ( renderSandbox ( "none" ) ) . toBe ( linkSandbox ) ;
87- expect ( renderSandbox ( "granted" ) ) . toBe ( linkSandbox ) ;
88- } ) ;
89-
90- it ( "passes the Control UI origin and base path to the widget host" , ( ) => {
91- const widget = { name : "links" , revision : 1 , grantState : "none" } as BoardWidget ;
92- const lifecycle = new BoardWidgetFrameLifecycle ( {
93- active : ( ) => true ,
94- connected : ( ) => true ,
95- context : ( ) =>
96- ( {
97- basePath : "/control" ,
98- gateway : {
99- connection : { gatewayUrl : "https://gateway.example" } ,
100- snapshot : { } ,
101- } ,
102- } ) as ApplicationContext ,
103- refreshFrame : ( ) => undefined ,
104- reportContentHeight : ( ) => { } ,
105- requestUpdate : ( ) => { } ,
106- resolveFrameUrl : ( ) => ( ) => "/widget" ,
107- root : ( ) => document ,
108- widget : ( ) => widget ,
109- } ) ;
110- const frame = document . createElement ( "iframe" ) ;
111-
112- const options = ( lifecycle as unknown as LifecycleInternals ) . sandboxHostOptions ( frame , widget ) ;
113-
114- expect ( options ?. controlUiBaseUrl ) . toBe ( `${ window . location . origin } /control` ) ;
115- } ) ;
116- } ) ;
117-
11846// Drives the private terminal-failure path directly: attempts are exhausted so
11947// refreshFailedFrame surfaces the terminal message for the given sandbox origin.
12048function terminalFailureError ( params : {
0 commit comments