# Release v0.6.0

## Quality & Testing Improvements

This release focuses on significantly improving code quality, test coverage, and developer experience. We've completed all P0 (high priority) and P1 (medium priority) improvements from our TODO list.

### Test Coverage Increased by 11.7%

**Total tests: 248 → 277** (+29 new tests)

All core modules now have comprehensive test coverage:
- ✅ Provider validation: 9 tests
- ✅ Git repository operations: 14 tests
- ✅ Review command: 6 tests

### Real API Health Checks for Providers

The `gcop config validate` command has been **significantly enhanced** to perform real API connectivity checks instead of just checking if API keys are non-empty.

**Before v0.6.0:**
```bash
$ gcop config validate
✓ Configuration loaded
✓ Provider 'claude' configured
# Only checked if API key exists, didn't test actual connectivity
```

**After v0.6.0:**
```bash
$ gcop config validate
[1/2] Validating configuration...
[2/2] Testing provider connection...
✓ Provider 'claude' validated successfully
# Actually sends a test request to verify API works!
```

**What's new:**

1. **Claude/OpenAI Providers**: Send minimal test requests (`max_tokens=1`) to verify API connectivity
   - Detects invalid API keys (401 errors)
   - Detects rate limits (429 errors)
   - Minimal cost: only 1 token per validation

2. **Ollama Provider**: Checks `/api/tags` health endpoint
   - Verifies Ollama server is running
   - Checks if configured model is downloaded
   - Provides helpful suggestion: `ollama pull <model>` if model not found

3. **FallbackProvider**: Validates all configured providers
   - Shows status for each provider in fallback chain
   - Aggregates results and warns if all providers fail

4. **Better Error Messages**: Enhanced error output with actionable suggestions
   ```bash
   ✗ Validation failed: Claude API validation failed: Invalid API key

   💡 Suggestion: Check your ANTHROPIC_API_KEY environment variable or
      api_key in config file (~/.config/gcop/config.toml)
   ```

**Impact:**
- Catch configuration issues **before** running `gcop commit`
- Save time debugging API connectivity problems
- Better onboarding experience for new users

### Git Repository Test Coverage

Added comprehensive test suite for Git repository operations (`tests/git_repository_test.rs` with 14 tests):

**Edge Cases Covered:**
- ✅ Empty repositories (no commits yet)
- ✅ Large file size limits (default 10MB, custom limits)
- ✅ Paths with spaces and Unicode characters
- ✅ First commit in repository (no parent)
- ✅ Invalid commit hashes and range formats
- ✅ Detached HEAD state
- ✅ Concurrent test safety (using `serial_test` crate)

**Example Test:**
```rust
#[test]
fn test_get_file_content_exceeds_max_size() {
    // Creates 11MB file (exceeds default 10MB limit)
    // Expects: InvalidInput error with "File too large" message
}
```

These tests ensure robustness when dealing with unusual repository states and prevent regressions.

### Review Command Tests

Added integration tests for the `gcop review` command (`tests/review_command_test.rs` with 6 tests):

**Coverage:**
- ✅ All 4 target types: `--changes`, `--commit <hash>`, `--range <range>`, `--file <path>`
- ✅ Error handling: empty diff, LLM failures
- ✅ Correct routing to Git operations

**Architectural Improvement:**

Refactored `review.rs` to support dependency injection:
```rust
// Public API (unchanged)
pub async fn run(cli: &Cli, config: &AppConfig, ...) -> Result<()>

// Internal implementation (testable with mocks)
pub async fn run_internal(
    config: &AppConfig,
    git: &dyn GitOperations,  // ← Injectable for tests
    llm: &dyn LLMProvider,     // ← Injectable for tests
) -> Result<()>
```

This pattern maintains **backward compatibility** while enabling thorough testing with mock objects.

### MSRV (Minimum Supported Rust Version) Fixed

**Rust 1.92.0 or higher** is now officially required (Rust 2024 edition).

**What's added:**
1. **`rust-toolchain.toml`**: Ensures consistent Rust version across all environments
   ```toml
   [toolchain]
   channel = "stable"
   components = ["rustfmt", "clippy"]
   ```

2. **`Cargo.toml`**: Declares MSRV for crates.io and cargo
   ```toml
   rust-version = "1.92.0"
   ```

3. **CI/CD**: Added MSRV check job in GitHub Actions
   - Ensures code compiles with minimum Rust version
   - Prevents accidental use of newer Rust features

4. **Documentation**: Updated all installation guides (English/Chinese)
   - README.md
   - README_ZH.md
   - docs/guide/installation.md
   - docs/zh/guide/installation.md

**Why this matters:**
- Clear expectations for contributors
- Prevents "it works on my machine" issues
- Maintains compatibility with Rust 2024 edition requirements

## Technical Details

### Provider Validation Implementation

Each provider implements the `validate()` method from the `LLMProvider` trait:

```rust
async fn validate(&self) -> Result<()> {
    // Claude/OpenAI: Send test request
    let test_request = Request {
        model: self.model.clone(),
        max_tokens: 1,  // Minimal cost
        ...
    };

    let response = self.client.post(&self.endpoint)
        .json(&test_request)
        .send()
        .await?;

    if !response.status().is_success() {
        return Err(GcopError::LlmApi { ... });
    }

    Ok(())
}
```

For Ollama, we use the `/api/tags` endpoint:
```rust
async fn validate(&self) -> Result<()> {
    let tags_response = self.client
        .get(&health_endpoint)
        .send()
        .await?;

    // Check if configured model exists
    if !models.iter().any(|m| m.name.starts_with(&self.model)) {
        return Err(GcopError::Config(
            "Model not found. Run 'ollama pull <model>' first."
        ));
    }

    Ok(())
}
```

### Test Infrastructure

New tests use:
- **`mockito`**: HTTP mocking for provider tests
- **`mockall`**: Trait mocking for Git/LLM operations
- **`tempfile`**: Temporary directories for Git repository tests
- **`serial_test`**: Serialized execution for tests that modify global state
- **`tokio::test`**: Async test support

## Upgrade Notes

Upgrading from v0.5.1 requires **no action**. This release is **fully backward compatible**.

**What stays the same:**
- All public APIs remain unchanged
- Configuration file format unchanged
- Command-line interface unchanged

**What improves:**
- `gcop config validate` now performs real API checks
- Better error messages and suggestions
- More robust with comprehensive test coverage

## Breaking Changes

**None.** This is a minor version bump (0.5.1 → 0.6.0) with new features and improvements, but no breaking changes.

## Installation

```bash
# Homebrew (macOS/Linux)
brew tap AptS-1547/gcop-rs
brew upgrade gcop-rs

# pipx (Python users, recommended)
pipx upgrade gcop-rs

# cargo-binstall (no compilation)
cargo binstall gcop-rs

# cargo install (compile from source)
cargo install gcop-rs --force
```

Or download pre-built binaries from [Releases](https://github.com/AptS-1547/gcop-rs/releases).

## What's Next

Remaining low-priority improvements (P2):
- UI module testability improvements
- Diff syntax highlighting with `syntect`

See [TODO.md](../../TODO.md) for details.

## Statistics

- **Files changed**: 22
- **Lines added**: +1,726
- **Lines removed**: -64
- **New test files**: 3
- **New tests**: 29
- **Test coverage increase**: 248 → 277 (+11.7%)

## Contributors

- AptS-1547 (Yuhan Bian / 卞雨涵)
- AptS-1548 (48)

## Feedback

If you have any issues or suggestions, please submit an [Issue](https://github.com/AptS-1547/gcop-rs/issues).

---

**Full Changelog**: [v0.5.1...v0.6.0](https://github.com/AptS-1547/gcop-rs/compare/v0.5.1...v0.6.0)
