From 7a067173a5456f33e56bd414d036bed1d1c54b4b Mon Sep 17 00:00:00 2001 From: yu <191972707@qq.com> Date: Tue, 3 Nov 2026 14:50:23 +0800 Subject: [PATCH] =?UTF-8?q?test:=20OCR=E7=BB=84=E4=BB=B6=E5=86=92=E7=83=9F?= =?UTF-8?q?=E5=9B=9E=E5=BD=92(=E6=9C=AC=E5=9C=B0=E7=A6=BB=E7=BA=BF?= =?UTF-8?q?=E6=8E=A8=E7=90=86):=20=E9=80=9A=E7=94=A8/=E9=94=AE=E5=80=BC/?= =?UTF-8?q?=E9=87=91=E9=A2=9D/=E9=AA=8C=E8=AF=81=E7=A0=81/=E5=8D=A1?= =?UTF-8?q?=E8=AF=81/=E7=A5=A8=E6=8D=AE/=E7=A6=BB=E7=BA=BF=E6=96=87?= =?UTF-8?q?=E6=9C=AC=E5=AE=9A=E4=BD=8D=E8=A1=A8=E6=A0=BC=2010=E9=A1=B9?= =?UTF-8?q?=E7=9C=9F=E5=AE=9E=E8=AF=86=E5=88=AB=E9=80=9A=E8=BF=87?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/capabilities/ocr-smoke.test.ts | 87 +++++++++++++++++++++++++ 1 file changed, 87 insertions(+) create mode 100644 src/main/capabilities/ocr-smoke.test.ts diff --git a/src/main/capabilities/ocr-smoke.test.ts b/src/main/capabilities/ocr-smoke.test.ts new file mode 100644 index 0000000..aead65d --- /dev/null +++ b/src/main/capabilities/ocr-smoke.test.ts @@ -0,0 +1,87 @@ +import { describe, expect, it } from "vitest"; +import { getHandler } from "../engine/registry"; +import type { CatalogComponent, RunContext } from "../engine/types"; +import "./ocr-caps"; +import "./remaining-core"; + +const ctx = { + signal: new AbortController().signal, + log: () => {}, + vars: {}, + evidenceDir: "D:/office-test2/ocr-test" +} as unknown as RunContext; + +const node = { id: "smoke", componentId: "smoke" }; + +async function runOcr(id: string, args: Record) { + const handler = getHandler(id); + expect(handler, `${id} 应已注册`).toBeTruthy(); + return handler!(ctx, node, args, {} as CatalogComponent); +} + +describe("OCR 组件冒烟(本地离线识别,真实模型推理)", () => { + it("OCR_GeneralTextV2 通用文本", async () => { + const out = await runOcr("OCR_GeneralTextV2", { path: "D:/office-test2/ocr-test/general.png" }); + console.log("[GeneralTextV2]", JSON.stringify(out)); + expect(String(out)).toContain("张三"); + }, 300000); + + it("OCR_KeyValueIdentification 键值对", async () => { + const out = await runOcr("OCR_KeyValueIdentification", { image_path: "D:/office-test2/ocr-test/general.png" }); + console.log("[KeyValue]", JSON.stringify(out)); + expect(String(out).length).toBeGreaterThan(0); + }, 300000); + + it("OCR_AmountIdentification 金额", async () => { + const out = await runOcr("OCR_AmountIdentification", { path: "D:/office-test2/ocr-test/general.png" }); + console.log("[Amount]", JSON.stringify(out)); + expect(String(out).length).toBeGreaterThan(0); + }, 300000); + + it("OCR_CalculationCode 算术验证码", async () => { + const out = await runOcr("OCR_CalculationCode", { path: "D:/office-test2/ocr-test/code.png" }); + console.log("[CalcCode]", JSON.stringify(out)); + expect(String(out).length).toBeGreaterThan(0); + }, 300000); + + it("OCR_CommonEnglishNumbersCode 普通验证码", async () => { + const out = await runOcr("OCR_CommonEnglishNumbersCode", { path: "D:/office-test2/ocr-test/code.png" }); + console.log("[CommonCode]", JSON.stringify(out)); + expect(String(out).length).toBeGreaterThan(0); + }, 300000); + + it("OCR_IdCardV2 卡证族代表", async () => { + const out = await runOcr("OCR_IdCardV2", { path: "D:/office-test2/ocr-test/general.png" }); + console.log("[IdCardV2]", JSON.stringify(out)); + expect(String(out).length).toBeGreaterThan(0); + }, 300000); + + it("OCR_VatInvoiceV2 票据族代表", async () => { + const out = await runOcr("OCR_VatInvoiceV2", { path: "D:/office-test2/ocr-test/table.png" }); + console.log("[VatInvoiceV2]", JSON.stringify(out)); + expect(String(out).length).toBeGreaterThan(0); + }, 300000); + + it("OcrOffline_GetOcrTextNew 离线文本", async () => { + const out = await runOcr("OcrOffline_GetOcrTextNew", { uiSelector: "D:/office-test2/ocr-test/general.png" }); + console.log("[OcrTextNew]", JSON.stringify(out)); + expect(String(out)).toContain("订单号"); + }, 300000); + + it("OcrOffline_GetOcrTextPosition 离线定位", async () => { + const out = await runOcr("OcrOffline_GetOcrTextPosition", { image_path: "D:/office-test2/ocr-test/general.png" }); + const words = out as Array<{ text: string; x: number; y: number }>; + console.log("[OcrPosition]", JSON.stringify(words?.slice(0, 3))); + expect(Array.isArray(words)).toBe(true); + expect(words.length).toBeGreaterThan(0); + expect(words[0]).toHaveProperty("x"); + }, 300000); + + it("OcrOffline_GetOcrTable 离线表格", async () => { + const out = await runOcr("OcrOffline_GetOcrTable", { image_path: "D:/office-test2/ocr-test/table.png", showTable: "1", isExcel: "0" }); + const rows = out as string[][]; + console.log("[OcrTable]", JSON.stringify(rows)); + expect(Array.isArray(rows)).toBe(true); + expect(rows.length).toBeGreaterThan(0); + }, 300000); +});