@rafinery/cli 0.8.16 → 0.11.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 (76) hide show
  1. package/CHANGELOG.md +130 -0
  2. package/bin/rafa.mjs +11 -0
  3. package/blueprint/.claude/agents/atlas.md +21 -3
  4. package/blueprint/.claude/agents/bloom.md +2 -2
  5. package/blueprint/.claude/agents/prism.md +42 -3
  6. package/blueprint/.claude/agents/sage.md +1 -1
  7. package/blueprint/.claude/commands/rafa.md +24 -13
  8. package/blueprint/.claude/rafa/contract.md +23 -0
  9. package/blueprint/.claude/rafa/hooks/brain-commit.mjs +4 -0
  10. package/blueprint/.claude/rafa/hooks/session-start.mjs +66 -0
  11. package/blueprint/.claude/skills/rafa-build/SKILL.md +111 -20
  12. package/blueprint/.claude/skills/rafa-commit/SKILL.md +22 -0
  13. package/blueprint/.claude/skills/rafa-distill/SKILL.md +37 -4
  14. package/blueprint/.claude/skills/rafa-improve/SKILL.md +22 -0
  15. package/blueprint/.claude/skills/rafa-leverage/SKILL.md +6 -1
  16. package/blueprint/.claude/skills/rafa-plan/SKILL.md +36 -1
  17. package/blueprint/.claude/skills/rafa-review/SKILL.md +16 -2
  18. package/blueprint/.claude/skills/rafa-sage/SKILL.md +8 -2
  19. package/blueprint/.claude/skills/rafa-scan/SKILL.md +4 -1
  20. package/lib/brain-repo.mjs +1 -1
  21. package/lib/checkpoint.mjs +26 -15
  22. package/lib/distill.mjs +56 -3
  23. package/lib/distiller/doctrine.mjs +5 -16
  24. package/lib/distiller/schema-ladder.mjs +186 -0
  25. package/lib/doctor.mjs +19 -1
  26. package/lib/facts.mjs +130 -0
  27. package/lib/gate/compile.mjs +12 -0
  28. package/lib/gate/verify-citations.mjs +78 -1
  29. package/lib/hydrate.mjs +45 -0
  30. package/lib/init.mjs +9 -1
  31. package/lib/leverage/engine.mjs +32 -3
  32. package/lib/leverage.mjs +11 -2
  33. package/lib/loop-cache.mjs +67 -0
  34. package/lib/mcp-client.mjs +19 -0
  35. package/lib/push.mjs +18 -4
  36. package/lib/reflex.mjs +5 -1
  37. package/lib/releases.mjs +78 -0
  38. package/lib/review.mjs +32 -6
  39. package/lib/session-facts.mjs +108 -0
  40. package/lib/skill-deps.mjs +377 -0
  41. package/lib/stamp.mjs +24 -0
  42. package/lib/update.mjs +9 -0
  43. package/package.json +3 -2
  44. package/skills-bundle/frontend-design/LICENSE.txt +177 -0
  45. package/skills-bundle/frontend-design/SKILL.md +55 -0
  46. package/{LICENSE → skills-bundle/grill-me/LICENSE} +6 -6
  47. package/skills-bundle/grill-me/SKILL.md +7 -0
  48. package/skills-bundle/grill-me/agents/openai.yaml +5 -0
  49. package/skills-bundle/grilling/SKILL.md +53 -0
  50. package/skills-bundle/improve-codebase-architecture/HTML-REPORT.md +123 -0
  51. package/skills-bundle/improve-codebase-architecture/LICENSE +21 -0
  52. package/skills-bundle/improve-codebase-architecture/SKILL.md +71 -0
  53. package/skills-bundle/improve-codebase-architecture/agents/openai.yaml +5 -0
  54. package/skills-bundle/requesting-code-review/LICENSE +21 -0
  55. package/skills-bundle/requesting-code-review/SKILL.md +95 -0
  56. package/skills-bundle/requesting-code-review/code-reviewer.md +172 -0
  57. package/skills-bundle/skills-manifest.json +72 -0
  58. package/skills-bundle/tdd/LICENSE +21 -0
  59. package/skills-bundle/tdd/SKILL.md +36 -0
  60. package/skills-bundle/tdd/agents/openai.yaml +3 -0
  61. package/skills-bundle/tdd/mocking.md +59 -0
  62. package/skills-bundle/tdd/tests.md +77 -0
  63. package/skills-bundle/vercel-composition-patterns/AGENTS.md +946 -0
  64. package/skills-bundle/vercel-composition-patterns/README.md +60 -0
  65. package/skills-bundle/vercel-composition-patterns/SKILL.md +89 -0
  66. package/skills-bundle/vercel-composition-patterns/metadata.json +11 -0
  67. package/skills-bundle/vercel-composition-patterns/rules/_sections.md +29 -0
  68. package/skills-bundle/vercel-composition-patterns/rules/_template.md +24 -0
  69. package/skills-bundle/vercel-composition-patterns/rules/architecture-avoid-boolean-props.md +100 -0
  70. package/skills-bundle/vercel-composition-patterns/rules/architecture-compound-components.md +112 -0
  71. package/skills-bundle/vercel-composition-patterns/rules/patterns-children-over-render-props.md +87 -0
  72. package/skills-bundle/vercel-composition-patterns/rules/patterns-explicit-variants.md +100 -0
  73. package/skills-bundle/vercel-composition-patterns/rules/react19-no-forwardref.md +42 -0
  74. package/skills-bundle/vercel-composition-patterns/rules/state-context-interface.md +191 -0
  75. package/skills-bundle/vercel-composition-patterns/rules/state-decouple-implementation.md +113 -0
  76. package/skills-bundle/vercel-composition-patterns/rules/state-lift-state.md +125 -0
@@ -0,0 +1,172 @@
1
+ # Code Reviewer Prompt Template
2
+
3
+ Use this template when dispatching a code reviewer subagent.
4
+
5
+ **Purpose:** Review completed work against requirements and code quality standards before it cascades into more work.
6
+
7
+ ```
8
+ Subagent (general-purpose):
9
+ description: "Review code changes"
10
+ prompt: |
11
+ You are a Senior Code Reviewer with expertise in software architecture,
12
+ design patterns, and best practices. Your job is to review completed work
13
+ against its plan or requirements and identify issues before they cascade.
14
+
15
+ ## What Was Implemented
16
+
17
+ [DESCRIPTION]
18
+
19
+ ## Requirements / Plan
20
+
21
+ [PLAN_OR_REQUIREMENTS]
22
+
23
+ ## Git Range to Review
24
+
25
+ **Base:** [BASE_SHA]
26
+ **Head:** [HEAD_SHA]
27
+
28
+ ```bash
29
+ git diff --stat [BASE_SHA]..[HEAD_SHA]
30
+ git diff [BASE_SHA]..[HEAD_SHA]
31
+ ```
32
+
33
+ ## Read-Only Review
34
+
35
+ Your review is read-only on this checkout. Do not mutate the working tree, the index, HEAD, or branch state in any way. Use tools like `git show`, `git diff`, and `git log` to inspect history. If you need a working copy of a different revision, check it out into a separate temporary directory (e.g. `git worktree add /tmp/review-[SHA] [SHA]`) — never move HEAD on this checkout.
36
+
37
+ ## What to Check
38
+
39
+ **Plan alignment:**
40
+ - Does the implementation match the plan / requirements?
41
+ - Are deviations justified improvements, or problematic departures?
42
+ - Is all planned functionality present?
43
+
44
+ **Code quality:**
45
+ - Clean separation of concerns?
46
+ - Proper error handling?
47
+ - Type safety where applicable?
48
+ - DRY without premature abstraction?
49
+ - Edge cases handled?
50
+
51
+ **Architecture:**
52
+ - Sound design decisions?
53
+ - Reasonable scalability and performance?
54
+ - Security concerns?
55
+ - Integrates cleanly with surrounding code?
56
+
57
+ **Testing:**
58
+ - Tests verify real behavior, not mocks?
59
+ - Edge cases covered?
60
+ - Integration tests where they matter?
61
+ - All tests passing?
62
+
63
+ **Production readiness:**
64
+ - Migration strategy if schema changed?
65
+ - Backward compatibility considered?
66
+ - Documentation complete?
67
+ - No obvious bugs?
68
+
69
+ ## Calibration
70
+
71
+ Categorize issues by actual severity. Not everything is Critical.
72
+ Acknowledge what was done well before listing issues — accurate praise
73
+ helps the implementer trust the rest of the feedback.
74
+
75
+ If you find significant deviations from the plan, flag them specifically
76
+ so the implementer can confirm whether the deviation was intentional.
77
+ If you find issues with the plan itself rather than the implementation,
78
+ say so.
79
+
80
+ ## Output Format
81
+
82
+ ### Strengths
83
+ [What's well done? Be specific.]
84
+
85
+ ### Issues
86
+
87
+ #### Critical (Must Fix)
88
+ [Bugs, security issues, data loss risks, broken functionality]
89
+
90
+ #### Important (Should Fix)
91
+ [Architecture problems, missing features, poor error handling, test gaps]
92
+
93
+ #### Minor (Nice to Have)
94
+ [Code style, optimization opportunities, documentation polish]
95
+
96
+ For each issue:
97
+ - File:line reference
98
+ - What's wrong
99
+ - Why it matters
100
+ - How to fix (if not obvious)
101
+
102
+ ### Recommendations
103
+ [Improvements for code quality, architecture, or process]
104
+
105
+ ### Assessment
106
+
107
+ **Ready to merge?** [Yes | No | With fixes]
108
+
109
+ **Reasoning:** [1-2 sentence technical assessment]
110
+
111
+ ## Critical Rules
112
+
113
+ **DO:**
114
+ - Categorize by actual severity
115
+ - Be specific (file:line, not vague)
116
+ - Explain WHY each issue matters
117
+ - Acknowledge strengths
118
+ - Give a clear verdict
119
+
120
+ **DON'T:**
121
+ - Say "looks good" without checking
122
+ - Mark nitpicks as Critical
123
+ - Give feedback on code you didn't actually read
124
+ - Be vague ("improve error handling")
125
+ - Avoid giving a clear verdict
126
+ ```
127
+
128
+ **Placeholders:**
129
+ - `[DESCRIPTION]` — brief summary of what was built
130
+ - `[PLAN_OR_REQUIREMENTS]` — what it should do (plan file path, task text, or requirements)
131
+ - `[BASE_SHA]` — starting commit
132
+ - `[HEAD_SHA]` — ending commit
133
+
134
+ **Reviewer returns:** Strengths, Issues (Critical / Important / Minor), Recommendations, Assessment
135
+
136
+ ## Example Output
137
+
138
+ ```
139
+ ### Strengths
140
+ - Clean database schema with proper migrations (db.ts:15-42)
141
+ - Comprehensive test coverage (18 tests, all edge cases)
142
+ - Good error handling with fallbacks (summarizer.ts:85-92)
143
+
144
+ ### Issues
145
+
146
+ #### Important
147
+ 1. **Missing help text in CLI wrapper**
148
+ - File: index-conversations:1-31
149
+ - Issue: No --help flag, users won't discover --concurrency
150
+ - Fix: Add --help case with usage examples
151
+
152
+ 2. **Date validation missing**
153
+ - File: search.ts:25-27
154
+ - Issue: Invalid dates silently return no results
155
+ - Fix: Validate ISO format, throw error with example
156
+
157
+ #### Minor
158
+ 1. **Progress indicators**
159
+ - File: indexer.ts:130
160
+ - Issue: No "X of Y" counter for long operations
161
+ - Impact: Users don't know how long to wait
162
+
163
+ ### Recommendations
164
+ - Add progress reporting for user experience
165
+ - Consider config file for excluded projects (portability)
166
+
167
+ ### Assessment
168
+
169
+ **Ready to merge: With fixes**
170
+
171
+ **Reasoning:** Core implementation is solid with good architecture and tests. Important issues (help text, date validation) are easily fixed and don't affect core functionality.
172
+ ```
@@ -0,0 +1,72 @@
1
+ {
2
+ "generatedAt": "2026-07-25T21:14:46.864Z",
3
+ "skills": {
4
+ "tdd": {
5
+ "version": "1.0.0",
6
+ "files": {
7
+ "LICENSE": "0e7ac423bf2c6e223b7c5b156f8cf72da49d748e56a1641402c31f22ad07dbb5",
8
+ "SKILL.md": "5363bb2775679fe9311fbb67947f95359169c6e7f1fac77c0f25e190bca6cf2f",
9
+ "agents/openai.yaml": "ea6f01cf1b8c06a4b0f5b649d74b1b8ce8685e72af1b38d70d877693e092af0b",
10
+ "mocking.md": "3ceb807fdf4a47d6a93d4d9a891e5ba6d362a6247bd08adc451feebfc17361ef",
11
+ "tests.md": "859f9e592c188fda4fc7277dd180e4ce9c7a2e13f6efe1f6f29eccc9d28c106a"
12
+ }
13
+ },
14
+ "frontend-design": {
15
+ "version": "1.0.0",
16
+ "files": {
17
+ "LICENSE.txt": "0d542e0c8804e39aa7f37eb00da5a762149dc682d7829451287e11b938e94594",
18
+ "SKILL.md": "1608ea77fbb6fc30d13a97d12cfa8ebf31358d40f0dd97beed24829d6b3f45dd"
19
+ }
20
+ },
21
+ "vercel-composition-patterns": {
22
+ "version": "1.0.0",
23
+ "files": {
24
+ "AGENTS.md": "89e3ddd58fcf99a53a50e25dfd21b8cde1be5f10b7df6bacd3dfa6796932f516",
25
+ "README.md": "85915a43a6f0b4efe525e3cf6398dd866166da2025837c4460468a24a940da94",
26
+ "SKILL.md": "e38e0eaa609316b10423a9a138ed95e35099accd3f735585295c8a8f165c28a3",
27
+ "metadata.json": "49262ed5cb4186f31ee980cf8d990be0170c51efed4908d0464a1cff9905bd05",
28
+ "rules/_sections.md": "a174213b87e6911e2b766995a2cbaf8d1534057076e82fb79fe3f0ecb38047df",
29
+ "rules/_template.md": "587f7d16b0660eb61fee4a4d3d7df2b3077d6835de170602c7d6e60bee559131",
30
+ "rules/architecture-avoid-boolean-props.md": "007555ebb020f4d552582a2c4db194db71a1fd33094012e5187bcfa4f8c392d5",
31
+ "rules/architecture-compound-components.md": "f246af13dc269b521cf20eb8ad99a0cb645beac381c8c9b117262c34612c8457",
32
+ "rules/patterns-children-over-render-props.md": "7c45a0d21b3c4126a32cba916ee31adeae195386ad1dbbe6634aedb7457aa0ad",
33
+ "rules/patterns-explicit-variants.md": "8c19e596e61807549d01ce8c6954c6358199f97a8511c0c02c625ec0efda8c0e",
34
+ "rules/react19-no-forwardref.md": "881830adb7534c4b2d70db426556646ad9837f5478f744f35641f635ada22227",
35
+ "rules/state-context-interface.md": "09e73afbf9285fa416679cc864a287b9e8b821d0969272ab784295386d8c9bc3",
36
+ "rules/state-decouple-implementation.md": "76a8c1eb29a70d8996ab3f71260345af2f7bc89deab815a421d6c87c6591a9c3",
37
+ "rules/state-lift-state.md": "74c54038a6c554c748fe31cec673b80861b5d920b7553cf78cdf10d18b4b759b"
38
+ }
39
+ },
40
+ "requesting-code-review": {
41
+ "version": "1.0.0",
42
+ "files": {
43
+ "LICENSE": "a37e0e9697144819e1d965176ac4ae5bc3fa02d11e7812036bbcadf6dafe2400",
44
+ "SKILL.md": "d71cc01ba56d2325cf8af5f7c11837819b63ecd57de0bfdb812f7f3ff7751df8",
45
+ "code-reviewer.md": "b2f2ec7596925fe52dac158fdfbca19b3a7d779d619c481e6706a6c0001662d3"
46
+ }
47
+ },
48
+ "improve-codebase-architecture": {
49
+ "version": "1.0.0",
50
+ "files": {
51
+ "HTML-REPORT.md": "0b0936104158abeef7246ff6cbabefa4dc055f17589f2833f2d93001421910a1",
52
+ "LICENSE": "0e7ac423bf2c6e223b7c5b156f8cf72da49d748e56a1641402c31f22ad07dbb5",
53
+ "SKILL.md": "4b4cb798c3863d5b6f5c0b4604af1ecb5beb6df82553c972898a91ba38bcf289",
54
+ "agents/openai.yaml": "c8cb20f68ebf0edb4e497bc11ae5fcaa196004e661cd189015b04f4109ced7f1"
55
+ }
56
+ },
57
+ "grill-me": {
58
+ "version": "1.0.0",
59
+ "files": {
60
+ "LICENSE": "0e7ac423bf2c6e223b7c5b156f8cf72da49d748e56a1641402c31f22ad07dbb5",
61
+ "SKILL.md": "6189dfceb7304a6e5558f75d87e68fa3bc7fcf7ba120e44f21f8a61fe01eba54",
62
+ "agents/openai.yaml": "c061e39c3e0f9d865fb1b97556d485704af2a8a58f4b8221a8917a5c2074a32b"
63
+ }
64
+ },
65
+ "grilling": {
66
+ "version": "1.0.0",
67
+ "files": {
68
+ "SKILL.md": "a45540c9b5c4f70eb0d4e6ead6498741d5479f72ad1e18036a88e51297f6a366"
69
+ }
70
+ }
71
+ }
72
+ }
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Matt Pocock
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,36 @@
1
+ ---
2
+ name: tdd
3
+ description: Test-driven development. Use when the user wants to build features or fix bugs test-first, mentions "red-green-refactor", or wants integration tests.
4
+ ---
5
+
6
+ # Test-Driven Development
7
+
8
+ TDD is the red → green loop. This skill is the reference that makes that loop produce tests worth keeping: what a good test is, where tests go, the anti-patterns, and the rules of the loop. Every section applies on every cycle — consult them before and during the loop, not after.
9
+
10
+ When exploring the codebase, read `CONTEXT.md` (if it exists) so test names and interface vocabulary match the project's domain language, and respect ADRs in the area you're touching.
11
+
12
+ ## What a good test is
13
+
14
+ Tests verify behavior through public interfaces, not implementation details. Code can change entirely; tests shouldn't. A good test reads like a specification — "user can checkout with valid cart" tells you exactly what capability exists — and survives refactors because it doesn't care about internal structure.
15
+
16
+ See [tests.md](tests.md) for examples and [mocking.md](mocking.md) for mocking guidelines.
17
+
18
+ ## Seams — where tests go
19
+
20
+ A **seam** is the public boundary you test at: the interface where you observe behavior without reaching inside. Tests live at seams, never against internals.
21
+
22
+ **Test only at pre-agreed seams.** Before writing any test, write down the seams under test and confirm them with the user. No test is written at an unconfirmed seam. You can't test everything — agreeing the seams up front is how testing effort lands on the critical paths and complex logic instead of every edge case.
23
+
24
+ Ask: "What's the public interface, and which seams should we test?"
25
+
26
+ ## Anti-patterns
27
+
28
+ - **Implementation-coupled** — mocks internal collaborators, tests private methods, or verifies through a side channel (querying the database instead of using the interface). The tell: the test breaks when you refactor but behavior hasn't changed.
29
+ - **Tautological** — the assertion recomputes the expected value the way the code does (`expect(add(a, b)).toBe(a + b)`, a snapshot derived by hand the same way, a constant asserted equal to itself), so it passes by construction and can never disagree with the code. Expected values must come from an independent source of truth — a known-good literal, a worked example, the spec.
30
+ - **Horizontal slicing** — writing all tests first, then all implementation. Bulk tests verify _imagined_ behavior: you test the _shape_ of things rather than user-facing behavior, the tests go insensitive to real changes, and you commit to test structure before understanding the implementation. Work in **vertical slices** instead — one test → one implementation → repeat, each test a **tracer bullet** that responds to what the last cycle taught you.
31
+
32
+ ## Rules of the loop
33
+
34
+ - **Red before green.** Write the failing test first, then only enough code to pass it. Don't anticipate future tests or add speculative features.
35
+ - **One slice at a time.** One seam, one test, one minimal implementation per cycle.
36
+ - **Refactoring is not part of the loop.** It belongs to the review stage (see the `code-review` skill), not the red → green implementation cycle.
@@ -0,0 +1,3 @@
1
+ interface:
2
+ display_name: "TDD"
3
+ short_description: "Test-driven red-green-refactor"
@@ -0,0 +1,59 @@
1
+ # When to Mock
2
+
3
+ Mock at **system boundaries** only:
4
+
5
+ - External APIs (payment, email, etc.)
6
+ - Databases (sometimes - prefer test DB)
7
+ - Time/randomness
8
+ - File system (sometimes)
9
+
10
+ Don't mock:
11
+
12
+ - Your own classes/modules
13
+ - Internal collaborators
14
+ - Anything you control
15
+
16
+ ## Designing for Mockability
17
+
18
+ At system boundaries, design interfaces that are easy to mock:
19
+
20
+ **1. Use dependency injection**
21
+
22
+ Pass external dependencies in rather than creating them internally:
23
+
24
+ ```typescript
25
+ // Easy to mock
26
+ function processPayment(order, paymentClient) {
27
+ return paymentClient.charge(order.total);
28
+ }
29
+
30
+ // Hard to mock
31
+ function processPayment(order) {
32
+ const client = new StripeClient(process.env.STRIPE_KEY);
33
+ return client.charge(order.total);
34
+ }
35
+ ```
36
+
37
+ **2. Prefer SDK-style interfaces over generic fetchers**
38
+
39
+ Create specific functions for each external operation instead of one generic function with conditional logic:
40
+
41
+ ```typescript
42
+ // GOOD: Each function is independently mockable
43
+ const api = {
44
+ getUser: (id) => fetch(`/users/${id}`),
45
+ getOrders: (userId) => fetch(`/users/${userId}/orders`),
46
+ createOrder: (data) => fetch('/orders', { method: 'POST', body: data }),
47
+ };
48
+
49
+ // BAD: Mocking requires conditional logic inside the mock
50
+ const api = {
51
+ fetch: (endpoint, options) => fetch(endpoint, options),
52
+ };
53
+ ```
54
+
55
+ The SDK approach means:
56
+ - Each mock returns one specific shape
57
+ - No conditional logic in test setup
58
+ - Easier to see which endpoints a test exercises
59
+ - Type safety per endpoint
@@ -0,0 +1,77 @@
1
+ # Good and Bad Tests
2
+
3
+ ## Good Tests
4
+
5
+ **Integration-style**: Test through real interfaces, not mocks of internal parts.
6
+
7
+ ```typescript
8
+ // GOOD: Tests observable behavior
9
+ test("user can checkout with valid cart", async () => {
10
+ const cart = createCart();
11
+ cart.add(product);
12
+ const result = await checkout(cart, paymentMethod);
13
+ expect(result.status).toBe("confirmed");
14
+ });
15
+ ```
16
+
17
+ Characteristics:
18
+
19
+ - Tests behavior users/callers care about
20
+ - Uses public API only
21
+ - Survives internal refactors
22
+ - Describes WHAT, not HOW
23
+ - One logical assertion per test
24
+
25
+ ## Bad Tests
26
+
27
+ **Implementation-detail tests**: Coupled to internal structure.
28
+
29
+ ```typescript
30
+ // BAD: Tests implementation details
31
+ test("checkout calls paymentService.process", async () => {
32
+ const mockPayment = jest.mock(paymentService);
33
+ await checkout(cart, payment);
34
+ expect(mockPayment.process).toHaveBeenCalledWith(cart.total);
35
+ });
36
+ ```
37
+
38
+ Red flags:
39
+
40
+ - Mocking internal collaborators
41
+ - Testing private methods
42
+ - Asserting on call counts/order
43
+ - Test breaks when refactoring without behavior change
44
+ - Test name describes HOW not WHAT
45
+ - Verifying through external means instead of interface
46
+
47
+ ```typescript
48
+ // BAD: Bypasses interface to verify
49
+ test("createUser saves to database", async () => {
50
+ await createUser({ name: "Alice" });
51
+ const row = await db.query("SELECT * FROM users WHERE name = ?", ["Alice"]);
52
+ expect(row).toBeDefined();
53
+ });
54
+
55
+ // GOOD: Verifies through interface
56
+ test("createUser makes user retrievable", async () => {
57
+ const user = await createUser({ name: "Alice" });
58
+ const retrieved = await getUser(user.id);
59
+ expect(retrieved.name).toBe("Alice");
60
+ });
61
+ ```
62
+
63
+ **Tautological tests**: Expected value restates the implementation, so the test passes by construction.
64
+
65
+ ```typescript
66
+ // BAD: Expected value is recomputed the way the code computes it
67
+ test("calculateTotal sums line items", () => {
68
+ const items = [{ price: 10 }, { price: 5 }];
69
+ const expected = items.reduce((sum, i) => sum + i.price, 0);
70
+ expect(calculateTotal(items)).toBe(expected);
71
+ });
72
+
73
+ // GOOD: Expected value is an independent, known literal
74
+ test("calculateTotal sums line items", () => {
75
+ expect(calculateTotal([{ price: 10 }, { price: 5 }])).toBe(15);
76
+ });
77
+ ```