1
0

feat: 新增 DB checker — 支持 PostgreSQL/MySQL/SQLite 连接测试与 SQL 查询断言

- 实现 db 类型 checker,使用 Bun 内置 SQL 类
- 支持 db.url 连接字符串和可选 db.query 查询语句
- expect 支持 maxDurationMs、rowCount、rows 逐列校验
- 凭据屏蔽序列化输出
- SQLite 内存数据库测试覆盖
This commit is contained in:
2026-05-16 09:00:15 +08:00
parent c36df94e59
commit 146cef982e
16 changed files with 1344 additions and 7 deletions

View File

@@ -91,6 +91,17 @@ targets:
exitCode: [0]
stdout:
- contains: "ok"
- name: "SQLite 数据库检查"
type: db
db:
url: "sqlite:///path/to/db.sqlite"
query: "SELECT COUNT(*) as cnt FROM users WHERE status = 'active'"
expect:
maxDurationMs: 5000
rowCount: { gte: 1 }
rows:
- cnt: { gte: 0 }
```
### 配置说明
@@ -114,7 +125,7 @@ targets:
- `cwd`: 默认工作目录(相对于配置文件所在目录解析,默认 `.`
- **targets**: 拨测目标列表(必填)
- `name`: 目标名称(必填,唯一)
- `type`: 目标类型,`http``cmd`(必填)
- `type`: 目标类型,`http``cmd``db`(必填)
- `group`: 分组名称(可选,默认 `"default"`
- `http`: HTTP 拨测配置type 为 http 时必填)
- `url`: 目标 URL
@@ -126,6 +137,9 @@ targets:
- `args`: 命令行参数列表
- `env`: 环境变量覆盖(可选,继承进程环境变量并合并覆盖)
- `cwd`: 工作目录(可选,相对于配置文件所在目录解析,默认 `.`
- `db`: 数据库拨测配置type 为 db 时必填)
- `url`: 数据库连接字符串,支持 `postgres://``mysql://``sqlite://` 协议
- `query`: SQL 查询语句(可选,不配置时仅测试连接)
- `interval``timeout`: 覆盖全局默认值
- `expect`: 期望校验
- `status`: 可接受的状态码列表HTTP支持精确状态码和范围模式`"2xx"`)混合配置;未指定时默认 `[200]`
@@ -148,6 +162,8 @@ targets:
- `path`: XPath 表达式(必填,如 `/html/body/h1/text()`
- 比较操作符(可选,无操作符时仅检查节点是否存在)
- `stdout` / `stderr`: Cmd 输出校验(数组,每项为一个操作符对象)
- `rowCount`: DB 查询返回行数校验(支持操作符对象)
- `rows`: DB 查询结果逐行校验(数组,每项为列名→操作符映射)
- 比较操作符:`equals`(默认)、`contains``match`(正则,启动期会拒绝存在 ReDoS 风险的模式)、`empty``exists``gte``lte``gt``lt`
大小说明:`maxBodyBytes``maxOutputBytes` 支持单位 `KB``MB``GB`,也可直接使用数字(非负安全整数字节数)。
@@ -178,7 +194,7 @@ JSON Schema仓库根目录导出 `probe-config.schema.json`,可在 YAML 文
**MetaResponse**: `checkerTypes`(已注册 checker 类型标识符列表)
**TargetStatus**: `id``name``type`checker 类型,如 http/cmd`target`URL 或命令摘要)、`group``interval``latestCheck``stats``currentStreak``recentSamples`
**TargetStatus**: `id``name``type`checker 类型,如 http/cmd/db)、`target`URL、命令摘要或数据库连接摘要)、`group``interval``latestCheck``stats``currentStreak``recentSamples`
**RecentSample**: `timestamp``durationMs``up`