1
0

refactor: 统一 expect 断言体系,引入共享 ValueMatcher/ContentRules/KeyValueExpect 模型

- 引入共享 ValueMatcher(equals/contains/regex/exists/empty/gt/gte/lt/lte)
- 引入共享 ContentRules 数组(direct/json/css/xpath 提取器)
- 引入共享 KeyValueExpect(动态键值断言,字面量等价 equals)
- maxDurationMs → durationMs: ValueMatcher(所有 checker)
- match → regex(固定无 flags)
- Ping max* → packetLossPercent/avgLatencyMs/maxLatencyMs(ValueMatcher)
- LLM finishReason/rawFinishReason → ValueMatcher
- DB 新增 result: ContentRules
- TCP banner → ContentRules 数组
- 删除旧模块:operator.ts、validate-operator.ts、duration.ts、body.ts、text.ts、output.ts
- 更新全部 checker schema/validate/expect/execute
- 更新 probe-config.schema.json、probes.example.yaml
- 更新 README.md、DEVELOPMENT.md(含 expect 字段选择规范)
- 同步 10 个 delta specs 到主 specs,归档 change
This commit is contained in:
2026-05-19 14:24:27 +08:00
parent 349896bd02
commit 7a635a0a9f
85 changed files with 4290 additions and 2028 deletions

View File

@@ -93,7 +93,8 @@ targets:
url: "https://www.baidu.com"
expect:
status: [200]
maxDurationMs: 10000
durationMs:
lte: 10000
- id: "json-api"
name: "${env_name} JSON API 示例"
@@ -130,7 +131,8 @@ targets:
url: "${sqlite_url}"
query: "SELECT COUNT(*) as cnt FROM users WHERE status = 'active'"
expect:
maxDurationMs: 5000
durationMs:
lte: 5000
rowCount: { gte: 1 }
rows:
- cnt: { gte: 0 }
@@ -142,7 +144,8 @@ targets:
host: "127.0.0.1"
port: 6379
expect:
maxDurationMs: 3000
durationMs:
lte: 3000
- id: "udp-heartbeat"
name: "UDP 心跳检测"
@@ -154,7 +157,8 @@ targets:
expect:
response:
- contains: "PONG"
maxDurationMs: 100
durationMs:
lte: 100
- id: "gateway-ping"
name: "网关 ICMP 可达"
@@ -165,10 +169,14 @@ targets:
packetSize: 56
expect:
alive: true
maxPacketLoss: 10
maxAvgLatencyMs: 100
maxMaxLatencyMs: 300
maxDurationMs: 5000
packetLossPercent:
lte: 10
avgLatencyMs:
lte: 100
maxLatencyMs:
lte: 300
durationMs:
lte: 5000
```
### 配置说明
@@ -292,29 +300,35 @@ Ping checker 通过系统 `ping` 命令执行 ICMP 探测,支持 Linux、macOS
#### expect — 期望校验
| 字段 | 适用类型 | 说明 |
| ------------------- | -------- | ---------------------------------------------------------------- |
| `status` | HTTP | 可接受的状态码列表,支持精确码和范围(如 `"2xx"`);默认 `[200]` |
| `exitCode` | Cmd | 可接受的退出码列表;未指定时不校验 |
| `headers` | HTTP | 响应头校验 |
| `maxDurationMs` | 全部 | 最大耗时阈值(毫秒) |
| `output` | LLM | 模型输出校验(数组:`equals`/`contains`/`regex`/`json` |
| `finishReason` | LLM | 期望的 finish reason 字符串 |
| `rawFinishReason` | LLM | 期望的原始 finish reason 字符串 |
| `usage` | LLM | Token usage 校验(`inputTokens`/`outputTokens`/`totalTokens` |
| `stream` | LLM | 流式断言(`completed``firstTokenMs`,仅 `mode: stream` |
| `body` | HTTP | 响应体校验(数组,可组合使用,见下方) |
| `stdout` / `stderr` | Cmd | 输出校验(数组,每项一个操作符对象) |
| `rowCount` | DB | 查询返回行数校验(操作符对象) |
| `rows` | DB | 查询结果逐行校验数组,列名→操作符映射) |
| `connected` | TCP | 期望连接结果`true`(默认)可达或 `false` 期望不可达 |
| `banner` | TCP | Banner 文本校验(操作符对象,需开启 `tcp.readBanner` |
| `alive` | Ping | 期望主机可达性,默认 `true` |
| `maxPacketLoss` | Ping | 最大丢包率百分比,范围 `0-100` |
| `maxAvgLatencyMs` | Ping | 最大平均延迟(毫秒) |
| `maxMaxLatencyMs` | Ping | 最大单次延迟(毫秒) |
| 字段 | 适用类型 | 说明 |
| ------------------- | -------- | ---------------------------------------------------------------------- |
| `status` | HTTP/LLM | 可接受的状态码列表,支持精确码和范围(如 `"2xx"`);默认 `[200]` |
| `exitCode` | Cmd | 可接受的退出码列表;未指定时默认 `[0]` |
| `headers` | HTTP/LLM | 响应头校验,使用动态键名和 `KeyValueExpect` |
| `durationMs` | 全部 | 完整执行耗时校验,使用 `ValueMatcher`,如 `{ lte: 1000 }` |
| `output` | LLM | 模型输出校验,使用 `ContentRules` 数组 |
| `finishReason` | LLM | finish reason 校验,使用 `ValueMatcher` |
| `rawFinishReason` | LLM | 原始 finish reason 校验,使用 `ValueMatcher` |
| `usage` | LLM | Token usage 校验(`inputTokens`/`outputTokens`/`totalTokens` matcher |
| `stream` | LLM | 流式断言(`completed``firstTokenMs` matcher,仅 `mode: stream` |
| `body` | HTTP | 响应体校验,使用 `ContentRules` 数组 |
| `stdout` / `stderr` | Cmd | 输出校验,使用 `ContentRules` 数组 |
| `rowCount` | DB | 查询返回行数校验,使用 `ValueMatcher` |
| `rows` | DB | 查询结果逐行校验数组内每行为列名到 `KeyValueExpect` 的映射 |
| `result` | DB | 完整查询结果 `{ rows, rowCount }` 校验,使用 `ContentRules` 数组 |
| `connected` | TCP | 期望连接结果,`true`(默认)可达或 `false` 期望不可达 |
| `banner` | TCP | Banner 内容校验,使用 `ContentRules` 数组,需开启 `tcp.readBanner` |
| `responded` | UDP | 期望是否收到响应,默认 `true` |
| `response` | UDP | 响应内容校验,使用 `ContentRules` 数组 |
| `responseSize` | UDP | 响应字节数校验,使用 `ValueMatcher` |
| `sourceHost` | UDP | 响应来源地址校验,使用 `ValueMatcher` |
| `sourcePort` | UDP | 响应来源端口校验,使用 `ValueMatcher` |
| `alive` | Ping | 期望主机可达性,默认 `true` |
| `packetLossPercent` | Ping | 丢包率百分比校验,范围 `0-100`,使用 `ValueMatcher` |
| `avgLatencyMs` | Ping | 平均延迟校验,使用 `ValueMatcher` |
| `maxLatencyMs` | Ping | 最大单次延迟校验,使用 `ValueMatcher` |
**body 校验项**(数组中可混合使用
**ContentRules 校验项**`body``stdout``stderr``banner``response``output``result` 均使用数组
- `contains` — 响应体包含指定文本
- `regex` — 正则匹配(启动期会拒绝存在 ReDoS 风险的模式)
@@ -322,7 +336,9 @@ Ping checker 通过系统 `ping` 命令执行 ICMP 探测,支持 Linux、macOS
- `css` — CSS 选择器提取 HTML 元素(`selector` 必填,`attr` 可选提取属性)
- `xpath` — XPath 提取 XML/HTML 节点(`path` 必填,如 `/html/body/h1/text()`
**比较操作符**`equals`(默认)`contains``match`(正则)`empty``exists``gte``lte``gt``lt`
**ValueMatcher 字段**`equals``contains``regex``empty``exists``gte``lte``gt``lt``equals` 支持 JSON 深度相等;`regex` 固定使用无 flags 正则;提取器未配置 matcher 时等价于 `exists: true`
旧字段 `maxDurationMs``maxPacketLoss``maxAvgLatencyMs``maxMaxLatencyMs` 和旧正则字段 `match` 已移除,请分别改用 `durationMs`、Ping matcher 字段和 `regex`
**大小说明**`maxBodyBytes``maxOutputBytes` 支持 `KB``MB``GB` 单位,也可直接使用数字。