Files
im0o c5ac59ecf9 按审查结论重构:先补测试网,再搬代码
顺序是刻意的。前端一行测试都没有,直接挪代码挪坏了 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 的测试改走生产路径,之前它自己拼了一遍三步流程,落盘链路漏掉其中一步
测试照样会绿。
2026-08-10 18:21:23 +08:00

53 lines
2.1 KiB
TypeScript
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
import { describe, expect, it } from 'bun:test'
import { ApiError } from './api'
import { describeTestFailure } from './delay-test'
const LINE = '[vless]Gomami.SIN Secret'
describe('延迟测试失败时告诉用户什么', () => {
it('超时说明是几秒内没完成', () => {
// 只说「超时」,用户不知道是等了 1 秒还是 60 秒,也就不知道该不该重试
expect(describeTestFailure(LINE, new ApiError(504, {}), 5000)).toBe(
`${LINE} 延迟测试超时,5 秒内没有取到测试地址`,
)
})
it('找不到这个名字时指出该从订阅进去测', () => {
// 订阅线路不在内核的全局出站表里,这是本项目最容易踩的一条约束
expect(describeTestFailure(LINE, new ApiError(404, { message: 'Resource not found' }))).toContain(
'不在内核的出站表里',
)
})
it('连接失败且内核没给具体原因时,给出能指导排查的话', () => {
const generic = new ApiError(503, { message: 'An error occurred in the delay test' })
expect(describeTestFailure(LINE, generic)).toBe(
`${LINE} 无法建立连接,线路可能已失效,或本机到该服务器的网络不通`,
)
})
it('内核给了具体原因就原样带上', () => {
const specific = new ApiError(503, { message: 'dial tcp: i/o timeout' })
expect(describeTestFailure(LINE, specific)).toBe(`${LINE} 无法建立连接:dial tcp: i/o timeout`)
})
it('没见过的状态码带上状态码和内核原话', () => {
expect(describeTestFailure(LINE, new ApiError(500, { message: 'boom' }))).toBe(
`${LINE} 延迟测试失败(HTTP 500):boom`,
)
})
it('状态码没见过且内核没说话时不留一个空冒号', () => {
expect(describeTestFailure(LINE, new ApiError(500, {}))).toBe(
`${LINE} 延迟测试失败(HTTP 500)`,
)
})
it('不是接口错误时也要说出是什么', () => {
// 网络断了、代码抛了异常,都会走到这里,不能显示成 [object Object]
expect(describeTestFailure(LINE, new TypeError('Failed to fetch'))).toBe(
`${LINE} 延迟测试失败:TypeError: Failed to fetch`,
)
})
})