test(desktop): keep the EIO probe case in the HostFileRead suite

Move the transient stat case into HostFileRead.test.ts behind a
pass-through fs mock (only one fixture name fails), instead of a
separate module-mocked file.

Refs #9703

Co-Authored-By: gensokyo-dev <342580529+gensokyo-dev@users.noreply.github.com>
This commit is contained in:
gensokyo-devandgensokyo-dev authored and Ysopwnable committed 2026-11-14 12:13:50 +01:00
1 parent b3c0ac4bc4
commit ac7b9250d1
2 files changed
+27 -29

No files matched your search

+27 -3
View File
@@ -1,9 +1,25 @@
import { mkdir, chmod, symlink, writeFile } from "node:fs/promises";
import { join } from "node:path";
import { describe, expect, it } from "vitest";
import { describe, expect, it, vi } from "vitest";
import { probeHostFile } from "./HostFileRead.js";
// Pass-through except for one name, so the transient (EIO) branch is reachable
// without a host fault; every other probe here uses the real filesystem.
vi.mock("node:fs/promises", async (importOriginal) => {
const fs = await importOriginal<typeof import("node:fs/promises")>();
return {
...fs,
stat: async (...args: Parameters<typeof fs.stat>) => {
if (String(args[0]).endsWith("transient.so"))
throw Object.assign(new Error("injected I/O failure"), {
code: "EIO",
});
return fs.stat(...args);
},
};
});
import { hostFileKind, probeHostFile } from "./HostFileRead.js";
import { createTestTempDirectory } from "../../tests/fixtures/temporaryDirectory.js";
describe.skipIf(process.platform === "win32")("probeHostFile", () => {
@@ -33,7 +49,6 @@ describe.skipIf(process.platform === "win32")("probeHostFile", () => {
});
it("reports a readable regular file as a file", async () => {
// The transient (EIO) branch is covered in HostFileRead.transient.test.ts.
const root = await createTestTempDirectory("rea-host-file-probe-");
const path = join(root, "libcore.so");
await writeFile(path, "carrier");
@@ -59,3 +74,12 @@ describe.skipIf(process.platform === "win32")("probeHostFile", () => {
}
});
});
it("keeps a transient stat failure unresolved rather than absent", async () => {
// EIO neither proves absence nor lets ld.so search past the candidate.
await expect(probeHostFile("/fixture/lib/transient.so")).resolves.toEqual({
kind: "unknown",
unreachable: false,
});
await expect(hostFileKind("/fixture/lib/transient.so")).resolves.toBeNull();
});
@@ -1,26 +0,0 @@
import { expect, it, vi } from "vitest";
vi.mock("node:fs/promises", async (importOriginal) => {
const fs = await importOriginal<typeof import("node:fs/promises")>();
return {
...fs,
stat: async (...args: Parameters<typeof fs.stat>) => {
if (String(args[0]).endsWith("transient.so"))
throw Object.assign(new Error("injected I/O failure"), {
code: "EIO",
});
return fs.stat(...args);
},
};
});
import { hostFileKind, probeHostFile } from "./HostFileRead.js";
it("keeps a transient stat failure unresolved rather than absent", async () => {
// EIO neither proves absence nor lets ld.so search past the candidate.
await expect(probeHostFile("/fixture/lib/transient.so")).resolves.toEqual({
kind: "unknown",
unreachable: false,
});
await expect(hostFileKind("/fixture/lib/transient.so")).resolves.toBeNull();
});