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:
@@ -54,7 +54,13 @@ rtt min/avg/max/mdev = 1.234/2.345/3.456/0.567 ms`);
|
||||
const result = await checker.execute(makeTarget(), makeCtx());
|
||||
expect(result.matched).toBe(true);
|
||||
expect(result.failure).toBeNull();
|
||||
expect(result.statusDetail).toBe("alive, avg 2.345ms, loss 0% (3/3)");
|
||||
expect(result.observation).toMatchObject({
|
||||
alive: true,
|
||||
avgLatencyMs: 2.345,
|
||||
packetLoss: 0,
|
||||
received: 3,
|
||||
transmitted: 3,
|
||||
});
|
||||
expect(calls[0]).toContain("ping");
|
||||
});
|
||||
|
||||
@@ -66,7 +72,7 @@ rtt min/avg/max/mdev = 1.234/2.345/3.456/0.567 ms`);
|
||||
);
|
||||
expect(result.matched).toBe(false);
|
||||
expect(result.failure?.phase).toBe("alive");
|
||||
expect(result.statusDetail).toBe("unreachable (0/3 received)");
|
||||
expect(result.observation).toMatchObject({ alive: false, received: 0, transmitted: 3 });
|
||||
});
|
||||
|
||||
test("反向 alive 断言通过", async () => {
|
||||
@@ -81,7 +87,7 @@ rtt min/avg/max/mdev = 1.234/156.000/340.000/0.567 ms`);
|
||||
const result = await checker.execute(makeTarget({ expect: { packetLossPercent: { lte: 10 } } }), makeCtx());
|
||||
expect(result.matched).toBe(false);
|
||||
expect(result.failure?.phase).toBe("packetLoss");
|
||||
expect(result.statusDetail).toContain("max 340ms");
|
||||
expect(result.observation).toMatchObject({ alive: true, maxLatencyMs: 340 });
|
||||
});
|
||||
|
||||
test("解析失败返回结构化错误", async () => {
|
||||
@@ -98,7 +104,7 @@ rtt min/avg/max/mdev = 1.234/156.000/340.000/0.567 ms`);
|
||||
const result = await checker.execute(makeTarget(), makeCtx());
|
||||
expect(result.matched).toBe(false);
|
||||
expect(result.failure?.message).toContain("ping 命令不可用");
|
||||
expect(result.statusDetail).toBe("ping command not found");
|
||||
expect(result.observation).toBeNull();
|
||||
});
|
||||
|
||||
test("预 abort 返回超时错误", async () => {
|
||||
|
||||
Reference in New Issue
Block a user