按审查结论重构:先补测试网,再搬代码

顺序是刻意的。前端一行测试都没有,直接挪代码挪坏了 bun test 不会红,所以先把纯逻辑
抽到能被测试的位置并补上用例,最后才动组件。测试从 37 条增加到 77 条。

抽出来的四块:
- shared/outbound-chain.ts  「这个端口现在走哪条线」的链路解析,带防环,9 条测试
- web/delay-test.ts          延迟测试失败时说什么,6 个分支原本一条测试都没有
- web/runtime.ts             运行时状态的模块级单例,照 prefs.ts 已有的模式
- web/components/InboundList.vue  入站列表

出站的文本原本散成四份(读一份、显示一份、写回一份、表单又抄一份),加一种出站模式
要同时改四处,漏一个就是显示与写回不一致。合并成 OUTBOUND_PRESETS 一张表。

给认证和透传白名单补了 20 条测试。两者都是安全边界、都是纯函数、都不需要内核在线,
之前却只靠需要活内核的冒烟脚本间接覆盖。其中「形似但不是健康检查的路径」几条确认了
正则没写松。

另外:配置快照不再把整份文件原文下发(前端从不读,白白让响应体积翻倍);
yaml-cosmetics 的测试改走生产路径,之前它自己拼了一遍三步流程,落盘链路漏掉其中一步
测试照样会绿。
This commit is contained in:
im0o
2026-08-10 18:21:23 +08:00
parent 6b208847a2
commit c5ac59ecf9
19 changed files with 781 additions and 355 deletions
+8 -5
View File
@@ -1,8 +1,9 @@
import { describe, expect, it } from 'bun:test'
import { readFileSync } from 'node:fs'
import { join } from 'node:path'
import { openDocument, replaceDocumentData } from '../vendor/config-editor/index.ts'
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 { restoreInlineCommentAlignment } from './yaml-cosmetics.ts'
const fixture = readFileSync(
@@ -12,12 +13,14 @@ const fixture = readFileSync(
const clone = (v: unknown) => JSON.parse(JSON.stringify(v)) as ConfigObject
/** 走一遍真实的写回链路:解析 → 改 → 写回 → 修复格式。 */
/**
* 走**生产用的那一条**写回路径,而不是在测试里重拼一遍。
* 自己拼的话,落盘链路里漏掉其中一步这些测试照样会绿——那就白写了。
*/
function roundtrip(source: string, mutate: (draft: ConfigObject) => void): string {
const doc = openDocument(source)
const draft = clone(doc.data)
const draft = clone(openDocument(source).data)
mutate(draft)
return restoreInlineCommentAlignment(source, replaceDocumentData(doc, draft).yaml)
return rewriteYaml(source, draft)
}
describe('写回一份带注释的配置', () => {