feat: 结构化 observation 替代 statusDetail,API 层动态构造 detail
- CheckResult: statusDetail -> observation (持久化) + detail (API 动态派生) - 存储: status_detail 列 -> observation TEXT (JSON) - CheckerDefinition: 新增 buildDetail(observation) 方法 - 各 checker 返回结构化 observation,API 层通过 registry 调用 buildDetail - HTTP: bodyPreview 在 status/header 失败时也提前采集 - UDP: observation 包含 durationMs,未响应归为 error failure - CMD: 超时/输出超限时保留已收集 observation - TCP: connectTimeMs 仅含连接建立耗时,不含 banner 等待 - 新增 buildDetail 单测和 mapCheckResult 覆盖测试 - 同步 openspec 主规范,归档 checker-observation 变更
This commit is contained in:
@@ -127,7 +127,7 @@ describe("TcpChecker execute", () => {
|
||||
expect(result.matched).toBe(true);
|
||||
expect(result.failure).toBeNull();
|
||||
expect(result.durationMs).toBeGreaterThanOrEqual(0);
|
||||
expect(result.statusDetail).toMatch(/^connected in \d+ms$/);
|
||||
expect(result.observation).toMatchObject({ connected: true });
|
||||
});
|
||||
|
||||
test("TCP 连接失败", async () => {
|
||||
@@ -145,7 +145,7 @@ describe("TcpChecker execute", () => {
|
||||
);
|
||||
expect(result.matched).toBe(true);
|
||||
expect(result.failure).toBeNull();
|
||||
expect(result.statusDetail).toBeTruthy();
|
||||
expect(result.observation).toMatchObject({ connected: false });
|
||||
});
|
||||
|
||||
test("期望端口不可达但连接成功", async () => {
|
||||
@@ -171,8 +171,11 @@ describe("TcpChecker execute", () => {
|
||||
makeCtx(),
|
||||
);
|
||||
expect(result.matched).toBe(true);
|
||||
expect(result.statusDetail).toContain("banner:");
|
||||
expect(result.statusDetail).toContain("220 smtp.example.com ESMTP");
|
||||
const obs = result.observation!;
|
||||
expect(obs).toMatchObject({
|
||||
connected: true,
|
||||
});
|
||||
expect(obs["banner"]).toContain("220 smtp.example.com ESMTP");
|
||||
});
|
||||
|
||||
test("banner operator 校验通过", async () => {
|
||||
@@ -206,7 +209,7 @@ describe("TcpChecker execute", () => {
|
||||
makeCtx(),
|
||||
);
|
||||
expect(result.matched).toBe(true);
|
||||
expect(result.statusDetail).not.toContain("banner:");
|
||||
expect(result.observation?.["banner"]).toBeFalsy();
|
||||
});
|
||||
|
||||
test("banner 超时空字符串继续执行", async () => {
|
||||
|
||||
Reference in New Issue
Block a user