60 lines
2.2 KiB
TypeScript
60 lines
2.2 KiB
TypeScript
import { existsSync } from "node:fs";
|
|
import { describe, expect, it } from "vitest";
|
|
import { getHandler } from "../../src/engine/registry";
|
|
import type { CatalogComponent, FlowNode } from "../../src/types";
|
|
import type { RunContext } from "../../src/engine/types";
|
|
import "../../src/capabilities/vision";
|
|
import "../../src/capabilities/remaining-core";
|
|
|
|
const ctx = {
|
|
signal: new AbortController().signal,
|
|
log: () => {},
|
|
vars: {},
|
|
evidenceDir: "D:/office-test2/ocr-test"
|
|
} as unknown as RunContext;
|
|
|
|
const node = { id: "smoke-rp", componentId: "Image_RelativePosition", position: { x: 0, y: 0 }, values: {}, options: {} };
|
|
const relativePositionFixtures = [
|
|
"D:/office-test2/ocr-test/general.png",
|
|
"D:/office-test2/ocr-test/order-template.png",
|
|
];
|
|
const relativePositionFixturesReady = relativePositionFixtures.every((file) => existsSync(file));
|
|
|
|
describe.skipIf(!relativePositionFixturesReady)("对比图像相对位置冒烟", () => {
|
|
it("小图在大图中命中并返回坐标", async () => {
|
|
const handler = getHandler("Image_RelativePosition");
|
|
expect(handler).toBeTruthy();
|
|
const out = await handler!(
|
|
ctx,
|
|
node,
|
|
{
|
|
source: "D:/office-test2/ocr-test/general.png",
|
|
template: "D:/office-test2/ocr-test/order-template.png"
|
|
},
|
|
{} as CatalogComponent
|
|
);
|
|
console.log("[RelativePosition 正向]", JSON.stringify(out));
|
|
const hit = out as { x: number; y: number; width: number; height: number; score: number };
|
|
expect(hit.x).toBeGreaterThanOrEqual(0);
|
|
expect(hit.y).toBeGreaterThan(0);
|
|
expect(hit.score).toBeGreaterThan(0.9);
|
|
}, 120000);
|
|
|
|
it("填反(大图填进查找目标)自动互换后仍命中", async () => {
|
|
const logs: string[] = [];
|
|
const ctxWithLog = { ...ctx, log: (m: string) => logs.push(m) } as unknown as RunContext;
|
|
const handler = getHandler("Image_RelativePosition")!;
|
|
const out = await handler!(
|
|
ctxWithLog,
|
|
node,
|
|
{
|
|
source: "D:/office-test2/ocr-test/order-template.png",
|
|
template: "D:/office-test2/ocr-test/general.png"
|
|
},
|
|
{} as CatalogComponent
|
|
);
|
|
console.log("[RelativePosition 互换]", JSON.stringify(out), "logs:", logs.join(" | "));
|
|
expect(out).toBeTruthy();
|
|
}, 120000);
|
|
});
|