mirror of
https://github.com/morluto/rea.git
synced 2026-11-19 21:23:45 +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.3 KiB
TypeScript
95 lines
3.3 KiB
TypeScript
import { execFileSync } from "node:child_process";
|
|
import { chmod, readFile, writeFile } from "node:fs/promises";
|
|
import { join } from "node:path";
|
|
import { expect, it } from "vitest";
|
|
import { createTestTempDirectory } from "../../tests/fixtures/temporaryDirectory.js";
|
|
import { ScreenJudgeProcess } from "./ScreenJudgeProcess.js";
|
|
import { waitFor } from "../../tests/support/testWait.js";
|
|
|
|
const check = { id: "x", kind: "screen_judge", question: "ready?" } as const;
|
|
|
|
it.skipIf(process.platform === "win32")(
|
|
"returns the judge's answer for its screenshot",
|
|
async () => {
|
|
const folder = await createTestTempDirectory("screen-answer-");
|
|
const python = execFileSync("which", ["python3"], {
|
|
encoding: "utf8",
|
|
}).trim();
|
|
const runner = join(folder, "agent-env");
|
|
const verifier = join(folder, "verify.py");
|
|
await writeFile(runner, `#!${python}\n`);
|
|
await chmod(runner, 0o700);
|
|
await writeFile(
|
|
verifier,
|
|
'import json, sys\nprint(json.dumps({"id": "x", "result": open(sys.argv[3], "rb").read() == b"image", "description": "checked"}))\n',
|
|
);
|
|
const judge = new ScreenJudgeProcess({
|
|
...process.env,
|
|
REA_AGENT_ENV_COMMAND: runner,
|
|
});
|
|
expect(
|
|
await judge.judge(
|
|
verifier,
|
|
check,
|
|
Buffer.from("image"),
|
|
new AbortController().signal,
|
|
),
|
|
).toEqual({ id: "x", passed: true, description: "checked" });
|
|
expect(await judge.close()).toMatchObject({ verified: true });
|
|
},
|
|
);
|
|
|
|
it.skipIf(process.platform === "win32")(
|
|
"stops the judge and a separate-session child before cancellation settles",
|
|
async () => {
|
|
const folder = await createTestTempDirectory("screen-owner-");
|
|
const python = execFileSync("which", ["python3"], {
|
|
encoding: "utf8",
|
|
}).trim();
|
|
const runner = join(folder, "agent-env");
|
|
const verifier = join(folder, "verify.py");
|
|
const marker = join(folder, "child.pid");
|
|
await writeFile(runner, `#!${python}\n`);
|
|
await chmod(runner, 0o700);
|
|
await writeFile(
|
|
verifier,
|
|
`import subprocess, sys, time\np = subprocess.Popen([sys.executable, "-c", "import time; time.sleep(60)"], start_new_session=True)\nopen(${JSON.stringify(marker)}, "w").write(str(p.pid))\ntime.sleep(60)\n`,
|
|
);
|
|
const judge = new ScreenJudgeProcess({
|
|
...process.env,
|
|
REA_AGENT_ENV_COMMAND: runner,
|
|
});
|
|
const controller = new AbortController();
|
|
const running = judge.judge(
|
|
verifier,
|
|
check,
|
|
new Uint8Array([1]),
|
|
controller.signal,
|
|
);
|
|
void running.catch(() => undefined);
|
|
let pid = 0;
|
|
try {
|
|
await waitFor(async () => {
|
|
pid = Number(await readFile(marker, "utf8"));
|
|
expect(pid).toBeGreaterThan(0);
|
|
});
|
|
controller.abort(new Error("cancelled by caller"));
|
|
await expect(running).rejects.toThrow();
|
|
let state = "";
|
|
try {
|
|
state = execFileSync("ps", ["-p", String(pid), "-o", "stat="], {
|
|
encoding: "utf8",
|
|
}).trim();
|
|
} catch {
|
|
/* Process no longer exists. */
|
|
}
|
|
expect(state === "" || state.startsWith("Z")).toBe(true);
|
|
expect(await judge.close()).toMatchObject({ verified: true });
|
|
} finally {
|
|
controller.abort(new Error("test cleanup"));
|
|
await running.catch(() => undefined);
|
|
expect(await judge.close()).toMatchObject({ verified: true });
|
|
}
|
|
},
|
|
);
|