Skip to content
Draft
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
123 changes: 123 additions & 0 deletions .claude/QUICKSTART.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,123 @@
# Quick Start: Test Coverage Commands

## Setup (One-time)

Install the coverage tool:
```bash
cargo install cargo-llvm-cov
```

This takes a few minutes but only needs to be done once.

## Using the Commands

### Check Coverage (Read-only)

Simply type in your Claude Code chat:
```
/check-coverage
```

This will:
- Run coverage analysis
- Show you a detailed report
- Tell you exactly what needs testing
- **Not make any changes to your code**

### Generate Tests (Auto-write)

Type in your Claude Code chat:
```
/test-coverage
```

This will:
- Run coverage analysis
- Identify gaps
- **Automatically create test files**
- Write tests following project patterns
- Verify tests compile and run
- Report on coverage improvement

## Example Session

**You:** `/check-coverage`

**Claude:**
```
Coverage Report:
- Overall: 78.5%
- src/madmin/builders/metrics.rs: 45.2% (missing error path tests)
- src/madmin/response/kms_status.rs: 67.8% (missing JSON parse error test)

Recommendations:
1. Add test for metrics builder with invalid parameters
2. Test KMS status response with malformed JSON
```

**You:** `/test-coverage`

**Claude:**
```
Analyzing coverage... Installing cargo-llvm-cov...
Running coverage analysis...

Identified 5 uncovered code paths:
1. src/madmin/builders/metrics.rs:85-92 (error handling)
2. src/madmin/response/kms_status.rs:34-38 (JSON parse error)
...

Creating tests:
✓ Created tests/madmin/test_metrics_errors.rs
✓ Created tests/madmin/test_kms_errors.rs
✓ Updated tests/madmin/mod.rs

Running tests...
✓ All 48 tests passing

New coverage: 95.2% (+16.7%)

Remaining gaps:
- src/madmin/types/kms.rs:45 (trivial getter)
```

## Tips

1. **Run `/check-coverage` frequently** - It's fast and shows what needs work
2. **Use `/test-coverage` for bulk work** - When you've added multiple APIs
3. **Review generated tests** - They follow patterns but may need refinement
4. **Some tests will be ignored** - If they need special environment (distributed mode, KMS, etc.)

## Troubleshooting

**"cargo-llvm-cov not found"**
- Run: `cargo install cargo-llvm-cov`
- Wait for installation to complete

**"Tests are failing"**
- Check if MinIO server is running
- Verify credentials in environment variables
- Some tests are marked `#[ignore]` on purpose

**"Coverage percentage seems wrong"**
- Make sure you're testing the right code (`--lib --tests`)
- Excluded files (like generated code) won't affect percentage

## What Gets Tested

The commands focus on:
- ✅ `src/madmin/` - All MinIO Admin API code
- ✅ `src/s3/` - All S3 API code
- ✅ Public API methods
- ✅ Error handling paths
- ✅ Builder patterns
- ✅ Response parsing
- ✅ Network error scenarios
- ❌ Test files themselves (not counted in coverage)
- ❌ Generated code (has marker comments)

## Tracking Files

After generating tests, the agent updates:
- **`tests/TEST_COVERAGE.md`** - Overall statistics and coverage by API category
- **`tests/API_TEST_MATRIX.md`** - Detailed test-to-API mappings
146 changes: 146 additions & 0 deletions .claude/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,146 @@
# Claude Code Commands for MinIO Rust SDK

This directory contains custom slash commands for working with the MinIO Rust SDK project.

## Available Commands

### `/check-coverage`
Analyzes test coverage and provides a detailed report without making changes.

**Usage:**
```
/check-coverage
```

**What it does:**
- Runs `cargo tarpaulin` to measure code coverage
- Shows overall coverage percentage
- Lists files with incomplete coverage
- Identifies specific uncovered lines and functions
- Provides recommendations for missing tests

**When to use:**
- Before writing new tests to see what needs coverage
- After implementing new features to verify they're tested
- During code review to ensure quality standards

---

### `/test-coverage`
Actively generates tests to achieve 100% code coverage.

**Usage:**
```
/test-coverage
```

**What it does:**
- Runs coverage analysis (same as `/check-coverage`)
- Identifies uncovered code paths in both madmin and s3 modules
- Automatically generates test files following project patterns
- Adds tests to appropriate directories:
- `tests/madmin/` for Admin API tests
- `tests/` for S3 API tests
- Registers new test modules appropriately
- Verifies tests compile and run
- Updates tracking files (`TEST_COVERAGE.md` and `API_TEST_MATRIX.md`)
- Re-checks coverage to confirm improvement

**When to use:**
- When you want to quickly boost test coverage
- After implementing multiple new APIs without tests
- To generate test scaffolding that you can then refine

**Note:** Generated tests follow project conventions:
- Proper copyright headers
- Async tokio tests
- `#[ignore]` attribute for environment-dependent tests
- Clear assertions and output messages

---

## Installing Coverage Tools

### Option 1: cargo-tarpaulin (Linux, macOS)
```bash
cargo install cargo-tarpaulin
```

### Option 2: cargo-llvm-cov (Windows, cross-platform)
```bash
cargo install cargo-llvm-cov
```

Then modify the commands to use:
```bash
cargo llvm-cov --lib --tests --lcov --output-path target/coverage/lcov.info
```

---

## Coverage Goals

For the MinIO Rust SDK:
- **Target:** 100% coverage for `src/madmin` and `src/s3` modules
- **Focus Areas:**
- Public API methods
- Error handling paths
- Builder pattern combinations
- JSON parsing edge cases
- Network error scenarios
- Validation logic
- **Acceptable Gaps:**
- Generated code (with proper headers indicating so)
- Trivial getters/setters
- Debug implementations

## Tracking Files

The project maintains detailed tracking documents:
- **`tests/TEST_COVERAGE.md`** - Statistics, coverage percentages, and API implementation status
- **`tests/API_TEST_MATRIX.md`** - Detailed mapping of which test files exercise which APIs

The `/test-coverage` command automatically updates these files after generating tests.

---

## Example Workflow

1. **Check current coverage:**
```
/check-coverage
```

2. **Review the report and decide:**
- If gaps are small, write tests manually
- If gaps are large, use `/test-coverage` to generate scaffolding

3. **Generate tests automatically:**
```
/test-coverage
```

4. **Review and refine generated tests:**
- Check that tests make sense for the functionality
- Add more specific assertions if needed
- Un-ignore tests that can actually run in your environment

5. **Run tests:**
```bash
cargo test --test test_madmin
```

6. **Re-check coverage:**
```
/check-coverage
```

---

## Tips

- Run `/check-coverage` frequently during development
- Use `/test-coverage` when you have multiple new APIs without tests
- Always review auto-generated tests for correctness
- Some tests will be marked `#[ignore]` - review these to determine if they can be enabled
- Generated tests follow the patterns in existing test files
68 changes: 68 additions & 0 deletions .claude/commands/check-coverage.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
# Check Test Coverage

Analyze code coverage for the MinIO Rust SDK and provide a detailed report.

## Your Task

1. **Install cargo-llvm-cov if needed**
- Check if llvm-cov is installed: `cargo llvm-cov --version`
- If not installed: `cargo install cargo-llvm-cov`
- This tool works well on Windows and all platforms

2. **Run Coverage Analysis**
- For text report: `cargo llvm-cov --lib --tests`
- For HTML report: `cargo llvm-cov --lib --tests --html --output-dir target/coverage`
- For detailed output: `cargo llvm-cov --lib --tests --text`
- Focus on library code, not test code itself

3. **Parse and Present Results**
- Show overall coverage percentage
- List files with their coverage percentages
- Identify files/functions with <100% coverage
- Highlight critical uncovered code paths in `src/madmin` and `src/s3`
- Separate coverage by module (madmin vs s3)

4. **Provide Actionable Report**
Present findings in this format:

```
## Coverage Summary
- Overall: XX.XX%
- Lines covered: XXXX / XXXX
- Functions covered: XXX / XXX

### Module Breakdown
- src/madmin: XX.XX% (XXXX/XXXX lines)
- src/s3: XX.XX% (XXXX/XXXX lines)

## Files Below 100% Coverage

### MinIO Admin (madmin)
#### src/madmin/builders/some_file.rs (XX.XX%)
- Line 45-52: Error handling path not tested
- Line 78: Builder method combination not covered

#### src/madmin/response/other_file.rs (XX.XX%)
- Line 23-25: JSON parsing error path missing test

### S3 API (s3)
#### src/s3/client.rs (XX.XX%)
- Line 123-130: Error handling for network failures
- Line 245: Retry logic not tested

#### src/s3/args/some_arg.rs (XX.XX%)
- Line 67-70: Validation edge case

## Recommendations
1. [madmin] Add test for error case in some_file.rs:45-52
2. [madmin] Test builder method combinations in some_file.rs:78
3. [s3] Add network failure test in client.rs:123-130
4. [s3] Test validation edge case in args/some_arg.rs:67-70
```

5. **Suggest Next Steps**
- Recommend which tests to write first (prioritize critical paths)
- Suggest whether to run `/test-coverage` to auto-generate tests
- Identify if any coverage gaps are in trivial code that can be ignored

Do not make any code changes - only analyze and report.
Loading
Loading