import { join } from "node:path"; import { tmpdir } from "node:os"; import { describe, expect, it } from "vitest"; import { AliyunDocmindClient, DocmindClientError, DOCMIND_CONNECT_TIMEOUT_MS, DOCMIND_READ_TIMEOUT_MS, createDocmindRuntimeOptions, } from "../../src/capability/docmindClient.js"; describe("createDocmindRuntimeOptions", () => { it("overrides httpx's 3s default so PDF OSS uploads can complete", () => { const runtime = createDocmindRuntimeOptions(); // Production failure: ReadTimeout(3000) on docmind OSS upload. expect(DOCMIND_CONNECT_TIMEOUT_MS).toBeGreaterThan(3_000); expect(DOCMIND_READ_TIMEOUT_MS).toBeGreaterThan(3_000); expect(runtime.connectTimeout).toBe(DOCMIND_CONNECT_TIMEOUT_MS); expect(runtime.readTimeout).toBe(DOCMIND_READ_TIMEOUT_MS); }); }); describe("AliyunDocmindClient local file open", () => { it("rejects a missing input file without crashing the process", async () => { const client = new AliyunDocmindClient(); const missing = join(tmpdir(), `docmind-missing-${Date.now()}.pdf`); // If createReadStream errors are left unhandled, Vitest aborts the suite // with an unhandled 'error' event instead of reaching this assertion. await expect(client.parse( { accessKeyId: "ak", accessKeySecret: "sk", endpoint: "docmind-api.cn-hangzhou.aliyuncs.com", }, { inputFilePath: missing }, )).rejects.toBeInstanceOf(DocmindClientError); await expect(client.parse( { accessKeyId: "ak", accessKeySecret: "sk", endpoint: "docmind-api.cn-hangzhou.aliyuncs.com", }, { inputFilePath: missing }, )).rejects.toMatchObject({ code: "docmind_rejected", message: expect.stringContaining("input file not found"), }); }); });