refactor: checker 模块内聚化 — 每个 checker 自包含于独立目录
将 checker 架构重构为完全内聚模式:每个 checker 目录包含自身的 types、schema、validate、execute、expect 和 index,新增 checker 只需创建一个目录并在 runner/index.ts 添加一行注册。 主要变更: - runner/shared/ 拆分:断言基础设施迁入 checker/expect/, body.ts 迁入 http/,text.ts 迁入 command/ - config-contract/ 重命名为 schema/,schema.ts → builder.ts - size.ts + parseDuration 合并为 utils.ts - 顶层 types.ts 改为 base interface + index signature, checker 专属类型下沉到各自 types.ts - runner/index.ts 改为显式数组注册模式 - 更新 DEVELOPMENT.md 项目结构和开发新 Checker 指南
This commit is contained in:
34
src/server/checker/expect/failure.ts
Normal file
34
src/server/checker/expect/failure.ts
Normal file
@@ -0,0 +1,34 @@
|
||||
import type { CheckFailure } from "../types";
|
||||
|
||||
export function errorFailure(phase: CheckFailure["phase"], path: string, message: string): CheckFailure {
|
||||
return {
|
||||
kind: "error",
|
||||
message,
|
||||
path,
|
||||
phase,
|
||||
};
|
||||
}
|
||||
|
||||
export function mismatchFailure(
|
||||
phase: CheckFailure["phase"],
|
||||
path: string,
|
||||
expected: unknown,
|
||||
actual: unknown,
|
||||
message: string,
|
||||
): CheckFailure {
|
||||
return {
|
||||
actual: truncateActual(actual),
|
||||
expected,
|
||||
kind: "mismatch",
|
||||
message,
|
||||
path,
|
||||
phase,
|
||||
};
|
||||
}
|
||||
|
||||
export function truncateActual(value: unknown, maxLen = 200): unknown {
|
||||
if (value === undefined || value === null) return value;
|
||||
const str = typeof value === "string" ? value : JSON.stringify(value);
|
||||
if (str.length <= maxLen) return value;
|
||||
return str.slice(0, maxLen) + "...";
|
||||
}
|
||||
Reference in New Issue
Block a user