Files
reverse-engineering-anything/tests/support/testDeadlines.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

39 lines
1.4 KiB
TypeScript

/**
* Hang-detection deadlines that the Vitest project policy applies. Tests do not
* restate them; see docs/development/testing.md#developer-commands.
*/
export const TEST_DEADLINE_MS = { source: 30_000, built: 120_000 } as const;
/** Deadline for a bounded workload tagged `long-running`. */
export const LONG_RUNNING_DEADLINE_MS = 300_000;
/** Coverage instrumentation slows every lane, so it scales every deadline. */
export const COVERAGE_DEADLINE_SCALE = 2;
/** Hosted CI runs a worker per core, so it also scales every deadline. */
export const HOSTED_RUNNER_DEADLINE_SCALE = 2;
/** Least time kept back from a test deadline to stop work and report it. */
const MIN_REPORT_RESERVE_MS = 5_000;
/** Least deadline handed to work that starts late in a test. */
const MIN_REMAINING_DEADLINE_MS = 1_000;
/**
* Deadline for a wait or child started `elapsedMs` into a test: what remains,
* less a reserve for stopping the work and reporting why. Hung work then fails
* with its own diagnostics instead of an opaque test timeout, without a fixed
* value that assumes a host's speed. Undefined when the test has no deadline.
*/
export const remainingTestDeadline = (
testDeadlineMs: number,
elapsedMs: number,
): number | undefined => {
if (!(testDeadlineMs > 0)) return undefined;
const reserve = Math.max(MIN_REPORT_RESERVE_MS, testDeadlineMs / 10);
return Math.max(
MIN_REMAINING_DEADLINE_MS,
Math.floor(testDeadlineMs - elapsedMs - reserve),
);
};