- engine/(registry/types/runtime/expression)物理迁入包, 解耦shared/types(域类型归包, 宿主type-only re-export) - 31个纯Node能力+27个测试迁入包; 宿主留守Electron/浏览器/AI依赖能力, index.ts经@rpa/core/capabilities拉起 - 新增createEngine()/defaultEngine: excel缓存/Excel句柄/db连接/FTP客户端/OCR实例/拟真设置挂引擎实例 - remaining-core子流程依赖改为host-bridge注入, 包内不再import宿主flows - 宿主main/index.ts启动时注入子流程源; electron-vite/vitest/tsconfig配@rpa/core源码别名 - 验证: typecheck绿, 快照909个id diff为零, 332测试过(2个桌面冒烟因会话无交互SetForegroundWindow被拒, 环境阻塞)
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 "../engine/registry";
|
|
import type { CatalogComponent, FlowNode } from "../types";
|
|
import type { RunContext } from "../engine/types";
|
|
import "./vision";
|
|
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-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);
|
|
});
|