Skip to content

Commit bca3af8

Browse files
jgarzikclaude
andcommitted
Expand validation suite with mock_webapp fixture and 23 new tests
Add comprehensive mock_webapp fixture with intentional issues: - Hardcoded API key in auth.rs (security issue) - Deprecated old_query() function in database.rs - Validation bug: "@." accepted as valid email - Undocumented handler functions - One intentionally failing test Add 8 new test categories (23 tests total): - 10-tdd: Test-driven development workflow - 11-debugging: Bug fixing, security review, error tracing - 12-refactoring: Deprecated code, modernization, renames - 13-documentation: Find undocumented, add docs, update README - 14-git: Git status, commit, branch creation - 15-multi-file: Cross-file changes and module extraction - 16-review: Security and code review, custom commands - 17-mcp: MCP calculator integration Add test infrastructure: - run_yo_in_mock_webapp() for webapp-specific tests - reset_mock_webapp() / cleanup_mock_webapp() helpers - assert_cargo_test_passes/fails() assertions - assert_git_clean/dirty/has_commits() assertions Test results: 43/51 passing (84%) - failures are expected non-deterministic LLM behavior variations. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
1 parent a03dd91 commit bca3af8

48 files changed

Lines changed: 1510 additions & 2 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
# Code Review Command
2+
3+
Review the mock_webapp codebase for common issues.
4+
5+
## Instructions
6+
7+
Please review this codebase and identify:
8+
9+
1. **Security Issues**: Look for hardcoded credentials, API keys, or sensitive data
10+
2. **Deprecated Code**: Find any deprecated functions or patterns
11+
3. **Missing Documentation**: Identify functions without doc comments
12+
4. **Code Smells**: Look for TODO comments, dead code, or poor patterns
13+
5. **Test Coverage Gaps**: Identify untested functionality
14+
15+
Focus on the `src/` directory and provide a summary of findings with file locations.

fixtures/mock_webapp/Cargo.lock

Lines changed: 7 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

fixtures/mock_webapp/Cargo.toml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
[package]
2+
name = "mock_webapp"
3+
version = "0.1.0"
4+
edition = "2021"
5+
6+
[dependencies]
7+
8+
[dev-dependencies]

fixtures/mock_webapp/README.md

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
# Mock Web Application
2+
3+
A simple web API for demonstration purposes.
4+
5+
## Features
6+
7+
- User management
8+
- Session handling
9+
- Authentication
10+
11+
## Getting Started
12+
13+
```bash
14+
cargo build
15+
cargo test
16+
```
17+
18+
## Configuration
19+
20+
Set environment variables or use config file.
21+
22+
<!-- TODO: Add API documentation section -->
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
//! HTTP request handlers.
2+
3+
use crate::models::user::User;
4+
use crate::services::auth::AuthService;
5+
6+
// Handler for getting user by ID
7+
pub fn get_user(user_id: u64) -> Option<User> {
8+
// Simulate database lookup
9+
if user_id == 1 {
10+
Some(User::new(1, "admin".to_string(), "admin@example.com".to_string()))
11+
} else {
12+
None
13+
}
14+
}
15+
16+
// Handler for creating a new user
17+
pub fn create_user(name: String, email: String) -> Result<User, String> {
18+
if name.is_empty() {
19+
return Err("Name cannot be empty".to_string());
20+
}
21+
Ok(User::new(0, name, email))
22+
}
23+
24+
// Handler for user login
25+
pub fn login(email: &str, password: &str, auth: &AuthService) -> Result<String, String> {
26+
if auth.verify_credentials(email, password) {
27+
Ok(auth.generate_token(email))
28+
} else {
29+
Err("Invalid credentials".to_string())
30+
}
31+
}
32+
33+
// Handler for listing all users
34+
pub fn list_users() -> Vec<User> {
35+
vec![
36+
User::new(1, "admin".to_string(), "admin@example.com".to_string()),
37+
User::new(2, "user".to_string(), "user@example.com".to_string()),
38+
]
39+
}
40+
41+
// Handler for deleting a user
42+
pub fn delete_user(user_id: u64) -> bool {
43+
// Simulate deletion
44+
user_id > 0
45+
}
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
//! API module.
2+
3+
pub mod handlers;
4+
pub mod routes;
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
//! Route definitions.
2+
3+
/// Available API routes.
4+
#[derive(Debug, Clone, Copy)]
5+
pub enum Route {
6+
/// GET /users
7+
ListUsers,
8+
/// GET /users/:id
9+
GetUser,
10+
/// POST /users
11+
CreateUser,
12+
/// DELETE /users/:id
13+
DeleteUser,
14+
/// POST /login
15+
Login,
16+
}
17+
18+
impl Route {
19+
/// Get the HTTP method for this route.
20+
pub fn method(&self) -> &'static str {
21+
match self {
22+
Route::ListUsers | Route::GetUser => "GET",
23+
Route::CreateUser | Route::Login => "POST",
24+
Route::DeleteUser => "DELETE",
25+
}
26+
}
27+
28+
/// Get the path pattern for this route.
29+
pub fn path(&self) -> &'static str {
30+
match self {
31+
Route::ListUsers => "/users",
32+
Route::GetUser => "/users/:id",
33+
Route::CreateUser => "/users",
34+
Route::DeleteUser => "/users/:id",
35+
Route::Login => "/login",
36+
}
37+
}
38+
}

fixtures/mock_webapp/src/config.rs

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
//! Application configuration.
2+
3+
/// Application configuration settings.
4+
#[derive(Debug, Clone)]
5+
pub struct Config {
6+
/// Database connection string
7+
pub database_url: String,
8+
/// Server port
9+
pub port: u16,
10+
/// Enable debug mode
11+
pub debug: bool,
12+
}
13+
14+
impl Config {
15+
/// Load configuration from environment.
16+
pub fn load() -> Self {
17+
Self {
18+
database_url: std::env::var("DATABASE_URL")
19+
.unwrap_or_else(|_| "sqlite::memory:".to_string()),
20+
port: std::env::var("PORT")
21+
.ok()
22+
.and_then(|p| p.parse().ok())
23+
.unwrap_or(8080),
24+
debug: std::env::var("DEBUG").is_ok(),
25+
}
26+
}
27+
}
28+
29+
impl Default for Config {
30+
fn default() -> Self {
31+
Self::load()
32+
}
33+
}

fixtures/mock_webapp/src/lib.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
//! Mock Web Application library.
2+
3+
pub mod api;
4+
pub mod config;
5+
pub mod models;
6+
pub mod services;
7+
pub mod utils;

fixtures/mock_webapp/src/main.rs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
//! Mock Web Application entry point.
2+
3+
mod api;
4+
mod config;
5+
mod models;
6+
mod services;
7+
mod utils;
8+
9+
fn main() {
10+
let config = config::Config::load();
11+
println!("Starting server with config: {:?}", config);
12+
13+
// Initialize services
14+
let _auth = services::auth::AuthService::new(&config);
15+
let _db = services::database::Database::new(&config);
16+
17+
println!("Server ready!");
18+
}

0 commit comments

Comments
 (0)