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>
This commit is contained in:
gensokyo-devandgensokyo-dev authored and gensokyo-dev committed 2026-11-14 19:28:38 +08:00
1 parent 054fbc4c26
commit 07e4b700ac
119 files changed
+818 -648

No files matched your search

@@ -32,6 +32,7 @@ import {
PlaywrightElectronActiveProvider,
safeElectronEnvironment,
} from "./PlaywrightElectronActiveProvider.js";
import { waitFor } from "../../tests/support/testWait.js";
afterEach(() => {
vi.restoreAllMocks();
@@ -1051,7 +1052,7 @@ it("reports an expired final state grace period as the caller's cancellation", a
};
const capture = captureWithController(controller, application, []);
await vi.waitFor(() => expect(evaluate).toHaveBeenCalled());
await waitFor(() => expect(evaluate).toHaveBeenCalled());
await vi.advanceTimersByTimeAsync(5_000);
const result = await capture;
+3 -2
View File
@@ -4,6 +4,7 @@ import type { BrowserContext, Page, Request, Response } from "playwright-core";
import { browserScenarioSchema } from "../domain/browserScenario.js";
import { resolveScenarioSecrets } from "../../tests/fixtures/browserScenarioSecrets.js";
import { PlaywrightScenarioEvents } from "./PlaywrightScenarioEvents.js";
import { waitFor } from "../../tests/support/testWait.js";
describe("declared secrets in scenario events", () => {
it("redacts encoded declared secrets from text evidence and fingerprints", () => {
@@ -544,7 +545,7 @@ const sourceTransactionCapture = async (
};
listeners.get("request")!(request);
if (!options.metadataOnly)
await vi.waitFor(() =>
await waitFor(() =>
expect(capture.result().items).toContainEqual(
expect.objectContaining({ kind: "network-content", phase: "request" }),
),
@@ -592,7 +593,7 @@ const sourceTransactionCapture = async (
});
listeners.get("requestfinished")!(followup);
if (!options.metadataOnly)
await vi.waitFor(() =>
await waitFor(() =>
expect(
capture
.result()
@@ -6,6 +6,7 @@ import type { BrowserScenarioAction } from "../domain/browserScenarioValues.js";
import { BrowserScenarioSecrets } from "./BrowserScenarioSecrets.js";
import { responsePointerValue } from "./BrowserScenarioResponseValues.js";
import { performPlaywrightScenarioAction } from "./PlaywrightScenarioActions.js";
import { waitFor } from "../../tests/support/testWait.js";
const ORIGIN = "https://app.example.test";
@@ -1614,7 +1615,7 @@ describe("ambiguous saved response observations", () => {
]);
const running = perform(page, parsed.actions[0]!, secrets);
const rejected = expect(running).rejects.toThrow("ambiguous");
await vi.waitFor(() => expect(reads.count).toBe(1));
await waitFor(() => expect(reads.count).toBe(1));
for (const listener of listeners)
listener({ method: () => "POST", url: () => `${ORIGIN}/api/items` });
release('{"id":"wrong-object"}');
@@ -121,6 +121,7 @@ vi.mock("./PlaywrightScenarioEvents.js", () => ({
import { browserScenarioSchema } from "../domain/browserScenario.js";
import { PlaywrightScenarioSession } from "./PlaywrightScenarioSession.js";
import { PlaywrightScenarioBrowserCleanupOwner } from "./PlaywrightScenarioBrowser.js";
import { waitFor } from "../../tests/support/testWait.js";
const scenario = browserScenarioSchema.parse({
browser: { mode: "launch", executable_path: process.execPath },
@@ -1304,7 +1305,7 @@ it("can retry cleanup of a browser that opened after request cancellation", asyn
controller.abort();
await cancelled;
resolveOpening?.(lateOpened);
await vi.waitFor(() => expect(closeBrowser).toHaveBeenCalledTimes(1));
await waitFor(() => expect(closeBrowser).toHaveBeenCalledTimes(1));
expect(retained).toHaveLength(1);
await expect(retained[0]?.release()).resolves.toBeUndefined();
expect(closeBrowser).toHaveBeenCalledTimes(2);