@@ -271,6 +271,14 @@ function syncCashOnlyExecutionForAccount(state, form, platform, account) {
271271 form . cashOnlyExecutionMode = effective === true ? "enabled" : ( effective === false ? "disabled" : "current" ) ;
272272}
273273
274+ function syncStrategyForAccount ( state , form , platform , account ) {
275+ if ( ! form ) return ;
276+ const selected = account || makeAccount ( "preview" ) ;
277+ syncReservePolicyForAccount ( state , form , platform , selected ) ;
278+ syncCashOnlyExecutionForAccount ( state , form , platform , selected ) ;
279+ reconcileExecutionCashPolicy ( form , "margin" ) ;
280+ }
281+
274282// --- 初始加载互斥检查(从 syncStrategyForAccount 提取) ---
275283function enforceMutualExclusionAfterSync ( form ) {
276284 if ( form && allowMarginExplicitlySelected ( form ) ) {
@@ -781,6 +789,52 @@ console.log("\n=== 8. 回归测试:旧行为不应出现 ===\n");
781789 assert ( form . reservePolicyMode === "none" , "8c: schwab reserve cleared to 'none'" ) ;
782790}
783791
792+ // ============================================================
793+ // 15. syncStrategyForAccount 初始互斥纠偏
794+ // ============================================================
795+
796+ console . log ( "\n=== 15. syncStrategyForAccount 初始互斥纠偏 ===\n" ) ;
797+
798+ // 15a: 融资映射+预留现金配置时,应在同步后清空为 none(修复初始映射 bug)
799+ {
800+ const state = {
801+ currentStrategies : {
802+ longbridge : {
803+ sg : {
804+ cash_only_execution : false , // financing allowed
805+ min_reserved_cash_usd : "10000" ,
806+ reserved_cash_ratio : "0.05" ,
807+ } ,
808+ } ,
809+ } ,
810+ } ;
811+ const form = defaultReserveForm ( ) ;
812+ syncStrategyForAccount ( state , form , "longbridge" , makeAccount ( "sg" ) ) ;
813+ assert ( form . cashOnlyExecutionMode === "disabled" , "15a: cash-only mode resolves to disabled (allow margin)" ) ;
814+ assert ( form . reservePolicyMode === "none" , "15a: reserve policy auto-cleared to none" ) ;
815+ }
816+
817+ // 15b: cash-only=enabled 时,不应清空已有预留现金
818+ {
819+ const state = {
820+ currentStrategies : {
821+ longbridge : {
822+ sg : {
823+ cash_only_execution : true , // no financing
824+ min_reserved_cash_usd : "10000" ,
825+ reserved_cash_ratio : "0.05" ,
826+ } ,
827+ } ,
828+ } ,
829+ } ;
830+ const form = defaultReserveForm ( ) ;
831+ syncStrategyForAccount ( state , form , "longbridge" , makeAccount ( "sg" ) ) ;
832+ assert ( form . cashOnlyExecutionMode === "enabled" , "15b: cash-only mode resolves to enabled (no margin)" ) ;
833+ assert ( form . reservePolicyMode === "max" , "15b: reserve policy keeps max" ) ;
834+ assert ( form . minReservedCashUsd === "10000" , "15b: reserve floor preserved" ) ;
835+ assert ( form . reservedCashRatio === "0.05" , "15b: reserve ratio preserved" ) ;
836+ }
837+
784838// ============================================================
785839// 9. syncRuntimeTargetForAccount (解析为具体值)
786840// ============================================================
0 commit comments