Skip to content

fix(tests): stop the suite reading the agent session's own sandbox environment - #1207

Merged
max-sixty merged 2 commits into
mainfrom
fix/test-suite-sandbox-isolation
Sep 11, 2026
Merged

max-sixty merged 2 commits into
mainfrom
fix/test-suite-sandbox-isolation

Conversation

@tend-agent

Copy link
Copy Markdown
Collaborator

Five tests read tend's own runtime environment instead of setting it, so uv run pytest — the command CLAUDE.md gives every agent — comes back red inside a tend session and green on a CI runner. A session that runs the suite before pushing sees five failures that have nothing to do with its change, and has to work out from ValueError: unknown AUTH_MODE: <unset> that the cause is the lifecycle hosting it.

Three independent leaks:

  • generator/tests/test_codex_runner.py asserts codex run refuses to start a second execution boundary, which holds only while TEND_INSIDE_SANDBOX is unset. Inside a session it is 1, so the run proceeds past the refusal and dies later on the auth mode. _set_sandbox_env now clears it and AUTH_MODE, the way shared/steps/test_sandbox_setup.py's step_env already clears TEND_SANDBOX_SETUP.
  • shared/steps/test_run_claude.py's launch fixture builds an explicit environment for every variable run_claude reads except TEND_AUTO_MEMORY_SETTINGS. The host run's settings file falls through, and three argv assertions pick up -u CLAUDE_CODE_DISABLE_AUTO_MEMORY and a --settings pair the test never asked for. Set to "" alongside the other explicit empties.
  • shared/steps/test_prepare_agent_workspace.py calls prepare.main(), which roots the agent workspace at the runner's /tmp — read-only under the SRT boundary, so the step reports [Errno 30] Read-only file system. The real mkdtemp still runs, with tmp_path as its parent, so the clone the assertions read is unchanged and pytest now owns the cleanup.

Each fix carries an assertion that fails on main in any environment, since CI cannot reproduce the leak on its own: the first two seed the inherited value before the fixture runs, and the third pins the workspace under tmp_path — mkdtemp(dir="/tmp") can never satisfy it. Verified by applying the three assertions alone to a main worktree, where all three fail.

Not addressed: generator/tests/test_refresh_consumers.py (2 tests) drives refresh_consumers.py through uv run --script, which resolves ruamel.yaml from PyPI. The sandbox has no DNS, so those two still fail in-session. That is the boundary working as designed rather than a test defect, and the failure names pypi.org and dns error directly, so it does not mislead the way these five did.

…vironment

Five tests inherited TEND_INSIDE_SANDBOX, TEND_AUTO_MEMORY_SETTINGS, and a
writable /tmp from whatever tend run was hosting them, so `uv run pytest`
was red in-session and green on a runner. Set or clear each in the test,
and add assertions that fail on main wherever the suite runs.

@tend-agent tend-agent left a comment

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Self-review. One gap in the deliverable, plus a comment fix inline.

uv run pytest still comes back red inside a session after this — generator/tests/test_refresh_consumers.py's two tests resolve ruamel.yaml from PyPI through uv run --script, and the sandbox has no DNS. The PR body records that, but the next session runs the command documented in CLAUDE.md and reads CLAUDE.md, not this thread, so it re-derives the same diagnosis from a dns error traceback. CLAUDE.md's Commands section already carries this exact shape of caveat for pre-commit not being on the sandbox PATH; the matching line for the two network-bound tests belongs beside it. I'll push it together with the inline comment fix.

Comment thread generator/tests/test_codex_runner.py Resolved
…un fails

The suite is otherwise clean inside a tend session after this branch, so the
remaining red is the `uv run --script` PyPI resolution in
test_refresh_consumers.py. Record it beside the pre-commit PATH caveat rather
than leaving each session to read it out of a dns error.

Also correct the refusal test's comment: the seeded values are what
`_set_sandbox_env` clears, not values the refusal holds against.
@max-sixty
max-sixty merged commit 76d2740 into main Sep 11, 2026
12 checks passed
@max-sixty
max-sixty deleted the fix/test-suite-sandbox-isolation branch September 11, 2026 17:14
max-sixty pushed a commit that referenced this pull request Sep 11, 2026
#1211)

## Problem

zsh names its here-document temp file from `TMPPREFIX`, which defaults
to `/tmp/zsh` and never consults `TMPDIR`. The sandbox's `allowWrite`
set covers the agent workspace and the agent home only, so root `/tmp`
stays read-only and every heredoc in an agent Bash call fails —
including the `--body-file` idiom `running-in-ci` recommends for
composing comment bodies. #1199 made `TMPDIR` writable but left
`TMPPREFIX` untouched, so it did not reach this.

The redirection is the sharp edge: zsh opens `> file` before it creates
the heredoc temp file, so the target is truncated to zero bytes and then
the command exits 1. A session that doesn't check the exit code has an
empty body file where its comment should be.

## Solution

Set `TMPPREFIX` to `$AGENT_TMP_DIR/zsh` alongside the `TMPDIR` entry in
the agent environment. `TMPPREFIX` is a prefix, so only its directory
has to exist, and `AGENT_TMP_DIR` is already created during workspace
handoff — no new `mkdir`. The key joins `RESERVED_SANDBOX_ENV` in both
`proxy/setup_sandbox.py` and `generator/src/tend/config.py` (the env
dict is asserted against the runtime set, and the parity hook requires
the two to match), which also stops an adopter's `sandbox_env` from
pointing it back outside the write set. The `sandbox_env` list in
`docs/tend.example.yaml` names it, and the pre-commit mirror hook
propagated that to the `install-tend` reference copy.

bash reads `TMPDIR` for its own heredocs, so it was already fine; this
affects the shells that read `TMPPREFIX`.

## Testing

`test_agent_environment_keeps_zsh_heredoc_scratch_writable` asserts the
assignment is present; it fails before the change and passes after. The
reserved-set parity pre-commit hook passes with the three sets aligned.

Seven tests fail both on this branch and on a clean `main` checkout in
this environment — `test_run_claude.py` argv assertions,
`test_codex_runner.py`'s `AUTH_MODE`, `test_prepare_agent_workspace.py`,
and the two `test_refresh_consumers.py` cases that need DNS. They are
the sandbox-environment-leakage class #1207 addresses, not this change.

Closes #1208 — automated triage

Co-authored-by: tend-agent <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants