Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions .amazonq/rules/dev-workflow.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,9 @@ When user mentions:
**ALWAYS check existing utilities first:**

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

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

- Duplicated test setup patterns
- Reimplemented utility functions
- Direct `DockerGit`/`NativeGit` usage instead of `get_git_impl()`
- Reimplemented Git operations instead of using `GitOperations` trait
- Similar helper functions across files
- Unused existing utilities in `src/test_utils/`
- Unused existing utilities in `src/test_utils/git/`
66 changes: 50 additions & 16 deletions .amazonq/rules/docker-git-testing.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,14 @@
# Docker Git Testing Bug - Complete Fix Guide
# Docker Git Testing Guide - Multi-Platform Architecture

## ✅ CURRENT STATUS: Multi-Platform CI Implemented

**Architecture Update**: The project now uses environment-aware Git testing:

- **Local Development**: Uses `DockerGit` for isolation
- **CI Environment**: Uses `NativeGit` for real platform testing
- **Platform Coverage**: Linux, macOS, Windows all tested with native Git

## Legacy Docker Git Testing Bug - Historical Reference

## Bug Symptoms

Expand Down Expand Up @@ -192,33 +202,57 @@ make test

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

## Files to Update When Fixing
## Current Architecture Files

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

## Testing Verification
## Current Testing Verification

```bash
# Local test (now includes strict mode)
# Local test (uses DockerGit for isolation)
make test

# Test validation works
cargo test test_docker_validation --lib

# Check specific git tests
# Check specific git tests (Docker tests only run on Linux)
cargo test git --include-ignored

# Verify CI will pass (should be consistent now)
git push # Check GitHub Actions
# Verify multi-platform CI passes
git push # Check GitHub Actions on Linux, macOS, Windows
```

## Why This Bug Repeats
## Multi-Platform CI Benefits

**Real Platform Testing Achieved**:

- ✅ **Windows CI**: Tests actual Windows Git behavior, CRLF line endings, Windows paths
- ✅ **macOS CI**: Tests actual macOS Git behavior, case-insensitive filesystem
- ✅ **Linux CI**: Tests actual Linux Git behavior, permissions

**Local Safety Maintained**:

- ✅ **Docker Isolation**: Protects personal git config during local development
- ✅ **Environment Detection**: Automatic switching via `ZERV_CI=true`
- ✅ **Consistent API**: Same `GitOperations` trait for both implementations

## Architecture Evolution

**Problem Solved**: The original Docker CI issues are resolved by using native Git in CI:

1. **No more Docker in CI** - Windows/macOS/Linux CI all use native Git
2. **Real platform testing** - Catches actual platform-specific issues
3. **Local isolation maintained** - Docker still used for local development safety
4. **Consistent behavior** - GitOperations trait ensures same API across implementations

**When to Use This Guide**:

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

This bug has occurred multiple times - always refer to this guide when Docker git tests fail in CI but pass locally.
**Current Best Practice**: Use `get_git_impl()` helper function for environment-aware Git operations instead of direct Docker commands.
43 changes: 34 additions & 9 deletions .amazonq/rules/testing-standards.md
Original file line number Diff line number Diff line change
@@ -1,20 +1,44 @@
# Testing Standards

## Docker Isolation for VCS Tests
## Environment-Aware Git Testing

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

- Use Docker for all Git/VCS tests to avoid interfering with local machine state
**Local Development:**

- Use `DockerGit` for isolation to avoid interfering with local machine state
- Isolate test environment completely from host git config and repositories
- Use `DockerGit` utility from `src/test_utils/git.rs` for git operations in tests
- Use `get_git_impl()` helper function for environment-aware selection

**CI Environment:**

- Use `NativeGit` for real platform testing (Windows/macOS/Linux)
- Enabled automatically via `ZERV_CI=true` environment variable
- Tests actual platform-specific Git behavior, paths, line endings

**Implementation Pattern:**

```rust
use crate::test_utils::{GitOperations, should_use_native_git};
use crate::test_utils::git::{DockerGit, NativeGit};

fn get_git_impl() -> Box<dyn GitOperations> {
if should_use_native_git() {
Box::new(NativeGit::new())
} else {
Box::new(DockerGit::new())
}
}
```

## Race Condition Prevention

**Atomic Operations Required:**

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

**Flaky Test Detection:**

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

**Before committing:**

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