@@ -32,6 +32,7 @@ const mocks = vi.hoisted(() => ({
3232 pictureInPicture : false ,
3333 showEmptyState : false ,
3434 loading : false ,
35+ nativeServerTab : false ,
3536 serverEpoch : null as string | null ,
3637 servers : [ ] as PreviewableServer [ ] ,
3738 recordingTabIds : new Set < string > ( ) ,
@@ -115,6 +116,7 @@ vi.mock(import("~/previewStateStore"), async (original) => ({
115116 "tab-1" : {
116117 threadId : "thread-1" ,
117118 tabId : "tab-1" ,
119+ runtime : mocks . nativeServerTab ? "server" : "desktop" ,
118120 navStatus : { _tag : "Success" , url : "http://example.com/" , title : "Example" } ,
119121 canGoBack : false ,
120122 canGoForward : false ,
@@ -147,6 +149,11 @@ vi.mock(import("./usePreviewSession"), async (original) => ({
147149 usePreviewSession : ( ) => { } ,
148150} ) ) ;
149151
152+ vi . mock ( import ( "~/browser/previewRuntime" ) , async ( original ) => ( {
153+ ...( await original ( ) ) ,
154+ useRendersServerTabNatively : ( ) => mocks . nativeServerTab ,
155+ } ) ) ;
156+
150157vi . mock ( import ( "~/browser/browserViewportActions" ) , { spy : true } ) ;
151158
152159import { commitBrowserViewportChange } from "~/browser/browserViewportActions" ;
@@ -217,6 +224,7 @@ describe("PreviewView", () => {
217224 mocks . pictureInPicture = false ;
218225 mocks . showEmptyState = false ;
219226 mocks . loading = false ;
227+ mocks . nativeServerTab = false ;
220228 mocks . serverEpoch = null ;
221229 mocks . servers = [ ] ;
222230 mocks . recordingTabIds = new Set ( ) ;
@@ -260,62 +268,66 @@ describe("PreviewView", () => {
260268 expect ( mocks . recordingTabIds . has ( TEST_RUNTIME_TAB_ID ) ) . toBe ( true ) ;
261269 } ) ;
262270
263- it ( "aligns the cursor and initial responsive viewport after the host zoom changes" , async ( ) => {
264- let windowZoom = 1 ;
265- vi . stubGlobal ( "desktopBridge" , {
266- getWindowZoomFactor : ( ) => windowZoom ,
267- getLocalEnvironmentBootstraps : ( ) => [ ] ,
268- } ) ;
269- const commit = vi . mocked ( commitBrowserViewportChange ) . mockResolvedValueOnce ( undefined ) ;
270- try {
271- await render ( view ( ) ) ;
272- await act ( ( ) => {
273- const surfaces = useBrowserSurfaceStore . getState ( ) ;
274- const slot = document . querySelector < HTMLElement > ( "[data-browser-surface-slot]" ) ! ;
275- slot . style . width = "1020px" ;
276- slot . style . height = "798px" ;
277- surfaces . presentContent ( TEST_RUNTIME_TAB_ID , {
278- x : 20 ,
279- y : 40 ,
280- width : 500 ,
281- height : 375 ,
282- scale : 0.5 ,
283- scrollLeft : 7 ,
284- scrollTop : 11 ,
285- } ) ;
286- useBrowserPointerStore . setState ( {
287- byTabId : {
288- [ TEST_RUNTIME_TAB_ID ] : {
289- tabId : TEST_RUNTIME_TAB_ID ,
290- phase : "move" ,
291- x : 100 ,
292- y : 200 ,
293- sequence : 1 ,
294- createdAt : "2026-07-27T00:00:00Z" ,
271+ it . each ( [ false , true ] ) (
272+ "aligns the cursor and responsive viewport after host zoom changes (native server tab: %s)" ,
273+ async ( nativeServerTab ) => {
274+ mocks . nativeServerTab = nativeServerTab ;
275+ let windowZoom = 1 ;
276+ vi . stubGlobal ( "desktopBridge" , {
277+ getWindowZoomFactor : ( ) => windowZoom ,
278+ getLocalEnvironmentBootstraps : ( ) => [ ] ,
279+ } ) ;
280+ const commit = vi . mocked ( commitBrowserViewportChange ) . mockResolvedValueOnce ( undefined ) ;
281+ try {
282+ await render ( view ( ) ) ;
283+ await act ( ( ) => {
284+ const surfaces = useBrowserSurfaceStore . getState ( ) ;
285+ const slot = document . querySelector < HTMLElement > ( "[data-browser-surface-slot]" ) ! ;
286+ slot . style . width = "1020px" ;
287+ slot . style . height = "798px" ;
288+ surfaces . presentContent ( TEST_RUNTIME_TAB_ID , {
289+ x : 20 ,
290+ y : 40 ,
291+ width : 500 ,
292+ height : 375 ,
293+ scale : 0.5 ,
294+ scrollLeft : 7 ,
295+ scrollTop : 11 ,
296+ } ) ;
297+ useBrowserPointerStore . setState ( {
298+ byTabId : {
299+ [ TEST_RUNTIME_TAB_ID ] : {
300+ tabId : TEST_RUNTIME_TAB_ID ,
301+ phase : "move" ,
302+ x : 100 ,
303+ y : 200 ,
304+ sequence : 1 ,
305+ createdAt : "2026-07-27T00:00:00Z" ,
306+ } ,
295307 } ,
296- } ,
308+ } ) ;
309+ windowZoom = 1.25 ;
310+ window . dispatchEvent ( new Event ( "resize" ) ) ;
297311 } ) ;
298- windowZoom = 1.25 ;
299- window . dispatchEvent ( new Event ( "resize" ) ) ;
300- } ) ;
301- const cursor = document . querySelector ( "[data-agent-browser-cursor]" ) ;
302- expect ( cursor ) . not . toBeNull ( ) ;
303- const position = new DOMMatrixReadOnly ( getComputedStyle ( cursor ! ) . transform ) ;
304- expect ( position . e ) . toBe ( 53 ) ;
305- expect ( position . f ) . toBe ( 109 ) ;
306-
307- await userEvent . click ( page . getByRole ( "button" , { name : "Preview menu" } ) ) ;
308- await userEvent . click ( page . getByRole ( "menuitem" , { name : "Show device toolbar" } ) ) ;
309- expect ( commit ) . toHaveBeenCalledExactlyOnceWith ( TEST_RUNTIME_TAB_ID , {
310- _tag : "freeform" ,
311- width : 1250 ,
312- height : 938 ,
313- } ) ;
314- } finally {
315- commit . mockReset ( ) ;
316- await act ( ( ) => useBrowserSurfaceStore . setState ( { activityByTabId : { } , byTabId : { } } ) ) ;
317- }
318- } ) ;
312+ const cursor = document . querySelector ( "[data-agent-browser-cursor]" ) ;
313+ expect ( cursor ) . not . toBeNull ( ) ;
314+ const position = new DOMMatrixReadOnly ( getComputedStyle ( cursor ! ) . transform ) ;
315+ expect ( position . e ) . toBe ( 53 ) ;
316+ expect ( position . f ) . toBe ( 109 ) ;
317+
318+ await userEvent . click ( page . getByRole ( "button" , { name : "Preview menu" } ) ) ;
319+ await userEvent . click ( page . getByRole ( "menuitem" , { name : "Show device toolbar" } ) ) ;
320+ expect ( commit ) . toHaveBeenCalledExactlyOnceWith ( TEST_RUNTIME_TAB_ID , {
321+ _tag : "freeform" ,
322+ width : 1250 ,
323+ height : 938 ,
324+ } ) ;
325+ } finally {
326+ commit . mockReset ( ) ;
327+ await act ( ( ) => useBrowserSurfaceStore . setState ( { activityByTabId : { } , byTabId : { } } ) ) ;
328+ }
329+ } ,
330+ ) ;
319331
320332 it ( "does not rerender while loading time passes" , async ( ) => {
321333 vi . useFakeTimers ( ) ;
0 commit comments