2026-04-23 15:26:24 +08:00
|
|
|
import { beforeAll, describe, expect, it, vi } from "vitest";
|
|
|
|
|
|
|
|
|
|
vi.mock("./account-binder", () => ({
|
|
|
|
|
probePublishAccountSession: vi.fn(),
|
|
|
|
|
silentRefreshPublishAccountSession: vi.fn(),
|
|
|
|
|
}));
|
|
|
|
|
|
|
|
|
|
let getPlatformAdapter: typeof import("./platform-auth-adapters").getPlatformAdapter;
|
|
|
|
|
|
|
|
|
|
beforeAll(async () => {
|
|
|
|
|
({ getPlatformAdapter } = await import("./platform-auth-adapters"));
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
describe("platform auth adapters", () => {
|
|
|
|
|
it("classifies Wenxin environment abnormal messages as risk control", () => {
|
|
|
|
|
const adapter = getPlatformAdapter("wenxin");
|
|
|
|
|
|
|
|
|
|
expect(
|
|
|
|
|
adapter.classifyFailure({
|
|
|
|
|
message: "当前访问环境存在异常,请更换浏览器再尝试提问",
|
|
|
|
|
}),
|
|
|
|
|
).toBe("risk_control");
|
|
|
|
|
});
|
2026-04-26 21:57:04 +08:00
|
|
|
|
|
|
|
|
it("classifies Qiehao missing cookie as auth failure", () => {
|
|
|
|
|
const adapter = getPlatformAdapter("qiehao");
|
|
|
|
|
|
|
|
|
|
expect(
|
|
|
|
|
adapter.classifyFailure({
|
|
|
|
|
error: {
|
|
|
|
|
code: "qiehao_cookie_missing",
|
|
|
|
|
},
|
|
|
|
|
}),
|
|
|
|
|
).toBe("auth_failure");
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it("classifies Bilibili missing csrf as auth failure", () => {
|
|
|
|
|
const adapter = getPlatformAdapter("bilibili");
|
|
|
|
|
|
|
|
|
|
expect(
|
|
|
|
|
adapter.classifyFailure({
|
|
|
|
|
error: {
|
|
|
|
|
code: "bilibili_csrf_missing",
|
|
|
|
|
},
|
|
|
|
|
}),
|
|
|
|
|
).toBe("auth_failure");
|
|
|
|
|
});
|
2026-04-27 00:57:37 +08:00
|
|
|
|
|
|
|
|
it("classifies Juejin missing login as auth failure", () => {
|
|
|
|
|
const adapter = getPlatformAdapter("juejin");
|
|
|
|
|
|
|
|
|
|
expect(
|
|
|
|
|
adapter.classifyFailure({
|
|
|
|
|
error: {
|
|
|
|
|
code: "juejin_not_logged_in",
|
|
|
|
|
},
|
|
|
|
|
}),
|
|
|
|
|
).toBe("auth_failure");
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it("classifies Sohuhao missing login as auth failure", () => {
|
|
|
|
|
const adapter = getPlatformAdapter("sohuhao");
|
|
|
|
|
|
|
|
|
|
expect(
|
|
|
|
|
adapter.classifyFailure({
|
|
|
|
|
error: {
|
|
|
|
|
code: "sohuhao_not_logged_in",
|
|
|
|
|
},
|
|
|
|
|
}),
|
|
|
|
|
).toBe("auth_failure");
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it("classifies Wangyihao missing token as auth failure", () => {
|
|
|
|
|
const adapter = getPlatformAdapter("wangyihao");
|
|
|
|
|
|
|
|
|
|
expect(
|
|
|
|
|
adapter.classifyFailure({
|
|
|
|
|
error: {
|
|
|
|
|
code: "wangyihao_token_missing",
|
|
|
|
|
},
|
|
|
|
|
}),
|
|
|
|
|
).toBe("auth_failure");
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it("classifies Weixin GZH verification as challenge", () => {
|
|
|
|
|
const adapter = getPlatformAdapter("weixin_gzh");
|
|
|
|
|
|
|
|
|
|
expect(
|
|
|
|
|
adapter.classifyFailure({
|
|
|
|
|
error: {
|
|
|
|
|
code: "weixin_gzh_challenge_required",
|
|
|
|
|
},
|
|
|
|
|
}),
|
|
|
|
|
).toBe("challenge");
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it("classifies ZOL missing login as auth failure", () => {
|
|
|
|
|
const adapter = getPlatformAdapter("zol");
|
|
|
|
|
|
|
|
|
|
expect(
|
|
|
|
|
adapter.classifyFailure({
|
|
|
|
|
error: {
|
|
|
|
|
code: "zol_not_logged_in",
|
|
|
|
|
},
|
|
|
|
|
}),
|
|
|
|
|
).toBe("auth_failure");
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it("classifies Dongchedi platform verification as challenge", () => {
|
|
|
|
|
const adapter = getPlatformAdapter("dongchedi");
|
|
|
|
|
|
|
|
|
|
expect(
|
|
|
|
|
adapter.classifyFailure({
|
|
|
|
|
error: {
|
|
|
|
|
code: "dongchedi_challenge_required",
|
|
|
|
|
},
|
|
|
|
|
}),
|
|
|
|
|
).toBe("challenge");
|
|
|
|
|
});
|
2026-04-23 15:26:24 +08:00
|
|
|
});
|