rag-service/tests/ocr/help-workflow.test.ts

41 lines
2.5 KiB
TypeScript

import assert from "node:assert/strict";
import test from "node:test";
import { createApp } from "../../src/app.js";
import { buildApiHelp, openApiDocument } from "../../src/api/openapi.js";
test("served help workflow references real OpenAPI operations and their authentication", async () => {
const server = createApp({ catalog: undefined, startReconciler: false }).listen(0);
try {
const address = server.address();
assert.ok(address && typeof address === "object");
const base = `http://127.0.0.1:${address.port}`;
const helpResponse = await fetch(`${base}/help`);
assert.equal(helpResponse.status, 200);
const help = await helpResponse.json() as ReturnType<typeof buildApiHelp>;
const apiResponse = await fetch(`${base}/openapi.json`);
assert.equal(apiResponse.status, 200);
const api = await apiResponse.json() as {
paths: Record<string, Record<string, { security?: unknown }>>;
components: { schemas: Record<string, { required?: string[]; properties?: Record<string, unknown> }> };
};
assert.deepEqual(help.ingestionWorkflow.map(({ step }) => step), [1, 2, 3, 4, 5]);
for (const step of help.ingestionWorkflow) {
assert.ok(step.input && step.expected && step.next && step.responsibility);
for (const operation of step.operations) {
const definition = api.paths[operation.path]?.[operation.method.toLowerCase()];
assert.ok(definition, `${operation.method} ${operation.path}`);
assert.equal(operation.authentication, definition.security ? "Bearer lifecycle admin token" : "Public");
}
}
for (const mode of help.queryModes) assert.ok(api.paths[mode.path]?.post);
const required = api.components.schemas.RetrieveRequest!.required!;
for (const field of required) assert.ok(field in help.retrieveExample);
const properties = api.components.schemas.RetrieveRequest!.properties!;
for (const field of Object.keys(help.retrieveExample)) assert.ok(field in properties);
assert.equal(help.retrieveExample.useModelInRetrieve, false);
assert.match(help.ingestionWorkflow[2]!.next, /skipped for native/u);
assert.match(help.ingestionWorkflow[3]!.expected, /not automatically reset/u);
assert.match(help.queryModes[2]!.output, /only when additional retrieval/u);
assert.deepEqual(api.components.schemas.OcrDecisionResponse, openApiDocument.components.schemas.OcrDecisionResponse);
} finally { await new Promise<void>((resolve) => server.close(() => resolve())); }
});