Files
reverse-engineering-anything/tests/boundary/providers/apktoolProcessFixture.test.ts
T
morluto 182cca1cbe test(providers): name the refusal behind bare toThrow assertions (#15525)
* test(providers): name the refusal behind bare toThrow assertions

Replace argument-less toThrow()/rejects.toThrow() in provider boundary
tests with the observed refusal: ENOENT/ESRCH codes for removed roots and
stopped processes, retained cleanup reason and resources for retry
failures, stop-failed debugger cleanup, cancellation tags, input issue
paths, and the fixture scripts' diagnostics.

* test(ida): give the verifier's containment-reason refusal a stable message

The assertion had no message, so Node copied its source expression into
the error and the test could only match that text. Name the reference
and the rejected reason instead, as the sibling assertions already do.
2026-12-01 17:34:24 +00:00

83 lines
3.2 KiB
TypeScript

import { HOST_PLATFORM } from "../../../src/platform/HostPlatform.js";
import { mkdir, rm, writeFile } from "node:fs/promises";
import { expect, it } from "vitest";
import { ApktoolCommandCleanup } from "../../../src/apktool/ApktoolCommandCleanup.js";
import { inspectApktoolClient } from "../../../src/apktool/ApktoolConfiguration.js";
import { createApktoolProcessFixture } from "../../fixtures/apktoolProcessTree.js";
import { createTestTempDirectory } from "../../fixtures/temporaryDirectory.js";
import {
observePosixProcess,
waitForPosixObservation,
} from "../../support/process/observePosixProcess.js";
const VERSION_PROBE_DEADLINE_MS = 20_000;
it
.skipIf(process.platform === "win32")
.each(["malformed", "unreadable"] as const)(
"retains fixture cleanup ownership when its published marker becomes %s",
async (failure) => {
const root = await createTestTempDirectory("rea-apktool-marker-failure-");
const fixture = await createApktoolProcessFixture(root, "probe");
await expect(fixture.readMarker()).resolves.toBeUndefined();
const commands = new ApktoolCommandCleanup();
const controller = new AbortController();
const probeStarted = performance.now();
const probe = inspectApktoolClient(
{ command: fixture.command, commandSource: "environment" },
commands,
{
signal: controller.signal,
environment: process.env,
platform: HOST_PLATFORM.platform,
},
).catch((cause: unknown) => cause);
try {
await expect
.poll(async () => (await fixture.readMarker())?.ready, {
interval: 25,
})
.toBe(true);
const marker = await fixture.readMarker();
if (marker === undefined) throw new Error("Fixture marker disappeared");
const pids = [marker.rootPid, marker.childPid];
expect(await Promise.all(pids.map(observePosixProcess))).toEqual([
expect.objectContaining({ kind: "running" }),
expect.objectContaining({ kind: "running" }),
]);
if (failure === "malformed") {
await writeFile(fixture.markerPath, "not-json");
} else {
await rm(fixture.markerPath);
await mkdir(fixture.markerPath);
}
const markerFailure =
failure === "malformed"
? expect.any(SyntaxError)
: expect.objectContaining({ code: "EISDIR" });
await expect(fixture.readMarker()).rejects.toThrow(markerFailure);
// No cancellation has run: fallback teardown must use the last valid
// token owner even when the current marker cannot be read or parsed.
await expect(fixture.cleanup()).rejects.toThrow(markerFailure);
await waitForPosixObservation(
async () =>
(await Promise.all(pids.map(observePosixProcess))).every(
({ kind }) => kind !== "running",
)
? true
: undefined,
{ interval: 25 },
);
// The still-running version probe would also stop them at its own
// deadline (ApktoolConfiguration: 20 s); fixture teardown must be first.
expect(performance.now() - probeStarted).toBeLessThan(
VERSION_PROBE_DEADLINE_MS,
);
} finally {
controller.abort();
await fixture.cleanup([probe, commands.close()]);
}
},
);