feat: 增强 HTTP checker 鲁棒性 — 严格配置校验、完整耗时、流式body、重定向与编码完善
启动期校验: 新增 validate.ts 对 HTTP config/expect/body rule/operator 全方位严格校验 执行语义: body 改为 Web Stream 流式超限中止,durationMs 覆盖完整执行 错误归属: status/header 失败不读 body,phase 分层 request/body,early duration skip body 重定向: 跟随前释放 body,POST/303 改 GET 清理 header,跨 origin 剥离敏感 header 编码: 支持 quoted charset,未知编码返回结构化解码错误 文档: README match→regex+durationMs,DEVELOPMENT 执行流程与错误归属 测试: +63 测试覆盖全部新增场景,325 pass 0 fail 规格: 同步 probe-config/probe-engine/expect-body-checkers 3 个 delta spec
This commit is contained in:
@@ -52,6 +52,7 @@ src/
|
||||
http/ HTTP Checker 子包
|
||||
runner.ts HttpChecker(resolve/execute/serialize)
|
||||
expect.ts HTTP 专用断言(status/headers)
|
||||
validate.ts HTTP 配置与 expect 启动期校验
|
||||
command/ Command Checker 子包
|
||||
runner.ts CommandChecker(resolve/execute/serialize)
|
||||
expect.ts Command 专用断言(exitCode)
|
||||
@@ -183,11 +184,13 @@ export function handleXxx(params, store: ProbeStore, method: string, mode: Runti
|
||||
**HTTP 校验流程**:
|
||||
|
||||
```
|
||||
runHttpCheck → 收集观测(statusCode/headers/body/durationMs)
|
||||
→ checkHttpExpect → status → duration → headers → body(可选)
|
||||
runHttpCheck → 收集观测(statusCode/headers)
|
||||
→ status → headers → (early duration) → body(按需) → (final duration)
|
||||
→ 首个失败即停止,返回 CheckFailure
|
||||
```
|
||||
|
||||
HTTP checker 的 `durationMs` 覆盖完整执行(含重定向、响应体读取、解码和 expect 校验)。status 或 headers 失败时不读取 body;进入 body 前若已超过 `maxDurationMs`,直接返回 duration failure。
|
||||
|
||||
**Command 校验流程**:
|
||||
|
||||
```
|
||||
@@ -199,7 +202,7 @@ runCommandCheck → 收集观测(exitCode/stdout/stderr/durationMs)
|
||||
**Body 规则类型**:
|
||||
|
||||
- `contains`:文本包含匹配
|
||||
- `regex`:正则表达式匹配
|
||||
- `regex`:正则表达式匹配(注意:body 正则字段为 `regex`,不是 `match`)
|
||||
- `json`:JSONPath 提取 + 操作符比较(使用 `es-toolkit/isPlainObject` 区分纯值和操作符)
|
||||
- `css`:cheerio CSS 选择器 + 操作符比较
|
||||
- `xpath`:XPath 节点提取 + 操作符比较
|
||||
@@ -210,7 +213,7 @@ runCommandCheck → 收集观测(exitCode/stdout/stderr/durationMs)
|
||||
|
||||
- **API 错误**:`{ error: "描述", status: <code> }`,状态码 400/404/405/503
|
||||
- **CheckFailure**:`{ kind: "error"|"mismatch", phase, path, expected?, actual?, message }`
|
||||
- **错误处理**:expect 校验失败记录首个失败原因;网络/超时/进程崩溃统一为 `kind:"error"`
|
||||
- **错误处理**:expect 校验失败记录首个失败原因;网络/超时/进程崩溃统一为 `kind:"error"`,请求/TLS/timeout 错误归属 `phase:"request"`,body 超限/解码/解析错误归属 `phase:"body"`
|
||||
- **日志**:解析失败等非致命异常用 `console.warn`,启动失败用 `console.error` + `process.exit(1)`
|
||||
|
||||
### 1.10 测试规范
|
||||
|
||||
Reference in New Issue
Block a user