mirror of
https://github.com/morluto/rea.git
synced 2026-11-16 19:53:50 +00:00
The case checks that a one-shot CLI exits after a retained-cleanup failure and that the operating system then releases the Hopper target lease to a retry. Since #10412, `cli.run` serves plain commands on the file's shared CLI process. That process keeps the lease, as the cleanup-ownership rules require while cleanup is incomplete, and never exits between commands, so the retry was refused as "already open" and the final lease check failed on macOS. Run both attempts with `freshProcess: true`, which the fixture provides for process-exit facts. The case is macOS-only because target leases are taken only on the macOS launcher route, and no CI lane ran it, so add it to the Apple lane and its change scope.
111 lines
3.6 KiB
TypeScript
111 lines
3.6 KiB
TypeScript
import { chmod, copyFile, rm } from "node:fs/promises";
|
|
|
|
import { describe, expect } from "vitest";
|
|
import { z } from "zod";
|
|
|
|
import { workspaceCliTest } from "../../support/cli/workspaceCliFixture.js";
|
|
|
|
import { acquireHopperTargetLease } from "../../../src/process/HopperLease.js";
|
|
|
|
const FAILED_LAUNCHER = `#!/bin/sh
|
|
printf 'Cannot launch Hopper!\\nDocument state is unknown.\\n' >&2
|
|
exit 2
|
|
`;
|
|
|
|
/** The private runtime directory a failed launch reports as retained. */
|
|
const RetainedRuntime = z.object({
|
|
details: z.object({
|
|
diagnostics: z.object({
|
|
cleanup_error: z.object({
|
|
details: z.object({
|
|
diagnostics: z.object({ runtime_root: z.string() }),
|
|
}),
|
|
}),
|
|
}),
|
|
}),
|
|
});
|
|
|
|
describe("Hopper launcher failure through the one-shot CLI", () => {
|
|
// Hopper target leases are acquired only for the macOS launcher route.
|
|
workspaceCliTest.skipIf(process.platform !== "darwin")(
|
|
"exits after a retained-cleanup failure and releases the target to a retry",
|
|
async ({ cli, workspace }) => {
|
|
const launcherPath = await workspace.write(
|
|
"failure-helper",
|
|
FAILED_LAUNCHER,
|
|
);
|
|
await chmod(launcherPath, 0o700);
|
|
const targetPath = workspace.path("probe");
|
|
await copyFile("/usr/bin/true", targetPath);
|
|
const loaderArgs = ["--probe"];
|
|
try {
|
|
for (const attempt of ["first", "retry"]) {
|
|
// The one-shot CLI keeps the lease while cleanup is incomplete, and
|
|
// the operating system releases it when that process exits. The
|
|
// file's shared process does not exit between commands, so each
|
|
// attempt needs its own process.
|
|
const result = await cli.run({
|
|
freshProcess: true,
|
|
arguments: [
|
|
"analyze",
|
|
targetPath,
|
|
"--provider",
|
|
"hopper",
|
|
"--json",
|
|
],
|
|
environment: {
|
|
...workspace.environment,
|
|
HOPPER_LAUNCHER_PATH: launcherPath,
|
|
HOPPER_LOADER_ARGS_JSON: JSON.stringify(loaderArgs),
|
|
REA_LOG_LEVEL: "silent",
|
|
},
|
|
});
|
|
const retained = RetainedRuntime.safeParse(result.json);
|
|
if (retained.success)
|
|
await rm(
|
|
retained.data.details.diagnostics.cleanup_error.details
|
|
.diagnostics.runtime_root,
|
|
{ recursive: true, force: true },
|
|
);
|
|
|
|
expect(result.exitCode, attempt).toBe(1);
|
|
expect(
|
|
result.json,
|
|
`${attempt}: ${JSON.stringify(result.json)}`,
|
|
).toMatchObject({
|
|
code: "cleanup_incomplete",
|
|
details: {
|
|
cleanup: "incomplete",
|
|
diagnostics: {
|
|
primary_error: {
|
|
code: "provider_unavailable",
|
|
details: {
|
|
stage: "launch",
|
|
launcher: {
|
|
exit_code: 2,
|
|
stderr: {
|
|
text: expect.stringContaining(
|
|
"Document state is unknown",
|
|
),
|
|
},
|
|
},
|
|
},
|
|
},
|
|
},
|
|
},
|
|
});
|
|
}
|
|
} finally {
|
|
const recovered = await acquireHopperTargetLease({
|
|
targetPath,
|
|
targetKind: "executable",
|
|
loaderArgs,
|
|
runId: "failed-cli-test-cleanup",
|
|
});
|
|
expect(recovered.acquired).toBe(true);
|
|
if (recovered.acquired) await recovered.lease.release();
|
|
}
|
|
},
|
|
);
|
|
});
|