mirror of
https://github.com/morluto/rea.git
synced 2026-11-21 14:05:49 +00:00
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>
151 lines
4.7 KiB
TypeScript
151 lines
4.7 KiB
TypeScript
import { describe, expect, it, vi } from "vitest";
|
|
import { access } from "node:fs/promises";
|
|
|
|
import {
|
|
HopperFixtureLauncher,
|
|
startHopperFixtureClient,
|
|
} from "./hopperClient.fixture.js";
|
|
import { waitFor } from "../../../support/testWait.js";
|
|
|
|
describe("HopperClient request deadlines", () => {
|
|
it("propagates deadlines through the socket client and accepts late replies safely", async () => {
|
|
const launcher = new HopperFixtureLauncher();
|
|
const client = await startHopperFixtureClient(launcher);
|
|
const settled = vi.fn();
|
|
const pending = client
|
|
.callTool("echo", { gate: "deadline" }, { timeoutMs: 100 })
|
|
.then(settled);
|
|
const request = await launcher.waitForRequest("echo", "deadline");
|
|
try {
|
|
await waitFor(() =>
|
|
expect(settled).toHaveBeenCalledWith({
|
|
ok: false,
|
|
error: expect.objectContaining({
|
|
_tag: "HopperTimeoutError",
|
|
timeoutMs: 100,
|
|
operation: "echo",
|
|
}),
|
|
}),
|
|
);
|
|
expect(client.requestActivity()).toMatchObject({
|
|
callerState: "cancelled",
|
|
operation: "echo",
|
|
});
|
|
} finally {
|
|
await launcher.release(request);
|
|
await pending;
|
|
}
|
|
await expect(
|
|
client.callTool("echo", { value: "alive" }, { timeoutMs: 1000 }),
|
|
).resolves.toEqual({
|
|
ok: true,
|
|
value: { value: "alive" },
|
|
});
|
|
expect(settled).toHaveBeenCalledTimes(1);
|
|
expect(client.requestActivity()).toBeNull();
|
|
});
|
|
|
|
it("never transmits a request whose deadline expired in the FIFO", async () => {
|
|
const launcher = new HopperFixtureLauncher();
|
|
const client = await startHopperFixtureClient(launcher);
|
|
const active = client.callTool("echo", { gate: "hold-active" });
|
|
const request = await launcher.waitForRequest("echo", "hold-active");
|
|
try {
|
|
await expect(
|
|
client.callTool("echo", { value: "expired" }, { timeoutMs: 25 }),
|
|
).resolves.toMatchObject({
|
|
ok: false,
|
|
error: { _tag: "HopperTimeoutError" },
|
|
});
|
|
expect(
|
|
launcher.requests.some(({ params }) => params?.value === "expired"),
|
|
).toBe(false);
|
|
} finally {
|
|
await launcher.release(request);
|
|
await active;
|
|
}
|
|
await expect(client.callTool("echo", { value: "next" })).resolves.toEqual({
|
|
ok: true,
|
|
value: { value: "next" },
|
|
});
|
|
expect(
|
|
launcher.requests.some(({ params }) => params?.value === "expired"),
|
|
).toBe(false);
|
|
});
|
|
|
|
it("closes and releases pending callers and private resources after an active timeout", async () => {
|
|
const launcher = new HopperFixtureLauncher();
|
|
const client = await startHopperFixtureClient(launcher);
|
|
const pending = client.callTool(
|
|
"echo",
|
|
{ gate: "timeout-close" },
|
|
{ timeoutMs: 100 },
|
|
);
|
|
await launcher.waitForRequest("echo", "timeout-close");
|
|
await expect(pending).resolves.toMatchObject({
|
|
ok: false,
|
|
error: { _tag: "HopperTimeoutError" },
|
|
});
|
|
const queued = client.callTool(
|
|
"echo",
|
|
{ value: "queued" },
|
|
{ timeoutMs: 1000 },
|
|
);
|
|
await waitFor(() =>
|
|
expect(client.requestActivity()?.queuedRequests).toBe(1),
|
|
);
|
|
await client.close();
|
|
await expect(queued).resolves.toMatchObject({
|
|
ok: false,
|
|
error: { _tag: "HopperProcessError" },
|
|
});
|
|
expect(client.requestActivity()).toBeNull();
|
|
for (const directory of launcher.directories)
|
|
await expect(access(directory)).rejects.toBeDefined();
|
|
expect(
|
|
launcher.processes.every(
|
|
(child) => child.exitCode !== null || child.signalCode !== null,
|
|
),
|
|
).toBe(true);
|
|
});
|
|
});
|
|
|
|
it("does not send a mutation after its synchronous progress observer consumes the deadline", async () => {
|
|
const launcher = new HopperFixtureLauncher();
|
|
const client = await startHopperFixtureClient(launcher);
|
|
const result = await client.callTool(
|
|
"set_comment",
|
|
{ comment: "must not reach the native boundary" },
|
|
{
|
|
timeoutMs: 10,
|
|
progress: {
|
|
report: () => {
|
|
const started = performance.now();
|
|
while (performance.now() - started < 30) {
|
|
// Exercise an observer delaying dispatch of the actual deadline timer.
|
|
}
|
|
return Promise.resolve();
|
|
},
|
|
},
|
|
},
|
|
);
|
|
expect(result).toMatchObject({
|
|
ok: false,
|
|
error: {
|
|
_tag: "HopperTimeoutError",
|
|
operation: "set_comment",
|
|
providerState: "not_started",
|
|
},
|
|
});
|
|
await expect(
|
|
client.callTool("echo", { value: "recovered" }),
|
|
).resolves.toEqual({
|
|
ok: true,
|
|
value: { value: "recovered" },
|
|
});
|
|
expect(launcher.requests.some(({ method }) => method === "set_comment")).toBe(
|
|
false,
|
|
);
|
|
expect(client.requestActivity()).toBeNull();
|
|
});
|