import { describe, expect, it } from "vitest"; import { LocalHeuristicOcrProvider, sanitizeOcrDisplayText, } from "@/services/ocr"; describe("LocalHeuristicOcrProvider", () => { it("extracts CJK from buffer", async () => { const buf = Buffer.from("前置 卡转海 覆盖贴 后缀", "utf8"); const r = await new LocalHeuristicOcrProvider().recognize(buf); expect(r.text).toMatch(/卡转海|覆盖贴/); expect(r.provider).toBe("local"); }); it("does not treat PDF binary noise as Chinese", async () => { const junk = Buffer.from("%PDF-1.4\n" + "4稍擁咥\n涅樺\n膽蟈籃\n", "utf8"); const r = await new LocalHeuristicOcrProvider().recognize(junk, "application/pdf"); expect(r.text).not.toMatch(/稍擁|涅樺|膽蟈/); }); }); describe("sanitizeOcrDisplayText", () => { it("strips 【OCR:file】 wrappers and garbage lines", () => { const raw = [ "【OCR:WL103276-SBD1(1).pdf】", "4稍擁咥", "【OCR:WL103944-WL103940.pdf】", "请查收新增预报 柜号 ABCD1234567", ].join("\n"); const out = sanitizeOcrDisplayText(raw); expect(out).not.toMatch(/【OCR:/); expect(out).not.toMatch(/稍擁咥/); expect(out).toMatch(/请查收新增预报/); }); });