Skip to content

Commit 2e6193d

Browse files
authored
Add CLAUDE.md for Claude Code guidance (#841)
fix flaky tests
1 parent 911ac4e commit 2e6193d

File tree

3 files changed

+119
-2
lines changed

3 files changed

+119
-2
lines changed

CLAUDE.md

Lines changed: 109 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,109 @@
1+
# CLAUDE.md
2+
3+
This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
4+
5+
## Project Overview
6+
7+
ClashRS is a custom protocol, rule-based network proxy software written in Rust. It's a high-performance proxy with support for multiple protocols (Shadowsocks, Trojan, Vmess, Wireguard, Tor, Tuic, Socks5), flexible routing rules, DNS anti-spoofing, and cross-platform support.
8+
9+
## Workspace Structure
10+
11+
This is a Rust workspace with four main crates:
12+
- `clash/` - Main binary executable
13+
- `clash_lib/` - Core library containing all proxy logic
14+
- `clash_doc/` - Documentation generation
15+
- `clash_ffi/` - FFI bindings for mobile platforms
16+
17+
## Common Commands
18+
19+
### Build
20+
```bash
21+
cargo build # Debug build
22+
cargo build --release # Release build
23+
cargo build --features plus # Build with all features including Tor
24+
```
25+
26+
### Testing
27+
```bash
28+
cargo test --all --all-features # Run all tests
29+
CLASH_RS_CI=true cargo test --all --all-features # Run tests in CI mode
30+
make test-no-docker # Run tests without Docker
31+
```
32+
33+
### Documentation
34+
```bash
35+
make docs # Generate documentation
36+
cargo doc -p clash_doc --no-deps # Generate config docs only
37+
```
38+
39+
### Running
40+
```bash
41+
./target/debug/clash-rs -c config.yaml # Run with config file
42+
./target/debug/clash-rs -t # Test configuration
43+
./target/debug/clash-rs -h # Show help
44+
```
45+
46+
## Architecture
47+
48+
### Core Components
49+
50+
**clash_lib/src/app/** - Main application modules:
51+
- `api/` - REST API handlers for web dashboard
52+
- `dispatcher/` - Traffic routing and connection management
53+
- `dns/` - DNS resolution with anti-spoofing
54+
- `inbound/` - Inbound connection handling
55+
- `outbound/` - Outbound proxy connections
56+
- `router/` - Rule-based routing logic
57+
58+
**clash_lib/src/proxy/** - Protocol implementations:
59+
- `shadowsocks/`, `trojan/`, `vmess/`, `socks/` - Proxy protocols
60+
- `group/` - Proxy group types (selector, fallback, load balance)
61+
- `transport/` - Underlying transports (TLS, WebSocket, gRPC, H2)
62+
- `tun/` - TUN device support for transparent proxy
63+
64+
**clash_lib/src/config/** - Configuration parsing and validation
65+
66+
### Key Design Patterns
67+
68+
- **Async/await**: Heavy use of Tokio for async networking
69+
- **Trait-based**: Extensible proxy system using traits
70+
- **Error handling**: Comprehensive error types with `thiserror`
71+
- **Feature flags**: Conditional compilation for different protocols
72+
- **Zero-copy**: Optimized data paths where possible
73+
74+
## Testing
75+
76+
Tests are located in `clash_lib/tests/` and include:
77+
- `smoke_tests.rs` - Basic functionality tests
78+
- `api_tests.rs` - API endpoint tests
79+
- Integration tests with Docker containers for various proxy protocols
80+
81+
Set `CLASH_RS_CI=true` environment variable when running tests to enable CI-specific behavior.
82+
83+
## Platform-Specific Notes
84+
85+
- **iOS/macOS**: Use `scripts/build_apple.sh` to build XCFramework
86+
- **Windows**: Requires `wintun.dll` in same directory as executable
87+
- **Linux**: Enhanced with platform-specific UDP socket optimizations
88+
89+
## Feature Flags
90+
91+
Key features that can be enabled:
92+
- `shadowsocks` - Shadowsocks protocol support
93+
- `tuic` - TUIC protocol support
94+
- `ssh` - SSH tunnel support
95+
- `onion` - Tor support
96+
- `shadowquic` - ShadowQUIC protocol support
97+
- `tokio-console` - Tokio console debugging
98+
- `bench` - Benchmarking tools
99+
100+
## Configuration
101+
102+
The project uses YAML configuration files. Sample configs are in `clash/tests/data/config/`.
103+
104+
Main configuration sections:
105+
- `port` - HTTP/SOCKS proxy port
106+
- `dns` - DNS server settings
107+
- `rules` - Traffic routing rules
108+
- `proxies` - Outbound proxy definitions
109+
- `proxy-groups` - Proxy group configurations

clash_lib/src/app/remote_content_manager/providers/fetcher.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -262,7 +262,11 @@ mod tests {
262262
let tx1 = tx.clone();
263263

264264
let mut mock_vehicle = MockProviderVehicle::new();
265-
let mock_file = std::env::temp_dir().join("mock_provider_vehicle");
265+
let mock_file = std::env::temp_dir().join(format!(
266+
"{}-{}",
267+
"mock_provider_vehicle",
268+
uuid::Uuid::new_v4()
269+
));
266270
if Path::new(mock_file.to_str().unwrap()).exists() {
267271
std::fs::remove_file(&mock_file).unwrap();
268272
}

clash_lib/src/app/remote_content_manager/providers/rule_provider/provider.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -502,7 +502,11 @@ mod tests {
502502
let mock_geodata = MockGeoDataLookupTrait::new();
503503
let mut mock_vehicle = MockProviderVehicle::new();
504504

505-
let mock_file = std::env::temp_dir().join("mock_provider_vehicle");
505+
let mock_file = std::env::temp_dir().join(format!(
506+
"{}-{}",
507+
"mock_provider_vehicle",
508+
uuid::Uuid::new_v4()
509+
));
506510
if Path::new(mock_file.to_str().unwrap()).exists() {
507511
std::fs::remove_file(&mock_file).unwrap();
508512
}

0 commit comments

Comments
 (0)