Files
reverse-engineering-anything/tests/boundary/process/androidGuardianObservation.test.ts
T
morluto 5d4e9b8532 refactor(android): take the host in JADX configuration, doctor and workspace roots (#11086)
* refactor(android): take the host in JADX configuration, doctor and workspace roots

* fix(android): pass the host in verifiers, follow it for JAVA_HOME, and test the native cache split

* test(platform): count tests that redefine process.platform or process.arch (#11102)

Tests select a host by injection. A redefined process.platform stops exercising its branch once the module under test reads HOST_PLATFORM, and still passes. A counted baseline (105 sites in 20 files) may only shrink; each module migration switches its tests to injection.
2026-11-15 20:52:58 +08:00

62 lines
2.1 KiB
TypeScript

import { EventEmitter } from "node:events";
import { PassThrough } from "node:stream";
import { expect, it, vi } from "vitest";
const observation = vi.hoisted(() => ({
serial: 0,
failure: Object.assign(new Error("inert workspace observation"), {
code: "ENOENT",
}),
}));
vi.mock("node:fs/promises", async (original) => {
const fs = await original<typeof import("node:fs/promises")>();
return {
...fs,
stat: async (...args: Parameters<typeof fs.stat>) => {
if (!String(args[0]).startsWith("/rea-inert/")) return fs.stat(...args);
if (String(args[0]).endsWith("synthetic.txt")) return {};
throw observation.failure;
},
};
});
vi.mock("node:child_process", async (original) => {
const cp = await original<typeof import("node:child_process")>();
return {
...cp,
spawn: (...args: Parameters<typeof cp.spawn>) => {
if (args[1]?.[1] !== "owner") return cp.spawn(...args);
const events = new EventEmitter();
const child = Object.assign(events, {
stdout: new PassThrough(),
stderr: new PassThrough(),
exitCode: null as number | null,
signalCode: null,
kill() {
this.exitCode = 0;
events.emit("close", 0);
return true;
},
});
const path = `/rea-inert/owned-${++observation.serial}`;
queueMicrotask(() => child.stdout.write(JSON.stringify({ path }) + "\n"));
return child;
},
};
});
const { verifyWindowsGuardianIsolation } = await vi.importActual<{
verifyWindowsGuardianIsolation(platform?: NodeJS.Platform): Promise<void>;
}>("../../../scripts/verify/android/windows-guardian-isolation.mjs");
it.each(["ENOENT", "ENOTDIR", "EACCES", "EIO"])(
"admits only known workspace absence after owner exit (%s)",
async (code) => {
observation.failure = Object.assign(new Error(`inert stat ${code}`), {
code,
});
const result = verifyWindowsGuardianIsolation("win32");
if (code === "ENOENT" || code === "ENOTDIR")
await expect(result).resolves.toBeUndefined();
else await expect(result).rejects.toBe(observation.failure);
},
);