- 重命名 ContentRules→ContentExpectations, KeyValueExpect→KeyedExpectations - 新增 Raw/Resolved 双层模型:resolve 阶段物化为执行计划,store 持久化 Raw 快照 - HTTP body 按需读取:status/headers 失败或无 body expectation 时不读取 body - 新增 displayValueExpectation() 解包 failure.expected 用户可读展示 - 修复 checkEarlyTimeout 独立 lte/lt 检查,修复 KeyedExpectations JSON Schema - 新增 expect/value.ts(resolve/check/display)、keyed.ts、content.ts、headers.ts、status.ts - 删除旧 normalize.ts/matcher.ts/validate-matcher.ts/key-value.ts - 更新 DEVELOPMENT.md:expect 五层管线表、displayValueExpectation、1.7↔1.10 交叉引用 - 同步 13 个 main specs,归档 refactor-expect-type-model 变更(62/62 tasks)
58 lines
2.0 KiB
TypeScript
58 lines
2.0 KiB
TypeScript
import { describe, expect, test } from "bun:test";
|
|
|
|
import type { RawContentExpectations } from "../../../../../src/server/checker/expect/types";
|
|
|
|
import { checkContentExpectations, resolveContentExpectations } from "../../../../../src/server/checker/expect/content";
|
|
|
|
function checkTextRules(text: string, rawRules: RawContentExpectations, phase: string) {
|
|
const resolved = resolveContentExpectations(rawRules);
|
|
return checkContentExpectations(text, resolved, { path: phase, phase });
|
|
}
|
|
|
|
describe("checkTextRules", () => {
|
|
test("无规则返回匹配成功", () => {
|
|
const r = checkTextRules("hello", [], "stdout");
|
|
expect(r.matched).toBe(true);
|
|
expect(r.failure).toBeNull();
|
|
});
|
|
|
|
test("单条 contains 规则匹配成功", () => {
|
|
const r = checkTextRules("build completed successfully", [{ contains: "completed" }], "stdout");
|
|
expect(r.matched).toBe(true);
|
|
});
|
|
|
|
test("单条 contains 规则匹配失败", () => {
|
|
const r = checkTextRules("build completed successfully", [{ contains: "failed" }], "stdout");
|
|
expect(r.matched).toBe(false);
|
|
expect(r.failure!.phase).toBe("stdout");
|
|
expect(r.failure!.path).toBe("stdout[0]");
|
|
});
|
|
|
|
test("多条规则全部通过", () => {
|
|
const r = checkTextRules(
|
|
"version: 3.2.1, build: ok",
|
|
[{ contains: "version" }, { regex: "\\d+\\.\\d+\\.\\d+" }],
|
|
"stdout",
|
|
);
|
|
expect(r.matched).toBe(true);
|
|
});
|
|
|
|
test("第一条规则失败立即返回", () => {
|
|
const r = checkTextRules("error occurred", [{ contains: "success" }, { contains: "error" }], "stdout");
|
|
expect(r.matched).toBe(false);
|
|
expect(r.failure!.phase).toBe("stdout");
|
|
expect(r.failure!.path).toBe("stdout[0]");
|
|
});
|
|
|
|
test("stderr phase", () => {
|
|
const r = checkTextRules("warning: deprecated", [{ contains: "warning" }], "stderr");
|
|
expect(r.matched).toBe(true);
|
|
expect(r.failure).toBeNull();
|
|
});
|
|
|
|
test("empty 操作符", () => {
|
|
const r = checkTextRules("", [{ empty: true }], "stderr");
|
|
expect(r.matched).toBe(true);
|
|
});
|
|
});
|