@@ -2067,6 +2067,72 @@ describe('Proxy text producers', function () {
20672067 expect ( output ) . to . not . include ( 'Forced Mihomo=tuic-v5' ) ;
20682068 } ) ;
20692069
2070+ it ( 'merges SurgeMac _config once so GLOBAL lists each merged node once' , function ( ) {
2071+ // A Script Operator naturally builds the override once and assigns the
2072+ // same object to every node, so the shared reference must survive.
2073+ const override = {
2074+ 'proxy-groups' : [
2075+ {
2076+ name : 'GLOBAL' ,
2077+ type : 'fallback' ,
2078+ proxies : [ '20000' , '19999' , '19998' ] ,
2079+ url : 'http://cp.cloudflare.com/generate_204' ,
2080+ interval : 300 ,
2081+ } ,
2082+ ] ,
2083+ } ;
2084+ const proxies = [ 'A' , 'B' , 'C' ] . map ( ( name ) => ( {
2085+ type : 'trojan' ,
2086+ name,
2087+ server : `${ name . toLowerCase ( ) } .example.com` ,
2088+ port : 443 ,
2089+ password : 'secret' ,
2090+ _merge : true ,
2091+ _mihomoExternal : true ,
2092+ _localPort : 20000 ,
2093+ _config : override ,
2094+ } ) ) ;
2095+
2096+ const output = ProxyUtils . produce ( proxies , 'SurgeMac' , 'external' , { } ) ;
2097+
2098+ const args = [ ...output . matchAll ( / a r g s = " ( [ ^ " ] + ) " / g) ] . map ( ( m ) => m [ 1 ] ) ;
2099+ const config = JSON . parse ( Base64 . decode ( args [ args . length - 1 ] ) ) ;
2100+ const globalGroup = config [ 'proxy-groups' ] . find (
2101+ ( group ) => group . name === 'GLOBAL' ,
2102+ ) ;
2103+
2104+ expect ( globalGroup . proxies ) . to . deep . equal ( [ '20000' , '19999' , '19998' ] ) ;
2105+ expect ( globalGroup . url ) . to . equal (
2106+ 'http://cp.cloudflare.com/generate_204' ,
2107+ ) ;
2108+ expect ( globalGroup . interval ) . to . equal ( 300 ) ;
2109+ expect ( config . listeners ) . to . have . lengthOf ( 3 ) ;
2110+ expect ( config . proxies ) . to . have . lengthOf ( 3 ) ;
2111+ expect ( config [ 'mixed-port' ] ) . to . equal ( 19997 ) ;
2112+ } ) ;
2113+
2114+ it ( 'keeps earlier SurgeMac _config fields when later nodes add partial overrides' , function ( ) {
2115+ const overrides = [ { 'allow-lan' : true } , { 'log-level' : 'debug' } , { } ] ;
2116+ const proxies = [ 'A' , 'B' , 'C' ] . map ( ( name , index ) => ( {
2117+ type : 'trojan' ,
2118+ name,
2119+ server : `${ name . toLowerCase ( ) } .example.com` ,
2120+ port : 443 ,
2121+ password : 'secret' ,
2122+ _merge : true ,
2123+ _mihomoExternal : true ,
2124+ _localPort : 20000 ,
2125+ _config : overrides [ index ] ,
2126+ } ) ) ;
2127+
2128+ const output = ProxyUtils . produce ( proxies , 'SurgeMac' , 'external' , { } ) ;
2129+ const args = [ ...output . matchAll ( / a r g s = " ( [ ^ " ] + ) " / g) ] . map ( ( m ) => m [ 1 ] ) ;
2130+ const config = JSON . parse ( Base64 . decode ( args [ args . length - 1 ] ) ) ;
2131+
2132+ expect ( config [ 'allow-lan' ] ) . to . equal ( true ) ;
2133+ expect ( config [ 'log-level' ] ) . to . equal ( 'debug' ) ;
2134+ } ) ;
2135+
20702136 it ( 'produces URI WireGuard links with stored and default CIDR suffixes' , function ( ) {
20712137 const output = produceExternal ( 'URI' , [
20722138 {
0 commit comments