feat(web): 站点显示 Cloudflare 状态(CF-2)

Co-Authored-By: Claude Opus 5.5 <[email protected]>
This commit is contained in:
rootandClaude Opus 5.5 committed 2026-09-30 21:26:54 +08:00
1 parent 16083942c0
commit f16b97151b
4 files changed
+155 -3

No files matched your search

@@ -1,5 +1,5 @@
import { describe, expect, it } from "vitest";
import { healthLine, healthMessage, healthTechItems } from "./site-fields.ts";
import { cloudflareLine, cloudflareTechItems, healthLine, healthMessage, healthTechItems } from "./site-fields.ts";
describe("健康检测文案(HC-1)", () => {
it("人机验证单独成类;失败原因一句,原始判定进技术信息", () => {
@@ -24,3 +24,51 @@ describe("健康检测文案(HC-1)", () => {
expect(healthTechItems({ ok: true, status: "ok", latencyMs: 1, message: null })).toEqual([]);
});
});
describe("cloudflareLine / cloudflareTechItems(CF-2)", () => {
const now = new Date("2026-09-30T12:00:00+08:00");
const cfg = (cloudflare: Record<string, unknown>) => ({ cloudflare });
it("没遇到过挑战不显示", () => {
expect(cloudflareLine({}, now)).toBeNull();
expect(cloudflareLine(cfg({ lastSolvedBy: "auto" }), now)).toBeNull();
expect(cloudflareTechItems({})).toEqual([]);
});
it("需要你验证 > 浏览器代理中 > 自动通过", () => {
const at = "2026-09-30T11:00:00+08:00";
expect(cloudflareLine(cfg({ lastChallengeAt: at, pending: "human", lastSolvedBy: "auto" }), now)).toEqual({
text: "Cloudflare:需要你验证",
tone: "warning",
takeover: true,
});
const until = new Date("2026-09-30T17:30:00+08:00");
const line = cloudflareLine(cfg({ lastChallengeAt: at, browserUntil: until.toISOString() }), now);
const hm = `${String(until.getHours()).padStart(2, "0")}:${String(until.getMinutes()).padStart(2, "0")}`;
expect(line?.text).toBe(`Cloudflare:浏览器代理中,至 ${hm}`);
expect(cloudflareLine(cfg({ lastChallengeAt: at, lastSolvedBy: "vision" }), now)?.text).toBe(
"Cloudflare:自动通过",
);
// 代理期已过、没通过过、有错误
expect(
cloudflareLine(cfg({ lastChallengeAt: at, browserUntil: at, lastError: "浏览器服务不可用" }), now)?.text,
).toBe("Cloudflare:没能通过");
});
it("原始记录进技术信息", () => {
const items = cloudflareTechItems(
cfg({
lastChallengeAt: "2026-09-30T11:00:00+08:00",
lastRule: "header cf-mitigated=challenge",
lastResult: "reuse_fails",
lastSolvedBy: "auto",
cfReuse: "fails",
}),
);
expect(items.map((i) => i.label)).toEqual([
"最近遇到挑战",
"挑战规则",
"处理结果",
"最近通过方式",
"cf_clearance 复用",
]);
expect(items.find((i) => i.label === "处理结果")?.value).toContain("reuse_fails");
});
});