@@ -9,11 +9,46 @@ import test from "node:test";
99import ts from "typescript" ;
1010import {
1111 CLIENT_AUTH_CALLBACK ,
12+ decodeClientProtocolPayload ,
1213 findClientProtocolUrl ,
14+ isWebAssetClientProtocolPayload ,
1315 normalizeClientProtocolUrl ,
1416 registerClientProtocol
1517} from "../src/shared/client-protocol.ts" ;
1618
19+ function loadTestDependency ( require : NodeJS . Require , name : string ) {
20+ switch ( name ) {
21+ case "../../../ui/utils/apiError" :
22+ return require ( "../../../ui/utils/apiError" ) ;
23+ case "../package.json" :
24+ return require ( "../package.json" ) ;
25+ case "../shared/client-protocol" :
26+ return require ( "../shared/client-protocol" ) ;
27+ case "../shared/debug-log" :
28+ return require ( "../shared/debug-log" ) ;
29+ case "../shared/url" :
30+ return require ( "../shared/url" ) ;
31+ case "./oauth-callback" :
32+ return require ( "./oauth-callback" ) ;
33+ case "./shared/product-name" :
34+ return require ( "./shared/product-name" ) ;
35+ case "node:child_process" :
36+ return require ( "node:child_process" ) ;
37+ case "node:crypto" :
38+ return require ( "node:crypto" ) ;
39+ case "node:events" :
40+ return require ( "node:events" ) ;
41+ case "node:fs/promises" :
42+ return require ( "node:fs/promises" ) ;
43+ case "node:http" :
44+ return require ( "node:http" ) ;
45+ case "node:path" :
46+ return require ( "node:path" ) ;
47+ default :
48+ throw new Error ( `Unexpected test dependency: ${ name } ` ) ;
49+ }
50+ }
51+
1752// Execute the real entry/service code with Electron replaced; no desktop or OS
1853// registration is touched by these Windows lifecycle checks on other platforms.
1954function loadWithElectronMocks ( relativePath : string , replacements : Record < string , unknown > , runtime = process ) {
@@ -25,7 +60,8 @@ function loadWithElectronMocks(relativePath: string, replacements: Record<string
2560 const exports : Record < string , any > = { } ;
2661 runInNewContext ( output . outputText , {
2762 exports,
28- require : ( name : string ) => ( Object . hasOwn ( replacements , name ) ? replacements [ name ] : require ( name ) ) ,
63+ require : ( name : string ) =>
64+ Object . hasOwn ( replacements , name ) ? replacements [ name ] : loadTestDependency ( require , name ) ,
2965 process : runtime ,
3066 console,
3167 Buffer,
@@ -141,6 +177,20 @@ test("extracts Windows cold-start and forwarded URLs without changing their payl
141177 assert . equal ( normalizeClientProtocolUrl ( "jms2%3A%2F%2Fbad%ZZ" ) , undefined ) ;
142178} ) ;
143179
180+ test ( "routes only HTTP and HTTPS asset payloads to the built-in web proxy" , ( ) => {
181+ const encode = ( payload : unknown ) => `jms2://${ Buffer . from ( JSON . stringify ( payload ) ) . toString ( "base64" ) } ` ;
182+ const http = decodeClientProtocolPayload (
183+ encode ( { protocol : "http" , asset : { id : "asset-1" } , token : { id : "token" } } )
184+ ) ;
185+ const https = decodeClientProtocolPayload ( encode ( { protocol : "HTTPS" , asset : { id : "asset-2" } } ) ) ;
186+ const ssh = decodeClientProtocolPayload ( encode ( { protocol : "ssh" , asset : { id : "asset-3" } } ) ) ;
187+
188+ assert . equal ( isWebAssetClientProtocolPayload ( http ) , true ) ;
189+ assert . equal ( isWebAssetClientProtocolPayload ( https ) , true ) ;
190+ assert . equal ( isWebAssetClientProtocolPayload ( ssh ) , false ) ;
191+ assert . equal ( isWebAssetClientProtocolPayload ( { protocol : "http" , asset : { } } ) , false ) ;
192+ } ) ;
193+
144194test ( "registers only jms2 and keeps the Windows development entry path as one argument" , ( ) => {
145195 const calls : unknown [ ] [ ] = [ ] ;
146196 const app = {
0 commit comments