@@ -10,7 +10,7 @@ import { runBrowserActionsCommand, runBrowserScenarioCommand } from "../packages
1010import { runBrowserProbeCommand } from "../packages/runtime-playground/src/browser-probe-runner.js"
1111import type { BrowserArtifact } from "../packages/runtime-playground/src/browser-artifacts.js"
1212import { isBrowserCommandArtifactError } from "../packages/runtime-playground/src/browser-command-artifact-error.js"
13- import type { PlaygroundCliServer } from "../packages/runtime-playground/src/preview-server.js"
13+ import { closeHttpServer , listenLocalHttpServer , withPreviewProxy , type PlaygroundCliServer } from "../packages/runtime-playground/src/preview-server.js"
1414
1515const runtimeSpec : RuntimeCreateSpec = {
1616 backend : "wordpress-playground" ,
@@ -95,6 +95,56 @@ test("authored scenarios preserve init-script and page state from probe collecti
9595 }
9696} )
9797
98+ test ( "shared probe and actions sessions preserve canonical proxy transport and topology evidence" , async ( ) => {
99+ const canonicalHost = "shared-scenario.invalid"
100+ const upstreamRequests : Array < { host ?: string ; url ?: string } > = [ ]
101+ const upstream = createServer ( ( request , response ) => {
102+ upstreamRequests . push ( { host : request . headers . host , url : request . url } )
103+ response . setHeader ( "content-type" , "text/html" )
104+ response . end ( "<!doctype html><title>Shared canonical scenario</title><button>Continue</button>" )
105+ } )
106+ const upstreamUrl = await listenLocalHttpServer ( upstream )
107+ const proxy = await withPreviewProxy ( {
108+ playground : { async run ( ) { return { text : "" , exitCode : 0 } } } ,
109+ serverUrl : upstreamUrl ,
110+ async [ Symbol . asyncDispose ] ( ) { } ,
111+ } satisfies PlaygroundCliServer , 0 )
112+ const artifactRoot = await mkdtemp ( join ( tmpdir ( ) , "wp-codebox-browser-scenario-canonical-" ) )
113+ const canonicalUrl = `http://${ canonicalHost } /preview/`
114+ try {
115+ const result = await runBrowserScenarioCommand ( {
116+ artifactRoot,
117+ runtimeSpec : { ...runtimeSpec , preview : { siteUrl : canonicalUrl } } ,
118+ server : proxy ,
119+ spec : {
120+ command : "wordpress.browser-scenario" ,
121+ args : [
122+ `scenario-json=${ JSON . stringify ( {
123+ url : canonicalUrl ,
124+ captures : [ "performance" , "steps" , "network" ] ,
125+ prePageScript : "sessionStorage.setItem('shared-scenario-state', 'probe-preserved')" ,
126+ steps : [ { kind : "evaluate" , expression : "({ origin: location.origin, state: sessionStorage.getItem('shared-scenario-state') })" , assert : { origin : `http://${ canonicalHost } ` , state : "probe-preserved" } } ] ,
127+ } ) } `,
128+ `route-host=${ canonicalHost } ` ,
129+ ] ,
130+ } ,
131+ } )
132+
133+ assert . equal ( new URL ( result . artifact . canonicalBrowserOrigin ! ) . origin , `http://${ canonicalHost } ` )
134+ assert . equal ( new URL ( result . artifact . localProxyOrigin ! ) . origin , new URL ( proxy . serverUrl ) . origin )
135+ assert . equal ( new URL ( result . artifact . upstreamRuntimeOrigin ! ) . origin , new URL ( upstreamUrl ) . origin )
136+ assert . equal ( new URL ( result . artifact . summary . finalUrl ) . hostname , canonicalHost )
137+ assert ( upstreamRequests . some ( ( request ) => request . host === canonicalHost && request . url === "/preview/" ) , JSON . stringify ( upstreamRequests ) )
138+ const output = JSON . parse ( result . output )
139+ assert . equal ( output . scenario . summary . probe . finalUrl , canonicalUrl )
140+ assert . equal ( output . scenario . summary . actions . finalUrl , canonicalUrl )
141+ } finally {
142+ await rm ( artifactRoot , { recursive : true , force : true } )
143+ await proxy [ Symbol . asyncDispose ] ( )
144+ await closeHttpServer ( upstream )
145+ }
146+ } )
147+
98148test ( "scenario storage state and auth remain available after probe collection" , async ( ) => {
99149 const fixture = await browserFixture ( )
100150 try {
0 commit comments