Files
OmniRoute/tests/unit/imagetotext-derivation.test.ts
Diego Rodrigues de Sa e Souza fa0b0effbe feat(providers): derive imageToText from the OCR registry + chutes dots.ocr seed (#10400)
* feat(ocr): transformation layer on ocrRegistry (Mistral shape canonical)

* feat(ocr): Azure Document Intelligence provider (prebuilt-read, analyze+poll)

* feat(ocr): generic dispatch with per-provider transformation and DI poll loop

* test(ocr): align sanitized-500 assert with HR#12 error sanitization

The test's own title ("returns a sanitized 500") describes the new
behavior mandated by HR#12 (never leak err.message in a response body).
The old regex asserted the pre-sanitization leak (`OCR request failed:
socket closed`) as expected output, which contradicted its own title
and the sanitization this task intentionally introduced in
open-sse/handlers/ocr.ts. Scoped to this single assertion only.

* fix(ocr): fail fast on non-ok poll responses instead of misleading 504

pollOcrOperation now checks pollRes.ok and returns a sanitized 502
immediately (logging the upstream status via console.error) instead of
looping until the 30-attempt cap and surfacing a misleading timeout for
what was actually an auth/upstream error during polling.

* feat(ocr): route/docs for multi-provider /v1/ocr

- Route: map the connection's providerSpecificData.baseUrl onto
  credentials.baseUrl (resolveOcrCredentials) so azure-document-intelligence
  connections resolve their endpoint the same way every other custom-endpoint
  provider does (src/lib/providers/validation/*); previously handleOcr only
  saw a baseUrl when a caller set it directly, so the DB-backed Azure
  connection endpoint was never forwarded.
- v1OcrSchema.model is already a free-form string, no schema change needed.
- Docs: add the /v1/ocr provider table + example + Azure poll-flow note to
  API_REFERENCE.md, and describe the provider/model prefix + async poll
  behavior in openapi.yaml.
- Test: tests/unit/ocr-route-contract.test.ts covers getAllOcrModels/
  parseOcrModel for both providers and resolveOcrCredentials's mapping.

* feat(providers): derive imageToText serviceKind from the OCR registry

* feat(providers): chutes imageToText (dots.ocr seed)

* chore(quality): rebaseline gateways.ts file-size for imageToText serviceKinds

Same rebaseline as #10275 (frozen 1250 -> 1252): this branch adds the chutes
serviceKinds declaration, the second of the two data lines.

* chore(quality): rebaseline deadExports for the OCR/image-to-text series

---------

Co-authored-by: Xiangzhe <bakryun0718@proton.me>
2026-08-14 14:26:08 -03:00

22 lines
965 B
TypeScript

import { test } from "node:test";
import assert from "node:assert/strict";
import { resolveProviderServiceKinds } from "../../open-sse/config/mediaServiceKinds.ts";
import { AI_PROVIDERS } from "../../src/shared/constants/providers.ts";
test("OCR-registry providers derive imageToText without manual declaration", () => {
assert.ok(resolveProviderServiceKinds("mistral", undefined).includes("imageToText"));
assert.ok(
resolveProviderServiceKinds("azure-document-intelligence", undefined).includes("imageToText")
);
});
test("non-OCR providers do not gain imageToText implicitly", () => {
assert.ok(!resolveProviderServiceKinds("groq", undefined).includes("imageToText"));
});
test("chutes declares llm + imageToText (dots.ocr seed, served via passthrough discovery)", () => {
const kinds = resolveProviderServiceKinds("chutes", AI_PROVIDERS.chutes.serviceKinds);
assert.ok(kinds.includes("imageToText"));
assert.ok(kinds.includes("llm"));
});