Skip to content

armgit / qm

Public Imported from GitHub
0

Multiplayer agent harness for work.

Keep sandbox failure evidence instead of discarding it (#2351)

Regan Belldf1abd66c010
diff --git a/src/core/orchestrator/sandboxes.ts b/src/core/orchestrator/sandboxes.ts
index b6b002f2a..c539295e3 100644
--- a/src/core/orchestrator/sandboxes.ts
+++ b/src/core/orchestrator/sandboxes.ts
@@ -535,7 +535,10 @@ export function createTurnSandboxes(ctx: TurnSandboxContext) {
const visible = (await visibleSkillsForTurn()).flatMap((r) => (r.skill ? [r.skill, ...r.shadowed] : []));
const keep = new Set(visible.map((skill) => hashId([skill.id, String(skill.version)], 16)));
const stale = new Set<string>();
- for (const path of await deps.sandbox.listDir(handle, SKILLS_ROOT)) {
+ const listed = await deps.sandbox
+ .listDir(handle, SKILLS_ROOT)
+ .catch(swallowAs("orchestrator: list skills to prune", [] as string[]));
+ for (const path of listed) {
const [root, conversation, identity] = path.split("/");
if (root === SKILLS_ROOT && conversation && identity && !keep.has(identity))
stale.add(`${SKILLS_ROOT}/${conversation}/${identity}`);
@@ -552,7 +555,9 @@ export function createTurnSandboxes(ctx: TurnSandboxContext) {
? await deps.sandbox.removeDirAndList(handle, turnSessionDir, TURN_FILES_DIR)
: await (async () => {
await deps.sandbox.removeDir(handle, turnSessionDir);
- return deps.sandbox.listDir(handle, TURN_FILES_DIR);
+ return deps.sandbox
+ .listDir(handle, TURN_FILES_DIR)
+ .catch(swallowAs("orchestrator: list stale turn files", [] as string[]));
})();
const stale = new Set<string>();
for (const path of paths) {
diff --git a/src/processes/process-reaper.ts b/src/processes/process-reaper.ts
index 6c01a0054..3c90af5f6 100644
--- a/src/processes/process-reaper.ts
+++ b/src/processes/process-reaper.ts
@@ -4,7 +4,7 @@ import { createNoopLeaderLease, type LeaderLease } from "../persistence/leader-l
import { awaitProcessExit } from "../sandbox/await-process-exit.ts";
import { ProcessSessionGoneError } from "../sandbox/exec-process-session.ts";
import type { ProcessSandbox, SandboxHandle } from "../sandbox/sandbox.ts";
-import { errMessage } from "../util/errors.ts";
+import { errMessage, swallow } from "../util/errors.ts";
const PROCESS_REAPER_LEASE_KEY = "processes:reaper";
@@ -74,7 +74,8 @@ export function createProcessReaper(registry: ProcessRegistry, opts: ProcessReap
if (opts.kill) {
try {
await opts.kill(rec);
- } catch {
+ } catch (error) {
+ swallow(`process reaper: kill ${rec.processId}`, error);
continue;
}
}
diff --git a/src/sandbox/agent37-sandbox.ts b/src/sandbox/agent37-sandbox.ts
index ac5fd128b..587489113 100644
--- a/src/sandbox/agent37-sandbox.ts
+++ b/src/sandbox/agent37-sandbox.ts
@@ -420,11 +420,7 @@ export function createAgent37Sandbox(workspace: WorkspaceStore, opts: Agent37San
if (existing.status !== "running") await ensureRunning(existing.id);
return { coldStart: false };
}
- try {
- onStatus?.("Creating the sandbox…");
- } catch (error) {
- void error;
- }
+ onStatus?.("Creating the sandbox…");
const info = await createInstance(name);
idByName.set(name, info.id);
return { coldStart: true };
diff --git a/src/sandbox/e2b-sandbox.ts b/src/sandbox/e2b-sandbox.ts
index 239253f6a..f99c85089 100644
--- a/src/sandbox/e2b-sandbox.ts
+++ b/src/sandbox/e2b-sandbox.ts
@@ -197,11 +197,7 @@ export function createE2bSandbox(workspace: WorkspaceStore, opts: E2bSandboxOpti
if (stored?.nativePause) {
if (!stored.recoverySnapshotId)
throw new Error("e2b sandbox is gone; explicitly import a recovery snapshot before replacing its home");
- try {
- onStatus?.("Restoring the sandbox from its recovery snapshot…");
- } catch (error) {
- void error;
- }
+ onStatus?.("Restoring the sandbox from its recovery snapshot…");
let session: E2bSession;
try {
session = await client.create({
@@ -225,11 +221,7 @@ export function createE2bSandbox(workspace: WorkspaceStore, opts: E2bSandboxOpti
});
return adopt(session);
}
- try {
- onStatus?.("Creating the sandbox…");
- } catch (error) {
- void error;
- }
+ onStatus?.("Creating the sandbox…");
const session = await client.create({ metadata: { name }, autoPause: true });
sessionByName.set(name, session);
await store.put(scope, {
diff --git a/src/sandbox/exec-file-ops.ts b/src/sandbox/exec-file-ops.ts
index b03e396fb..0e24588b8 100644
--- a/src/sandbox/exec-file-ops.ts
+++ b/src/sandbox/exec-file-ops.ts
@@ -1,6 +1,6 @@
import { randomBytes } from "node:crypto";
import { shq } from "../util/shell.ts";
-import { swallowAs } from "../util/errors.ts";
+import { swallow, swallowAs } from "../util/errors.ts";
import { makeTar, parseTar } from "./tar.ts";
import { DISPLACED_DIR_REL } from "../credentials/resident-paths.ts";
import { proxyExportPrefix } from "./sandbox-env.ts";
@@ -49,6 +49,9 @@ export interface ExecFileOps {
removeDirAndList?(handle: SandboxHandle, removeRelDir: string, listRelDir: string): Promise<string[]>;
}
+const listFilesScript = (rootDir: string, rel: string): string =>
+ `cd ${shq(rootDir)} 2>/dev/null && [ -e ${shq(rel)} ] || exit 0; find ${shq(rel)} -type f`;
+
export function createExecFileOps({ label, exec, writeInline, combineRemoveAndList }: ExecFileOpsDeps): ExecFileOps {
return {
async importFiles(handle, entries): Promise<void> {
@@ -69,12 +72,8 @@ export function createExecFileOps({ label, exec, writeInline, combineRemoveAndLi
async listDir(handle, relDir): Promise<string[]> {
const rel = workspaceRel(relDir) || ".";
- const r = await exec(
- handle.id,
- `cd ${shq(handle.rootDir)} 2>/dev/null && find ${shq(rel)} -type f 2>/dev/null`,
- 60,
- );
- if (r.code !== 0) return [];
+ const r = await exec(handle.id, listFilesScript(handle.rootDir, rel), 60);
+ if (r.code !== 0) throw new Error(`${label} listDir failed (exit ${r.code}): ${r.stderr.trim()}`);
return r.stdout
.split("\n")
.map((s) => s.trim().replace(/^\.\//, ""))
@@ -89,10 +88,11 @@ export function createExecFileOps({ label, exec, writeInline, combineRemoveAndLi
const rel = workspaceRel(listRelDir) || ".";
const r = await exec(
handle.id,
- `${prep}listing=$(cd ${shq(handle.rootDir)} 2>/dev/null && find ${shq(rel)} -type f 2>/dev/null) && printf '%s\\n' "$listing"; exit 0`,
+ `${prep}listing=$(${listFilesScript(handle.rootDir, rel)}) || echo "listing exited $?" >&2; printf '%s\\n' "$listing"; exit 0`,
60,
);
if (r.code !== 0) throw new Error(`${label} removeDir ${removeRelDir} failed: ${r.stderr}`);
+ if (r.stderr.trim()) swallow(`${label} list ${listRelDir}`, new Error(r.stderr.trim()));
return r.stdout
.split("\n")
.map((s) => s.trim().replace(/^\.\//, ""))
diff --git a/src/sandbox/modal-client.ts b/src/sandbox/modal-client.ts
index 42524b688..7608461fd 100644
--- a/src/sandbox/modal-client.ts
+++ b/src/sandbox/modal-client.ts
@@ -24,14 +24,14 @@ export interface ModalSession {
terminate(): Promise<void>;
}
export class ModalSandboxGoneError extends Error {
- constructor(sandboxId: string, detail: string) {
- super(`modal sandbox ${sandboxId} is gone: ${detail}`);
+ constructor(sandboxId: string, detail: string, options?: ErrorOptions) {
+ super(`modal sandbox ${sandboxId} is gone: ${detail}`, options);
this.name = "ModalSandboxGoneError";
}
}
export class ModalNameConflictError extends Error {
- constructor(name: string, detail: string) {
- super(`modal sandbox name ${name} already taken: ${detail}`);
+ constructor(name: string, detail: string, options?: ErrorOptions) {
+ super(`modal sandbox name ${name} already taken: ${detail}`, options);
this.name = "ModalNameConflictError";
}
}
@@ -188,7 +188,8 @@ export function createSdkModalClient(opts: SdkModalClientOptions): ModalClient {
const [stdout, stderr, exitCode] = await Promise.all([p.stdout.readText(), p.stderr.readText(), p.wait()]);
return { stdout, stderr, exitCode };
} catch (err) {
- if (await hasExited(sdk, sbx, err)) throw new ModalSandboxGoneError(sbx.sandboxId, errText(err));
+ if (await hasExited(sdk, sbx, err))
+ throw new ModalSandboxGoneError(sbx.sandboxId, errText(err), { cause: err });
if (err instanceof sdk.TimeoutError || Date.now() >= deadlineAt)
return { stdout: "", stderr: errText(err), exitCode: 124 };
throw err;
@@ -204,7 +205,8 @@ export function createSdkModalClient(opts: SdkModalClientOptions): ModalClient {
`modal read ${absPath}: the file exceeds Modal's filesystem read limit; move it with blob staging or split it`,
{ cause: err },
);
- if (await hasExited(sdk, sbx, err)) throw new ModalSandboxGoneError(sbx.sandboxId, errText(err));
+ if (await hasExited(sdk, sbx, err))
+ throw new ModalSandboxGoneError(sbx.sandboxId, errText(err), { cause: err });
throw err;
}
},
@@ -212,7 +214,8 @@ export function createSdkModalClient(opts: SdkModalClientOptions): ModalClient {
try {
await sbx.filesystem.writeBytes(data, absPath);
} catch (err) {
- if (await hasExited(sdk, sbx, err)) throw new ModalSandboxGoneError(sbx.sandboxId, errText(err));
+ if (await hasExited(sdk, sbx, err))
+ throw new ModalSandboxGoneError(sbx.sandboxId, errText(err), { cause: err });
throw err;
}
},
@@ -251,7 +254,7 @@ export function createSdkModalClient(opts: SdkModalClientOptions): ModalClient {
return wrap(sdk, sbx);
} catch (err) {
if (err instanceof sdk.AlreadyExistsError)
- throw new ModalNameConflictError(createOpts.name ?? "(unnamed)", errText(err));
+ throw new ModalNameConflictError(createOpts.name ?? "(unnamed)", errText(err), { cause: err });
throw err;
}
},
@@ -264,7 +267,7 @@ export function createSdkModalClient(opts: SdkModalClientOptions): ModalClient {
return wrap(sdk, sbx);
} catch (err) {
if (err instanceof ModalSandboxGoneError) throw err;
- if (isSandboxIdLookupGone(sdk, err)) throw new ModalSandboxGoneError(sandboxId, errText(err));
+ if (isSandboxIdLookupGone(sdk, err)) throw new ModalSandboxGoneError(sandboxId, errText(err), { cause: err });
throw err;
}
},
@@ -282,6 +285,7 @@ export function createSdkModalClient(opts: SdkModalClientOptions): ModalClient {
if (exited !== null) return null;
} catch (err) {
if (isSandboxGoneError(sdk, err)) return null;
+ throw err;
}
return wrap(sdk, sbx);
},
diff --git a/src/sandbox/modal-sandbox.ts b/src/sandbox/modal-sandbox.ts
index 465878e18..406c93c54 100644
--- a/src/sandbox/modal-sandbox.ts
+++ b/src/sandbox/modal-sandbox.ts
@@ -251,6 +251,11 @@ export function createModalSandbox(workspace: WorkspaceStore, opts: ModalSandbox
lastActivityMs: Date.now(),
orgId: configOrgId(),
});
+ const terminateOrphan = (): Promise<unknown> =>
+ session.terminate().then(
+ () => store.merge(scope, { hydrationPending: false }),
+ (err: unknown) => reportError("sandbox_hydrate", "orphan_terminate_failed", errMessage(err), scope),
+ );
let hydrated: boolean;
try {
if (previous?.nativeSnapshotId) {
@@ -264,10 +269,7 @@ export function createModalSandbox(workspace: WorkspaceStore, opts: ModalSandbox
await store.merge(scope, { recoveryError: errMessage(e) });
reportError("sandbox_hydrate", "hydrate_failed", errMessage(e), scope);
sessionByName.delete(name);
- await session.terminate().then(
- () => store.merge(scope, { hydrationPending: false }),
- () => undefined,
- );
+ await terminateOrphan();
throw new Error(`modal provision: home hydration failed (${errMessage(e)}); not risking the stored snapshot`, {
cause: e,
});
@@ -275,10 +277,7 @@ export function createModalSandbox(workspace: WorkspaceStore, opts: ModalSandbox
const marked = await session.runCommand(`touch ${shq(HYDRATED_MARKER)}`, { timeoutMs: 30_000 });
if (marked.exitCode !== 0) {
sessionByName.delete(name);
- await session.terminate().then(
- () => store.merge(scope, { hydrationPending: false }),
- () => undefined,
- );
+ await terminateOrphan();
throw new Error(`modal provision: could not mark the sandbox hydrated: ${marked.stderr.slice(0, 200)}`);
}
await store.merge(scope, { hydrationPending: false });
@@ -361,7 +360,8 @@ export function createModalSandbox(workspace: WorkspaceStore, opts: ModalSandbox
}
}
sessionByName.delete(name);
- if (!(await store.get(scope))?.nativeSnapshotId) await store.delete(scope).catch(() => undefined);
+ if (!(await store.get(scope))?.nativeSnapshotId)
+ await store.delete(scope).catch(swallowAs("modal-sandbox: forget retired sandbox", undefined));
}
if (!stored) {
@@ -379,11 +379,7 @@ export function createModalSandbox(workspace: WorkspaceStore, opts: ModalSandbox
}
}
- try {
- onStatus?.("Creating the sandbox…");
- } catch (error) {
- void error;
- }
+ onStatus?.("Creating the sandbox…");
return createHydrated(scope, name);
});
}
@@ -444,7 +440,7 @@ export function createModalSandbox(workspace: WorkspaceStore, opts: ModalSandbox
const now = Date.now();
if (now - (lastTouchMs.get(scope) ?? 0) < ACTIVITY_TOUCH_INTERVAL_MS) return;
lastTouchMs.set(scope, now);
- await store.merge(scope, { lastActivityMs: now }).catch(() => undefined);
+ await store.merge(scope, { lastActivityMs: now }).catch(swallowAs("modal-sandbox: record activity", undefined));
}
async function runTimed(
@@ -624,7 +620,8 @@ export function createModalSandbox(workspace: WorkspaceStore, opts: ModalSandbox
} catch (e) {
if (e instanceof ModalSandboxGoneError) {
sessionByName.delete(name);
- if (!(await store.get(scope))?.nativeSnapshotId) await store.delete(scope).catch(() => undefined);
+ if (!(await store.get(scope))?.nativeSnapshotId)
+ await store.delete(scope).catch(swallowAs("modal-sandbox: forget retired sandbox", undefined));
} else {
reportError("sandbox_reap", "deep_idle_reap_failed", errMessage(e), scope);
}
@@ -896,10 +893,14 @@ export function createModalSandbox(workspace: WorkspaceStore, opts: ModalSandbox
await store.merge(scope, { lastActivityMs: Date.now() });
} catch (e) {
reportError("sandbox_snapshot", "teardown_snapshot_failed", errMessage(e), scope);
- await store.merge(scope, { lastActivityMs: Date.now() }).catch(() => undefined);
+ await store
+ .merge(scope, { lastActivityMs: Date.now() })
+ .catch(swallowAs("modal-sandbox: record activity", undefined));
}
} else {
- await store.merge(scope, { lastActivityMs: Date.now() }).catch(() => undefined);
+ await store
+ .merge(scope, { lastActivityMs: Date.now() })
+ .catch(swallowAs("modal-sandbox: record activity", undefined));
}
});
},
@@ -925,7 +926,8 @@ export function createModalSandbox(workspace: WorkspaceStore, opts: ModalSandbox
}
if (!session) {
sessionByName.delete(name);
- if (!rec.nativeSnapshotId) await store.delete(scope).catch(() => undefined);
+ if (!rec.nativeSnapshotId)
+ await store.delete(scope).catch(swallowAs("modal-sandbox: forget retired sandbox", undefined));
else if (checkpointRenewalDue(rec, now)) await renewCheckpoint(scope, name, rec);
continue;
}
@@ -942,7 +944,8 @@ export function createModalSandbox(workspace: WorkspaceStore, opts: ModalSandbox
} catch (e) {
if (e instanceof ModalSandboxGoneError) {
sessionByName.delete(name);
- if (!rec.nativeSnapshotId) await store.delete(scope).catch(() => undefined);
+ if (!rec.nativeSnapshotId)
+ await store.delete(scope).catch(swallowAs("modal-sandbox: forget retired sandbox", undefined));
} else {
reportError("sandbox_reap", "deep_idle_probe_failed", errMessage(e), scope);
}
diff --git a/src/sandbox/porter-sandbox.ts b/src/sandbox/porter-sandbox.ts
index f6eb50239..2f5375cba 100644
--- a/src/sandbox/porter-sandbox.ts
+++ b/src/sandbox/porter-sandbox.ts
@@ -187,11 +187,7 @@ export function createPorterSandbox(workspace: WorkspaceStore, opts: PorterSandb
bodies.delete(slug);
await retirePorterBody(existing.sb, true);
}
- try {
- onStatus?.("Starting your computer…");
- } catch (error) {
- void error;
- }
+ onStatus?.("Starting your computer…");
const ref = await createBody(slug, egressMode, { mountPath: homeDir, id: volume.id });
scopeByBody.set(ref.name, scope);
return { name: ref.name, coldStart: volume.created };
diff --git a/src/sandbox/sandbox-routing.ts b/src/sandbox/sandbox-routing.ts
index 906e72ec7..eb15be4c2 100644
--- a/src/sandbox/sandbox-routing.ts
+++ b/src/sandbox/sandbox-routing.ts
@@ -165,7 +165,9 @@ export function createSandboxRouter(opts: RoutingSandboxOptions): Sandbox {
const sandbox = forHandle(handle);
if (sandbox.removeDirAndList) return sandbox.removeDirAndList(handle, removeRelDir, listRelDir);
await sandbox.removeDir(handle, removeRelDir);
- return sandbox.listDir(handle, listRelDir);
+ return sandbox
+ .listDir(handle, listRelDir)
+ .catch(swallowAs(`sandbox-routing: list ${listRelDir}`, [] as string[]));
});
},
teardown(handle, tdOpts?: TeardownOptions): Promise<void> {
diff --git a/src/sandbox/smolmachines-sandbox.ts b/src/sandbox/smolmachines-sandbox.ts
index c95af4ef6..16f3f00a7 100644
--- a/src/sandbox/smolmachines-sandbox.ts
+++ b/src/sandbox/smolmachines-sandbox.ts
@@ -402,11 +402,7 @@ export function createSmolmachinesSandbox(workspace: WorkspaceStore, opts: Smolm
return { coldStart: false };
}
await mergeStored(scope, { initializationPending: true });
- try {
- onStatus?.("Preparing the sandbox…");
- } catch (error) {
- void error;
- }
+ onStatus?.("Preparing the sandbox…");
try {
const info = existing ?? (await createMachine(name, false)).info;
idByName.set(name, info.id);
diff --git a/src/sandbox/sprites-sandbox.ts b/src/sandbox/sprites-sandbox.ts
index 805466cc1..db25b6256 100644
--- a/src/sandbox/sprites-sandbox.ts
+++ b/src/sandbox/sprites-sandbox.ts
@@ -67,6 +67,11 @@ function parsePressure(ioFull10Raw: string, ioFull60Raw: string, load1Raw: strin
};
}
+function withoutSdkUrl(message: string): string {
+ const url = message.lastIndexOf(" (url: ");
+ return url < 0 ? message : message.slice(0, url);
+}
+
export function spritesErrorDetail(e: unknown): string {
if (!(e instanceof APIError)) return errMessage(e);
const parts = [e.message];
@@ -194,13 +199,7 @@ export function createSpritesSandbox(workspace: WorkspaceStore, opts: SpritesSan
const phase = submissionStarted ? "script submission started; execution unknown" : "script not submitted";
reject(new Error(`sprites exec: WebSocket error (${phase}): ${detail}`));
};
- cmd.on("error", (e) => {
- const detail =
- /^(?:WebSocket error: )?(TypeError|ECONNRESET|ECONNREFUSED|ENOTFOUND|EAI_AGAIN|ETIMEDOUT|connection reset by peer|Received network error or non-101 status code|WebSocket closed before open)\b/.exec(
- errMessage(e),
- )?.[1] ?? "unknown transport error";
- fail(detail);
- });
+ cmd.on("error", (e) => fail(withoutSdkUrl(e.message)));
cmd.once("exit", (code) => {
if (code < 0) fail("connection closed without an exit status");
else resolve(code);
@@ -468,11 +467,7 @@ export function createSpritesSandbox(workspace: WorkspaceStore, opts: SpritesSan
return { coldStart: false };
}
await initializationStore.put(name, { pending: true });
- try {
- onStatus?.("Preparing the sandbox…");
- } catch (error) {
- void error;
- }
+ onStatus?.("Preparing the sandbox…");
const scope = base.scopeFor(name);
try {
if (!exists) await attempt(`create ${name}`, () => client.createSprite(name, { waitForCapacity: true }));
@@ -637,12 +632,13 @@ export function createSpritesSandbox(workspace: WorkspaceStore, opts: SpritesSan
};
let guestResponsive = false;
let pressure: ExecPressure | undefined;
+ let probeError: string | undefined;
try {
const probe = await execRaw(name, "true", GUEST_PROBE_TIMEOUT_SEC);
guestResponsive = probe.code === 0;
pressure = probe.pressure;
} catch (e) {
- void e;
+ probeError = errMessage(e);
}
return {
machine,
@@ -650,6 +646,7 @@ export function createSpritesSandbox(workspace: WorkspaceStore, opts: SpritesSan
guestResponsive,
recovery,
...(pressure ? { pressure } : {}),
+ ...(probeError ? { probeError } : {}),
};
},
diff --git a/src/sandbox/superserve-sandbox.ts b/src/sandbox/superserve-sandbox.ts
index 61ce73036..ab73a219d 100644
--- a/src/sandbox/superserve-sandbox.ts
+++ b/src/sandbox/superserve-sandbox.ts
@@ -350,11 +350,7 @@ export function createSuperserveSandbox(workspace: WorkspaceStore, opts: Superse
}
}
- try {
- onStatus?.("Creating the sandbox…");
- } catch (error) {
- void error;
- }
+ onStatus?.("Creating the sandbox…");
const session = await client.create({
name,
metadata: await scopeMetadata(name),
diff --git a/test/exec-file-ops.test.ts b/test/exec-file-ops.test.ts
index 712656f26..3a1c2a606 100644
--- a/test/exec-file-ops.test.ts
+++ b/test/exec-file-ops.test.ts
@@ -134,3 +134,29 @@ test("concurrent imports keep separate archives through extraction and cleanup",
await rm(rootDir, { recursive: true, force: true });
}
});
+
+test("listDir lists nothing for a missing directory but surfaces a failed listing", async () => {
+ const rootDir = await mkdtemp(join(tmpdir(), "qm-list-"));
+ let failing = false;
+ const ops = createExecFileOps({
+ label: "test",
+ exec: async (_id, script) => {
+ if (failing) return { code: 124, stdout: "", stderr: "timed out" };
+ return exec("sh", ["-c", script]).then(
+ (r) => ({ ...r, code: 0 }),
+ (e: { code: number; stdout: string; stderr: string }) => ({ code: e.code, stdout: e.stdout, stderr: e.stderr }),
+ );
+ },
+ writeInline: async () => {},
+ });
+ try {
+ await mkdir(join(rootDir, "d"), { recursive: true });
+ await writeFile(join(rootDir, "d/f"), "x");
+ assert.deepEqual(await ops.listDir({ id: "test", rootDir }, "d"), ["d/f"]);
+ assert.deepEqual(await ops.listDir({ id: "test", rootDir }, "missing"), []);
+ failing = true;
+ await assert.rejects(ops.listDir({ id: "test", rootDir }, "d"), /test listDir failed \(exit 124\): timed out/);
+ } finally {
+ await rm(rootDir, { recursive: true, force: true });
+ }
+});
diff --git a/test/sandbox-routing.test.ts b/test/sandbox-routing.test.ts
index f9d719fe9..7acbcaa09 100644
--- a/test/sandbox-routing.test.ts
+++ b/test/sandbox-routing.test.ts
@@ -423,3 +423,17 @@ for (const combined of [true, false]) {
assert.deepEqual(calls, combined ? ["combined:old:keep"] : ["remove:old", "list:keep"]);
});
}
+
+test("removeDirAndList keeps the removal strict but treats a failed listing as nothing to clean", async () => {
+ const r = resource("r1", "sprites");
+ const { router, sprites } = build({ "personal:a": r });
+ const h = await router.provision(layersFor("personal:a"));
+ sprites.listDir = async () => {
+ throw new Error("find: Permission denied");
+ };
+ assert.deepEqual(await router.removeDirAndList!(h, "turn/current", "turn"), []);
+ sprites.removeDir = async () => {
+ throw new Error("rm: read-only file system");
+ };
+ await assert.rejects(router.removeDirAndList!(h, "turn/current", "turn"), /read-only file system/);
+});
diff --git a/test/sprites-sandbox.test.ts b/test/sprites-sandbox.test.ts
index 1b27a054e..a742744ef 100644
--- a/test/sprites-sandbox.test.ts
+++ b/test/sprites-sandbox.test.ts
@@ -472,7 +472,7 @@ for (const submitted of [false, true]) {
}
}
-test("exec diagnostics retain known transport reasons without raw error causes", async (t) => {
+test("exec diagnostics keep the provider's transport reason but not its URL or raw cause", async (t) => {
const h = await sandbox.provision(layers);
let reason = "";
t.mock.method(SpriteCommand.prototype, "start", async () => {
@@ -483,7 +483,7 @@ test("exec diagnostics retain known transport reasons without raw error causes",
for (reason of ["TypeError", "unclassified provider failure"]) {
await assert.rejects(sandbox.run(h, "echo ignored"), (error: Error) => {
assert.match(error.message, /script not submitted/);
- assert.ok(error.message.endsWith(reason === "TypeError" ? "TypeError" : "unknown transport error"));
+ assert.ok(error.message.endsWith(`WebSocket error: ${reason}`));
assert.doesNotMatch(inspect(error), /example-secret|example\.invalid|token=/);
return true;
});