fix: make OCR portable and reliable across AMD64 and ARM64 (#519)

* fix: make OCR portable and reliable

* fix: harden OCR installation portability

* fix: pin OCR partials across downloads

* fix: make OCR execution reliably asynchronous

* fix: harden OCR portability and docs routes

* fix: preserve decoder and docs safeguards
This commit is contained in:
SnapOtter
2026-07-15 03:34:24 +08:00
committed by GitHub
parent 58121f205f
commit 991c981529
409 changed files with 67151 additions and 8076 deletions
+23
View File
@@ -13,6 +13,11 @@ vi.mock("@fastify/static", () => ({ default: "fastify-static-plugin" }));
const mockMultipartPlugin = vi.fn();
vi.mock("@fastify/multipart", () => ({ default: mockMultipartPlugin }));
const multipartPartsMock = vi.hoisted(() => vi.fn());
vi.mock("../../../apps/api/src/lib/multipart-parts.js", () => ({
multipartParts: multipartPartsMock,
}));
vi.mock("node:fs", async (importOriginal) => {
const actual = (await importOriginal()) as Record<string, unknown>;
return {
@@ -170,4 +175,22 @@ describe("registerUpload", () => {
},
});
});
it("forwards route-specific limits through the request.parts replacement", async () => {
let hook: ((request: unknown) => Promise<void>) | undefined;
const app = {
register: vi.fn().mockResolvedValue(undefined),
addHook: vi.fn((_name, handler) => {
hook = handler;
}),
};
await registerUpload(app as never);
const iterator = {};
multipartPartsMock.mockReturnValueOnce(iterator);
const request = { isMultipart: () => true, parts: vi.fn() };
await hook?.(request);
expect(request.parts({ limits: { fileSize: 1234, files: 2 } })).toBe(iterator);
expect(multipartPartsMock).toHaveBeenCalledWith(request, { fileSize: 1234, files: 2 });
});
});