Skip to content

Commit c6a3267

Browse files
committed
Address Copilot feedback and add tests
- Fix SQL duplication bug with DISTINCT ON for get_user_submissions - Add input validation for limit (1-100) and offset (>=0) - Use consistent response format {"status": "ok", "submission_id": ...} - Add unit tests for get_user_submissions DB method - Update CLAUDE.md with testing guidance
1 parent 36d9253 commit c6a3267

File tree

2 files changed

+52
-2
lines changed

2 files changed

+52
-2
lines changed

CLAUDE.md

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,52 @@ All PRs must pass:
2626
- `cargo test` - All tests pass
2727
- Builds on Linux, macOS, and Windows
2828

29+
### Testing
30+
31+
#### Unit Tests
32+
33+
Tests are in the same file as the code (Rust convention):
34+
- `src/service/mod.rs` - API client tests
35+
- `src/utils/mod.rs` - Utility function tests
36+
37+
Run all tests:
38+
```bash
39+
cargo test
40+
```
41+
42+
Run specific tests:
43+
```bash
44+
cargo test test_name
45+
```
46+
47+
#### Test Requirements
48+
49+
When adding new functionality:
50+
51+
1. **Service functions** (`src/service/mod.rs`):
52+
- Add tests in the `#[cfg(test)] mod tests` block
53+
- Test error handling, response parsing
54+
55+
2. **Command handlers** (`src/cmd/`):
56+
- Integration testing via E2E regression tests
57+
58+
#### E2E Regression Testing
59+
60+
Use a local instance of kernelbot to test CLI functionality end-to-end:
61+
62+
```bash
63+
# Start local kernelbot server (see kernelbot repo)
64+
cd ../kernelbot
65+
docker compose up -d
66+
uv run uvicorn src.kernelbot.api.main:app --reload --port 8000
67+
68+
# Test CLI against local instance
69+
export POPCORN_API_URL=http://localhost:8000
70+
cargo run -- submissions list --leaderboard test-leaderboard
71+
cargo run -- submissions show 123
72+
cargo run -- submissions delete 123 --force
73+
```
74+
2975
## Architecture Overview
3076

3177
Popcorn CLI is a command-line tool for submitting GPU kernel optimization solutions to [gpumode.com](https://gpumode.com) competitions.

src/cmd/submissions.rs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -135,8 +135,12 @@ pub async fn delete_submission(cli_id: String, submission_id: i64, force: bool)
135135
}
136136

137137
// Delete the submission
138-
service::delete_user_submission(&client, submission_id).await?;
139-
println!("Submission {} deleted successfully.", submission_id);
138+
let result = service::delete_user_submission(&client, submission_id).await?;
139+
if result.get("status").and_then(|s| s.as_str()) == Some("ok") {
140+
println!("Submission {} deleted successfully.", submission_id);
141+
} else {
142+
println!("Submission deleted.");
143+
}
140144

141145
Ok(())
142146
}

0 commit comments

Comments
 (0)