1
0

feat: HTTP 探针增强 — ignoreSSL、精确重定向控制、状态码范围匹配、编码自动检测

This commit is contained in:
2026-05-13 00:02:04 +08:00
parent 87d946a441
commit 2fd0f206be
16 changed files with 642 additions and 22 deletions

View File

@@ -1,6 +1,6 @@
import { describe, expect, test } from "bun:test";
import { checkHttpExpect } from "../../../../../src/server/checker/runner/http/expect";
import { checkHttpExpect, checkStatus } from "../../../../../src/server/checker/runner/http/expect";
function obs(
overrides: { body?: null | string; durationMs?: number; headers?: Record<string, string>; statusCode?: number } = {},
@@ -145,3 +145,44 @@ describe("checkHttpExpect", () => {
expect(r.failure!.phase).toBe("body");
});
});
describe("checkStatus 范围匹配", () => {
test("2xx 范围匹配 200", () => {
expect(checkStatus(200, ["2xx"]).matched).toBe(true);
});
test("2xx 范围匹配 204", () => {
expect(checkStatus(204, ["2xx"]).matched).toBe(true);
});
test("2xx 范围不匹配 301", () => {
expect(checkStatus(301, ["2xx"]).matched).toBe(false);
});
test("5xx 范围匹配 503", () => {
expect(checkStatus(503, ["5xx"]).matched).toBe(true);
});
test("混合精确值与范围模式 — 精确命中", () => {
expect(checkStatus(301, ["2xx", 301]).matched).toBe(true);
});
test("混合精确值与范围模式 — 范围命中", () => {
expect(checkStatus(204, ["2xx", 301]).matched).toBe(true);
});
test("混合模式都不匹配", () => {
expect(checkStatus(404, ["2xx", 301]).matched).toBe(false);
});
test("纯精确值仍正常工作", () => {
expect(checkStatus(200, [200, 201]).matched).toBe(true);
expect(checkStatus(404, [200, 201]).matched).toBe(false);
});
test("范围匹配失败返回 phase=status 的 failure", () => {
const r = checkStatus(404, ["2xx"]);
expect(r.matched).toBe(false);
expect(r.failure!.phase).toBe("status");
});
});