// SPDX-License-Identifier: LicenseRef-ConusAI-Template-1.0 // Deterministic local platform fixture for the generated Convex app smoke. It runs on the host // gateway so Convex's Node action can call it, while the smoke itself uses loopback. import { readFile } from "node:fs/promises" import { startFakePlatform } from "@conusai-kit/testing/fake-platform" const port = Number(process.argv[2]) if (!Number.isInteger(port) || port < 1 || port > 65_535) throw new Error("a test platform port is required") const fixture = JSON.parse( await readFile(new URL("../../../modules/documents/__tests__/fixtures/ocr-document.json", import.meta.url), "utf8"), ) const platform = await startFakePlatform(port, { host: "0.0.0.0" }) platform.ocr.setDocument(fixture) platform.ai.respond(() => ({ content: JSON.stringify({ lines: [{ label: "Reference", value: "QR-2026-04", quote: "Reference: QR-2026-04" }], }), })) console.log("local fake platform ready") const stop = async () => { await platform.close() process.exit(0) } process.once("SIGINT", () => void stop()) process.once("SIGTERM", () => void stop())