每路入站配一组专属策略组,换线不再改配置文件
原本换一条线要改 config.yaml、跑校验、等内核重载,几秒起步;而换线恰恰是这个工具 最高频的动作,把它放在最重的路径上方向就错了。现在每一路配一个 select 组加 AUTO、 FALLBACK 两个,入站的 proxy 永久指向 select,换线只是调一次内核接口。这样做的前提是 选中不会丢:内核把它写进 cache 文件,重启后由 patchSelectGroup 恢复,而 profile.store-selected 默认为真。 链式代理靠给来源订阅复制一份声明、挂上 override.dialer-proxy 实现,因为这个字段写在 策略组上内核只会打条日志然后忽略。副本是 type: file 读原订阅已经落盘的缓存,而不是 自己再拉一次:自己拉的话订阅地址一不可达副本就是空的,那一路入站会一条线都不剩, 表现是端口还在监听却没有任何出口。 顺带把 shared/outbound-chain.ts 里「只有 Selector 接受手动选择」那条断言删了,它是 错的(内核检查的是 SelectAble 接口,URLTest 和 Fallback 也实现了)。界面仍然只让 Selector 可点,但理由换成了另外两种的手动指定会被它们自己撤销。 完整取舍见工作区决策记录 0007。
This commit is contained in:
@@ -0,0 +1,49 @@
|
||||
/**
|
||||
* 验证「每路一个专属代理组」和链式代理生成的配置内核真的接受。
|
||||
*
|
||||
* 单元测试只能证明字符串拼对了,证明不了内核认。这里走一遍真实的写回路径,
|
||||
* 产物交给 mihomo -t 校验。特别要看的是订阅副本上的 dialer-proxy 引用能不能过
|
||||
* `validateDialerProxies`(内核源码 config/utils.go:148-176)。
|
||||
*
|
||||
* 用法:bun run scripts/verify-chain.ts <源配置> <输出路径>
|
||||
*/
|
||||
import { readFileSync, writeFileSync } from 'node:fs'
|
||||
import { openDocument } from '../vendor/config-editor/index.ts'
|
||||
import type { ConfigObject } from '../vendor/config-editor/index.ts'
|
||||
import { rewriteYaml } from '../server/config-store.ts'
|
||||
import { applySetup, pruneGenerated } from '../shared/inbound-groups.ts'
|
||||
|
||||
const [src, out] = process.argv.slice(2)
|
||||
if (!src || !out) {
|
||||
console.error('用法:bun run scripts/verify-chain.ts <源配置> <输出路径>')
|
||||
process.exit(1)
|
||||
}
|
||||
|
||||
const source = readFileSync(src, 'utf8')
|
||||
const data = JSON.parse(JSON.stringify(openDocument(source).data)) as ConfigObject
|
||||
|
||||
// 模拟界面上的三个动作:新增两路入站,一路直连,一路开链式代理并把入口筛到某一条线
|
||||
data.listeners = [
|
||||
{ name: '容器A', type: 'mixed', port: 17895 },
|
||||
{ name: '容器B', type: 'mixed', port: 17896 },
|
||||
]
|
||||
|
||||
let next = applySetup(data, '容器A', {
|
||||
proxy: { sources: ['subs'], filter: null },
|
||||
chain: null,
|
||||
})
|
||||
next = applySetup(next, '容器B', {
|
||||
proxy: { sources: ['subs'], filter: null },
|
||||
chain: { sources: ['subs'], filter: '(?i)DMIT' },
|
||||
})
|
||||
|
||||
writeFileSync(out, rewriteYaml(source, pruneGenerated(next)), 'utf8')
|
||||
|
||||
console.log('生成的策略组:')
|
||||
console.log(JSON.stringify(next['proxy-groups'], null, 2))
|
||||
console.log('\n生成的订阅副本(只看结构,url 不回显):')
|
||||
for (const [name, entry] of Object.entries(next['proxy-providers'] as ConfigObject)) {
|
||||
if (!name.startsWith('patchbay:')) continue
|
||||
const { url, ...rest } = entry as ConfigObject
|
||||
console.log(name, JSON.stringify({ ...rest, url: '<同源订阅>' }))
|
||||
}
|
||||
Reference in New Issue
Block a user