Skip to content

Commit ca38f01

Browse files
authored
feat: update new test architecture (#60)
1 parent 8211eca commit ca38f01

File tree

21 files changed

+1531
-235
lines changed

21 files changed

+1531
-235
lines changed

.amazonq/rules/dev-workflow.md

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,9 @@ When user mentions:
4343
**ALWAYS check existing utilities first:**
4444

4545
- Check `src/test_utils/` before creating new test utilities
46-
- Reuse `TestDir`, `DockerGit`, and other existing infrastructure
46+
- Reuse `TestDir`, `GitOperations` trait, and other existing infrastructure
47+
- Use `get_git_impl()` for environment-aware Git operations
48+
- Prefer `GitOperations` trait methods over direct Docker/Native calls
4749
- Avoid duplicating code across different files
4850
- Look for existing helper functions before implementing new ones
4951

@@ -59,6 +61,7 @@ When user mentions:
5961
→ Search codebase for violations:
6062

6163
- Duplicated test setup patterns
62-
- Reimplemented utility functions
64+
- Direct `DockerGit`/`NativeGit` usage instead of `get_git_impl()`
65+
- Reimplemented Git operations instead of using `GitOperations` trait
6366
- Similar helper functions across files
64-
- Unused existing utilities in `src/test_utils/`
67+
- Unused existing utilities in `src/test_utils/git/`

.amazonq/rules/docker-git-testing.md

Lines changed: 50 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,14 @@
1-
# Docker Git Testing Bug - Complete Fix Guide
1+
# Docker Git Testing Guide - Multi-Platform Architecture
2+
3+
## ✅ CURRENT STATUS: Multi-Platform CI Implemented
4+
5+
**Architecture Update**: The project now uses environment-aware Git testing:
6+
7+
- **Local Development**: Uses `DockerGit` for isolation
8+
- **CI Environment**: Uses `NativeGit` for real platform testing
9+
- **Platform Coverage**: Linux, macOS, Windows all tested with native Git
10+
11+
## Legacy Docker Git Testing Bug - Historical Reference
212

313
## Bug Symptoms
414

@@ -192,33 +202,57 @@ make test
192202

193203
**Result**: You'll now get errors like `❌ Missing --entrypoint sh for alpine/git:latest (will fail in CI)` locally instead of discovering issues in CI.
194204

195-
## Files to Update When Fixing
205+
## Current Architecture Files
196206

197-
1. `src/test_utils/git.rs` - Docker git utility functions
198-
2. `src/vcs/git.rs` - Git VCS implementation test helpers
199-
3. Any other files using Docker git commands
207+
1. `src/test_utils/git/mod.rs` - GitOperations trait and exports
208+
2. `src/test_utils/git/docker.rs` - DockerGit implementation (local development)
209+
3. `src/test_utils/git/native.rs` - NativeGit implementation (CI testing)
210+
4. `src/config.rs` - Environment detection via `ZERV_CI` variable
211+
5. `src/test_utils/mod.rs` - `should_use_native_git()` helper function
200212

201-
## Testing Verification
213+
## Current Testing Verification
202214

203215
```bash
204-
# Local test (now includes strict mode)
216+
# Local test (uses DockerGit for isolation)
205217
make test
206218

207219
# Test validation works
208220
cargo test test_docker_validation --lib
209221

210-
# Check specific git tests
222+
# Check specific git tests (Docker tests only run on Linux)
211223
cargo test git --include-ignored
212224

213-
# Verify CI will pass (should be consistent now)
214-
git push # Check GitHub Actions
225+
# Verify multi-platform CI passes
226+
git push # Check GitHub Actions on Linux, macOS, Windows
215227
```
216228

217-
## Why This Bug Repeats
229+
## Multi-Platform CI Benefits
230+
231+
**Real Platform Testing Achieved**:
232+
233+
-**Windows CI**: Tests actual Windows Git behavior, CRLF line endings, Windows paths
234+
-**macOS CI**: Tests actual macOS Git behavior, case-insensitive filesystem
235+
-**Linux CI**: Tests actual Linux Git behavior, permissions
236+
237+
**Local Safety Maintained**:
238+
239+
-**Docker Isolation**: Protects personal git config during local development
240+
-**Environment Detection**: Automatic switching via `ZERV_CI=true`
241+
-**Consistent API**: Same `GitOperations` trait for both implementations
242+
243+
## Architecture Evolution
244+
245+
**Problem Solved**: The original Docker CI issues are resolved by using native Git in CI:
246+
247+
1. **No more Docker in CI** - Windows/macOS/Linux CI all use native Git
248+
2. **Real platform testing** - Catches actual platform-specific issues
249+
3. **Local isolation maintained** - Docker still used for local development safety
250+
4. **Consistent behavior** - GitOperations trait ensures same API across implementations
251+
252+
**When to Use This Guide**:
218253

219-
1. **Local testing masks the issue** - Docker Desktop is more forgiving
220-
2. **The error is subtle** - Commands might partially work locally
221-
3. **CI environment is different** - Only fails in the strict CI environment
222-
4. **Git directory context** - After `git init`, subsequent commands need `--git-dir=.git` in containers
254+
- Reference for understanding DockerGit implementation details
255+
- Debugging local Docker-based tests
256+
- Historical context for architecture decisions
223257

224-
This bug has occurred multiple times - always refer to this guide when Docker git tests fail in CI but pass locally.
258+
**Current Best Practice**: Use `get_git_impl()` helper function for environment-aware Git operations instead of direct Docker commands.
Lines changed: 34 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,44 @@
11
# Testing Standards
22

3-
## Docker Isolation for VCS Tests
3+
## Environment-Aware Git Testing
44

5-
**MANDATORY: Use Docker for VCS operations that modify state**
5+
**MANDATORY: Use appropriate Git implementation based on environment**
66

7-
- Use Docker for all Git/VCS tests to avoid interfering with local machine state
7+
**Local Development:**
8+
9+
- Use `DockerGit` for isolation to avoid interfering with local machine state
810
- Isolate test environment completely from host git config and repositories
9-
- Use `DockerGit` utility from `src/test_utils/git.rs` for git operations in tests
11+
- Use `get_git_impl()` helper function for environment-aware selection
12+
13+
**CI Environment:**
14+
15+
- Use `NativeGit` for real platform testing (Windows/macOS/Linux)
16+
- Enabled automatically via `ZERV_CI=true` environment variable
17+
- Tests actual platform-specific Git behavior, paths, line endings
18+
19+
**Implementation Pattern:**
20+
21+
```rust
22+
use crate::test_utils::{GitOperations, should_use_native_git};
23+
use crate::test_utils::git::{DockerGit, NativeGit};
24+
25+
fn get_git_impl() -> Box<dyn GitOperations> {
26+
if should_use_native_git() {
27+
Box::new(NativeGit::new())
28+
} else {
29+
Box::new(DockerGit::new())
30+
}
31+
}
32+
```
1033

1134
## Race Condition Prevention
1235

1336
**Atomic Operations Required:**
1437

15-
- Use single Docker commands with shell scripts instead of multiple separate commands
16-
- Combine git operations like `git init && git add . && git commit` in one Docker call
17-
- Avoid multi-step Docker operations that can cause filesystem race conditions
38+
- Use `GitOperations` trait methods for consistent behavior across implementations
39+
- Prefer trait methods like `init_repo()`, `create_tag()`, `create_commit()` over raw commands
40+
- Avoid multi-step operations that can cause filesystem race conditions
41+
- Use shared logic in trait implementations for consistency
1842

1943
**Flaky Test Detection:**
2044

@@ -31,7 +55,8 @@ When user mentions:
3155

3256
**Before committing:**
3357

34-
- All tests must pass consistently
58+
- All tests must pass consistently on all platforms (Linux, macOS, Windows)
3559
- Use `make test` multiple times to verify stability
3660
- Fix any intermittent failures before proceeding
37-
- Document any Docker or environment dependencies
61+
- Ensure tests work in both local (Docker) and CI (Native) environments
62+
- Use `#[cfg(target_os = "linux")]` for Docker-specific tests

0 commit comments

Comments
 (0)