forked from EduCraft/curriculum-project-hub
fix(hub): do not crash Hub on missing DocMind input files
createReadStream emits async ENOENT without a listener, which became an unhandled 'error' event and exited the silo process. Teachers then saw the startup "process restart" notice. Wait for stream open and convert missing files into DocmindClientError instead.
This commit is contained in:
@@ -0,0 +1,34 @@
|
||||
import { join } from "node:path";
|
||||
import { tmpdir } from "node:os";
|
||||
import { describe, expect, it } from "vitest";
|
||||
import { AliyunDocmindClient, DocmindClientError } from "../../src/capability/docmindClient.js";
|
||||
|
||||
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"),
|
||||
});
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user