forked from EduCraft/curriculum-project-hub
97a99cd381
SubmitDocParserJobAdvance uploads PDFs to Aliyun OSS via tea/httpx, which defaults readTimeout to 3000ms when RuntimeOptions is empty. Multi-MB teacher PDFs on para silo failed with ReadTimeout(3000) before the job could start. Set connectTimeout=15s and readTimeout=5m.
51 lines
1.8 KiB
TypeScript
51 lines
1.8 KiB
TypeScript
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"),
|
|
});
|
|
});
|
|
});
|