Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01Cxwgnn2pbzQ7rXv3rq7fei
62 lines
3.4 KiB
TypeScript
62 lines
3.4 KiB
TypeScript
import { describe, expect, it } from "vitest";
|
|
import { looksLikeCode, matchGapText, matchGapTexts, reasonSentence, reasonText } from "../src/reasons.ts";
|
|
|
|
describe("reasonText(DEAI-2 原因码人话化)", () => {
|
|
it("裸码、blocked:多码、带后缀的码都能翻译", () => {
|
|
expect(reasonText("identity_unknown")).toEqual({ text: "没识别出作品", action: "指定作品后重新整理" });
|
|
expect(reasonText("blocked:target_exists")?.text).toBe("媒体库里已有同名文件");
|
|
expect(reasonText("blocked:target_exists,hnr_unknown")?.text).toBe("媒体库里已有同名文件;不确定做种要求是否满足");
|
|
expect(reasonText("move_downgraded_to_copy:hnr_unknown")?.text).toBe("做种未完成,已改为复制");
|
|
expect(reasonText("below_min_size")?.text).toContain("最小体积");
|
|
});
|
|
|
|
it("下载面板用到的码(DL-2b):整理失败、冲突、下载被删", () => {
|
|
expect(reasonSentence("transfer_failed")).toBe("文件没有整理成功。在整理记录里查看失败的文件");
|
|
expect(reasonSentence("blocked")).toBe("有冲突要先处理。去待处理");
|
|
expect(reasonText("download_removed")?.text).toBe("下载任务已从下载器删除");
|
|
expect(reasonText("target_root_not_managed")?.text).toContain("本工具管理");
|
|
for (const c of ["blocked_by_conflict", "main_failed", "not_imported_kind"]) expect(reasonText(c)).not.toBeNull();
|
|
});
|
|
|
|
it("智能体汇报里的码(FIX-7):能力错误、带分类前缀的空间判定、站点登录", () => {
|
|
expect(reasonText("invalid_input")?.text).toBe("参数不对");
|
|
expect(reasonText("cache:volume_state_unknown")?.text).toBe("下载目录读不到容量");
|
|
expect(reasonText("deferred:no_downloader_instance")?.text).toBe("没有可用的下载器");
|
|
expect(reasonText("auth_missing")?.text).toContain("Cookie");
|
|
expect(reasonText("unidentifiable")?.text).toBe("没识别出作品");
|
|
expect(reasonText("cache:some_new_code")).toBeNull();
|
|
});
|
|
|
|
it("不认识的码返回 null;句子兜底不把码原样给人看", () => {
|
|
expect(reasonText("some_new_code")).toBeNull();
|
|
expect(reasonSentence("some_new_code")).toBe("处理失败");
|
|
expect(reasonSentence("磁盘已满")).toBe("磁盘已满");
|
|
expect(reasonSentence("identity_unknown")).toBe("没识别出作品。指定作品后重新整理");
|
|
});
|
|
|
|
it("looksLikeCode 只认内部码", () => {
|
|
expect(looksLikeCode("blocked:target_exists")).toBe(true);
|
|
expect(looksLikeCode("identity_unknown")).toBe(true);
|
|
expect(looksLikeCode("目标已存在")).toBe(false);
|
|
expect(looksLikeCode("Connection refused")).toBe(false);
|
|
});
|
|
});
|
|
|
|
describe("matchGapText(POLISH-1 入库版本差距)", () => {
|
|
it("带参数的码转成短句", () => {
|
|
expect(matchGapText("version_resolution:2160p")).toBe("可换成 2160p");
|
|
expect(matchGapText("version_hdr")).toBe("缺 HDR 版本");
|
|
expect(matchGapText("version_hdr:DV")).toBe("缺 DV 版本");
|
|
expect(matchGapText("version_source:REMUX")).toBe("可换成 Remux");
|
|
expect(matchGapText("version_subtitles:zh-Hans")).toBe("缺简中字幕");
|
|
expect(matchGapText("version_subtitles:chs")).toBe("缺 chs 字幕");
|
|
});
|
|
|
|
it("不认识的码返回 null;列表去重", () => {
|
|
expect(matchGapText("nope")).toBeNull();
|
|
expect(matchGapTexts(["version_resolution:2160p", "version_resolution_upgrade:2160p", "nope"])).toEqual([
|
|
"可换成 2160p",
|
|
]);
|
|
});
|
|
});
|