删除规则组的引用拦截连附加规则一起查

之前只扫顶层 rules。附加规则(sub-rules)里的 RULE-SET 引用漏过的话,
删除会被内核重载拒掉——保护链路能回滚,但用户看到的是解析错误原文
而不是「谁在引用它」。
This commit is contained in:
2026-08-12 04:02:56 +08:00
parent c3c0f56e56
commit 955fa340af
3 changed files with 45 additions and 2 deletions
+15
View File
@@ -16,6 +16,7 @@ import {
ruleSetReferences,
setRuleProviders,
setRules,
subRuleSetReferences,
} from './rules.ts'
import type { ConfigObject } from '../vendor/config-editor/index.ts'
@@ -316,3 +317,17 @@ describe('清单格式与缓存路径', () => {
expect(ruleProviderPathConflict(data, 'x', ruleProviderPath('x', 'yaml'))).toBeNull()
})
})
describe('附加规则里的规则组引用', () => {
it('sub-rules 各表里的 RULE-SET 引用都认出来,别的表不误报', () => {
const data = {
'sub-rules': {
'patchbay:t1 附加': ['RULE-SET,ads,REJECT', 'MATCH,patchbay:t1'],
mine: ['RULE-SET,other,DIRECT'],
},
}
expect(subRuleSetReferences(data, 'ads')).toEqual(['RULE-SET,ads,REJECT'])
expect(subRuleSetReferences(data, 'ghost')).toEqual([])
expect(subRuleSetReferences({}, 'ads')).toEqual([])
})
})