Skip to main content
Agent Safehouse includes a comprehensive test suite to verify policy behavior and prevent regressions. Tests use sandbox-exec to validate that allowed operations succeed and denied operations fail.

Running Tests

Tests must run outside an existing sandbox. sandbox-exec cannot nest. If your terminal session is already sandboxed, tests will fail immediately.
Run the full test suite from the repository root:
Expected output:
Skipped tests typically occur when optional dependencies (like git, docker, kubectl) are not installed on the test system.

Test Structure

Tests are organized under tests/sections/ by functional area:

Test Helpers

All test sections use helpers from tests/lib/common.sh:

Writing New Tests

When adding or modifying policy behavior:
1

Create or update test section

Add a new function in the appropriate tests/sections/*.sh file:
tests/sections/20-integrations.sh
2

Use descriptive test names

Test descriptions should clearly state what behavior is being verified:✅ Good: "write to --add-dirs path"❌ Bad: "test 3"
3

Run tests locally

Validate your changes:
4

Register the section

Always call register_section at the end of your test file:

Policy Assembly Tests

For changes to policy assembly logic or module dependencies, use structure and ordering assertions:
The #safehouse-test-id:*# markers in .sb files are used by ordering tests. Preserve these when editing profiles.

CI Validation

GitHub Actions runs tests automatically on:
  • All pull requests
  • Pushes to main
  • macOS runners only (sandbox-exec is macOS-specific)
CI also validates that dist/ artifacts are up-to-date when policy or runtime files change.

Test Environment

The test harness (tests/lib/setup.sh) creates isolated directories: All test artifacts are cleaned up automatically on exit.

Preflight Checks

The test runner performs these checks before starting:
1

Sandbox nesting check

Verifies the current session is not already sandboxed (tests cannot run inside a sandbox).
2

Binary validation

Confirms sandbox-exec is available and bin/safehouse.sh exists.
3

Environment setup

Creates temporary directories and generates test policies.
If preflight fails, tests exit with status 2 and an explanation.

Debugging Test Failures

Check policy contents

Generated test policies are in /tmp/safehouse-test-*/:

Run commands manually

Execute test commands directly with sandbox-exec:

Watch denial logs

Stream sandbox denials while running tests:

Verify outside sandbox

Confirm the command works unsandboxed:

E2E and Live Agent Tests

For heavier integration testing:
E2E and live agent tests may incur API usage costs and are not run by default in CI.

Next Steps

Debugging

Diagnose sandbox denial events

Contributing

Learn the development workflow and PR process