Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions src/lib/adapters/openshell/grpc-sandbox-control.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -205,15 +205,15 @@ describe("gRPC OpenShell sandbox control", () => {
).toEqual(["printf", boundaryArgument]);
});

it("resolves a sandbox id and normalizes streamed output", async () => {
it("resolves a sandbox id and preserves exit status 255 with normalized output", async () => {
const euro = Buffer.from("€");
const fake = fakeApi({
emit(stream) {
stream.emit("data", { stdout: { data: Buffer.from("hello ") } });
stream.emit("data", { stdout: { data: euro.subarray(0, 1) } });
stream.emit("data", { stdout: { data: euro.subarray(1) } });
stream.emit("data", { stderr: { data: Buffer.from("warning\n") } });
stream.emit("data", { exit: { exitCode: 7 } });
stream.emit("data", { exit: { exitCode: 255 } });
stream.emit("end");
},
});
Expand All @@ -229,7 +229,7 @@ describe("gRPC OpenShell sandbox control", () => {
stdin: "request body",
}),
).resolves.toEqual({
status: 7,
status: 255,
stdout: "hello €",
stderr: "warning\n",
});
Expand Down
6 changes: 3 additions & 3 deletions src/lib/adapters/openshell/sandbox-control.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -226,10 +226,10 @@ describe("OpenShell exec request validation", () => {
});

describe("CLI OpenShell sandbox control", () => {
it("maps a typed exec request to the existing CLI contract", async () => {
it("maps a typed exec request and preserves exit status 255", async () => {
const capture = vi.fn(
(): CaptureOpenshellBinaryResult => ({
status: 0,
status: 255,
stdout: Buffer.from("hello\n"),
stderr: Buffer.from("warning\n"),
}),
Expand All @@ -253,7 +253,7 @@ describe("CLI OpenShell sandbox control", () => {
},
);
expect(result).toEqual({
status: 0,
status: 255,
stdout: "hello\n",
stderr: "warning\n",
});
Expand Down
8 changes: 4 additions & 4 deletions src/lib/state/sandbox-backup-grpc.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -510,9 +510,9 @@ describe("backupSandboxState OpenShell directory transport", () => {
});

it.each([
["error", { error: new Error("sandbox exec stream reset") }],
["signal", { signal: "SIGTERM" as const }],
])("rejects tar bytes returned with a transport %s even when tar reports success", async (_failureKind, transportFailure) => {
["transport error", { error: new Error("sandbox exec stream reset") }, true],
["stale signal", { signal: "SIGTERM" as const }, false],
])("rejects tar bytes returned with a %s even when tar reports success", async (_failureKind, transportFailure, expectedUnreachable) => {
const { archive } = createBinaryTarArchive();
queueSuccessfulProbeAndAudit();
mocks.execSandboxReadOnlyWithGrpcFallback.mockResolvedValueOnce({
Expand All @@ -525,7 +525,7 @@ describe("backupSandboxState OpenShell directory transport", () => {

expect(result).toMatchObject({
success: false,
unreachable: true,
unreachable: expectedUnreachable,
backedUpDirs: [],
failedDirs: ["state"],
});
Expand Down
28 changes: 28 additions & 0 deletions src/lib/state/sandbox-state-file-backup.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -166,12 +166,40 @@ describe("state-file backup exec request", () => {

expect(isSandboxExecTransportFailure({ status: null, error: outputLimit })).toBe(false);
expect(isSandboxExecTransportFailure({ status: null, error: invalidRequest })).toBe(false);
expect(isSandboxExecTransportFailure({ status: 255 })).toBe(false);
expect(isSandboxExecTransportFailure({ status: 0, signal: "SIGKILL" })).toBe(false);
expect(isSandboxExecTransportFailure({ status: 1, signal: "SIGINT" })).toBe(false);
expect(isSandboxExecTransportFailure({ status: null })).toBe(true);
expect(isSandboxExecTransportFailure({ status: null, error: new Error("UNAVAILABLE") })).toBe(
true,
);
expect(isSandboxExecTransportFailure({ status: null, signal: "SIGKILL" })).toBe(true);
});

it.each([
["a non-zero status", "terminal-status", { status: 255, stdout: "", stderr: "" }],
[
"a terminal signal",
"terminal-signal",
{ status: 0, stdout: "", stderr: "", signal: "SIGKILL" as const },
],
])("keeps state-file backup failure from %s reachable without persisting bytes", async (_failureKind, backupName, execResult) => {
execReadOnly.mockResolvedValue(execResult);

const result = await backupSandboxState("hermes", { name: backupName });

expect(result).toMatchObject({
success: false,
backedUpFiles: [],
failedFiles: ["runtime/state.db"],
unreachable: false,
});
expect(execReadOnly).toHaveBeenCalledTimes(1);
expect(fs.existsSync(path.join(result.manifest!.backupPath, "runtime", "state.db"))).toBe(
false,
);
});

it("persists binary state-file bytes with private mode and complete backup bookkeeping", async () => {
const bytes = Buffer.from([0x53, 0x51, 0x4c, 0x00, 0xff, 0xfe, 0x80, 0x0a]);
execReadOnly.mockResolvedValue({
Expand Down
8 changes: 4 additions & 4 deletions src/lib/state/sandbox.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1081,9 +1081,11 @@ export function isSandboxExecTransportFailure(result: {
const code = (result.error as NodeJS.ErrnoException | undefined)?.code;
// Both transports use ENOBUFS for the shared raw-output cap. The canonical
// request validator uses OPENSHELL_EXEC_INVALID_ARGUMENT. Neither can be
// repaired by retrying or by treating the sandbox as unreachable.
// repaired by retrying or by treating the sandbox as unreachable. OpenShell
// status 255 and stale signal fields are terminal remote results, not SSH
// transport conventions.
if (code === "ENOBUFS" || code === "OPENSHELL_EXEC_INVALID_ARGUMENT") return false;
return Boolean(result.error || result.signal || result.status === null);
return Boolean(result.error || result.status === null);
}

/** @internal Pin the binary state-file result contract independently of filesystem writes. */
Expand Down Expand Up @@ -1146,8 +1148,6 @@ async function backupStateFile(
* Uses the agent manifest to determine which directories contain state.
*/

export { isSshTransportFailure } from "./ssh-transport.js";

export async function backupSandboxState(
sandboxName: string,
options: BackupOptions = {},
Expand Down
42 changes: 0 additions & 42 deletions src/lib/state/ssh-transport.test.ts

This file was deleted.

33 changes: 0 additions & 33 deletions src/lib/state/ssh-transport.ts

This file was deleted.