1
0
Files
DiAL/src/server/checker/normalizer.ts
lanyuanxiaoyao 77c6015b3a 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
2026-05-25 16:16:41 +08:00

43 lines
1.4 KiB
TypeScript

import { isPlainObject } from "es-toolkit";
import type { CheckerRegistry } from "./runner/registry";
import type { ConfigValidationIssue } from "./schema/issues";
import type { AuthoringProbeConfig, NormalizedProbeConfig } from "./schema/types";
import type { RawTargetConfig } from "./types";
import { checkerRegistry } from "./runner";
import { resolveVariables } from "./variables";
export function normalizeAuthoringConfig(
config: unknown,
registry: CheckerRegistry = checkerRegistry,
): {
config: unknown;
issues: ConfigValidationIssue[];
} {
const variableResult = resolveVariables(config);
if (!isPlainObject(variableResult.config)) {
return variableResult;
}
const normalized = { ...(variableResult.config as Record<string, unknown>) };
delete normalized["variables"];
if (Array.isArray(normalized["targets"])) {
normalized["targets"] = normalized["targets"].map((target) => normalizeTarget(target, registry));
}
return { config: normalized, issues: variableResult.issues };
}
function normalizeTarget(target: unknown, registry: CheckerRegistry): unknown {
if (!isPlainObject(target)) return target;
const result = { ...(target as RawTargetConfig) };
const type = result.type;
if (typeof type !== "string") return result;
const checker = registry?.tryGet(type);
if (!checker) return result;
return checker.normalize(result);
}
export type { AuthoringProbeConfig, NormalizedProbeConfig };