- 重命名 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)
66 lines
2.3 KiB
TypeScript
66 lines
2.3 KiB
TypeScript
import { describe, expect, test } from "bun:test";
|
|
|
|
import type { CheckerValidationInput } from "../../../../../src/server/checker/runner/types";
|
|
|
|
import { validateDbConfig } from "../../../../../src/server/checker/runner/db/validate";
|
|
import { validateHttpConfig } from "../../../../../src/server/checker/runner/http/validate";
|
|
import { validateLlmConfig } from "../../../../../src/server/checker/runner/llm/validate";
|
|
|
|
function input(target: Record<string, unknown>): CheckerValidationInput {
|
|
return { defaults: {}, targets: [target as CheckerValidationInput["targets"][number]] };
|
|
}
|
|
|
|
describe("HTTP/LLM headers reject case-insensitive duplicate keys", () => {
|
|
test("HTTP headers 大小写不同的重复 key 报错", () => {
|
|
const target = {
|
|
expect: { headers: { "Content-Type": "application/json", "content-type": "text/plain" } },
|
|
http: { url: "https://example.com" },
|
|
id: "dup",
|
|
type: "http",
|
|
};
|
|
|
|
const issues = validateHttpConfig(input(target));
|
|
expect(issues.some((i) => i.code === "duplicate-key" && i.path.includes("headers"))).toBe(true);
|
|
});
|
|
|
|
test("LLM headers 大小写不同的重复 key 报错", () => {
|
|
const target = {
|
|
expect: { headers: { "X-Trace": "a", "x-trace": "b" } },
|
|
id: "dup",
|
|
llm: {
|
|
mode: "stream",
|
|
model: "test-model",
|
|
prompt: "hello",
|
|
provider: "openai",
|
|
url: "https://example.com/v1/chat/completions",
|
|
},
|
|
type: "llm",
|
|
};
|
|
|
|
const issues = validateLlmConfig(input(target));
|
|
expect(issues.some((i) => i.code === "duplicate-key" && i.path.includes("headers"))).toBe(true);
|
|
});
|
|
|
|
test("HTTP headers 不同 key 不触发 duplicate-key", () => {
|
|
const target = {
|
|
expect: { headers: { Accept: "application/json", "Content-Type": "application/json" } },
|
|
http: { url: "https://example.com" },
|
|
id: "ok",
|
|
type: "http",
|
|
};
|
|
|
|
expect(validateHttpConfig(input(target)).some((i) => i.code === "duplicate-key")).toBe(false);
|
|
});
|
|
|
|
test("DB rows 保留大小写敏感不触发 duplicate-key", () => {
|
|
const target = {
|
|
db: { query: "SELECT 1", url: "sqlite://:memory:" },
|
|
expect: { rows: [{ Name: "a", name: "b" }] },
|
|
id: "dup-rows",
|
|
type: "db",
|
|
};
|
|
|
|
expect(validateDbConfig(input(target)).some((i) => i.code === "duplicate-key")).toBe(false);
|
|
});
|
|
});
|