1
0

refactor: expect 类型模型重构,Raw/Resolved 双层分离与断言基础设施内聚

- 重命名 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)
This commit is contained in:
2026-05-20 16:12:48 +08:00
parent 6098be2d9e
commit 60a54b483f
90 changed files with 2487 additions and 1493 deletions

View File

@@ -214,7 +214,7 @@ describe("LlmChecker validate", () => {
defaults: {},
targets: [makeRawTarget({ expect: { output: [{ contains: "y", json: { path: "$.status" } }] } })],
});
expect(issues.some((i) => i.code === "invalid-content-rule")).toBe(true);
expect(issues.some((i) => i.code === "invalid-content-expectation")).toBe(true);
});
test("expect.output regex ReDoS 报错", () => {
@@ -284,6 +284,44 @@ describe("LlmChecker resolve", () => {
expect(resolved.group).toBe("default");
expect(resolved.intervalMs).toBe(30000);
expect(resolved.timeoutMs).toBe(10000);
expect(resolved.rawExpect).toBeUndefined();
expect(resolved.expect).toEqual({ status: [200] });
});
test("stream mode 未配置 expect.stream 时不物化 completed", () => {
const raw = makeRawTarget({
expect: { output: [{ contains: "OK" }] },
llm: {
mode: "stream",
model: "gpt-4o-mini",
prompt: "Say OK",
provider: "openai",
url: "https://api.openai.com/v1",
},
});
const resolved = asLlm(checker.resolve(raw, makeResolveContext()));
expect(resolved.rawExpect).toEqual({ output: [{ contains: "OK" }] });
expect(resolved.expect?.stream).toBeUndefined();
});
test("配置 expect.stream 但省略 completed 时默认 true", () => {
const raw = makeRawTarget({
expect: { stream: { firstTokenMs: 100 } },
llm: {
mode: "stream",
model: "gpt-4o-mini",
prompt: "Say OK",
provider: "openai",
url: "https://api.openai.com/v1",
},
});
const resolved = asLlm(checker.resolve(raw, makeResolveContext()));
expect(resolved.rawExpect).toEqual({ stream: { firstTokenMs: 100 } });
expect(resolved.expect?.stream).toEqual({ completed: true, firstTokenMs: { equals: 100 } });
});
test("defaults.llm 与 target.llm 浅合并", () => {