mirror of
https://github.com/morluto/rea.git
synced 2026-11-21 14:05:49 +00:00
fix(ci): verify packaged Agent Environment bridges (#12874)
* test(agentenv): observe timeout before polling a pending run * test(agentenv): verify bridge files at package boundary
This commit is contained in:
1 parent
b38438bab4
commit
41fc470072
14 files changed
+58
-94
No files matched your search
@@ -88,10 +88,6 @@ class LongRunTest(unittest.TestCase):
|
||||
"if len(sys.argv) > 1 and sys.argv[1] == 'wait':\n"
|
||||
" open(sys.argv[2], 'w').close()\n"
|
||||
" time.sleep(30)\n"
|
||||
"if len(sys.argv) > 1 and sys.argv[1] == 'ignore':\n"
|
||||
" signal.signal(signal.SIGINT, signal.SIG_IGN)\n"
|
||||
" open(sys.argv[2], 'w').close()\n"
|
||||
" while not os.path.exists(sys.argv[3]): time.sleep(0.02)\n"
|
||||
"if len(sys.argv) > 1 and sys.argv[1] == 'stderr':\n"
|
||||
" sys.stderr.write('x' * 100000 + 'TAIL')\n"
|
||||
" print(hashlib.sha256(json.dumps(sys.argv[2:]).encode()).hexdigest())\n"
|
||||
@@ -251,16 +247,18 @@ class LongRunTest(unittest.TestCase):
|
||||
self.assertTrue(result["pending"])
|
||||
|
||||
def test_reports_a_timed_out_child_that_has_not_stopped(self):
|
||||
ready, release = self.root / "ready", self.root / "release"
|
||||
self.assertEqual(self.begin(["ignore", str(ready), str(release)], timeout=3), {"started": True})
|
||||
release = self.start_resistant_child()
|
||||
try:
|
||||
result = self.command("run-poll", job=str(self.job), token="owner-token", timeout_s=4)
|
||||
self.assertTrue(self.wait_until((self.job / "timed_out").exists))
|
||||
self.assertTrue(self.wait_until((self.root / "release.pid").is_file))
|
||||
result = self.command("run-poll", job=str(self.job), token="owner-token", timeout_s=0)
|
||||
self.assertTrue(result["pending"])
|
||||
self.assertTrue(result["timed_out"])
|
||||
self.assertTrue(ready.exists())
|
||||
finally:
|
||||
release.touch()
|
||||
self.command("run-poll", job=str(self.job), token="owner-token", timeout_s=5)
|
||||
finished = self.command("run-poll", job=str(self.job), token="owner-token", timeout_s=5)
|
||||
self.assertTrue(finished["finished"] and finished["settled"])
|
||||
self.assertEqual(finished["exit_code"], 0)
|
||||
|
||||
def start_foreign_stderr_holder(self, timeout):
|
||||
release = self.root / "release"
|
||||
@@ -380,7 +378,7 @@ class LongRunTest(unittest.TestCase):
|
||||
release.touch()
|
||||
closer.join(timeout=2)
|
||||
|
||||
def test_kills_a_leader_that_ignores_sigint_and_sigterm(self):
|
||||
def start_resistant_child(self):
|
||||
release = self.root / "release"
|
||||
# Inherit the mask until the command installs both ignore handlers.
|
||||
# A slow startup can cross the real deadline before Python reaches them.
|
||||
@@ -391,6 +389,10 @@ class LongRunTest(unittest.TestCase):
|
||||
self.assertEqual(self.begin(["resist", str(release)], timeout=1), {"started": True})
|
||||
finally:
|
||||
signal.pthread_sigmask(signal.SIG_SETMASK, previous_mask)
|
||||
return release
|
||||
|
||||
def test_kills_a_leader_that_ignores_sigint_and_sigterm(self):
|
||||
self.start_resistant_child()
|
||||
result = self.command(
|
||||
"run-poll", job=str(self.job), token="owner-token", timeout_s=12, command_timeout=20,
|
||||
)
|
||||
|
||||
@@ -244,6 +244,7 @@ const PATH_SCOPES = {
|
||||
"tests/process-global/runnerCancellation.test.ts",
|
||||
"tests/process-global/windowsOwnedCommand.test.ts",
|
||||
"tests/process-global/curatedWindowsLane.test.ts",
|
||||
"src/desktop/AgentEnvBridgeSources.ts",
|
||||
"src/ghidra/GhidraBridgeSources.ts",
|
||||
"native/windows/**",
|
||||
"src/process/capture/FilesystemSnapshot.ts",
|
||||
|
||||
@@ -1,7 +1,15 @@
|
||||
import { relative, sep } from "node:path";
|
||||
import { fileURLToPath } from "node:url";
|
||||
|
||||
import { AGENTENV_BRIDGE_SOURCES } from "../src/desktop/AgentEnvBridgeSources.ts";
|
||||
import { GHIDRA_BRIDGE_SOURCES } from "../src/ghidra/GhidraBridgeSources.ts";
|
||||
|
||||
const packedHopperBridge = "package/bridge/hopper_bridge.py";
|
||||
const packedCutterBridge = "package/bridge/cutter/rea_bridge.py";
|
||||
const root = fileURLToPath(new URL("../", import.meta.url));
|
||||
const packedAgentEnvSources = Object.values(AGENTENV_BRIDGE_SOURCES).map(
|
||||
(url) => `package/${relative(root, fileURLToPath(url)).split(sep).join("/")}`,
|
||||
);
|
||||
|
||||
/** Check shipped bridge files; real-provider lanes verify runtime behavior. */
|
||||
export async function verifyPackedBridge({ tarball, packedFiles, commands }) {
|
||||
@@ -15,6 +23,7 @@ export async function verifyPackedBridge({ tarball, packedFiles, commands }) {
|
||||
for (const path of [
|
||||
packedHopperBridge,
|
||||
packedCutterBridge,
|
||||
...packedAgentEnvSources,
|
||||
...Object.values(GHIDRA_BRIDGE_SOURCES).map(
|
||||
(name) => `package/bridge/ghidra/${name}`,
|
||||
),
|
||||
|
||||
@@ -8,7 +8,6 @@ it("keeps complete note records and an unfinished trailing fragment", () => {
|
||||
expect(parseAgentEnvNotes(`${JSON.stringify(record)}\n{"id":`)).toEqual([
|
||||
record,
|
||||
]);
|
||||
expect(parseAgentEnvNotes(`${JSON.stringify(record)}\n`)).toEqual([record]);
|
||||
expect(parseAgentEnvNotes("")).toEqual([]);
|
||||
});
|
||||
|
||||
@@ -16,5 +15,4 @@ it("rejects a newline-terminated note that is not a record", () => {
|
||||
expect(() =>
|
||||
parseAgentEnvNotes(`${JSON.stringify(record)}\n{bad}\n`),
|
||||
).toThrow(SyntaxError);
|
||||
expect(() => parseAgentEnvNotes("{bad}\n")).toThrow(SyntaxError);
|
||||
});
|
||||
@@ -1,30 +0,0 @@
|
||||
import { readdir, readFile } from "node:fs/promises";
|
||||
|
||||
import { expect, it } from "vitest";
|
||||
|
||||
const ROOT = new URL("../../", import.meta.url);
|
||||
|
||||
it("ships every agentenv helper the desktop code launches in the package", async () => {
|
||||
const files = (
|
||||
JSON.parse(await readFile(new URL("package.json", ROOT), "utf8")) as {
|
||||
files: string[];
|
||||
}
|
||||
).files;
|
||||
const sources = await readdir(new URL("src/desktop/", ROOT));
|
||||
const launched = new Set<string>();
|
||||
for (const source of sources.filter(
|
||||
(name) => name.endsWith(".ts") && !name.endsWith(".test.ts"),
|
||||
))
|
||||
for (const [, helper] of (
|
||||
await readFile(new URL(`src/desktop/${source}`, ROOT), "utf8")
|
||||
).matchAll(/"\.\.\/\.\.\/(bridge\/agentenv\/[\w.-]+\.py)"/gu))
|
||||
launched.add(helper as string);
|
||||
|
||||
expect([...launched].sort()).toEqual([
|
||||
"bridge/agentenv/capture.py",
|
||||
"bridge/agentenv/computer.py",
|
||||
"bridge/agentenv/solve.py",
|
||||
"bridge/agentenv/solve_cleanup.py",
|
||||
]);
|
||||
for (const helper of launched) expect(files).toContain(helper);
|
||||
});
|
||||
@@ -0,0 +1,10 @@
|
||||
/** Bridge files shared by the runtime and the package verifier. */
|
||||
export const AGENTENV_BRIDGE_SOURCES = Object.freeze({
|
||||
capture: new URL("../../bridge/agentenv/capture.py", import.meta.url).href,
|
||||
computer: new URL("../../bridge/agentenv/computer.py", import.meta.url).href,
|
||||
solve: new URL("../../bridge/agentenv/solve.py", import.meta.url).href,
|
||||
solveCleanup: new URL(
|
||||
"../../bridge/agentenv/solve_cleanup.py",
|
||||
import.meta.url,
|
||||
).href,
|
||||
} as const);
|
||||
@@ -25,12 +25,11 @@ import {
|
||||
import { errorMessage } from "../kernel/errorMessage.js";
|
||||
import type { ComputerRelease } from "../domain/desktop/computerRelease.js";
|
||||
import { AGENTENV_PROVIDER } from "./AgentEnvProviderIdentity.js";
|
||||
import { AGENTENV_BRIDGE_SOURCES } from "./AgentEnvBridgeSources.js";
|
||||
|
||||
const execFileAsync = promisify(execFile);
|
||||
|
||||
const HELPER = fileURLToPath(
|
||||
new URL("../../bridge/agentenv/computer.py", import.meta.url),
|
||||
);
|
||||
const HELPER = fileURLToPath(AGENTENV_BRIDGE_SOURCES.computer);
|
||||
const HANDSHAKE_BYTES = 64 * 1024;
|
||||
const STDERR_BYTES = 16 * 1024;
|
||||
const TEARDOWN_MS = 120_000;
|
||||
|
||||
@@ -20,10 +20,9 @@ import {
|
||||
} from "./AgentEnvComputerHelper.js";
|
||||
import { AGENTENV_PROVIDER } from "./AgentEnvProviderIdentity.js";
|
||||
import { errorMessage } from "../kernel/errorMessage.js";
|
||||
import { AGENTENV_BRIDGE_SOURCES } from "./AgentEnvBridgeSources.js";
|
||||
|
||||
const HELPER = fileURLToPath(
|
||||
new URL("../../bridge/agentenv/solve.py", import.meta.url),
|
||||
);
|
||||
const HELPER = fileURLToPath(AGENTENV_BRIDGE_SOURCES.solve);
|
||||
const REPORT_BYTES = 256 * 1024;
|
||||
const STDERR_BYTES = 16 * 1024;
|
||||
/** The longest one solve may take, its deploy and teardown included, before REA stops it. */
|
||||
|
||||
@@ -17,10 +17,9 @@ import type {
|
||||
BuildControllerAnswer,
|
||||
ControlledComputer,
|
||||
} from "../ports/BuildComputerControl.js";
|
||||
import { AGENTENV_BRIDGE_SOURCES } from "./AgentEnvBridgeSources.js";
|
||||
|
||||
const CONTROLLER = fileURLToPath(
|
||||
new URL("../../bridge/agentenv/capture.py", import.meta.url),
|
||||
);
|
||||
const CONTROLLER = fileURLToPath(AGENTENV_BRIDGE_SOURCES.capture);
|
||||
/** The most file bytes one `data/get` brings back, so a large bundle arrives in several answers. */
|
||||
const FETCH_BATCH_BYTES = 8 * 1024 * 1024;
|
||||
/** Default time allowed for one REA command in the build computer. */
|
||||
|
||||
@@ -11,10 +11,9 @@ import {
|
||||
spawnOwnedProviderProcess,
|
||||
} from "../process/ProviderProcess.js";
|
||||
import { errorMessage } from "../kernel/errorMessage.js";
|
||||
import { AGENTENV_BRIDGE_SOURCES } from "./AgentEnvBridgeSources.js";
|
||||
|
||||
const CLEANUP = fileURLToPath(
|
||||
new URL("../../bridge/agentenv/solve_cleanup.py", import.meta.url),
|
||||
);
|
||||
const CLEANUP = fileURLToPath(AGENTENV_BRIDGE_SOURCES.solveCleanup);
|
||||
const resultSchema = z.discriminatedUnion("ok", [
|
||||
z.object({ ok: z.literal(true) }),
|
||||
z.object({ ok: z.literal(false), error: z.string() }),
|
||||
|
||||
@@ -1478,6 +1478,10 @@ it.each([
|
||||
"src/application/DshCordisYaml.ts",
|
||||
{ code: true, package: true, runtime: true, apple: false },
|
||||
],
|
||||
[
|
||||
"src/desktop/AgentEnvBridgeSources.ts",
|
||||
{ code: true, package: true, runtime: true, apple: false },
|
||||
],
|
||||
[
|
||||
"scripts/verify-packed-bridge.mjs",
|
||||
{
|
||||
|
||||
@@ -211,39 +211,6 @@ it.skipIf(process.platform === "win32").each([
|
||||
},
|
||||
);
|
||||
|
||||
it("rejects an omitted auxiliary source at the actual package verification boundary", async () => {
|
||||
const source = GHIDRA_BRIDGE_SOURCES.prepareCom;
|
||||
const packedFiles = [
|
||||
"package/bridge/hopper_bridge.py",
|
||||
"package/bridge/cutter/rea_bridge.py",
|
||||
...Object.values(GHIDRA_BRIDGE_SOURCES)
|
||||
.filter((name) => name !== source)
|
||||
.map((name) => `package/bridge/ghidra/${name}`),
|
||||
];
|
||||
await expect(
|
||||
execute(process.execPath, [
|
||||
"--input-type=module",
|
||||
"-e",
|
||||
`import { verifyPackedBridge } from "./scripts/verify-packed-bridge.mjs";
|
||||
import { createPackageVerifierCommands } from "./scripts/lib/verify-package-commands.mjs";
|
||||
import { withVerifierCleanup } from "./scripts/lib/verifier-cleanup.mjs";
|
||||
import { PrivateRuntimeRoot } from "./dist/process/PrivateRuntimeRoot.js";
|
||||
const root = await PrivateRuntimeRoot.create({ prefix: "rea-bridge-admission-" });
|
||||
let commands;
|
||||
await withVerifierCleanup(async () => {
|
||||
commands = await createPackageVerifierCommands({ workspace: root });
|
||||
await verifyPackedBridge({ tarball: "unused-because-admission-must-fail", packedFiles: JSON.parse(process.argv[1]), commands });
|
||||
}, [() => commands === undefined ? root.close() : commands.close()]);`,
|
||||
JSON.stringify(packedFiles),
|
||||
]),
|
||||
).rejects.toMatchObject({
|
||||
code: 1,
|
||||
stderr: expect.stringContaining(
|
||||
`package omitted package/bridge/ghidra/${source}`,
|
||||
),
|
||||
});
|
||||
});
|
||||
|
||||
it("binds the workflow SDK pin and verified compile mode to the canonical release", async () => {
|
||||
const { jobs } = z
|
||||
.object({
|
||||
|
||||
@@ -18,6 +18,10 @@ const bridge = "package/bridge/hopper_bridge.py";
|
||||
const members = [
|
||||
bridge,
|
||||
"package/bridge/cutter/rea_bridge.py",
|
||||
"package/bridge/agentenv/capture.py",
|
||||
"package/bridge/agentenv/computer.py",
|
||||
"package/bridge/agentenv/solve.py",
|
||||
"package/bridge/agentenv/solve_cleanup.py",
|
||||
...Object.values(GHIDRA_BRIDGE_SOURCES).map(
|
||||
(name) => `package/bridge/ghidra/${name}`,
|
||||
),
|
||||
|
||||
@@ -32,6 +32,10 @@ const exec = promisify(execFile);
|
||||
const packedFiles = [
|
||||
"package/bridge/hopper_bridge.py",
|
||||
"package/bridge/cutter/rea_bridge.py",
|
||||
"package/bridge/agentenv/capture.py",
|
||||
"package/bridge/agentenv/computer.py",
|
||||
"package/bridge/agentenv/solve.py",
|
||||
"package/bridge/agentenv/solve_cleanup.py",
|
||||
...Object.values(GHIDRA_BRIDGE_SOURCES).map(
|
||||
(name) => `package/bridge/ghidra/${name}`,
|
||||
),
|
||||
@@ -167,19 +171,18 @@ try {
|
||||
},
|
||||
);
|
||||
|
||||
it.each(packedFiles)(
|
||||
"rejects an unadvertised required member: %s",
|
||||
async (member) => {
|
||||
const input = await fixture();
|
||||
it("rejects each omitted required bridge before parsing the archive", async () => {
|
||||
const input = await fixture();
|
||||
for (const member of packedFiles)
|
||||
await expect(
|
||||
verifyPackedBridge({
|
||||
...input,
|
||||
tarball: join(input.workspace, "missing.tgz"),
|
||||
packedFiles: packedFiles.filter((path) => path !== member),
|
||||
}),
|
||||
).rejects.toThrow(`package omitted ${member}`);
|
||||
expect(await readdir(input.workspace)).toEqual([]);
|
||||
},
|
||||
);
|
||||
expect(await readdir(input.workspace)).toEqual([]);
|
||||
});
|
||||
|
||||
it("rejects a missing actual Python member even when the listing advertises it", async () => {
|
||||
const input = await fixture(validSource, true);
|
||||
|
||||
Reference in new issue
Block a user