kodelyth-ecc 1.7.0 → 1.7.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (166) hide show
  1. package/CHANGELOG.md +28 -0
  2. package/CLAUDE.md +1 -1
  3. package/README.md +23 -3
  4. package/package.json +1 -1
  5. package/scripts/supply-chain/manifest.js +5 -4
  6. package/social/facebook-v150.svg +3 -3
  7. package/social/github-social-preview.svg +6 -6
  8. package/social/readme-hero.svg +6 -6
  9. package/social/section-install.svg +1 -1
  10. package/tests/evolve/stats.test.js +10 -2
  11. package/tests/mcp/client.test.js +8 -4
  12. package/wiki/FAQ.md +1 -1
  13. package/wiki/Home.md +19 -20
  14. package/wiki/Installation-Guide.md +1 -1
  15. package/wiki/Platform-Support.md +116 -213
  16. package/wiki/Skill-Reference.md +1 -1
  17. package/.agent/rules/README.md +0 -108
  18. package/.agent/rules/agents.md +0 -94
  19. package/.agent/rules/code-review.md +0 -124
  20. package/.agent/rules/coding-style.md +0 -122
  21. package/.agent/rules/design-quality.md +0 -63
  22. package/.agent/rules/development-workflow.md +0 -44
  23. package/.agent/rules/git-mastery.md +0 -366
  24. package/.agent/rules/git-workflow.md +0 -24
  25. package/.agent/rules/hooks.md +0 -25
  26. package/.agent/rules/kodelyth-always-on.md +0 -63
  27. package/.agent/rules/kodelyth-quickstart.md +0 -207
  28. package/.agent/rules/observability.md +0 -390
  29. package/.agent/rules/patterns.md +0 -50
  30. package/.agent/rules/performance.md +0 -178
  31. package/.agent/rules/security.md +0 -58
  32. package/.agent/rules/smart-debug.md +0 -241
  33. package/.agent/rules/soul.md +0 -32
  34. package/.agent/rules/testing.md +0 -46
  35. package/.agent/skills/api-guardian.md +0 -279
  36. package/.agent/skills/architect.md +0 -211
  37. package/.agent/skills/build-error-resolver.md +0 -114
  38. package/.agent/skills/chief-of-staff.md +0 -151
  39. package/.agent/skills/code-architect.md +0 -71
  40. package/.agent/skills/code-explorer.md +0 -69
  41. package/.agent/skills/code-reviewer.md +0 -237
  42. package/.agent/skills/code-simplifier.md +0 -47
  43. package/.agent/skills/comment-analyzer.md +0 -45
  44. package/.agent/skills/conversation-analyzer.md +0 -52
  45. package/.agent/skills/cpp-build-resolver.md +0 -90
  46. package/.agent/skills/cpp-reviewer.md +0 -72
  47. package/.agent/skills/csharp-reviewer.md +0 -101
  48. package/.agent/skills/dart-build-resolver.md +0 -201
  49. package/.agent/skills/database-reviewer.md +0 -91
  50. package/.agent/skills/debug-detective.md +0 -409
  51. package/.agent/skills/doc-updater.md +0 -107
  52. package/.agent/skills/docs-lookup.md +0 -68
  53. package/.agent/skills/e2e-runner.md +0 -107
  54. package/.agent/skills/flutter-reviewer.md +0 -243
  55. package/.agent/skills/gan-evaluator.md +0 -209
  56. package/.agent/skills/gan-generator.md +0 -131
  57. package/.agent/skills/gan-planner.md +0 -99
  58. package/.agent/skills/go-build-resolver.md +0 -94
  59. package/.agent/skills/go-reviewer.md +0 -76
  60. package/.agent/skills/harness-optimizer.md +0 -35
  61. package/.agent/skills/healthcare-reviewer.md +0 -83
  62. package/.agent/skills/java-build-resolver.md +0 -153
  63. package/.agent/skills/java-reviewer.md +0 -92
  64. package/.agent/skills/kodelyth-advisor.md +0 -172
  65. package/.agent/skills/kotlin-build-resolver.md +0 -118
  66. package/.agent/skills/kotlin-reviewer.md +0 -159
  67. package/.agent/skills/loop-operator.md +0 -36
  68. package/.agent/skills/migration-guide.md +0 -368
  69. package/.agent/skills/opensource-forker.md +0 -198
  70. package/.agent/skills/opensource-packager.md +0 -249
  71. package/.agent/skills/opensource-sanitizer.md +0 -188
  72. package/.agent/skills/pair-programmer.md +0 -260
  73. package/.agent/skills/performance-optimizer.md +0 -446
  74. package/.agent/skills/planner.md +0 -212
  75. package/.agent/skills/pr-test-analyzer.md +0 -45
  76. package/.agent/skills/python-reviewer.md +0 -98
  77. package/.agent/skills/pytorch-build-resolver.md +0 -120
  78. package/.agent/skills/refactor-cleaner.md +0 -85
  79. package/.agent/skills/rust-build-resolver.md +0 -148
  80. package/.agent/skills/rust-reviewer.md +0 -94
  81. package/.agent/skills/security-reviewer.md +0 -108
  82. package/.agent/skills/seo-specialist.md +0 -62
  83. package/.agent/skills/silent-failure-hunter.md +0 -50
  84. package/.agent/skills/tdd-guide.md +0 -91
  85. package/.agent/skills/type-design-analyzer.md +0 -41
  86. package/.agent/skills/typescript-reviewer.md +0 -112
  87. package/.agent/skills/ux-reviewer.md +0 -483
  88. package/.agent/workflows/agent-sort.md +0 -23
  89. package/.agent/workflows/aside.md +0 -164
  90. package/.agent/workflows/build-fix.md +0 -62
  91. package/.agent/workflows/checkpoint.md +0 -74
  92. package/.agent/workflows/claw.md +0 -23
  93. package/.agent/workflows/code-review.md +0 -289
  94. package/.agent/workflows/context-budget.md +0 -23
  95. package/.agent/workflows/cpp-build.md +0 -173
  96. package/.agent/workflows/cpp-review.md +0 -132
  97. package/.agent/workflows/cpp-test.md +0 -251
  98. package/.agent/workflows/devfleet.md +0 -23
  99. package/.agent/workflows/docs.md +0 -23
  100. package/.agent/workflows/e2e.md +0 -268
  101. package/.agent/workflows/eval.md +0 -23
  102. package/.agent/workflows/evolve.md +0 -178
  103. package/.agent/workflows/feature-dev.md +0 -49
  104. package/.agent/workflows/flutter-build.md +0 -164
  105. package/.agent/workflows/flutter-review.md +0 -116
  106. package/.agent/workflows/flutter-test.md +0 -144
  107. package/.agent/workflows/gan-build.md +0 -99
  108. package/.agent/workflows/gan-design.md +0 -35
  109. package/.agent/workflows/go-build.md +0 -183
  110. package/.agent/workflows/go-review.md +0 -148
  111. package/.agent/workflows/go-test.md +0 -268
  112. package/.agent/workflows/gradle-build.md +0 -70
  113. package/.agent/workflows/harness-audit.md +0 -73
  114. package/.agent/workflows/hookify-configure.md +0 -14
  115. package/.agent/workflows/hookify-help.md +0 -46
  116. package/.agent/workflows/hookify-list.md +0 -21
  117. package/.agent/workflows/hookify.md +0 -50
  118. package/.agent/workflows/instinct-export.md +0 -66
  119. package/.agent/workflows/instinct-import.md +0 -114
  120. package/.agent/workflows/instinct-status.md +0 -59
  121. package/.agent/workflows/jira.md +0 -106
  122. package/.agent/workflows/kotlin-build.md +0 -174
  123. package/.agent/workflows/kotlin-review.md +0 -140
  124. package/.agent/workflows/kotlin-test.md +0 -312
  125. package/.agent/workflows/learn-eval.md +0 -116
  126. package/.agent/workflows/learn.md +0 -70
  127. package/.agent/workflows/loop-start.md +0 -32
  128. package/.agent/workflows/loop-status.md +0 -24
  129. package/.agent/workflows/model-route.md +0 -26
  130. package/.agent/workflows/multi-backend.md +0 -158
  131. package/.agent/workflows/multi-execute.md +0 -315
  132. package/.agent/workflows/multi-frontend.md +0 -158
  133. package/.agent/workflows/multi-plan.md +0 -268
  134. package/.agent/workflows/multi-workflow.md +0 -191
  135. package/.agent/workflows/orchestrate.md +0 -135
  136. package/.agent/workflows/plan.md +0 -117
  137. package/.agent/workflows/pm2.md +0 -272
  138. package/.agent/workflows/projects.md +0 -39
  139. package/.agent/workflows/promote.md +0 -41
  140. package/.agent/workflows/prompt-optimize.md +0 -23
  141. package/.agent/workflows/prp-commit.md +0 -112
  142. package/.agent/workflows/prp-implement.md +0 -385
  143. package/.agent/workflows/prp-plan.md +0 -502
  144. package/.agent/workflows/prp-pr.md +0 -184
  145. package/.agent/workflows/prp-prd.md +0 -447
  146. package/.agent/workflows/prune.md +0 -31
  147. package/.agent/workflows/python-review.md +0 -297
  148. package/.agent/workflows/quality-gate.md +0 -29
  149. package/.agent/workflows/refactor-clean.md +0 -80
  150. package/.agent/workflows/resume-session.md +0 -156
  151. package/.agent/workflows/review-pr.md +0 -37
  152. package/.agent/workflows/rules-distill.md +0 -20
  153. package/.agent/workflows/rust-build.md +0 -187
  154. package/.agent/workflows/rust-review.md +0 -142
  155. package/.agent/workflows/rust-test.md +0 -308
  156. package/.agent/workflows/santa-loop.md +0 -175
  157. package/.agent/workflows/save-session.md +0 -275
  158. package/.agent/workflows/sessions.md +0 -333
  159. package/.agent/workflows/setup-pm.md +0 -80
  160. package/.agent/workflows/skill-create.md +0 -174
  161. package/.agent/workflows/skill-health.md +0 -54
  162. package/.agent/workflows/tdd.md +0 -231
  163. package/.agent/workflows/test-coverage.md +0 -69
  164. package/.agent/workflows/update-codemaps.md +0 -72
  165. package/.agent/workflows/update-docs.md +0 -84
  166. package/.agent/workflows/verify.md +0 -23
@@ -1,187 +0,0 @@
1
- ---
2
- description: Fix Rust build errors, borrow checker issues, and dependency problems incrementally. Invokes the rust-build-resolver agent for minimal, surgical fixes.
3
- ---
4
-
5
- # Rust Build and Fix
6
-
7
- This command invokes the **rust-build-resolver** agent to incrementally fix Rust build errors with minimal changes.
8
-
9
- ## What This Command Does
10
-
11
- 1. **Run Diagnostics**: Execute `cargo check`, `cargo clippy`, `cargo fmt --check`
12
- 2. **Parse Errors**: Identify error codes and affected files
13
- 3. **Fix Incrementally**: One error at a time
14
- 4. **Verify Each Fix**: Re-run `cargo check` after each change
15
- 5. **Report Summary**: Show what was fixed and what remains
16
-
17
- ## When to Use
18
-
19
- Use `/rust-build` when:
20
- - `cargo build` or `cargo check` fails with errors
21
- - `cargo clippy` reports warnings
22
- - Borrow checker or lifetime errors block compilation
23
- - Cargo dependency resolution fails
24
- - After pulling changes that break the build
25
-
26
- ## Diagnostic Commands Run
27
-
28
- ```bash
29
- # Primary build check
30
- cargo check 2>&1
31
-
32
- # Lints and suggestions
33
- cargo clippy -- -D warnings 2>&1
34
-
35
- # Formatting check
36
- cargo fmt --check 2>&1
37
-
38
- # Dependency issues
39
- cargo tree --duplicates
40
-
41
- # Security audit (if available)
42
- if command -v cargo-audit >/dev/null; then cargo audit; else echo "cargo-audit not installed"; fi
43
- ```
44
-
45
- ## Example Session
46
-
47
- ````text
48
- User: /rust-build
49
-
50
- Agent:
51
- # Rust Build Resolution
52
-
53
- ## Initial Diagnostics
54
-
55
- ```bash
56
- $ cargo check
57
- error[E0502]: cannot borrow `map` as mutable because it is also borrowed as immutable
58
- --> src/service/cache.rs:25:5
59
- error[E0308]: mismatched types
60
- --> src/handler/api.rs:42:12
61
- error[E0425]: cannot find value `db` in this scope
62
- --> src/handler/api.rs:58:9
63
- ```
64
-
65
- Errors found: 3
66
-
67
- ## Fix 1: Borrow Checker Error
68
-
69
- File: src/service/cache.rs:25
70
- Error: E0502 — cannot borrow `map` as mutable because also borrowed as immutable
71
- Cause: Immutable borrow still active during mutable insert
72
-
73
- ```rust
74
- // Changed: restructured to end immutable borrow before mutable access
75
- if !map.contains_key("key") {
76
- map.insert("key".into(), default);
77
- }
78
- ```
79
-
80
- ```bash
81
- $ cargo check
82
- # 2 errors remaining
83
- ```
84
-
85
- ## Fix 2: Type Mismatch
86
-
87
- File: src/handler/api.rs:42
88
- Error: E0308 — mismatched types: expected `usize`, found `&str`
89
-
90
- ```rust
91
- // Changed
92
- let count = params.get("count");
93
- // To
94
- let count: usize = params.get("count")
95
- .and_then(|s| s.parse().ok())
96
- .unwrap_or(0);
97
- ```
98
-
99
- ```bash
100
- $ cargo check
101
- # 1 error remaining
102
- ```
103
-
104
- ## Fix 3: Unresolved Name
105
-
106
- File: src/handler/api.rs:58
107
- Error: E0425 — cannot find value `db` in this scope
108
- Cause: Missing import
109
-
110
- ```rust
111
- // Added
112
- use crate::db;
113
- ```
114
-
115
- ```bash
116
- $ cargo check
117
- # Build successful!
118
- ```
119
-
120
- ## Final Verification
121
-
122
- ```bash
123
- $ cargo clippy -- -D warnings
124
- # No warnings
125
-
126
- $ cargo test
127
- running 6 tests
128
- test service::cache::tests::test_insert ... ok
129
- test service::cache::tests::test_get ... ok
130
- test handler::api::tests::test_parse_count ... ok
131
- test handler::api::tests::test_missing_count ... ok
132
- test handler::api::tests::test_db_import ... ok
133
- test handler::api::tests::test_response ... ok
134
-
135
- test result: ok. 6 passed; 0 failed; 0 ignored
136
- ```
137
-
138
- ## Summary
139
-
140
- | Metric | Count |
141
- |--------|-------|
142
- | Build errors fixed | 3 |
143
- | Clippy warnings fixed | 0 |
144
- | Files modified | 2 |
145
- | Remaining issues | 0 |
146
-
147
- Build Status: SUCCESS
148
- ````
149
-
150
- ## Common Errors Fixed
151
-
152
- | Error | Typical Fix |
153
- |-------|-------------|
154
- | `cannot borrow as mutable` | Restructure to end immutable borrow first; clone only if justified |
155
- | `does not live long enough` | Use owned type or add lifetime annotation |
156
- | `cannot move out of` | Restructure to take ownership; clone only as last resort |
157
- | `mismatched types` | Add `.into()`, `as`, or explicit conversion |
158
- | `trait X not implemented` | Add `#[derive(Trait)]` or implement manually |
159
- | `unresolved import` | Add to Cargo.toml or fix `use` path |
160
- | `cannot find value` | Add import or fix path |
161
-
162
- ## Fix Strategy
163
-
164
- 1. **Build errors first** - Code must compile
165
- 2. **Clippy warnings second** - Fix suspicious constructs
166
- 3. **Formatting third** - `cargo fmt` compliance
167
- 4. **One fix at a time** - Verify each change
168
- 5. **Minimal changes** - Don't refactor, just fix
169
-
170
- ## Stop Conditions
171
-
172
- The agent will stop and report if:
173
- - Same error persists after 3 attempts
174
- - Fix introduces more errors
175
- - Requires architectural changes
176
- - Borrow checker error requires redesigning data ownership
177
-
178
- ## Related Commands
179
-
180
- - `/rust-test` - Run tests after build succeeds
181
- - `/rust-review` - Review code quality
182
- - `/verify` - Full verification loop
183
-
184
- ## Related
185
-
186
- - Agent: `agents/rust-build-resolver.md`
187
- - Skill: `skills/rust-patterns/`
@@ -1,142 +0,0 @@
1
- ---
2
- description: Comprehensive Rust code review for ownership, lifetimes, error handling, unsafe usage, and idiomatic patterns. Invokes the rust-reviewer agent.
3
- ---
4
-
5
- # Rust Code Review
6
-
7
- This command invokes the **rust-reviewer** agent for comprehensive Rust-specific code review.
8
-
9
- ## What This Command Does
10
-
11
- 1. **Verify Automated Checks**: Run `cargo check`, `cargo clippy -- -D warnings`, `cargo fmt --check`, and `cargo test` — stop if any fail
12
- 2. **Identify Rust Changes**: Find modified `.rs` files via `git diff HEAD~1` (or `git diff main...HEAD` for PRs)
13
- 3. **Run Security Audit**: Execute `cargo audit` if available
14
- 4. **Security Scan**: Check for unsafe usage, command injection, hardcoded secrets
15
- 5. **Ownership Review**: Analyze unnecessary clones, lifetime issues, borrowing patterns
16
- 6. **Generate Report**: Categorize issues by severity
17
-
18
- ## When to Use
19
-
20
- Use `/rust-review` when:
21
- - After writing or modifying Rust code
22
- - Before committing Rust changes
23
- - Reviewing pull requests with Rust code
24
- - Onboarding to a new Rust codebase
25
- - Learning idiomatic Rust patterns
26
-
27
- ## Review Categories
28
-
29
- ### CRITICAL (Must Fix)
30
- - Unchecked `unwrap()`/`expect()` in production code paths
31
- - `unsafe` without `// SAFETY:` comment documenting invariants
32
- - SQL injection via string interpolation in queries
33
- - Command injection via unvalidated input in `std::process::Command`
34
- - Hardcoded credentials
35
- - Use-after-free via raw pointers
36
-
37
- ### HIGH (Should Fix)
38
- - Unnecessary `.clone()` to satisfy borrow checker
39
- - `String` parameter where `&str` or `impl AsRef<str>` suffices
40
- - Blocking in async context (`std::thread::sleep`, `std::fs`)
41
- - Missing `Send`/`Sync` bounds on shared types
42
- - Wildcard `_ =>` match on business-critical enums
43
- - Large functions (>50 lines)
44
-
45
- ### MEDIUM (Consider)
46
- - Unnecessary allocation in hot paths
47
- - Missing `with_capacity` when size is known
48
- - Suppressed clippy warnings without justification
49
- - Public API without `///` documentation
50
- - Consider `#[must_use]` on non-`must_use` return types where ignoring values is likely a bug
51
-
52
- ## Automated Checks Run
53
-
54
- ```bash
55
- # Build gate (must pass before review)
56
- cargo check
57
-
58
- # Lints and suggestions
59
- cargo clippy -- -D warnings
60
-
61
- # Formatting
62
- cargo fmt --check
63
-
64
- # Tests
65
- cargo test
66
-
67
- # Security audit (if available)
68
- if command -v cargo-audit >/dev/null; then cargo audit; else echo "cargo-audit not installed"; fi
69
- ```
70
-
71
- ## Example Usage
72
-
73
- ````text
74
- User: /rust-review
75
-
76
- Agent:
77
- # Rust Code Review Report
78
-
79
- ## Files Reviewed
80
- - src/service/user.rs (modified)
81
- - src/handler/api.rs (modified)
82
-
83
- ## Static Analysis Results
84
- - Build: Successful
85
- - Clippy: No warnings
86
- - Formatting: Passed
87
- - Tests: All passing
88
-
89
- ## Issues Found
90
-
91
- [CRITICAL] Unchecked unwrap in Production Path
92
- File: src/service/user.rs:28
93
- Issue: Using `.unwrap()` on database query result
94
- ```rust
95
- let user = db.find_by_id(id).unwrap(); // Panics on missing user
96
- ```
97
- Fix: Propagate error with context
98
- ```rust
99
- let user = db.find_by_id(id)
100
- .context("failed to fetch user")?;
101
- ```
102
-
103
- [HIGH] Unnecessary Clone
104
- File: src/handler/api.rs:45
105
- Issue: Cloning String to satisfy borrow checker
106
- ```rust
107
- let name = user.name.clone();
108
- process(&user, &name);
109
- ```
110
- Fix: Restructure to avoid clone
111
- ```rust
112
- let result = process_name(&user.name);
113
- use_user(&user, result);
114
- ```
115
-
116
- ## Summary
117
- - CRITICAL: 1
118
- - HIGH: 1
119
- - MEDIUM: 0
120
-
121
- Recommendation: Block merge until CRITICAL issue is fixed
122
- ````
123
-
124
- ## Approval Criteria
125
-
126
- | Status | Condition |
127
- |--------|-----------|
128
- | Approve | No CRITICAL or HIGH issues |
129
- | Warning | Only MEDIUM issues (merge with caution) |
130
- | Block | CRITICAL or HIGH issues found |
131
-
132
- ## Integration with Other Commands
133
-
134
- - Use `/rust-test` first to ensure tests pass
135
- - Use `/rust-build` if build errors occur
136
- - Use `/rust-review` before committing
137
- - Use `/code-review` for non-Rust-specific concerns
138
-
139
- ## Related
140
-
141
- - Agent: `agents/rust-reviewer.md`
142
- - Skills: `skills/rust-patterns/`, `skills/rust-testing/`
@@ -1,308 +0,0 @@
1
- ---
2
- description: Enforce TDD workflow for Rust. Write tests first, then implement. Verify 80%+ coverage with cargo-llvm-cov.
3
- ---
4
-
5
- # Rust TDD Command
6
-
7
- This command enforces test-driven development methodology for Rust code using `#[test]`, rstest, proptest, and mockall.
8
-
9
- ## What This Command Does
10
-
11
- 1. **Define Types/Traits**: Scaffold function signatures with `todo!()`
12
- 2. **Write Tests**: Create comprehensive test module (RED)
13
- 3. **Run Tests**: Verify tests fail for the right reason
14
- 4. **Implement Code**: Write minimal code to pass (GREEN)
15
- 5. **Refactor**: Improve while keeping tests green
16
- 6. **Check Coverage**: Ensure 80%+ coverage with cargo-llvm-cov
17
-
18
- ## When to Use
19
-
20
- Use `/rust-test` when:
21
- - Implementing new Rust functions, methods, or traits
22
- - Adding test coverage to existing Rust code
23
- - Fixing bugs (write failing test first)
24
- - Building critical business logic
25
- - Learning TDD workflow in Rust
26
-
27
- ## TDD Cycle
28
-
29
- ```
30
- RED -> Write failing test first
31
- GREEN -> Implement minimal code to pass
32
- REFACTOR -> Improve code, tests stay green
33
- REPEAT -> Next test case
34
- ```
35
-
36
- ## Example Session
37
-
38
- ````text
39
- User: /rust-test I need a function to validate user registration
40
-
41
- Agent:
42
- # TDD Session: Registration Validator
43
-
44
- ## Step 1: Define Interface
45
-
46
- ```rust
47
- // src/validator.rs
48
- pub struct RegistrationRequest {
49
- pub name: String,
50
- pub email: String,
51
- pub password: String,
52
- }
53
-
54
- pub enum ValidationResult {
55
- Valid,
56
- Invalid(Vec<String>),
57
- }
58
-
59
- pub fn validate_registration(request: &RegistrationRequest) -> ValidationResult {
60
- todo!()
61
- }
62
- ```
63
-
64
- ## Step 2: Write Tests (RED)
65
-
66
- ```rust
67
- #[cfg(test)]
68
- mod tests {
69
- use super::*;
70
-
71
- #[test]
72
- fn valid_registration_returns_valid() {
73
- let request = RegistrationRequest {
74
- name: "Alice".into(),
75
- email: "alice@example.com".into(),
76
- password: "SecureP@ss1".into(),
77
- };
78
- assert!(matches!(validate_registration(&request), ValidationResult::Valid));
79
- }
80
-
81
- #[test]
82
- fn blank_name_returns_invalid() {
83
- let request = RegistrationRequest {
84
- name: "".into(),
85
- email: "alice@example.com".into(),
86
- password: "SecureP@ss1".into(),
87
- };
88
- match validate_registration(&request) {
89
- ValidationResult::Invalid(errors) => {
90
- assert!(errors.contains(&"Name is required".to_string()));
91
- }
92
- ValidationResult::Valid => panic!("expected Invalid"),
93
- }
94
- }
95
-
96
- #[test]
97
- fn invalid_email_returns_invalid() {
98
- let request = RegistrationRequest {
99
- name: "Alice".into(),
100
- email: "not-an-email".into(),
101
- password: "SecureP@ss1".into(),
102
- };
103
- assert!(matches!(
104
- validate_registration(&request),
105
- ValidationResult::Invalid(_)
106
- ));
107
- }
108
-
109
- #[test]
110
- fn short_password_returns_invalid() {
111
- let request = RegistrationRequest {
112
- name: "Alice".into(),
113
- email: "alice@example.com".into(),
114
- password: "short".into(),
115
- };
116
- assert!(matches!(
117
- validate_registration(&request),
118
- ValidationResult::Invalid(_)
119
- ));
120
- }
121
- }
122
- ```
123
-
124
- ## Step 3: Run Tests — Verify FAIL
125
-
126
- ```bash
127
- $ cargo test
128
- running 4 tests
129
- test tests::valid_registration_returns_valid ... FAILED (not yet implemented)
130
- test tests::blank_name_returns_invalid ... FAILED
131
- test tests::invalid_email_returns_invalid ... FAILED
132
- test tests::short_password_returns_invalid ... FAILED
133
- ```
134
-
135
- Tests fail as expected (todo! panic).
136
-
137
- ## Step 4: Implement Minimal Code (GREEN)
138
-
139
- ```rust
140
- pub fn validate_registration(request: &RegistrationRequest) -> ValidationResult {
141
- let mut errors = Vec::new();
142
-
143
- if request.name.trim().is_empty() {
144
- errors.push("Name is required".into());
145
- }
146
- if !request.email.contains('@') {
147
- errors.push("Invalid email format".into());
148
- }
149
- if request.password.len() < 8 {
150
- errors.push("Password must be at least 8 characters".into());
151
- }
152
-
153
- if errors.is_empty() {
154
- ValidationResult::Valid
155
- } else {
156
- ValidationResult::Invalid(errors)
157
- }
158
- }
159
- ```
160
-
161
- ## Step 5: Run Tests — Verify PASS
162
-
163
- ```bash
164
- $ cargo test
165
- running 4 tests
166
- test tests::valid_registration_returns_valid ... ok
167
- test tests::blank_name_returns_invalid ... ok
168
- test tests::invalid_email_returns_invalid ... ok
169
- test tests::short_password_returns_invalid ... ok
170
-
171
- test result: ok. 4 passed; 0 failed
172
- ```
173
-
174
- All tests passing!
175
-
176
- ## Step 6: Check Coverage
177
-
178
- ```bash
179
- $ cargo llvm-cov
180
- Coverage: 100.0% of lines
181
- ```
182
-
183
- Coverage: 100%
184
-
185
- ## TDD Complete!
186
- ````
187
-
188
- ## Test Patterns
189
-
190
- ### Unit Tests
191
-
192
- ```rust
193
- #[cfg(test)]
194
- mod tests {
195
- use super::*;
196
-
197
- #[test]
198
- fn adds_two_numbers() {
199
- assert_eq!(add(2, 3), 5);
200
- }
201
-
202
- #[test]
203
- fn handles_error() -> Result<(), Box<dyn std::error::Error>> {
204
- let result = parse_config(r#"port = 8080"#)?;
205
- assert_eq!(result.port, 8080);
206
- Ok(())
207
- }
208
- }
209
- ```
210
-
211
- ### Parameterized Tests with rstest
212
-
213
- ```rust
214
- use rstest::{rstest, fixture};
215
-
216
- #[rstest]
217
- #[case("hello", 5)]
218
- #[case("", 0)]
219
- #[case("rust", 4)]
220
- fn test_string_length(#[case] input: &str, #[case] expected: usize) {
221
- assert_eq!(input.len(), expected);
222
- }
223
- ```
224
-
225
- ### Async Tests
226
-
227
- ```rust
228
- #[tokio::test]
229
- async fn fetches_data_successfully() {
230
- let client = TestClient::new().await;
231
- let result = client.get("/data").await;
232
- assert!(result.is_ok());
233
- }
234
- ```
235
-
236
- ### Property-Based Tests
237
-
238
- ```rust
239
- use proptest::prelude::*;
240
-
241
- proptest! {
242
- #[test]
243
- fn encode_decode_roundtrip(input in ".*") {
244
- let encoded = encode(&input);
245
- let decoded = decode(&encoded).unwrap();
246
- assert_eq!(input, decoded);
247
- }
248
- }
249
- ```
250
-
251
- ## Coverage Commands
252
-
253
- ```bash
254
- # Summary report
255
- cargo llvm-cov
256
-
257
- # HTML report
258
- cargo llvm-cov --html
259
-
260
- # Fail if below threshold
261
- cargo llvm-cov --fail-under-lines 80
262
-
263
- # Run specific test
264
- cargo test test_name
265
-
266
- # Run with output
267
- cargo test -- --nocapture
268
-
269
- # Run without stopping on first failure
270
- cargo test --no-fail-fast
271
- ```
272
-
273
- ## Coverage Targets
274
-
275
- | Code Type | Target |
276
- |-----------|--------|
277
- | Critical business logic | 100% |
278
- | Public API | 90%+ |
279
- | General code | 80%+ |
280
- | Generated / FFI bindings | Exclude |
281
-
282
- ## TDD Best Practices
283
-
284
- **DO:**
285
- - Write test FIRST, before any implementation
286
- - Run tests after each change
287
- - Use `assert_eq!` over `assert!` for better error messages
288
- - Use `?` in tests that return `Result` for cleaner output
289
- - Test behavior, not implementation
290
- - Include edge cases (empty, boundary, error paths)
291
-
292
- **DON'T:**
293
- - Write implementation before tests
294
- - Skip the RED phase
295
- - Use `#[should_panic]` when `Result::is_err()` works
296
- - Use `sleep()` in tests — use channels or `tokio::time::pause()`
297
- - Mock everything — prefer integration tests when feasible
298
-
299
- ## Related Commands
300
-
301
- - `/rust-build` - Fix build errors
302
- - `/rust-review` - Review code after implementation
303
- - `/verify` - Run full verification loop
304
-
305
- ## Related
306
-
307
- - Skill: `skills/rust-testing/`
308
- - Skill: `skills/rust-patterns/`