@@ -1869,6 +1869,63 @@ test("runtime source loader preserves preact remote imports in browser runtime",
18691869 }
18701870} ) ;
18711871
1872+ test ( "runtime source loader blocks preserved preact imports by runtime network policy" , async ( ) => {
1873+ class BrowserWorkerMock { }
1874+ const restoreGlobals = installBrowserSandboxGlobals ( BrowserWorkerMock ) ;
1875+ const runtime = new DefaultRuntimeManager ( {
1876+ remoteFallbackCdnBases : [ ] ,
1877+ remoteFetchRetries : 0 ,
1878+ remoteFetchBackoffMs : 10 ,
1879+ remoteFetchTimeoutMs : 500 ,
1880+ allowArbitraryNetwork : false ,
1881+ allowedNetworkHosts : [ "cdn.jspm.io" ] ,
1882+ } ) ;
1883+
1884+ const internals = runtime as unknown as {
1885+ createSourceModuleLoader : (
1886+ moduleManifest : RuntimeModuleManifest | undefined ,
1887+ diagnostics : Array < { code ?: string ; message ?: string } > ,
1888+ ) => {
1889+ materializeRemoteModule ( url : string ) : Promise < string > ;
1890+ } ;
1891+ } ;
1892+
1893+ const preactUrl =
1894+ "https://ga.jspm.io/npm:preact@10.28.3/hooks/dist/hooks.module.js" ;
1895+ const diagnostics : Array < { code ?: string ; message ?: string } > = [ ] ;
1896+ const loader = internals . createSourceModuleLoader ( undefined , diagnostics ) ;
1897+
1898+ let fetchCount = 0 ;
1899+ const originalFetch = globalThis . fetch ;
1900+ globalThis . fetch = ( async ( _input : RequestInfo | URL ) => {
1901+ fetchCount += 1 ;
1902+ return new Response ( "export default 1;" , {
1903+ status : 200 ,
1904+ headers : {
1905+ "content-type" : "text/javascript; charset=utf-8" ,
1906+ } ,
1907+ } ) ;
1908+ } ) as typeof fetch ;
1909+
1910+ try {
1911+ await assert . rejects (
1912+ loader . materializeRemoteModule ( preactUrl ) ,
1913+ / R e m o t e m o d u l e U R L i s b l o c k e d b y r u n t i m e n e t w o r k p o l i c y / ,
1914+ ) ;
1915+ assert . equal ( fetchCount , 0 ) ;
1916+ assert . ok (
1917+ diagnostics . some (
1918+ ( item ) =>
1919+ item . code === "RUNTIME_SOURCE_IMPORT_BLOCKED" &&
1920+ item . message ?. includes ( preactUrl ) ,
1921+ ) ,
1922+ ) ;
1923+ } finally {
1924+ globalThis . fetch = originalFetch ;
1925+ restoreGlobals ( ) ;
1926+ }
1927+ } ) ;
1928+
18721929test ( "runtime source loader materializes preact remote imports outside browser runtime" , async ( ) => {
18731930 const runtime = new DefaultRuntimeManager ( {
18741931 remoteFallbackCdnBases : [ ] ,
0 commit comments