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

+8 -7
View File
@@ -2,13 +2,14 @@ import { once } from "node:events";
import { createServer, type Server } from "node:http";
import { connect } from "node:net";
import type { AddressInfo } from "node:net";
import { afterEach, expect, it, vi } from "vitest";
import { afterEach, expect, it } from "vitest";
import {
toWebRequest,
writeWebResponse,
type WebResponseOptions,
} from "./nodeHttpBridge.js";
import { waitFor } from "../../../tests/support/testWait.js";
const servers: Server[] = [];
const encoder = new TextEncoder();
@@ -66,7 +67,7 @@ it("ends a HEAD reply after the headers and cancels a body the handler attached"
const response = await fetch(`${origin}/events`, { method: "HEAD" });
expect(response.status).toBe(200);
expect(response.headers.get("content-type")).toBe("text/event-stream");
await vi.waitFor(() => {
await waitFor(() => {
expect(cancelled).toBe(true);
});
expect(pulls).toBeLessThanOrEqual(1);
@@ -93,7 +94,7 @@ it("finishes a HEAD reply without waiting on a teed body whose sibling stays liv
method: "HEAD",
});
expect(response.status).toBe(200);
await vi.waitFor(() => {
await waitFor(() => {
expect(finished).toBe(true);
});
});
@@ -126,11 +127,11 @@ it("cancels the body when an asynchronous route resolves after its client left",
const socket = connect(port, "127.0.0.1");
await once(socket, "connect");
socket.write("GET /late HTTP/1.1\r\nHost: 127.0.0.1\r\n\r\n");
await vi.waitFor(() => {
await waitFor(() => {
expect(received).toBe(true);
});
socket.destroy();
await vi.waitFor(() => {
await waitFor(() => {
expect(settled).toBe(true);
expect(cancelled).toBe(true);
});
@@ -165,7 +166,7 @@ it("returns when a client leaves a teed streaming body whose sibling stays live"
const first = await response.body.getReader().read();
expect(decoder.decode(first.value)).toBe("data: first\n\n");
leave.abort();
await vi.waitFor(() => {
await waitFor(() => {
expect(settled).toBe(true);
});
});
@@ -266,7 +267,7 @@ it("aborts the web Request and cancels its response body when the client leaves"
if (reader === undefined) throw new Error("Response body missing");
await reader.read();
controller.abort();
await vi.waitFor(() => {
await waitFor(() => {
expect(aborted).toBe(true);
expect(cancelled).toBe(true);
});
+11 -10
View File
@@ -25,6 +25,7 @@ import { StreamableHttpListenError } from "./streamableHttpListenError.js";
import { mcpAllowedHostsTextSchema } from "../../config/mcpHttpEndpoint.js";
import { parseMcpHttpArguments } from "../../main/mcpHttpArguments.js";
import { RequestTrackingMcpServer } from "../RequestTrackingMcpServer.js";
import { waitFor } from "../../../tests/support/testWait.js";
const servers: StreamableHttpServer[] = [];
@@ -1318,7 +1319,7 @@ it.each(["chunk", "headers"])(
.catch(() => undefined);
let closing: Promise<void> | undefined;
try {
await vi.waitFor(() => {
await waitFor(() => {
expect(cancelled).toBe(1);
});
expect((await fetch(new URL("/health", served.url))).status).toBe(503);
@@ -1403,7 +1404,7 @@ it("retains failed response cleanup and blocks provider teardown and further adm
const response = await fetch(new URL("/failed", served.url));
try {
await response.body?.cancel();
await vi.waitFor(async () => {
await waitFor(async () => {
expect((await fetch(new URL("/health", served.url))).status).toBe(503);
});
await expect(served.prepareShutdown()).rejects.toMatchObject({
@@ -1459,7 +1460,7 @@ it("retains plain-response admission until asynchronous cancellation settles", a
expect((await fetch(new URL("/health", served.url))).status).toBe(503);
expect(health).not.toHaveBeenCalled();
cleanup.release();
await vi.waitFor(async () => {
await waitFor(async () => {
expect((await fetch(new URL("/health", served.url))).status).toBe(200);
});
} finally {
@@ -1562,10 +1563,10 @@ it.each(["pending handler", "open response"])(
await first.promise;
socket.write(request("/second"));
socket.write(request("/health").repeat(32));
await vi.waitFor(() => {
await waitFor(() => {
expect(socket.destroyed).toBe(true);
});
await vi.waitFor(() => {
await waitFor(() => {
expect(finalized).toBe(mode === "pending handler" ? 1 : 0);
});
expect(secondCalled).toBe(0);
@@ -1687,12 +1688,12 @@ it("retains admission for an unread upload attached to a long response", async (
upload.once("error", () => undefined);
upload.write("prefix");
try {
await vi.waitFor(() => {
await waitFor(() => {
expect(received).toBe(true);
});
expect((await fetch(new URL("/health", served.url))).status).toBe(503);
upload.destroy();
await vi.waitFor(async () => {
await waitFor(async () => {
expect((await fetch(new URL("/health", served.url))).status).toBe(200);
});
} finally {
@@ -1737,7 +1738,7 @@ it("bounds HTTP input dispatch globally and releases admission when an upload le
}
// A plain route observes the same budget while both sessionless MCP probes
// wait for the rest of their bodies. Idle SSE connections consume no permit.
await vi.waitFor(async () => {
await waitFor(async () => {
expect((await fetch(new URL("/health", served.url))).status).toBe(503);
});
const refused = await rawHttpRequest(new URL(served.url), {
@@ -1752,7 +1753,7 @@ it("bounds HTTP input dispatch globally and releases admission when an upload le
expect(refused.headers.connection).toBe("close");
uploads[0]?.destroy();
await pending[0];
await vi.waitFor(async () => {
await waitFor(async () => {
expect((await fetch(new URL("/health", served.url))).status).toBe(200);
});
expect(await echo(first.client, "kept during overload")).toEqual([
@@ -1862,7 +1863,7 @@ it.each(["DELETE", "shutdown"])(
upload.write('{"jsonrpc":"2.0","id":2,"method":"tools/call",');
});
try {
await vi.waitFor(() => {
await waitFor(() => {
expect(
entered.mock.calls.some(
([request]) =>