Files
reverse-engineering-anything/src/apktool/ApktoolVersionProbe.lifecycle.test.ts
T
gensokyo-devandgensokyo-dev 07e4b700ac test: let the deadline policy own test waits
Vitest's expect.poll and vi.waitFor stop after one second by default, a
host-speed guess that the project's deadline policy does not see. Under
hosted-CI load, kunaProjectConcurrency failed that way twice on unrelated
PRs. Another 256 waits relied on the default, and 97 passed literals
picked to fit some host.

Waits now take as long as their test may run, less the reporting reserve
that children already keep. Each Vitest project sets expect.poll's
default, and the new waitFor in tests/support/testWait.ts replaces
vi.waitFor. Fixture readiness waits (awaitAcknowledgement and the provider
process waits) default to the same deadline, and their host-speed literal
arguments are removed. One remainingTestDeadline owns the arithmetic for
both children and waits.

Ten waits whose short timeout was the real check now assert it directly
(Kuna version probe, Cutter discovery, doctor and Inspector cancellation,
apktool fixture teardown, JADX disconnect): settlement before the
production deadline that would otherwise also satisfy the wait, or a
deadline pinned beyond every test deadline.

The rea/project-wait-deadline lint rule rejects vi.waitFor and explicit
expect.poll timeouts. The testing guide and the CI tests audit skill now
document the policy.

Co-Authored-By: gensokyo-dev <342580529+gensokyo-dev@users.noreply.github.com>
2026-11-14 19:28:38 +08:00

68 lines
2.5 KiB
TypeScript

import { ApktoolCommandCleanup } from "./ApktoolCommandCleanup.js";
import { afterEach, expect, it } from "vitest";
import { AnalysisCancelledError } from "../domain/analysisErrorCore.js";
import { createTestTempDirectory } from "../../tests/fixtures/temporaryDirectory.js";
import {
awaitApktoolOperation,
createApktoolProcessFixture,
} from "../../tests/fixtures/apktoolProcessTree.js";
import { observePosixProcess } from "../../tests/support/process/observePosixProcess.js";
import { inspectApktoolClient } from "./ApktoolConfiguration.js";
// The interpreter is the test runtime itself, so its environment (and the
// ownership run token) is readable on both Linux and macOS.
it.skipIf(process.platform === "win32")(
"stops an interpreter launcher and its pipe-holding child when the probe is cancelled",
async () => {
const root = await createTestTempDirectory("rea-apktool-probe-");
const fixture = await createApktoolProcessFixture(root, "probe");
const controller = new AbortController();
const started = performance.now();
const probe = inspectApktoolClient(
{ command: fixture.command, commandSource: "environment" },
commands,
{ signal: controller.signal, environment: process.env },
).catch((cause: unknown) => cause);
try {
let launched: readonly number[] = [];
await expect
.poll(
async () => {
const marker = await fixture.readMarker();
if (marker?.ready !== true) return false;
launched = [marker.rootPid, marker.childPid];
return (await Promise.all(launched.map(observePosixProcess))).every(
({ kind }) => kind === "running",
);
},
{ interval: 25 },
)
.toBe(true);
controller.abort();
// A regressed probe never settles; bound the wait so cleanup still runs.
const outcome = await awaitApktoolOperation(probe, 15_000);
expect(outcome).toBeInstanceOf(AnalysisCancelledError);
expect(performance.now() - started).toBeLessThan(15_000);
await expect
.poll(
async () =>
(await Promise.all(launched.map(observePosixProcess))).every(
({ kind }) => kind !== "running",
),
{ interval: 25 },
)
.toBe(true);
} finally {
controller.abort();
await fixture.cleanup([probe]);
}
},
);
let commands = new ApktoolCommandCleanup();
afterEach(async () => {
await commands.close();
commands = new ApktoolCommandCleanup();
});