# Build
cargo build
# Run tests
cargo test
# Format code (required before commits)
cargo fmt --all
# Lint (must pass with no warnings)
cargo clippy --all-targets --all-features -- -D warningsAll PRs must pass:
cargo fmt --all -- --check- Code formattingcargo clippy -- -D warnings- No clippy warnings allowedcargo test- All tests pass- Builds on Linux, macOS, and Windows
Tests are in the same file as the code (Rust convention):
src/service/mod.rs- API client testssrc/utils/mod.rs- Utility function tests
Run all tests:
cargo testRun specific tests:
cargo test test_nameWhen adding new functionality:
-
Service functions (
src/service/mod.rs):- Add tests in the
#[cfg(test)] mod testsblock - Test error handling, response parsing
- Add tests in the
-
Command handlers (
src/cmd/):- Integration testing via E2E regression tests
Full end-to-end testing requires a running kernelbot API server. You can test against production or a local instance.
export POPCORN_API_URL=https://site--bot--dxfjds728w5v.code.run
cargo run -- submissions list --leaderboard grayscaleThis tests the complete flow: CLI → API → Database → Modal runner.
Step 1: Set up kernelbot server (in the kernelbot repo):
# Start PostgreSQL
brew services start postgresql@14
# Create database and run migrations
createdb kernelbot
export DATABASE_URL="postgresql://$(whoami)@localhost:5432/kernelbot"
uv run yoyo apply --database "$DATABASE_URL" src/migrations/
# Create test user
psql "$DATABASE_URL" -c "INSERT INTO leaderboard.user_info (id, user_name, cli_id, cli_valid)
VALUES ('999999', 'testuser', 'test-cli-id-123', true)
ON CONFLICT (id) DO UPDATE SET cli_id = 'test-cli-id-123', cli_valid = true;"
# Start API server
cd src/kernelbot
export ADMIN_TOKEN="your-admin-token" # Check .env for LOCAL_ADMIN_TOKEN
uv run python main.py --api-onlyStep 2: Sync leaderboards:
curl -X POST "http://localhost:8000/admin/update-problems" \
-H "Authorization: Bearer $ADMIN_TOKEN" \
-H "Content-Type: application/json" \
-d '{"problem_set": "pmpp_v2"}'Step 3: Configure CLI for local testing:
# Backup and set test config
cp ~/.popcorn.yaml ~/.popcorn.yaml.bak
echo "cli_id: test-cli-id-123" > ~/.popcorn.yamlStep 4: Run CLI commands:
export POPCORN_API_URL=http://localhost:8000
# Test submissions commands
cargo run --release -- submissions list --leaderboard vectoradd_v2
cargo run --release -- submissions show <ID>
cargo run --release -- submissions delete <ID>
# Test actual submission (requires Modal account for GPU execution)
cargo run --release -- submit solution.py --gpu H100 --leaderboard vectoradd_v2 --mode testStep 5: Restore original config:
cp ~/.popcorn.yaml.bak ~/.popcorn.yaml && rm ~/.popcorn.yaml.bak- 401 Unauthorized: CLI ID not registered in database - create test user first
- 404 Not Found: Leaderboards not synced - run update-problems endpoint
- Connection refused: API server not running on localhost:8000
- "Device not configured": TTY issue - ensure POPCORN_API_URL is set
Admin commands require the POPCORN_ADMIN_TOKEN environment variable.
# Server control
popcorn admin start # Start accepting jobs
popcorn admin stop # Stop accepting jobs
popcorn admin stats # Get server statistics
popcorn admin stats --last-day # Stats for last 24 hours only
# Submission management
popcorn admin get-submission <ID> # Get any submission by ID
popcorn admin delete-submission <ID> # Delete any submission
# Leaderboard management
popcorn admin create-leaderboard <dir> # Create leaderboard from problem directory
popcorn admin delete-leaderboard <name> # Delete a leaderboard
popcorn admin delete-leaderboard <name> --force # Force delete with submissions
# Update problems from GitHub
popcorn admin update-problems
popcorn admin update-problems --problem-set nvidia --forcePopcorn CLI is a command-line tool for submitting GPU kernel optimization solutions to gpumode.com competitions.
src/
├── main.rs # Entry point, sets POPCORN_API_URL
├── cmd/ # Command handling
│ ├── mod.rs # CLI argument parsing (clap), config loading
│ ├── admin.rs # Admin commands (requires POPCORN_ADMIN_TOKEN)
│ ├── auth.rs # OAuth authentication (Discord/GitHub)
│ ├── submissions.rs # User submission management (list, show, delete)
│ └── submit.rs # Submission logic, TUI app state machine
├── service/
│ └── mod.rs # HTTP client, API calls, SSE streaming
├── models/
│ └── mod.rs # Data structures (LeaderboardItem, GpuItem, AppState)
├── utils/
│ └── mod.rs # Directive parsing, text wrapping, ASCII art
└── views/
├── loading_page.rs # TUI loading screen with progress bar
└── result_page.rs # TUI results display with scrolling
Important: Before implementing new functionality, check for existing code in both repos:
-
Check discord-cluster-manager for existing Discord commands and database methods:
src/kernelbot/cogs/- Discord bot commandssrc/libkernelbot/leaderboard_db.py- Database methodssrc/kernelbot/api/main.py- Existing API endpoints
-
Check popcorn-cli for existing service functions and commands:
src/service/mod.rs- API client functionssrc/cmd/- CLI command handlers
-
Reuse existing functionality where possible:
- Database methods (e.g.,
get_submission_by_id,delete_submission) - API response handling patterns
- Authentication validation (
validate_user_header,validate_cli_header)
- Database methods (e.g.,
-
Authentication (
cmd/auth.rs): User registers via Discord/GitHub OAuth. CLI ID stored in~/.popcorn.yaml. -
Submission (
cmd/submit.rs):- TUI mode: Interactive selection of leaderboard → GPU → mode
- Plain mode (
--no-tui): Direct submission with CLI flags - Reads solution file with optional
#!POPCORNdirectives for defaults
-
API Communication (
service/mod.rs):- Fetches available leaderboards and GPUs
- Submits solutions via multipart form POST
- Handles SSE (Server-Sent Events) streaming for real-time results
- Supports modes:
test,benchmark,leaderboard,profile
clap- CLI argument parsingratatui+crossterm- Terminal UIreqwest- HTTP client with SSE streamingtokio- Async runtimeserde/serde_yaml/serde_json- Serialization