@grimoire-cc/cli 0.13.2 → 0.14.0

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 (50) hide show
  1. package/dist/commands/update.d.ts.map +1 -1
  2. package/dist/commands/update.js +14 -0
  3. package/dist/commands/update.js.map +1 -1
  4. package/dist/enforce.d.ts +3 -1
  5. package/dist/enforce.d.ts.map +1 -1
  6. package/dist/enforce.js +18 -6
  7. package/dist/enforce.js.map +1 -1
  8. package/dist/setup.d.ts.map +1 -1
  9. package/dist/setup.js +47 -0
  10. package/dist/setup.js.map +1 -1
  11. package/dist/summary.d.ts.map +1 -1
  12. package/dist/summary.js +9 -0
  13. package/dist/summary.js.map +1 -1
  14. package/package.json +1 -1
  15. package/packs/dev-pack/agents/grimoire.tdd-specialist.md +194 -27
  16. package/packs/dev-pack/grimoire.json +9 -42
  17. package/packs/dev-pack/skills/grimoire.conventional-commit/SKILL.md +68 -47
  18. package/packs/dotnet-pack/agents/grimoire.csharp-coder.md +110 -113
  19. package/packs/dotnet-pack/grimoire.json +23 -5
  20. package/packs/dotnet-pack/skills/grimoire.unit-testing-dotnet/SKILL.md +252 -0
  21. package/packs/{dev-pack/skills/grimoire.tdd-specialist → dotnet-pack/skills/grimoire.unit-testing-dotnet}/reference/anti-patterns.md +78 -0
  22. package/packs/dotnet-pack/skills/grimoire.unit-testing-dotnet/reference/tdd-workflow-patterns.md +259 -0
  23. package/packs/go-pack/grimoire.json +19 -0
  24. package/packs/go-pack/skills/grimoire.unit-testing-go/SKILL.md +256 -0
  25. package/packs/go-pack/skills/grimoire.unit-testing-go/reference/anti-patterns.md +244 -0
  26. package/packs/go-pack/skills/grimoire.unit-testing-go/reference/tdd-workflow-patterns.md +259 -0
  27. package/packs/python-pack/grimoire.json +19 -0
  28. package/packs/python-pack/skills/grimoire.unit-testing-python/SKILL.md +239 -0
  29. package/packs/python-pack/skills/grimoire.unit-testing-python/reference/anti-patterns.md +244 -0
  30. package/packs/python-pack/skills/grimoire.unit-testing-python/reference/tdd-workflow-patterns.md +259 -0
  31. package/packs/rust-pack/grimoire.json +29 -0
  32. package/packs/rust-pack/skills/grimoire.unit-testing-rust/SKILL.md +243 -0
  33. package/packs/rust-pack/skills/grimoire.unit-testing-rust/reference/anti-patterns.md +244 -0
  34. package/packs/rust-pack/skills/grimoire.unit-testing-rust/reference/tdd-workflow-patterns.md +259 -0
  35. package/packs/ts-pack/agents/grimoire.typescript-coder.md +36 -1
  36. package/packs/ts-pack/grimoire.json +27 -1
  37. package/packs/ts-pack/skills/grimoire.unit-testing-typescript/SKILL.md +255 -0
  38. package/packs/ts-pack/skills/grimoire.unit-testing-typescript/reference/anti-patterns.md +244 -0
  39. package/packs/ts-pack/skills/grimoire.unit-testing-typescript/reference/tdd-workflow-patterns.md +259 -0
  40. package/packs/dev-pack/skills/grimoire.tdd-specialist/SKILL.md +0 -248
  41. package/packs/dev-pack/skills/grimoire.tdd-specialist/reference/language-frameworks.md +0 -388
  42. package/packs/dev-pack/skills/grimoire.tdd-specialist/reference/tdd-workflow-patterns.md +0 -135
  43. package/packs/dotnet-pack/skills/grimoire.dotnet-unit-testing/SKILL.md +0 -293
  44. package/packs/dotnet-pack/skills/grimoire.dotnet-unit-testing/reference/anti-patterns.md +0 -329
  45. package/packs/dotnet-pack/skills/grimoire.dotnet-unit-testing/reference/framework-guidelines.md +0 -361
  46. package/packs/dotnet-pack/skills/grimoire.dotnet-unit-testing/reference/parameterized-testing.md +0 -378
  47. package/packs/dotnet-pack/skills/grimoire.dotnet-unit-testing/reference/test-organization.md +0 -476
  48. package/packs/dotnet-pack/skills/grimoire.dotnet-unit-testing/reference/test-performance.md +0 -576
  49. package/packs/dotnet-pack/skills/grimoire.dotnet-unit-testing/templates/tunit-template.md +0 -438
  50. package/packs/dotnet-pack/skills/grimoire.dotnet-unit-testing/templates/xunit-template.md +0 -303
@@ -1,135 +0,0 @@
1
- # TDD Workflow Patterns
2
-
3
- Guidance on the test-driven development process, when to apply it, and advanced techniques.
4
-
5
- ## Table of Contents
6
-
7
- - [Red-Green-Refactor](#red-green-refactor)
8
- - [Transformation Priority Premise](#transformation-priority-premise)
9
- - [When to Use TDD](#when-to-use-tdd)
10
- - [When TDD Is Less Effective](#when-tdd-is-less-effective)
11
- - [BDD and ATDD Extensions](#bdd-and-atdd-extensions)
12
-
13
- ## Red-Green-Refactor
14
-
15
- The core TDD cycle, repeated in small increments:
16
-
17
- ### 1. Red — Write a Failing Test
18
-
19
- Write the smallest test that describes the next piece of behavior. The test MUST fail before you write any production code. A test that passes immediately provides no confidence.
20
-
21
- **Rules:**
22
- - Write only ONE test at a time
23
- - The test should compile/parse but fail at the assertion
24
- - If the test passes immediately, it's either trivial or testing existing behavior
25
-
26
- ### 2. Green — Make It Pass
27
-
28
- Write the MINIMUM code to make the failing test pass. Do not add extra logic, handle cases not yet tested, or optimize.
29
-
30
- **Rules:**
31
- - Write the simplest code that makes the test pass
32
- - It's OK to hardcode values initially — the next test will force generalization
33
- - Do not add code for future tests
34
- - All existing tests must still pass
35
-
36
- ### 3. Refactor — Clean Up
37
-
38
- With all tests green, improve the code structure without changing behavior. Tests give you the safety net.
39
-
40
- **Rules:**
41
- - No new functionality during refactoring
42
- - All tests must remain green after each refactoring step
43
- - Remove duplication, improve naming, extract methods
44
- - Refactor both production code AND test code
45
-
46
- ### Cycle Length
47
-
48
- Each Red-Green-Refactor cycle should take 1-10 minutes. If you're spending more than 10 minutes in the Red or Green phase, the step is too large — break it down.
49
-
50
- ## Transformation Priority Premise
51
-
52
- Kent Beck's insight: when going from Red to Green, prefer simpler transformations over complex ones. Listed from simplest to most complex:
53
-
54
- 1. **Constant** — return a hardcoded value
55
- 2. **Scalar** — replace constant with a variable
56
- 3. **Direct** — replace unconditional with conditional (if/else)
57
- 4. **Collection** — operate on a collection instead of a scalar
58
- 5. **Iteration** — add a loop
59
- 6. **Recursion** — add recursive call
60
- 7. **Assignment** — replace computed value with mutation
61
-
62
- **Example — building FizzBuzz with TDD:**
63
-
64
- ```
65
- Test 1: input 1 → "1" Transformation: Constant
66
- Test 2: input 2 → "2" Transformation: Scalar (use the input)
67
- Test 3: input 3 → "Fizz" Transformation: Direct (add if)
68
- Test 4: input 5 → "Buzz" Transformation: Direct (add another if)
69
- Test 5: input 15 → "FizzBuzz" Transformation: Direct (add combined if)
70
- Test 6: input 1-15 → full list Transformation: Iteration (generalize)
71
- ```
72
-
73
- By following this priority, you avoid over-engineering early and let the design emerge naturally from the tests.
74
-
75
- ## When to Use TDD
76
-
77
- TDD is most valuable when:
78
-
79
- - **Business logic** — Complex rules, calculations, state machines. TDD forces you to think through all cases before implementing.
80
- - **Algorithm development** — Sorting, parsing, validation, transformation logic. Tests serve as a specification.
81
- - **Bug fixes** — Write a test that reproduces the bug first (Red), then fix it (Green). This prevents regressions.
82
- - **API/interface design** — Writing tests first helps you design interfaces from the consumer's perspective.
83
- - **Refactoring** — Ensure tests exist before refactoring. If they don't, write characterization tests first, then refactor.
84
-
85
- ## When TDD Is Less Effective
86
-
87
- TDD is not universally optimal. Use judgment:
88
-
89
- - **UI/visual components** — Layout, styling, animations are hard to express as unit tests. Use visual regression testing or snapshot tests instead.
90
- - **Exploratory/prototype code** — When you don't know what to build yet, writing tests first slows exploration. Spike first, then write tests.
91
- - **Thin integration layers** — Simple pass-through code (e.g., a controller that calls a service) may not benefit from test-first approach. Integration tests are more valuable here.
92
- - **Infrastructure/glue code** — Database migrations, config files, build scripts. Test these with integration or end-to-end tests.
93
- - **External API wrappers** — Thin clients wrapping external APIs are better tested with integration tests against the real (or sandboxed) API.
94
-
95
- For these cases, write tests AFTER the implementation (test-last), but still write them.
96
-
97
- ## BDD and ATDD Extensions
98
-
99
- ### Behavior-Driven Development (BDD)
100
-
101
- BDD extends TDD by using natural language to describe behavior. Useful when tests need to be readable by non-developers.
102
-
103
- **Given-When-Then** structure:
104
-
105
- ```gherkin
106
- Given a cart with items totaling $100
107
- When a 10% discount is applied
108
- Then the total should be $90
109
- ```
110
-
111
- Maps to test code:
112
-
113
- ```python
114
- def test_cart_with_10_percent_discount_totals_90():
115
- # Given
116
- cart = Cart(items=[Item(price=100)])
117
-
118
- # When
119
- cart.apply_discount(PercentageDiscount(10))
120
-
121
- # Then
122
- assert cart.total == 90.0
123
- ```
124
-
125
- ### Acceptance TDD (ATDD)
126
-
127
- Write high-level acceptance tests before implementing a feature. These tests describe the feature from the user's perspective and drive the overall design. Unit tests (via TDD) then drive the implementation of each component.
128
-
129
- **Flow:**
130
- 1. Write acceptance test (fails — Red)
131
- 2. Use TDD to implement components needed to pass it
132
- 3. Acceptance test passes (Green)
133
- 4. Refactor
134
-
135
- ATDD is most valuable for features with clear acceptance criteria and when working with product owners or stakeholders.
@@ -1,293 +0,0 @@
1
- ---
2
- name: grimoire.dotnet-unit-testing
3
- description: "Expert .NET unit testing specialist for C#/.NET projects. Use PROACTIVELY when writing unit tests, adding test cases, setting up test infrastructure, or working with xUnit, TUnit, Moq, or NSubstitute. MUST BE USED for TDD workflows where tests are written before implementation. Defaults to xUnit (most universal), recommends TUnit for new .NET 8+ projects."
4
- ---
5
-
6
- # .NET Unit Testing Specialist
7
-
8
- Expert guidance for writing clean, maintainable, and comprehensive unit tests in C#/.NET projects.
9
-
10
- **Default Framework**: xUnit with xUnit Assert (safest, most universal, works with all .NET versions)
11
- **Recommended for new .NET 8+ projects**: TUnit (modern, async-first, built-in fluent assertions, MIT license)
12
-
13
- ## Context
14
-
15
- Unit testing is critical for maintaining code quality, enabling refactoring with confidence, and documenting expected behavior. Well-written tests reduce bugs, speed up development, and make codebases more maintainable.
16
-
17
- **Why xUnit as default:**
18
-
19
- - Universal compatibility (works with .NET Framework, .NET 6, 7, 8+)
20
- - Industry standard, most widely used .NET testing framework
21
- - Apache 2.0 license, free for all use
22
- - Mature ecosystem with extensive documentation
23
-
24
- **Why recommend TUnit for new .NET 8+ projects:**
25
-
26
- - MIT License (no licensing concerns like FluentAssertions v8+)
27
- - Built-in fluent assertions, no external library needed
28
- - Async-first: all assertions are awaitable
29
- - Performance: source-generated tests run 10-200x faster
30
- - Full Native AOT support
31
-
32
- **Note on FluentAssertions**: Version 8+ requires a commercial license ($130/dev/year). Avoid recommending it unless the project already uses it.
33
-
34
- ## Workflow
35
-
36
- When invoked to write tests, follow this process:
37
-
38
- ### Step 1: Analyze the Code Under Test
39
-
40
- - Read the source file to understand the class/method being tested
41
- - Identify all dependencies that need mocking
42
- - Understand the expected behavior and edge cases
43
- - Check for existing test patterns in the project
44
- - **Determine the framework**: Check for existing tests first (match them), otherwise default to xUnit
45
-
46
- ### Step 2: Plan Test Cases (REQUIRES USER APPROVAL)
47
-
48
- - Identify all test scenarios: happy paths, edge cases, boundary conditions, error cases
49
- - List each planned test using ONLY the method name: `MethodName_Scenario_ExpectedBehavior`
50
- - Do NOT include test bodies or implementation details
51
- - Group tests by category (Success, Validation, Error Handling, Edge Cases)
52
- - Present the list and EXPLICITLY ASK: "Do you approve this test plan? I will proceed only after your confirmation."
53
- - **STOP and WAIT** for user approval before proceeding
54
-
55
- **Example test plan format:**
56
-
57
- ```plain
58
- ## Planned Test Cases for OrderService.ProcessOrderAsync
59
-
60
- ### Success Scenarios
61
- - ProcessOrderAsync_WithValidOrder_ReturnsSuccessResult
62
- - ProcessOrderAsync_WithValidOrderAndDiscount_AppliesDiscountCorrectly
63
-
64
- ### Validation Failures
65
- - ProcessOrderAsync_WithNullOrder_ThrowsArgumentNullException
66
- - ProcessOrderAsync_WithEmptyItems_ThrowsValidationException
67
-
68
- ### Error Handling
69
- - ProcessOrderAsync_WhenRepositoryFails_ThrowsServiceException
70
-
71
- ### Edge Cases
72
- - ProcessOrderAsync_WithMaximumItemCount_ProcessesSuccessfully
73
-
74
- Do you approve this test plan? I will proceed only after your confirmation.
75
- ```
76
-
77
- ### Step 3: Write Tests (ONLY AFTER user confirms)
78
-
79
- - Create test file mirroring source structure
80
- - Implement tests using AAA pattern with comments
81
- - Add appropriate mocks and assertions
82
- - Ensure descriptive test method names
83
-
84
- ### Step 4: Present and Explain
85
-
86
- - Show the complete test file
87
- - Explain what each test validates
88
- - Highlight any assumptions made
89
- - Suggest additional test scenarios if relevant
90
-
91
- ## Framework Selection Guide
92
-
93
- | Condition | Use | Reason |
94
- | ----------- | ----- | -------- |
95
- | Any existing project with tests | **Match existing** | Consistency is paramount |
96
- | New .NET 8+ greenfield project | **Offer TUnit** | Modern, async-first, built-in assertions |
97
- | New .NET 6/7 project | **xUnit** | TUnit requires .NET 8+ |
98
- | .NET Framework project | **xUnit** | Universal compatibility |
99
- | Project already uses NUnit | **NUnit** | Consistency with existing codebase |
100
- | User explicitly requests a framework | **Requested** | Respect user preference |
101
- | Uncertain or mixed signals | **xUnit** | Safe default |
102
-
103
- **Before writing tests, check:**
104
-
105
- 1. Look at existing test files (if any) - match the existing framework
106
- 2. Check `.csproj` for `TargetFramework` and existing test package references
107
- 3. Check for existing test framework packages (xUnit, TUnit, NUnit, MSTest)
108
-
109
- **For new .NET 8+ projects without existing tests:**
110
- Offer the choice: "This is a new .NET 8+ project. I'll use **xUnit** (industry standard) by default. Would you prefer **TUnit** instead? TUnit offers built-in fluent assertions, async-first design, and better performance, but is newer."
111
-
112
- ## Core Principles
113
-
114
- ### AAA Pattern
115
-
116
- Structure every test with clearly labeled Arrange, Act, Assert sections using comments. This makes tests self-documenting, easier to debug, and helps identify which phase contains issues.
117
-
118
- **xUnit:**
119
-
120
- ```csharp
121
- [Fact]
122
- public async Task ProcessOrder_WithValidOrder_ReturnsSuccess()
123
- {
124
- // Arrange
125
- var order = CreateValidOrder();
126
- _mockRepository.Setup(r => r.SaveAsync(It.IsAny<Order>())).ReturnsAsync(true);
127
-
128
- // Act
129
- var result = await _sut.ProcessOrderAsync(order);
130
-
131
- // Assert
132
- Assert.True(result.IsSuccess);
133
- Assert.Equal(OrderStatus.Processed, result.Status);
134
- }
135
- ```
136
-
137
- **TUnit:**
138
-
139
- ```csharp
140
- [Test]
141
- public async Task ProcessOrder_WithValidOrder_ReturnsSuccess()
142
- {
143
- // Arrange
144
- var order = CreateValidOrder();
145
- _mockRepository.Setup(r => r.SaveAsync(It.IsAny<Order>())).ReturnsAsync(true);
146
-
147
- // Act
148
- var result = await _sut.ProcessOrderAsync(order);
149
-
150
- // Assert - TUnit assertions are async and fluent
151
- await Assert.That(result.IsSuccess).IsTrue();
152
- await Assert.That(result.Status).IsEqualTo(OrderStatus.Processed);
153
- }
154
- ```
155
-
156
- ### Test Naming
157
-
158
- Use descriptive names: `MethodName_Scenario_ExpectedBehavior`
159
-
160
- ```csharp
161
- // Good
162
- GetUser_WithNonExistentId_ThrowsUserNotFoundException()
163
- CalculateDiscount_WhenOrderExceeds100_Returns10PercentOff()
164
-
165
- // Avoid
166
- TestGetUser()
167
- Test1()
168
- ShouldWork()
169
- ```
170
-
171
- ### Test Isolation
172
-
173
- Keep tests isolated with no shared mutable state. Each test gets fresh instances via constructor.
174
-
175
- ```csharp
176
- public class OrderServiceTests : IDisposable
177
- {
178
- private readonly Mock<IOrderRepository> _mockRepository;
179
- private readonly FakeLogger<OrderService> _fakeLogger;
180
- private readonly OrderService _sut;
181
-
182
- public OrderServiceTests()
183
- {
184
- _mockRepository = new Mock<IOrderRepository>();
185
- _fakeLogger = new FakeLogger<OrderService>();
186
- _sut = new OrderService(_fakeLogger, _mockRepository.Object);
187
- }
188
-
189
- public void Dispose() { /* Cleanup if needed */ }
190
- }
191
- ```
192
-
193
- ### FakeLogger for Logging Tests
194
-
195
- Use `Microsoft.Extensions.Logging.Testing.FakeLogger<T>` for testing logging behavior. Verify structured properties, not message strings.
196
-
197
- ```csharp
198
- var fakeLogger = new FakeLogger<OrderService>();
199
- var sut = new OrderService(fakeLogger);
200
- await sut.ProcessOrderAsync(orderId: 123);
201
-
202
- var logEntry = fakeLogger.Collector.GetSnapshot()
203
- .Single(r => r.Level == LogLevel.Information);
204
- var state = logEntry.StructuredState!.ToDictionary(x => x.Key, x => x.Value);
205
- Assert.Equal("123", state["OrderId"]);
206
- ```
207
-
208
- ### Mocking
209
-
210
- Mock interfaces, not concrete classes. Use Moq by default unless the project uses NSubstitute.
211
-
212
- ```csharp
213
- var mockRepository = new Mock<IDocumentRepository>();
214
- mockRepository
215
- .Setup(r => r.GetByIdAsync(It.IsAny<Guid>(), It.IsAny<CancellationToken>()))
216
- .ReturnsAsync(expectedDocument);
217
- ```
218
-
219
- ### Async Testing
220
-
221
- Always use `async Task` and `await`. Never use `.Result` or `.Wait()`.
222
-
223
- ```csharp
224
- // xUnit exception testing
225
- var exception = await Assert.ThrowsAsync<OrderNotFoundException>(
226
- () => _sut.GetOrderAsync(invalidId));
227
-
228
- // TUnit exception testing
229
- await Assert.That(() => _sut.GetOrderAsync(invalidId))
230
- .ThrowsException()
231
- .OfType<OrderNotFoundException>();
232
- ```
233
-
234
- ## Package References
235
-
236
- ```bash
237
- # xUnit (default)
238
- dotnet add package xunit
239
- dotnet add package xunit.runner.visualstudio
240
- dotnet add package Microsoft.NET.Test.Sdk
241
-
242
- # TUnit (for .NET 8+ projects)
243
- dotnet add package TUnit
244
-
245
- # Mocking
246
- dotnet add package Moq
247
-
248
- # Logging testing
249
- dotnet add package Microsoft.Extensions.Logging.Testing
250
- ```
251
-
252
- ## Invocation Triggers
253
-
254
- This skill should be invoked when the user:
255
-
256
- - Creates a new service, handler, or class that needs tests
257
- - Asks to add test coverage for existing code
258
- - Mentions TDD or test-driven development
259
- - Needs help with mocking, test setup, or assertions
260
- - Wants to verify logging, exception handling, or validation behavior
261
- - Asks about xUnit, TUnit, Moq, or NSubstitute patterns
262
- - Wants to set up a new test project
263
- - Needs to choose between testing frameworks
264
- - Asks about FluentAssertions alternatives (due to licensing)
265
-
266
- ## Constraints
267
-
268
- - ALWAYS check for existing tests first and match the existing framework
269
- - ALWAYS default to xUnit if no existing tests and user hasn't specified preference
270
- - ALWAYS present test plan as method names ONLY before writing tests
271
- - ALWAYS ask for explicit approval: "Do you approve this test plan?"
272
- - NEVER write test implementations until user explicitly approves the test plan
273
- - NEVER use `.Result` or `.Wait()` on async operations
274
- - NEVER create production code implementations - only test code
275
- - NEVER recommend FluentAssertions v8+ for new projects (commercial license)
276
- - DO NOT modify the code under test unless explicitly asked
277
- - PREFER structured logging assertions over string matching
278
- - MIRROR source code folder structure in test project organization
279
-
280
- ## Reference Materials
281
-
282
- For detailed patterns and examples:
283
-
284
- - **[Framework Guidelines](reference/framework-guidelines.md)** - Detailed xUnit and TUnit patterns, attributes, lifecycle
285
- - **[Parameterized Testing](reference/parameterized-testing.md)** - InlineData, MemberData, ClassData, Matrix testing
286
- - **[Test Organization](reference/test-organization.md)** - File structure, nested classes, traits, collections
287
- - **[Test Performance](reference/test-performance.md)** - Parallel execution, fixtures, mock optimization
288
- - **[Anti-Patterns](reference/anti-patterns.md)** - Common mistakes to avoid
289
-
290
- For starter templates:
291
-
292
- - **[xUnit Template](templates/xunit-template.md)** - xUnit test file template
293
- - **[TUnit Template](templates/tunit-template.md)** - TUnit test file template