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
28 changes: 24 additions & 4 deletions packages/e2e/docs/coverage/sandbox.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ Status values are defined in the [coverage index](../coverage-matrix.md#status-l
- Surface: External dependency: sandboxing
- Status: `partial`
- Evidence: `tests/local/sandbox.test.ts` (single harness: native for claude-code, nono for goose; `claude-code,opencode` chain: per-harness doctor decision, native for claude-code, nono for opencode when installed, unsandboxed warning for opencode when nono is off `PATH`, docker never picked even with a ready stub `sbx`); `tests/local/sandbox-auto-chain-worker.test.ts` (real `devintern worker`, `claude-code,opencode` chain: the usage-limited claude-code stub runs with native's `--settings` file, the worker fails over and opencode completes the task under nono when installed, or unsandboxed with the documented warning when nono is off `PATH`; the doctor in the same environment names the same decisions; the stub `sbx` only answers detection); `tests/local/sandbox-auto-preferred-cannot-start.test.ts` (a `nono` on `PATH` whose `run` always fails: doctor and one-shot run); run with `bun run --filter @devintern/e2e test`
- Missing: Native harness path. A worker (rather than one-shot) run when the preferred provider cannot start. Observed (unconfirmed intent): when nono is on `PATH` but cannot start, `auto` still picks it (detection only checks `PATH`), `devintern sandbox` exits non-zero with nono's error in the harness preflight, and a one-shot run fails closed before the agent runs, with no fallback to another provider or to an unsandboxed run; it prints `🔒 Agent sandbox: nono (kernel sandbox)` before the start error. The docs do not say which outcome is intended, so the test asserts only that the agent never runs outside a sandbox without the unsandboxed warning and that the doctor's exit status matches the run. Observed (unconfirmed intent): in the worker chain the CLI's own `opencode --version` flag-detection probe runs outside nono (the readiness probe and the agent run are inside); the test leaves that probe unasserted.
- Last reviewed: 2026-12-01
- Missing: Native harness path. The worker case is covered by its own row at the end of this file. Observed (unconfirmed intent): when nono is on `PATH` but cannot start, `auto` still picks it (detection only checks `PATH`), `devintern sandbox` exits non-zero with nono's error in the harness preflight, and a one-shot run fails closed before the agent runs, with no fallback to another provider or to an unsandboxed run; it prints `🔒 Agent sandbox: nono (kernel sandbox)` before the start error. The docs do not say which outcome is intended, so the test asserts only that the agent never runs outside a sandbox without the unsandboxed warning and that the doctor's exit status matches the run. Observed (unconfirmed intent): in the worker chain the CLI's own `opencode --version` flag-detection probe runs outside nono (the readiness probe and the agent run are inside); the test leaves that probe unasserted.
- Last reviewed: 2026-12-04

### `native` provider (claude-code, codex)

Expand Down Expand Up @@ -77,8 +77,8 @@ Status values are defined in the [coverage index](../coverage-matrix.md#status-l
- Surface: External dependency: sandboxing
- Status: `default`
- Evidence: `tests/local/sandbox-harness-chain-worker.test.ts` (real `devintern worker`, `AGENT_SANDBOX=native`, `AGENT_HARNESS=claude-code,opencode`, usage-limited claude-code stub, recording opencode stub); run with `bun run --filter @devintern/e2e test`
- Missing: The same rule for `docker` and for a fallback that becomes unwrappable after startup. The worker spawns the primary stub once at startup as a readiness probe under the sandbox; the test only requires at least one primary spawn.
- Last reviewed: 2026-11-27
- Missing: A fallback that becomes unwrappable after startup. `docker` is covered by the row at the end of this file (fallback `goose`, which sbx cannot wrap). The worker spawns the primary stub once at startup as a readiness probe under the sandbox; the test only requires at least one primary spawn.
- Last reviewed: 2026-12-04

### One-shot task run with a chain uses only the first entry under an explicit provider

Expand All @@ -88,6 +88,22 @@ Status values are defined in the [coverage index](../coverage-matrix.md#status-l
- Missing: PR-review and interactive runs with a chain. Observed (unconfirmed intent): before the sandbox check fails closed, the one-shot run executes the first entry's CLI once with `--version` (version detection) outside any sandbox. No agent argv reaches it, and the test leaves that probe unasserted.
- Last reviewed: 2026-11-27

### Worker run with AGENT_SANDBOX=auto when the preferred provider cannot start

- Surface: External dependency: sandboxing
- Status: `default`
- Evidence: `tests/local/sandbox-auto-preferred-cannot-start-worker.test.ts` (real `devintern worker`, `AGENT_HARNESS=opencode`, a `nono` stub that answers `--version` but fails every `run`, recording opencode stub); run with `bun run --filter @devintern/e2e test`
- Missing: Whether a notification is raised for the repeated start failure (not asserted). Observed (unconfirmed intent): the worker fails closed. The agent never runs, the run is recorded as `deferred` (not failed) with nono's start error as its reason, the task row returns to `pending`, nothing is pushed, and the daemon stays up. Later polls retry the task (the log shows start attempt 2/5, then a 2 minute cooldown for the harness). The docs do not say whether a deferral or a failure is intended for a broken provider.
- Last reviewed: 2026-12-04

### Explicit `docker` provider in a worker failover chain skips a fallback it cannot wrap

- Surface: External dependency: sandboxing
- Status: `default`
- Evidence: `tests/local/sandbox-docker-chain-worker.test.ts` (real `devintern worker`, `AGENT_SANDBOX=docker`, `AGENT_HARNESS=claude-code,goose`, stub `sbx` whose `exec` prints a usage limit, recording goose stub); run with `bun run --filter @devintern/e2e test`
- Missing: A fallback that becomes unwrappable after startup. docker wraps only claude-code, codex, cursor, gemini, and opencode, so `goose` is the unwrappable entry. The task is requeued with a `deferred` run, goose never spawns, and nothing is pushed.
- Last reviewed: 2026-12-04

## Backlog

Priority numbers are the global ranking from the
Expand Down Expand Up @@ -250,3 +266,7 @@ pass `--agent-path`, so opencode resolves through `OPENCODE_CLI_PATH`.
bun run --filter @getdevintern/code build
bun run --filter @devintern/e2e test
```

### Worker sandbox fail-closed tests

- `tests/local/sandbox-auto-preferred-cannot-start-worker.test.ts` and `tests/local/sandbox-docker-chain-worker.test.ts`: run with `bun run --filter @devintern/e2e test` after `bun run --filter @getdevintern/code build`. They start the real built worker with stub `nono`, `sbx`, `bwrap`, and harness CLIs on `PATH`; no real sandbox binary, agent account, or network is needed. The docker test keeps its fixture root outside the OS temp dir because docker refuses `/tmp` worktrees.
Original file line number Diff line number Diff line change
@@ -0,0 +1,134 @@
/**
* A real `devintern worker` with `AGENT_SANDBOX=auto` when the provider `auto`
* prefers (nono, for opencode) is installed but cannot start.
*
* The one-shot twin is `sandbox-auto-preferred-cannot-start.test.ts`. Here a
* `nono` stub on `PATH` answers `--version` but fails every `nono run`, the
* harness is a recording opencode stub, and one task is queued. The test
* asserts what must hold whichever way the product decides: the agent never
* runs outside a sandbox without the documented unsandboxed warning, nothing
* is pushed when the agent never ran, and the run settles as a visible failure
* rather than a silent success. No real sandbox binary, agent, or network.
*/

import { expect, test } from "bun:test";
import { existsSync, mkdirSync, readFileSync } from "node:fs";
import { delimiter, join } from "node:path";
import { pathWithoutProvider, runtimeBinDir, stubExecutable } from "../../helpers/sandbox";
import { cliPath, WorkerFixture } from "../../helpers/worker";

const NONO_START_ERROR = "nono: Sandbox initialization failed: e2e stub cannot start";

function lines(path: string): string[] {
return existsSync(path) ? readFileSync(path, "utf8").split("\n").filter(Boolean) : [];
}

test.skipIf(!existsSync(cliPath))(
"a worker with auto and an installed nono that cannot start never runs the agent unsandboxed silently",
async () => {
const worker = new WorkerFixture({ env: { AGENT_SANDBOX: "auto" } });
try {
await worker.prepare();
const bin = join(worker.root, "stub-bin");
mkdirSync(bin, { recursive: true });
const nonoLog = join(worker.root, "nono-calls.txt");
const opencodeLog = join(worker.root, "opencode-calls.txt");
stubExecutable(
bin,
"nono",
[
"#!/bin/sh",
`printf '%s\\n' "$*" >> "${nonoLog}"`,
'if [ "${1:-}" = "--version" ]; then echo "nono 0.0.0-e2e-stub"; exit 0; fi',
`echo "${NONO_START_ERROR}" >&2`,
"exit 1",
"",
].join("\n"),
);
// native is available but cannot wrap opencode, so nono is preferred.
stubExecutable(bin, "bwrap", "#!/bin/sh\nexit 0\n");
const opencode = stubExecutable(
bin,
"opencode",
[
"#!/bin/sh",
"nono=no",
'if [ -n "${NONO_CAP_FILE:-}" ] && [ -f "$NONO_CAP_FILE" ]; then nono=yes; fi',
`printf '%s nono=%s\\n' "\${1:-}" "$nono" >> "${opencodeLog}"`,
'if [ "${1:-}" = "--version" ]; then echo "1.0.0"; exit 0; fi',
"exit 0",
"",
].join("\n"),
);
worker.env.PATH = [
bin,
pathWithoutProvider("nono", [runtimeBinDir(), worker.env.PATH ?? ""].join(delimiter)),
].join(delimiter);
delete worker.env.AGENT_CLI_PATH;
worker.env.AGENT_HARNESS = "opencode";
worker.env.OPENCODE_CLI_PATH = opencode;

const task = await worker.addTask({
title: "Auto sandbox with a nono that cannot start",
body: "Change the greeting to Hello, world! and run bun test.",
});
worker.start();
await worker.waitForReady();
// Observed: a harness that cannot start is deferred, not failed. The row
// goes back to pending with a deferred run, and later polls retry it.
const settled = await worker.waitFor(
`injected task #${task.id} to be deferred after the start failure`,
() => {
const current = worker.injectedTask(task.id);
return current?.status === "pending" &&
worker.runRecords(task.task_key).some((run) => run.status === "deferred")
? current
: undefined;
},
60_000,
);
const runs = worker.runRecords(task.task_key);
const agentSpawns = lines(opencodeLog).filter((call) => !call.startsWith("--version "));
const diagnostics = [
`injected task #${task.id} settled as "${settled.status}": ${settled.message ?? ""}`,
`runs: ${JSON.stringify(runs)}`,
`opencode agent spawns: ${JSON.stringify(agentSpawns)}`,
`nono calls: ${JSON.stringify(lines(nonoLog))}`,
worker.tail(),
].join("\n");

// Never a silent unsandboxed run.
const unsandboxed = agentSpawns.filter((call) => call.endsWith("nono=no"));
if (unsandboxed.length > 0) {
expect(worker.logs, diagnostics).toContain("running the agent unsandboxed");
}
// nono was really asked to start (not just probed with --version).
expect(
lines(nonoLog).some((call) => call.startsWith("run ")),
diagnostics,
).toBe(true);

// Observed today: fail closed. The agent never runs, the run is a visible
// deferral naming nono's start error, and nothing is pushed.
expect(agentSpawns, diagnostics).toEqual([]);
expect(settled.status, diagnostics).toBe("pending");
expect(
runs.every((run) => run.status === "deferred"),
diagnostics,
).toBe(true);
expect(runs[0]?.outcome_reason ?? "", diagnostics).toContain(NONO_START_ERROR);
expect(
runs.some((run) => run.status === "succeeded"),
diagnostics,
).toBe(false);
expect(worker.logs, diagnostics).toContain(NONO_START_ERROR);
expect(worker.logs, diagnostics).not.toContain("running the agent unsandboxed");
expect(await worker.remoteBranches(), diagnostics).toEqual([worker.baseBranch]);
// The daemon stays up after the failed run.
expect(worker.running, diagnostics).toBe(true);
} finally {
await worker.dispose();
}
},
120_000,
);
105 changes: 105 additions & 0 deletions packages/e2e/tests/local/sandbox-docker-chain-worker.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
/**
* An explicit `docker` provider in a worker `AGENT_HARNESS` failover chain.
*
* Twin of `sandbox-harness-chain-worker.test.ts` for `AGENT_SANDBOX=docker`
* with chain `claude-code,goose`. Docker (`sbx`) wraps only claude-code, codex,
* cursor, gemini, and opencode, so goose is a fallback it cannot wrap. A stub
* `sbx` answers detection, accepts create/rm, and makes every `sbx exec` print
* a usage limit (standing in for the in-guest claude). The recording goose
* stub must never spawn, and the task must not complete. No real sandbox
* binary, agent, account, or network access is involved.
*/

import { expect, test } from "bun:test";
import { existsSync, mkdirSync, readFileSync } from "node:fs";
import { delimiter, join } from "node:path";
import { configureFailover, invocationCount, stubDiagnostics } from "../../helpers/harness-stubs";
import { createSandboxHome, stubExecutable } from "../../helpers/sandbox";
import { cliPath, WorkerFixture } from "../../helpers/worker";

test.skipIf(!existsSync(cliPath))(
"an explicit docker provider skips a goose fallback it cannot wrap in a worker chain",
async () => {
// Docker refuses worktrees under the OS temp dir, so keep the root outside it.
const root = createSandboxHome("devintern-e2e-docker-chain-");
const temp = join(root, "tmp", "T");
mkdirSync(temp, { recursive: true });
const worker = new WorkerFixture({ root, env: { AGENT_SANDBOX: "docker", TMPDIR: temp } });
try {
await worker.prepare();
const stubBin = join(worker.root, "sbx-stub");
mkdirSync(stubBin, { recursive: true });
const sbxLog = join(worker.root, "sbx-calls.txt");
stubExecutable(
stubBin,
"sbx",
[
"#!/bin/sh",
`printf '%s\\n' "$*" >> "${sbxLog}"`,
'if [ "${1:-}" = "exec" ]; then',
' case " $* " in *" --version "*) echo "1.0.0"; exit 0 ;; esac',
"cat >&2 <<'E2E_USAGE_LIMIT'",
"Claude usage limit reached",
"resets in 1 hour",
"E2E_USAGE_LIMIT",
" exit 1",
"fi",
'echo "stub"',
"exit 0",
"",
].join("\n"),
);
worker.env.PATH = [stubBin, worker.env.PATH].join(delimiter);
const stubs = configureFailover(worker, { fallbackHarness: "goose" });
expect(worker.env.AGENT_HARNESS).toBe("claude-code,goose");
const task = await worker.addTask({
title: "Docker skips an unwrappable fallback",
body: "Change the greeting to Hello, world! and run bun test.",
});

worker.start();
await worker.waitForReady();
const sbxCalls = () =>
existsSync(sbxLog) ? readFileSync(sbxLog, "utf8").split("\n").filter(Boolean) : [];
const diagnostics = stubDiagnostics(worker, stubs, () => [
`injected row: ${JSON.stringify(worker.injectedTask(task.id))}`,
`runs: ${JSON.stringify(worker.runRecords(task.task_key))}`,
`sbx calls: ${JSON.stringify(sbxCalls())}`,
]);

await worker.waitFor(
"the primary's usage-limit window to be persisted",
() => ((worker.rateLimits()["claude-code"] ?? 0) > Date.now() ? true : undefined),
45_000,
);
const row = await worker.waitFor(`injected task #${task.id} to be requeued`, () => {
const current = worker.injectedTask(task.id);
return current?.status === "pending" && worker.runRecords(task.task_key).length > 0
? current
: undefined;
});
expect(row.status, diagnostics()).toBe("pending");
const runs = worker.runRecords(task.task_key);
expect(
runs.map((run) => run.status),
diagnostics(),
).toEqual(["deferred"]);
expect(runs[0]?.outcome_reason ?? "", diagnostics()).toContain("usage limit");
expect(worker.rateLimits().goose, diagnostics()).toBeUndefined();

// The primary ran through sbx exec; the unwrappable fallback never spawned.
expect(
sbxCalls().some((call) => call.startsWith("exec ")),
diagnostics(),
).toBe(true);
expect(invocationCount(stubs.fallbackInvocations), diagnostics()).toBe(0);
expect(worker.agentInvocations(), diagnostics()).toEqual([]);
expect(worker.activeHarness(), diagnostics()).not.toBe("goose");
expect(await worker.remoteBranches(), diagnostics()).toEqual([worker.baseBranch]);
expect(worker.running, diagnostics()).toBe(true);
} finally {
await worker.dispose();
}
},
120_000,
);
Loading