feat: 增强 HTTP checker 鲁棒性 — 严格配置校验、完整耗时、流式body、重定向与编码完善
启动期校验: 新增 validate.ts 对 HTTP config/expect/body rule/operator 全方位严格校验 执行语义: body 改为 Web Stream 流式超限中止,durationMs 覆盖完整执行 错误归属: status/header 失败不读 body,phase 分层 request/body,early duration skip body 重定向: 跟随前释放 body,POST/303 改 GET 清理 header,跨 origin 剥离敏感 header 编码: 支持 quoted charset,未知编码返回结构化解码错误 文档: README match→regex+durationMs,DEVELOPMENT 执行流程与错误归属 测试: +63 测试覆盖全部新增场景,325 pass 0 fail 规格: 同步 probe-config/probe-engine/expect-body-checkers 3 个 delta spec
This commit is contained in:
@@ -136,4 +136,42 @@ describe("checkBodyExpect (BodyRule[])", () => {
|
||||
expect(r.matched).toBe(false);
|
||||
expect(r.failure!.path).toContain("body[1]");
|
||||
});
|
||||
|
||||
test("JSON 响应不是合法 JSON 返回 error kind", () => {
|
||||
const r = checkBodyExpect("not json", [{ json: { equals: "ok", path: "$.status" } }]);
|
||||
expect(r.matched).toBe(false);
|
||||
expect(r.failure!.kind).toBe("error");
|
||||
expect(r.failure!.phase).toBe("body");
|
||||
expect(r.failure!.path).toContain("json");
|
||||
});
|
||||
|
||||
test("CSS selector 无匹配元素返回 mismatch kind", () => {
|
||||
const html = "<div>no match</div>";
|
||||
const r = checkBodyExpect(html, [{ css: { equals: "test", selector: "span.missing" } }]);
|
||||
expect(r.matched).toBe(false);
|
||||
expect(r.failure!.kind).toBe("mismatch");
|
||||
expect(r.failure!.phase).toBe("body");
|
||||
expect(r.failure!.path).toContain("css");
|
||||
});
|
||||
|
||||
test("XPath 无匹配节点返回 mismatch kind", () => {
|
||||
const xml = "<root><status>ok</status></root>";
|
||||
const r = checkBodyExpect(xml, [{ xpath: { equals: "ok", path: "/root/missing/text()" } }]);
|
||||
expect(r.matched).toBe(false);
|
||||
expect(r.failure!.kind).toBe("mismatch");
|
||||
expect(r.failure!.phase).toBe("body");
|
||||
expect(r.failure!.path).toContain("xpath");
|
||||
});
|
||||
|
||||
test("regex 规则使用 regex 字段", () => {
|
||||
const r = checkBodyExpect("status: ok", [{ regex: "^status:" }]);
|
||||
expect(r.matched).toBe(true);
|
||||
});
|
||||
|
||||
test("regex 规则失败返回 body phase", () => {
|
||||
const r = checkBodyExpect("status: error", [{ regex: "^ok$" }]);
|
||||
expect(r.matched).toBe(false);
|
||||
expect(r.failure!.phase).toBe("body");
|
||||
expect(r.failure!.path).toBe("body[0]");
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user