Skip to content

Commit b6bf67e

Browse files
authored
File-system snapshots (#50)
1 parent cf2cb72 commit b6bf67e

33 files changed

+2236
-107
lines changed

.agents/codex-setup

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ apt-get install -y --no-install-recommends \
88
fossil \
99
mercurial \
1010
just \
11-
ruby-full
11+
ruby-full \
12+
zfsutils-linux \
13+
btrfs-progs
1214

1315
sudo gem install rubocop
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
Carry out the first step of the plan in docs/fs-snapshots-workflow.md
2+
3+
If you find out that you miss any software, add it to .agents/codex-setup and the nix flake. Make sure that the flake can be loaded by running any command under nix develop (you'll have to install Nix first)

AGENTS.md

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,10 @@
66

77
## 🧪 Testing Tips
88

9-
- **Fix individual tests first**: `ruby -Itest test/test_file.rb -n test_method_name`
10-
- **Parent directory tests**: Require repos to be on agent task branches (not main)
11-
- **Full logs**: Available in `test/logs/` (path shown after test runs)
9+
When the test suite fails and you want to test potential fixes, try running only the affected
10+
tests firsts:
11+
12+
`ruby -Itest test/test_file.rb -n test_method_name`
1213

1314
## Keeping notes
1415

agent-task.gemspec

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,6 @@ Gem::Specification.new do |spec|
88
spec.files = Dir['bin/*', 'lib/**/*.rb', 'LICENSE', 'README.md', 'codex-setup']
99
spec.executables = Dir['bin/*'].select { |f| File.file?(f) }.map { |f| File.basename(f) }
1010
spec.require_paths = ['lib']
11-
spec.required_ruby_version = '>= 3.0.0'
11+
spec.required_ruby_version = '>= 2.6.0'
1212
spec.metadata['rubygems_mfa_required'] = 'true'
1313
end

docs/fs-snapshots-workflow.md

Lines changed: 0 additions & 100 deletions
This file was deleted.

docs/fs-snapshots/milestone_1.md

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
**Milestone 1: Core Filesystem Abstraction Layer**
2+
*Implementation:* Build fundamental filesystem operation primitives as the foundation. Create a `SnapshotProvider` abstraction with concrete implementations for each supported method:
3+
4+
* **Detection Logic:** Implement filesystem type detection by examining `/proc/mounts`, checking for ZFS/Btrfs tools availability, and falling back gracefully through the hierarchy (ZFS → Btrfs → OverlayFS → Copy).
5+
* **ZFS Provider:** Implement `zfs snapshot` and `zfs clone` operations with proper dataset path resolution and cleanup. Handle permissions and error cases (e.g., insufficient privileges, quota limits).
6+
* **Btrfs Provider:** Implement `btrfs subvolume snapshot` with automatic subvolume creation if needed. Handle the case where the repository is not yet a subvolume.
7+
* **OverlayFS Provider:** Create overlay mounts with proper `lowerdir`, `upperdir`, and `workdir` structure. Handle sudo requirements and privilege escalation gracefully.
8+
* **Copy Provider:** Implement fast copying using reflinks where available (`cp --reflink=auto`) or falling back to hard links and finally regular copying.
9+
10+
*Testing Strategy:* Create real filesystems within files using loop devices for comprehensive testing. This approach provides authentic filesystem behavior without requiring pre-configured test systems:
11+
12+
* **ZFS Testing:** Create ZFS pools using loop devices with `zpool create test_pool /path/to/file.img`. Create datasets, test snapshot/clone operations, verify CoW behavior, and test error conditions like insufficient space or permissions.
13+
* **Btrfs Testing:** Create Btrfs filesystems in files with `mkfs.btrfs /path/to/file.img`, mount via loop devices, create subvolumes, and test snapshot operations. Verify that non-subvolume directories are automatically converted when needed.
14+
* **OverlayFS Testing:** Create multiple loop-mounted filesystems to test overlay mounting with different combinations of lower/upper/work directories. Test with both writable and read-only lower layers.
15+
* **Copy Testing:** Test on various filesystem types (ext4, xfs, etc.) created in loop devices to verify reflink support detection and fallback behavior.
16+
* **Error Condition Testing:** Test quota limits, permission errors, disk full scenarios, and concurrent access patterns using the loop device filesystems.
17+
* **Performance Testing:** Measure snapshot creation/deletion times and space usage with real filesystems to establish baseline performance characteristics.
18+
19+
*CI Integration:* The test suite will create temporary filesystem images during test runs, eliminating the need for pre-configured CI environments with specific filesystems. Tests can run on any Linux system with loop device support (standard in most CI environments).

docs/fs-snapshots/milestone_2.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
**Milestone 2: Mock Agent Integration Testing**
2+
*Implementation:* Create a realistic mock agent that simulates actual AI agent behavior without requiring real AI services:
3+
4+
* **Mock Agent Behavior:** The mock agent will perform realistic file operations (reading source files, creating output files, modifying existing files), include configurable work duration with sleep calls, and generate logs of its activities. It will simulate the patterns of real agents like Codex or Goose.
5+
* **Docker Test Environment:** Build a minimal Alpine Linux Docker image containing the mock agent and Ruby runtime. This image will serve as a controlled environment for testing isolation and concurrency.
6+
* **Parallel Execution Tests:** Write integration tests that launch multiple mock agents simultaneously in separate isolated workspaces. Verify that agents cannot see each other's changes and that all file modifications remain properly isolated.
7+
* **Performance Testing:** Measure snapshot creation time, workspace cleanup time, and resource usage under concurrent load to ensure the system scales appropriately.
8+
9+
*Integration Testing:* These tests will use real filesystem operations but controlled environments. Test on multiple filesystems (ext4, btrfs) in CI. Verify isolation guarantees and measure performance characteristics.

docs/fs-snapshots/milestone_3.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
**Milestone 3: Credential Management System**
2+
*Implementation:* Based on research of actual AI agent tools, implement a comprehensive credential management system:
3+
4+
* **Credential Pattern Detection:** Support for different agent types with their specific credential requirements:
5+
- **Codex:** `OPENAI_API_KEY` environment variable, `~/.codex/auth.json` and config files
6+
- **GitHub Copilot:** `GITHUB_TOKEN` environment variable, `~/.config/gh/hosts.yml` for GitHub CLI auth
7+
- **Goose:** `OPENAI_API_KEY`, `ANTHROPIC_API_KEY` environment variables
8+
- **Gemini:** `GEMINI_API_KEY` environment variable
9+
- **Claude:** `ANTHROPIC_API_KEY` environment variable
10+
* **Secure Mounting:** For containerized execution, mount credential files read-only and propagate environment variables securely. For VM execution, sync credential files safely while preserving file permissions (0600 for auth files).
11+
* **Colima/VM Support:** Research confirms that Colima and similar VM solutions support both environment variable propagation and bind mounts for credential files. The system will use Docker's `--env-file` and `--mount` options for secure credential injection.
12+
13+
*Testing:* Test credential mounting with dummy credentials in controlled environments. Verify that credentials are accessible to agents. Test both file-based and environment variable credentials.

docs/fs-snapshots/milestone_4.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
**Milestone 4: SSH/Remote Execution Framework**
2+
*Implementation:* Build remote execution capabilities using Docker containers with SSH servers for realistic testing:
3+
4+
* **SSH Test Infrastructure:** Extend the test-purpose docker image with a configured SSH server. Use this for testing remote execution without requiring actual remote machines.
5+
* **File Synchronization:** Implement both one-shot sync (using `rsync`) and persistent sync (using Mutagen) approaches. Handle edge cases like network interruptions and large file transfers.
6+
* **Remote Filesystem Detection:** Extend the filesystem detection logic to work over SSH connections. Cache detection results to avoid repeated SSH calls.
7+
* **Error Handling:** Comprehensive error handling for network failures, authentication issues, insufficient remote permissions, and missing remote tools.
8+
9+
*Integration Testing:* Use Docker containers as SSH targets to test the complete remote workflow. Launch a container, establish SSH connection, sync files, create snapshots remotely, execute agents, and retrieve results. Test concurrent remote executions and verify isolation.

docs/fs-snapshots/milestone_5.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
**Milestone 5: Full Integration and CI/CD Pipeline**
2+
*Implementation:* Integrate all components and establish comprehensive CI testing:
3+
4+
* **CI Matrix Enhancement:** Add test jobs for different OS/filesystem combinations:
5+
- Ubuntu with btrfs support
6+
- Ubuntu with overlay-only (simulating basic ext4 systems)
7+
- macOS with Docker/Colima simulation
8+
- Windows with WSL2/Docker simulation
9+
* **End-to-End Testing:** Test complete workflows from `agent-task` CLI invocation through workspace creation, agent execution, and cleanup.
10+
* **Performance Monitoring:** Add benchmarks for snapshot creation/destruction, file sync performance, and concurrent agent execution. Set performance regression thresholds.
11+
* **Documentation and Examples:** Complete user documentation with setup instructions for each platform, credential configuration guides, and troubleshooting sections.
12+
13+
*Integration Testing:* The CI pipeline will run the full test suite across the matrix of supported platforms and configurations. This includes both unit tests of individual components and integration tests of complete workflows. All tests will run against real filesystem operations and network conditions to catch issues that mocks might miss.

0 commit comments

Comments
 (0)