mirror of
https://github.com/sub-store-org/Sub-Store.git
synced 2026-11-30 16:38:30 +00:00
fix(SurgeMac): 合并 mihomo 配置覆盖层一次, 避免 GLOBAL 出现重复节点 (#619)
延迟合并 mihomo 配置覆盖层,避免 GLOBAL 共享数组被逐节点追加;同时保留多个节点覆盖层的逐 key 浅合并语义,并补充回归测试。
This commit is contained in:
1 parent
a4c8741d24
commit
9e191de631
4 files changed
+78
-5
No files matched your search
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "sub-store",
|
||||
"version": "2.36.29",
|
||||
"version": "2.36.30",
|
||||
"description": "Advanced Subscription Manager for QX, Loon, Surge, Stash and Shadowrocket.",
|
||||
"main": "src/main.js",
|
||||
"packageManager": "pnpm@11.0.9",
|
||||
|
||||
@@ -598,6 +598,7 @@ function produce(proxies, targetPlatform, type, opts = {}) {
|
||||
Base64.encode(
|
||||
JSON.stringify({
|
||||
...opts._merged.config,
|
||||
...(opts._merged.configOverride || {}),
|
||||
'mixed-port': opts.localPort,
|
||||
}),
|
||||
),
|
||||
|
||||
@@ -206,10 +206,16 @@ function mihomo(proxy, type, opts) {
|
||||
...clashProxy,
|
||||
name: proxyName,
|
||||
});
|
||||
opts._merged.config = {
|
||||
...opts._merged.config,
|
||||
...(opts?.config || proxy._config || {}),
|
||||
};
|
||||
// 只记录覆盖层, 在所有节点都并入后由 index.js 统一合并一次.
|
||||
// 若在这里就合并, 覆盖层里的 proxy-groups 会成为后续节点
|
||||
// `proxy-groups[0].proxies.push()` 的目标, 使 GLOBAL 出现重复项.
|
||||
const configOverride = opts?.config || proxy._config;
|
||||
if (configOverride) {
|
||||
opts._merged.configOverride = {
|
||||
...(opts._merged.configOverride || {}),
|
||||
...configOverride,
|
||||
};
|
||||
}
|
||||
} else {
|
||||
const external_proxy = {
|
||||
name: proxy.name,
|
||||
|
||||
@@ -2067,6 +2067,72 @@ describe('Proxy text producers', function () {
|
||||
expect(output).to.not.include('Forced Mihomo=tuic-v5');
|
||||
});
|
||||
|
||||
it('merges SurgeMac _config once so GLOBAL lists each merged node once', function () {
|
||||
// A Script Operator naturally builds the override once and assigns the
|
||||
// same object to every node, so the shared reference must survive.
|
||||
const override = {
|
||||
'proxy-groups': [
|
||||
{
|
||||
name: 'GLOBAL',
|
||||
type: 'fallback',
|
||||
proxies: ['20000', '19999', '19998'],
|
||||
url: 'http://cp.cloudflare.com/generate_204',
|
||||
interval: 300,
|
||||
},
|
||||
],
|
||||
};
|
||||
const proxies = ['A', 'B', 'C'].map((name) => ({
|
||||
type: 'trojan',
|
||||
name,
|
||||
server: `${name.toLowerCase()}.example.com`,
|
||||
port: 443,
|
||||
password: 'secret',
|
||||
_merge: true,
|
||||
_mihomoExternal: true,
|
||||
_localPort: 20000,
|
||||
_config: override,
|
||||
}));
|
||||
|
||||
const output = ProxyUtils.produce(proxies, 'SurgeMac', 'external', {});
|
||||
|
||||
const args = [...output.matchAll(/args="([^"]+)"/g)].map((m) => m[1]);
|
||||
const config = JSON.parse(Base64.decode(args[args.length - 1]));
|
||||
const globalGroup = config['proxy-groups'].find(
|
||||
(group) => group.name === 'GLOBAL',
|
||||
);
|
||||
|
||||
expect(globalGroup.proxies).to.deep.equal(['20000', '19999', '19998']);
|
||||
expect(globalGroup.url).to.equal(
|
||||
'http://cp.cloudflare.com/generate_204',
|
||||
);
|
||||
expect(globalGroup.interval).to.equal(300);
|
||||
expect(config.listeners).to.have.lengthOf(3);
|
||||
expect(config.proxies).to.have.lengthOf(3);
|
||||
expect(config['mixed-port']).to.equal(19997);
|
||||
});
|
||||
|
||||
it('keeps earlier SurgeMac _config fields when later nodes add partial overrides', function () {
|
||||
const overrides = [{ 'allow-lan': true }, { 'log-level': 'debug' }, {}];
|
||||
const proxies = ['A', 'B', 'C'].map((name, index) => ({
|
||||
type: 'trojan',
|
||||
name,
|
||||
server: `${name.toLowerCase()}.example.com`,
|
||||
port: 443,
|
||||
password: 'secret',
|
||||
_merge: true,
|
||||
_mihomoExternal: true,
|
||||
_localPort: 20000,
|
||||
_config: overrides[index],
|
||||
}));
|
||||
|
||||
const output = ProxyUtils.produce(proxies, 'SurgeMac', 'external', {});
|
||||
const args = [...output.matchAll(/args="([^"]+)"/g)].map((m) => m[1]);
|
||||
const config = JSON.parse(Base64.decode(args[args.length - 1]));
|
||||
|
||||
expect(config['allow-lan']).to.equal(true);
|
||||
expect(config['log-level']).to.equal('debug');
|
||||
});
|
||||
|
||||
it('produces URI WireGuard links with stored and default CIDR suffixes', function () {
|
||||
const output = produceExternal('URI', [
|
||||
{
|
||||
|
||||
Reference in new issue
Block a user