@@ -7,6 +7,7 @@ import worker, { __test } from "../web/strategy-switch-console/worker.js";
77
88const root = resolve ( dirname ( fileURLToPath ( import . meta. url ) ) , ".." ) ;
99const indexHtml = readFileSync ( resolve ( root , "web/strategy-switch-console/index.html" ) , "utf8" ) ;
10+ assert . ok ( __test . currentStrategiesTimeoutMs >= 8000 ) ;
1011const renderPlatformsBody = indexHtml . match ( / f u n c t i o n r e n d e r P l a t f o r m s \( \) \{ ( [ \s \S ] * ?) \n \} / ) ?. [ 1 ] || "" ;
1112assert . ok ( ! renderPlatformsBody . includes ( "syncStrategyForAccount(" ) ) ;
1213assert . equal ( indexHtml . includes ( ".innerHTML" ) , false ) ;
@@ -406,6 +407,59 @@ try {
406407 globalThis . fetch = originalFetch ;
407408}
408409
410+ let releaseReservedVariables ;
411+ let reservedVariableRequests = 0 ;
412+ let reservedVariablesFinished = false ;
413+ let runtimeTargetStartedBeforeReservedVariablesFinished = false ;
414+ const reservedVariablesGate = new Promise ( ( resolve ) => {
415+ releaseReservedVariables = ( ) => {
416+ reservedVariablesFinished = true ;
417+ resolve ( ) ;
418+ } ;
419+ } ) ;
420+ const reservedVariableFallback = setTimeout ( releaseReservedVariables , 100 ) ;
421+ globalThis . fetch = async ( url ) => {
422+ const requestUrl = String ( url ) ;
423+ if ( requestUrl . endsWith ( "/CLOUD_RUN_SERVICE_TARGETS_JSON" ) ) {
424+ return new Response ( "" , { status : 404 } ) ;
425+ }
426+ if ( requestUrl . endsWith ( "/SCHWAB_MIN_RESERVED_CASH_USD" ) || requestUrl . endsWith ( "/SCHWAB_RESERVED_CASH_RATIO" ) ) {
427+ reservedVariableRequests += 1 ;
428+ await reservedVariablesGate ;
429+ return new Response ( JSON . stringify ( { value : requestUrl . endsWith ( "/SCHWAB_RESERVED_CASH_RATIO" ) ? "0.03" : "150" } ) , {
430+ status : 200 ,
431+ headers : { "Content-Type" : "application/json" } ,
432+ } ) ;
433+ }
434+ if ( requestUrl . endsWith ( "/RUNTIME_TARGET_JSON" ) ) {
435+ runtimeTargetStartedBeforeReservedVariablesFinished = reservedVariableRequests === 2 && ! reservedVariablesFinished ;
436+ releaseReservedVariables ( ) ;
437+ return new Response ( JSON . stringify ( {
438+ value : JSON . stringify ( {
439+ platform_id : "schwab" ,
440+ strategy_profile : "soxl_soxx_trend_income" ,
441+ dry_run_only : false ,
442+ account_scope : "schwab" ,
443+ service_name : "charles-schwab-quant-service" ,
444+ execution_mode : "live" ,
445+ } ) ,
446+ } ) , { status : 200 , headers : { "Content-Type" : "application/json" } } ) ;
447+ }
448+ return new Response ( "" , { status : 404 } ) ;
449+ } ;
450+ try {
451+ const currentStrategies = await __test . loadCurrentStrategies (
452+ { schwab : accountOptions . schwab } ,
453+ { RUNTIME_SETTINGS_DISPATCH_TOKEN : "test-token" } ,
454+ ) ;
455+ assert . equal ( currentStrategies . schwab . default . min_reserved_cash_usd , "150" ) ;
456+ assert . equal ( currentStrategies . schwab . default . reserved_cash_ratio , "0.03" ) ;
457+ assert . equal ( runtimeTargetStartedBeforeReservedVariablesFinished , true ) ;
458+ } finally {
459+ clearTimeout ( reservedVariableFallback ) ;
460+ globalThis . fetch = originalFetch ;
461+ }
462+
409463const longbridgeHk = __test . assertConfiguredAccount (
410464 {
411465 platform : "longbridge" ,
0 commit comments