mirror of
https://github.com/morluto/rea.git
synced 2026-11-23 23:15:58 +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>
95 lines
3.6 KiB
TypeScript
95 lines
3.6 KiB
TypeScript
import { expect, it } from "vitest";
|
|
import { WebRuntimeService } from "../../../src/application/WebRuntimeService.js";
|
|
import { CdpWebRuntimeProvider } from "../../../src/browser/execution/CdpWebRuntimeProvider.js";
|
|
import { AnalysisOutputError } from "../../../src/domain/analysisErrorCore.js";
|
|
import { startRuntimeBrowser } from "../../fixtures/webRuntime.js";
|
|
import { waitFor } from "../../support/testWait.js";
|
|
|
|
it.each([
|
|
new Error("operator stopped observation"),
|
|
new AnalysisOutputError("inspect_web_page", "caller supplied reason"),
|
|
{ requested: "stop the armed observation" },
|
|
])(
|
|
"preserves caller reason through the armed service workflow and stops instrumentation (%s)",
|
|
async (reason) => {
|
|
const browser = await startRuntimeBrowser();
|
|
const provider = new CdpWebRuntimeProvider();
|
|
const service = new WebRuntimeService(provider);
|
|
const input = {
|
|
cdp_endpoint: browser.endpoint,
|
|
target_id: "allowed-page",
|
|
observation_ms: 5,
|
|
};
|
|
try {
|
|
const before = await service.observe(input);
|
|
if (!before.ok) throw before.error;
|
|
const controller = new AbortController();
|
|
const cancelled = await service.observe(input, {
|
|
signal: controller.signal,
|
|
progress: {
|
|
report: async (update) => {
|
|
if (update.completed === 1) controller.abort(reason);
|
|
},
|
|
},
|
|
});
|
|
if (cancelled.ok) throw new Error("Expected cancellation at arming");
|
|
expect(cancelled.error._tag).toBe("AnalysisCancelledError");
|
|
expect(cancelled.error.cause).toBe(controller.signal.reason);
|
|
expect(cancelled.error.cause).toBe(reason);
|
|
expect(cancelled.error.cleanupIncomplete).toBe(false);
|
|
expect(
|
|
browser.commands.filter(
|
|
(command) => command.method === "Profiler.stopPreciseCoverage",
|
|
),
|
|
).toHaveLength(2);
|
|
await waitFor(() => expect(browser.activeConnectionCount()).toBe(0));
|
|
const after = await service.observe(input);
|
|
if (!after.ok) throw after.error;
|
|
await waitFor(() => expect(browser.activeConnectionCount()).toBe(0));
|
|
} finally {
|
|
await provider.close();
|
|
await browser.close();
|
|
}
|
|
},
|
|
);
|
|
|
|
it("preserves the caller reason when a navigation observation is cancelled at arming", async () => {
|
|
const { CdpBrowserProvider } =
|
|
await import("../../../src/browser/CdpBrowserProvider.js");
|
|
const { observeWebSession } =
|
|
await import("../../../src/application/BrowserObservationService.js");
|
|
const { observeWebSessionInputSchema } =
|
|
await import("../../../src/domain/browserSession.js");
|
|
const browser = await startRuntimeBrowser();
|
|
const provider = new CdpBrowserProvider();
|
|
const controller = new AbortController();
|
|
const reason = { requested: "stop navigation observation" };
|
|
try {
|
|
const result = await observeWebSession(
|
|
provider,
|
|
observeWebSessionInputSchema.parse({
|
|
cdp_endpoint: browser.endpoint,
|
|
allowed_origins: [browser.allowedOrigin],
|
|
target_id: "allowed-page",
|
|
observation_ms: 30_000,
|
|
}),
|
|
{
|
|
signal: controller.signal,
|
|
progress: {
|
|
report: async (update) => {
|
|
if (update.completed === 1) controller.abort(reason);
|
|
},
|
|
},
|
|
},
|
|
);
|
|
if (result.ok) throw new Error("Expected cancelled navigation observation");
|
|
expect(result.error._tag).toBe("AnalysisCancelledError");
|
|
expect(result.error.cause).toBe(reason);
|
|
expect(result.error.cleanupIncomplete).toBe(false);
|
|
await waitFor(() => expect(browser.activeConnectionCount()).toBe(0));
|
|
} finally {
|
|
await provider.close();
|
|
await browser.close();
|
|
}
|
|
});
|