Files
cleveragents-core/robot/overlay_sandbox.robot
brent.edwards 8a87262f86
CI / build (push) Successful in 17s
CI / lint (push) Successful in 3m41s
CI / quality (push) Successful in 3m47s
CI / unit_tests (push) Successful in 3m58s
CI / typecheck (push) Successful in 4m17s
CI / benchmark-regression (push) Has been skipped
CI / security (push) Successful in 4m22s
CI / docker (push) Successful in 1m22s
CI / e2e_tests (push) Successful in 8m57s
CI / coverage (push) Successful in 11m16s
CI / status-check (push) Successful in 3s
CI / benchmark-publish (push) Successful in 19m45s
CI / integration_tests (push) Failing after 20m53s
feat(sandbox): implement overlay filesystem sandbox strategy (#994)
## Summary

Implement the overlay filesystem sandbox strategy with OverlayFS support and userspace fallback.

### Implementation

**`OverlaySandbox`** (`infrastructure/sandbox/overlay.py`, 497 lines):
- Detects OverlayFS availability at runtime via `/proc/filesystems` + `os.geteuid() == 0` check
- **Real OverlayFS mode** (requires root): creates upper/work/merged dirs, mounts overlay filesystem, captures writes in upper layer
- **Userspace fallback** (default in CI/containers): `shutil.copytree` the original into merged dir, tracks changes via `filecmp` diff on commit
- `create()`: sets up directory structure, mounts if available
- `commit()`: copies changed/added files from overlay to original, removes deleted files
- `rollback()`: unmounts (or removes) merged, recreates from scratch
- `cleanup()`: unmounts, removes all temp dirs, idempotent

### Domain Model Updates
- Added `OVERLAY = "overlay"` to `SandboxStrategy` enum in both `resource_type.py` and `resource.py`
- Added `STRATEGY_OVERLAY` to `SandboxFactory`, registered for `fs-mount`, `fs-directory`, `fs-file` resources

### Tests
- **22 Behave scenarios**: full lifecycle (create/commit/rollback/cleanup), status transitions, path traversal guard, fallback detection, error handling
- **6 Robot integration tests**: end-to-end overlay sandbox operations

### Quality Gates

| Session | Result |
|---|---|
| `nox -s lint` | PASS |
| `nox -s typecheck` | PASS (0 errors) |
| `nox -s unit_tests` | PASS (10,917 scenarios) |
| `nox -s coverage_report` | 97% (>= 97%) |

Closes #880

Reviewed-on: #994
Co-authored-by: Brent Edwards <brent.edwards@cleverthis.com>
Co-committed-by: Brent Edwards <brent.edwards@cleverthis.com>
2026-03-21 03:14:40 +00:00

54 lines
2.9 KiB
Plaintext

*** Settings ***
Documentation Integration tests for overlay filesystem sandbox.
... Covers OverlaySandbox lifecycle, rollback, validation,
... directory structure, fallback mode, and state errors.
Resource ${CURDIR}/common.resource
Suite Setup Setup Test Environment
Suite Teardown Cleanup Test Environment
*** Variables ***
${HELPER_SCRIPT} robot/helper_overlay_sandbox.py
*** Test Cases ***
Overlay Sandbox Full Lifecycle
[Documentation] Verify create -> get_path -> modify -> commit -> cleanup
[Tags] sandbox overlay lifecycle
${result}= Run Process ${PYTHON} ${HELPER_SCRIPT} overlay-lifecycle cwd=${WORKSPACE} on_timeout=kill timeout=60s
Should Be Equal As Integers ${result.rc} 0
Should Contain ${result.stdout} overlay-lifecycle-ok
Overlay Sandbox Rollback
[Documentation] Verify rollback discards changes and restores original state
[Tags] sandbox overlay rollback
${result}= Run Process ${PYTHON} ${HELPER_SCRIPT} overlay-rollback cwd=${WORKSPACE} on_timeout=kill timeout=60s
Should Be Equal As Integers ${result.rc} 0
Should Contain ${result.stdout} overlay-rollback-ok
Overlay Sandbox Input Validation
[Documentation] Verify empty inputs and non-existent paths are rejected
[Tags] sandbox overlay validation
${result}= Run Process ${PYTHON} ${HELPER_SCRIPT} overlay-validation cwd=${WORKSPACE} on_timeout=kill timeout=60s
Should Be Equal As Integers ${result.rc} 0
Should Contain ${result.stdout} overlay-validation-ok
Overlay Sandbox Directory Structure
[Documentation] Verify upper/work/merged directories are created
[Tags] sandbox overlay structure
${result}= Run Process ${PYTHON} ${HELPER_SCRIPT} overlay-directory-structure cwd=${WORKSPACE} on_timeout=kill timeout=60s
Should Be Equal As Integers ${result.rc} 0
Should Contain ${result.stdout} overlay-directory-structure-ok
Overlay Sandbox Fallback Mode
[Documentation] Verify userspace fallback when OverlayFS unavailable
[Tags] sandbox overlay fallback
${result}= Run Process ${PYTHON} ${HELPER_SCRIPT} overlay-fallback-mode cwd=${WORKSPACE} on_timeout=kill timeout=60s
Should Be Equal As Integers ${result.rc} 0
Should Contain ${result.stdout} overlay-fallback-mode-ok
Overlay Sandbox State Errors
[Documentation] Verify state machine rejects invalid transitions
[Tags] sandbox overlay state
${result}= Run Process ${PYTHON} ${HELPER_SCRIPT} overlay-state-errors cwd=${WORKSPACE} on_timeout=kill timeout=60s
Should Be Equal As Integers ${result.rc} 0
Should Contain ${result.stdout} overlay-state-errors-ok