1
0
Files
DiAL/src/server/checker/expect/failure.ts
lanyuanxiaoyao bcfac52112 refactor: HTTP checker 质量加固
- failure actual 截断格式改为 …(共 N 字符),标量不序列化直接返回
- 新增 redos.ts 实现 ReDoS 静态检测(嵌套量词/重叠交替),启动期拒绝危险正则
- JSON body rules 共享同一次 JSON.parse 结果,避免重复解析
- checkCssRule 重构为线性流程,消除 exist:true 与无 operator 的冗余分支
- extract checkEarlyTimeout 辅助函数,明确提前 duration 检查意图
- 补充 303/307/308 重定向、相对路径 Location、混合 body rules 集成测试
2026-05-13 21:35:05 +08:00

37 lines
901 B
TypeScript

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 : typeof value === "object" ? JSON.stringify(value) : undefined;
if (str === undefined) return value;
if (str.length <= maxLen) return value;
return `${str.slice(0, maxLen)}…(共 ${str.length} 字符)`;
}