Skip to content

fix(tests): degrade gracefully on restricted hosts - #436

Merged
mohitranka merged 2 commits into
mainfrom
fix/env-dependent-tests
Aug 25, 2026
Merged

mohitranka merged 2 commits into
mainfrom
fix/env-dependent-tests

Conversation

@mohitranka

Copy link
Copy Markdown
Contributor

Summary

Fixes the test failures that appear on sandboxed hosts (nested sandboxes, agent harnesses) while CI stayed green. Three root causes:

  1. Seatbelt confinement failed to apply from inside an outer sandbox (sandbox_apply: Operation not permitted), so every confined spawn errored. availability() now probes that a profile can actually be applied, adding Unavailable::CannotApply. The supported CLI still refuses to start when the host cannot confine; library callers now fall back to plain execution rather than failing spawns mid-test.
  2. Unwritable platform application-data directory broke runtime-storage fallback tests (theme/files persistence, clipboard attachments). Those tests use a new fake_home_guard that redirects $HOME for the test's duration under the existing env lock and restores it on drop.
  3. Denied PTY allocation and loopback binds panicked the embedded-terminal, egress-proxy, and mock-HTTP-server tests. Shared helpers (pty_allocation_available, started_proxy, mock_http/serve returning Option) now detect the denial once and skip with a printed reason.

Test plan

  • cargo test --workspace --all-targets --locked: two consecutive full runs, all 27 suites green (previously 17 failures in forge-tui alone, plus forge-core/forge-connect/forge-model/forge-storage/forge-tools).
  • cargo fmt --all -- --check and cargo clippy --workspace --all-targets --locked -- -D warnings clean.
  • On unrestricted hosts (CI runners) every guarded test still runs — skips only trigger on PermissionDenied-style denials.

Mohit Ranka and others added 2 commits August 26, 2026 02:34
Three environment restrictions broke the suite on sandboxed hosts
(nested sandboxes, agent harnesses, hardened CI runners) while CI
stayed green:

- Seatbelt confinement could not be applied from inside an outer
  sandbox, so every confined spawn failed. availability() now probes
  that a profile can actually be applied (new Unavailable::CannotApply),
  which makes the CLI refuse to start on such hosts and lets library
  callers fall back to plain execution instead of failing spawns.
- The platform application-data directory was unwritable, breaking
  runtime-storage fallback tests. Tests that need it now use a
  fake-home guard that holds the test-env lock and restores $HOME.
- PTY allocation and loopback listener binds were denied, panicking
  terminal/egress/mock-server tests. Shared helpers now detect the
  denial once and skip with a reason instead of unwrapping.
The two direct-completion exec_command tests raced a single 400ms yield
against WSL2's slower confined spawn time and saw a still-running session
instead of the final result. Apply the same write_stdin polling loop the
denial-escalation test already uses.

Claude-Session: https://claude.ai/code/session_01Ca1Xpr9dmAUNsCR9dnh23R
@mohitranka
mohitranka merged commit 3724168 into main Aug 25, 2026
7 checks passed
@mohitranka
mohitranka deleted the fix/env-dependent-tests branch August 25, 2026 21:35
mohitranka added a commit that referenced this pull request Sep 11, 2026
* fix(tests): degrade gracefully on restricted hosts

Three environment restrictions broke the suite on sandboxed hosts
(nested sandboxes, agent harnesses, hardened CI runners) while CI
stayed green:

- Seatbelt confinement could not be applied from inside an outer
  sandbox, so every confined spawn failed. availability() now probes
  that a profile can actually be applied (new Unavailable::CannotApply),
  which makes the CLI refuse to start on such hosts and lets library
  callers fall back to plain execution instead of failing spawns.
- The platform application-data directory was unwritable, breaking
  runtime-storage fallback tests. Tests that need it now use a
  fake-home guard that holds the test-env lock and restores $HOME.
- PTY allocation and loopback listener binds were denied, panicking
  terminal/egress/mock-server tests. Shared helpers now detect the
  denial once and skip with a reason instead of unwrapping.

* fix(tests): poll exec_command to completion on slow sandbox spawns

The two direct-completion exec_command tests raced a single 400ms yield
against WSL2's slower confined spawn time and saw a still-running session
instead of the final result. Apply the same write_stdin polling loop the
denial-escalation test already uses.

Claude-Session: https://claude.ai/code/session_01Ca1Xpr9dmAUNsCR9dnh23R

---------

Co-authored-by: Mohit Ranka <[email protected]>
mohitranka added a commit that referenced this pull request Sep 11, 2026
* fix(tests): degrade gracefully on restricted hosts

Three environment restrictions broke the suite on sandboxed hosts
(nested sandboxes, agent harnesses, hardened CI runners) while CI
stayed green:

- Seatbelt confinement could not be applied from inside an outer
  sandbox, so every confined spawn failed. availability() now probes
  that a profile can actually be applied (new Unavailable::CannotApply),
  which makes the CLI refuse to start on such hosts and lets library
  callers fall back to plain execution instead of failing spawns.
- The platform application-data directory was unwritable, breaking
  runtime-storage fallback tests. Tests that need it now use a
  fake-home guard that holds the test-env lock and restores $HOME.
- PTY allocation and loopback listener binds were denied, panicking
  terminal/egress/mock-server tests. Shared helpers now detect the
  denial once and skip with a reason instead of unwrapping.

* fix(tests): poll exec_command to completion on slow sandbox spawns

The two direct-completion exec_command tests raced a single 400ms yield
against WSL2's slower confined spawn time and saw a still-running session
instead of the final result. Apply the same write_stdin polling loop the
denial-escalation test already uses.

Claude-Session: https://claude.ai/code/session_01Ca1Xpr9dmAUNsCR9dnh23R

---------
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.

1 participant