refactor: 将 checker normalize 职责下沉到各 runner 目录
- 新增 CheckerDefinition.normalize 必需方法,typecheck 兜底遗漏实现 - 新增 expect/normalize.ts 共享 helper(compactExpect、normalizeValue、 normalizeContent、normalizeKeyed) - 为 HTTP、Cmd、DB、TCP、UDP、ICMP、LLM、WS、DNS 各新增独立 normalize.ts - 简化 normalizer.ts:删除所有 checker type switch,改为 registry 委托 - 修复 DNS authoring 简写 bug:durationMs、valueCount、result 等字段 现可通过完整加载链路 - 新增 DNS 回归测试和 registry 级合同测试 - 更新 docs/development/checker.md:补充 normalize 规范、文件结构、 测试要求和 checklist
This commit is contained in:
87
tests/server/checker/runner/dns/normalize.test.ts
Normal file
87
tests/server/checker/runner/dns/normalize.test.ts
Normal file
@@ -0,0 +1,87 @@
|
||||
import { describe, expect, test } from "bun:test";
|
||||
|
||||
import { normalizeAuthoringConfig } from "../../../../../src/server/checker/normalizer";
|
||||
import { checkerRegistry } from "../../../../../src/server/checker/runner";
|
||||
import { validateProbeConfigContract } from "../../../../../src/server/checker/schema/validate";
|
||||
|
||||
describe("DNS normalize", () => {
|
||||
test("ValueMatcher 简写被展开", () => {
|
||||
const result = normalizeAuthoringConfig(
|
||||
{
|
||||
targets: [
|
||||
{
|
||||
dns: { name: "example.com", resolver: "server", server: "8.8.8.8" },
|
||||
expect: { durationMs: 1000, valueCount: { gte: 1 } },
|
||||
id: "dns-test",
|
||||
type: "dns",
|
||||
},
|
||||
],
|
||||
},
|
||||
checkerRegistry,
|
||||
);
|
||||
expect(result.issues).toHaveLength(0);
|
||||
const target = (result.config as { targets: Array<{ expect: Record<string, unknown> }> }).targets[0]!;
|
||||
expect(target.expect["durationMs"]).toEqual({ equals: 1000 });
|
||||
expect(target.expect["valueCount"]).toEqual({ gte: 1 });
|
||||
});
|
||||
|
||||
test("ContentExpectations 简写被展开", () => {
|
||||
const result = normalizeAuthoringConfig(
|
||||
{
|
||||
targets: [
|
||||
{
|
||||
dns: { name: "example.com", resolver: "server", server: "8.8.8.8" },
|
||||
expect: { result: [{ contains: "NOERROR" }] },
|
||||
id: "dns-test",
|
||||
type: "dns",
|
||||
},
|
||||
],
|
||||
},
|
||||
checkerRegistry,
|
||||
);
|
||||
expect(result.issues).toHaveLength(0);
|
||||
const target = (result.config as { targets: Array<{ expect: Record<string, unknown> }> }).targets[0]!;
|
||||
const resultExpect = target.expect["result"] as Array<Record<string, unknown>>;
|
||||
expect(resultExpect[0]!["kind"]).toBe("value");
|
||||
expect((resultExpect[0]!["matcher"] as Record<string, unknown>)["contains"]).toBe("NOERROR");
|
||||
});
|
||||
|
||||
test("DNS authoring 简写经 normalize 后通过 normalized contract 校验", () => {
|
||||
const result = normalizeAuthoringConfig(
|
||||
{
|
||||
targets: [
|
||||
{
|
||||
dns: { name: "example.com", resolver: "server", server: "8.8.8.8" },
|
||||
expect: { durationMs: 1000, result: [{ contains: "NOERROR" }], valueCount: { gte: 1 } },
|
||||
id: "dns-test",
|
||||
type: "dns",
|
||||
},
|
||||
],
|
||||
},
|
||||
checkerRegistry,
|
||||
);
|
||||
expect(result.issues).toHaveLength(0);
|
||||
const contract = validateProbeConfigContract(result.config, checkerRegistry);
|
||||
expect(contract.config).not.toBeNull();
|
||||
expect(contract.issues).toHaveLength(0);
|
||||
});
|
||||
|
||||
test("DNS system 模式 ValueMatcher 简写被展开", () => {
|
||||
const result = normalizeAuthoringConfig(
|
||||
{
|
||||
targets: [
|
||||
{
|
||||
dns: { name: "example.com", resolver: "system" },
|
||||
expect: { durationMs: 500, valueCount: { gte: 1 } },
|
||||
id: "dns-system-test",
|
||||
type: "dns",
|
||||
},
|
||||
],
|
||||
},
|
||||
checkerRegistry,
|
||||
);
|
||||
expect(result.issues).toHaveLength(0);
|
||||
const target = (result.config as { targets: Array<{ expect: Record<string, unknown> }> }).targets[0]!;
|
||||
expect(target.expect["durationMs"]).toEqual({ equals: 500 });
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user