nightytidy 0.3.7 → 0.3.9
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.
- package/bin/nightytidy.js +1 -1
- package/package.json +1 -1
- package/src/agent/git-integration.js +4 -1
- package/src/claude.js +1 -1
- package/src/prompts/manifest.json +138 -138
- package/src/prompts/steps/02-test-coverage.md +181 -181
- package/src/prompts/steps/03-test-hardening.md +181 -181
- package/src/prompts/steps/04-test-architecture.md +130 -130
- package/src/prompts/steps/05-test-consolidation.md +165 -165
- package/src/prompts/steps/06-test-quality.md +211 -211
- package/src/prompts/steps/07-api-design.md +165 -165
- package/src/prompts/steps/08-security-sweep.md +207 -207
- package/src/prompts/steps/09-dependency-health.md +217 -217
- package/src/prompts/steps/10-codebase-cleanup.md +189 -189
- package/src/prompts/steps/11-crosscutting-concerns.md +196 -196
- package/src/prompts/steps/12-file-decomposition.md +263 -263
- package/src/prompts/steps/13-code-elegance.md +329 -329
- package/src/prompts/steps/14-architectural-complexity.md +297 -297
- package/src/prompts/steps/15-type-safety.md +192 -192
- package/src/prompts/steps/16-logging-error-message.md +173 -173
- package/src/prompts/steps/17-data-integrity.md +139 -139
- package/src/prompts/steps/18-performance.md +183 -183
- package/src/prompts/steps/19-cost-resource-optimization.md +136 -136
- package/src/prompts/steps/20-error-recovery.md +145 -145
- package/src/prompts/steps/21-race-condition-audit.md +178 -178
- package/src/prompts/steps/22-bug-hunt.md +229 -229
- package/src/prompts/steps/23-frontend-quality.md +210 -210
- package/src/prompts/steps/24-uiux-audit.md +284 -284
- package/src/prompts/steps/25-state-management.md +170 -170
- package/src/prompts/steps/26-perceived-performance.md +190 -190
- package/src/prompts/steps/27-devops.md +165 -165
- package/src/prompts/steps/28-scheduled-job-chron-jobs.md +141 -141
- package/src/prompts/steps/29-observability.md +152 -152
- package/src/prompts/steps/30-backup-check.md +155 -155
- package/src/prompts/steps/31-product-polish-ux-friction.md +122 -122
- package/src/prompts/steps/32-feature-discovery-opportunity.md +128 -128
- package/src/prompts/steps/33-strategic-opportunities.md +217 -217
|
@@ -1,181 +1,181 @@
|
|
|
1
|
-
# Test Hardening
|
|
2
|
-
|
|
3
|
-
## Prompt
|
|
4
|
-
|
|
5
|
-
```
|
|
6
|
-
You are running an overnight test hardening pass. You have several hours. Your job is to make the existing test suite more reliable and more complete in two specific areas: flaky test diagnosis/repair and API contract testing.
|
|
7
|
-
|
|
8
|
-
Work on a branch called `test-hardening-[date]`.
|
|
9
|
-
|
|
10
|
-
## Your Mission
|
|
11
|
-
|
|
12
|
-
### Phase 1: Flaky Test Diagnosis & Repair
|
|
13
|
-
|
|
14
|
-
Flaky tests are tests that sometimes pass and sometimes fail without code changes. They erode trust in the test suite and train developers to ignore failures. Your job is to find and fix them.
|
|
15
|
-
|
|
16
|
-
**Detection:**
|
|
17
|
-
- Run the full test suite 3-5 times in sequence
|
|
18
|
-
- Note any tests that produce different results across runs
|
|
19
|
-
- Look for tests that have been skipped/disabled with comments like "flaky", "intermittent", "timing issue", "TODO: fix"
|
|
20
|
-
- Search git history for tests that have been re-run in CI (if CI config is visible)
|
|
21
|
-
- Look for common flaky patterns even in currently-passing tests:
|
|
22
|
-
- Tests that depend on wall clock time or `Date.now()`
|
|
23
|
-
- Tests that depend on execution order (shared mutable state between tests)
|
|
24
|
-
- Tests that use `setTimeout` or arbitrary delays instead of proper async waiting
|
|
25
|
-
- Tests that depend on database auto-increment IDs or insertion order
|
|
26
|
-
- Tests that depend on file system state, network availability, or external services without mocking
|
|
27
|
-
- Tests that use random/non-deterministic data without seeding
|
|
28
|
-
- Tests with race conditions in async setup/teardown
|
|
29
|
-
- Tests that assert on floating point equality without tolerance
|
|
30
|
-
- Tests that depend on object key ordering or array sort stability
|
|
31
|
-
|
|
32
|
-
**For each flaky or potentially flaky test found:**
|
|
33
|
-
1. Diagnose the root cause — explain WHY it's flaky
|
|
34
|
-
2. Fix it:
|
|
35
|
-
- Replace time-dependent assertions with deterministic alternatives (mock clocks, inject time)
|
|
36
|
-
- Isolate shared state — each test gets its own setup
|
|
37
|
-
- Replace arbitrary delays with proper async waiting (waitFor, polling, event-based)
|
|
38
|
-
- Mock external dependencies that introduce non-determinism
|
|
39
|
-
- Use deterministic test data with explicit seeds if randomness is needed
|
|
40
|
-
- Fix setup/teardown ordering issues
|
|
41
|
-
3. Run the test 5 times to verify the fix holds
|
|
42
|
-
4. Commit: `fix: resolve flaky test in [module] — [root cause]`
|
|
43
|
-
|
|
44
|
-
**For currently-disabled flaky tests:**
|
|
45
|
-
- Attempt to fix and re-enable them
|
|
46
|
-
- If you can fix them, commit with: `fix: re-enable previously flaky test [name]`
|
|
47
|
-
- If you can't fix them, document why in the report
|
|
48
|
-
|
|
49
|
-
### Phase 2: API Contract Testing
|
|
50
|
-
|
|
51
|
-
Verify that the actual API behavior matches what consumers expect. This catches drift between documentation, types, and reality.
|
|
52
|
-
|
|
53
|
-
**Step 1: Map all API endpoints**
|
|
54
|
-
- Crawl the routing layer to find every endpoint
|
|
55
|
-
- For each endpoint, document:
|
|
56
|
-
- Method (GET/POST/PUT/DELETE/PATCH)
|
|
57
|
-
- Path (including URL parameters)
|
|
58
|
-
- Expected request body schema
|
|
59
|
-
- Expected response body schema for each status code
|
|
60
|
-
- Required headers / authentication
|
|
61
|
-
- Query parameters
|
|
62
|
-
|
|
63
|
-
**Step 2: Compare against documentation**
|
|
64
|
-
- If OpenAPI/Swagger docs exist, compare the actual code against the spec
|
|
65
|
-
- If TypeScript types/interfaces exist for request/response, compare against actual behavior
|
|
66
|
-
- Flag any discrepancies:
|
|
67
|
-
- Endpoints that exist in code but not in docs (undocumented)
|
|
68
|
-
- Endpoints in docs but not in code (stale docs)
|
|
69
|
-
- Response fields that exist in code but not in types
|
|
70
|
-
- Required fields in types that are actually optional in practice
|
|
71
|
-
- Status codes returned that aren't documented
|
|
72
|
-
|
|
73
|
-
**Step 3: Write contract tests**
|
|
74
|
-
For each endpoint, write tests that verify:
|
|
75
|
-
- Correct response status code for valid requests
|
|
76
|
-
- Correct response body structure (all expected fields present, correct types)
|
|
77
|
-
- Correct error response format for invalid requests (400, 401, 403, 404, 422)
|
|
78
|
-
- Required fields are actually required (omitting them returns appropriate error)
|
|
79
|
-
- Optional fields work when omitted
|
|
80
|
-
- Pagination behavior if applicable (correct page size, next/prev links, total count)
|
|
81
|
-
- Content-Type headers are correct
|
|
82
|
-
- CORS headers are present if expected
|
|
83
|
-
|
|
84
|
-
**Contract test quality standards:**
|
|
85
|
-
- Tests should validate STRUCTURE and TYPES, not specific values (unless values are constants)
|
|
86
|
-
- Use schema validation where possible (JSON Schema, Zod, Joi — match what the project uses)
|
|
87
|
-
- Test against a running instance of the app with a test database — not mocked responses
|
|
88
|
-
- Each endpoint gets its own test file or describe block
|
|
89
|
-
- Include authentication setup in test fixtures
|
|
90
|
-
|
|
91
|
-
**Step 4: Identify undocumented behavior**
|
|
92
|
-
As you write contract tests, you'll discover behavior that isn't documented anywhere:
|
|
93
|
-
- Default values for optional parameters
|
|
94
|
-
- Implicit filtering or sorting
|
|
95
|
-
- Hidden query parameters that work but aren't documented
|
|
96
|
-
- Rate limiting behavior
|
|
97
|
-
- Error message formats and codes
|
|
98
|
-
|
|
99
|
-
Document all of this. It's valuable even if you don't write tests for all of it.
|
|
100
|
-
|
|
101
|
-
## Output Requirements
|
|
102
|
-
|
|
103
|
-
Create the `audit-reports/` directory in the project root if it doesn't already exist. Save the report as `audit-reports/03_TEST_HARDENING_REPORT_[run-number]_[date]_[time in user's local time].md` (e.g., `03_TEST_HARDENING_REPORT_01_2026-02-16_2129.md`). Increment the run number based on any existing reports with the same name prefix in that folder.
|
|
104
|
-
|
|
105
|
-
### Report Structure
|
|
106
|
-
|
|
107
|
-
1. **Summary**
|
|
108
|
-
- Flaky tests found and fixed: X
|
|
109
|
-
- Flaky tests found but couldn't fix: X
|
|
110
|
-
- Previously disabled tests re-enabled: X
|
|
111
|
-
- API endpoints found: X
|
|
112
|
-
- Contract tests written: X
|
|
113
|
-
- Documentation discrepancies found: X
|
|
114
|
-
|
|
115
|
-
2. **Flaky Tests Fixed**
|
|
116
|
-
- Table: | Test Name | File | Root Cause | Fix Applied |
|
|
117
|
-
|
|
118
|
-
3. **Flaky Tests Unresolved**
|
|
119
|
-
- Table: | Test Name | File | Root Cause | Why It Couldn't Be Fixed |
|
|
120
|
-
|
|
121
|
-
4. **API Endpoint Map**
|
|
122
|
-
- Complete table of all endpoints with method, path, auth requirement, and test status
|
|
123
|
-
|
|
124
|
-
5. **Documentation Discrepancies**
|
|
125
|
-
- Every mismatch between docs/types and actual behavior
|
|
126
|
-
- Include what the docs say vs. what the code does
|
|
127
|
-
|
|
128
|
-
6. **Undocumented Behavior**
|
|
129
|
-
- Behavior you discovered that isn't documented anywhere
|
|
130
|
-
|
|
131
|
-
7. **Recommendations**
|
|
132
|
-
- Patterns that are causing flakiness that the team should stop using
|
|
133
|
-
- Suggestions for preventing future documentation drift
|
|
134
|
-
|
|
135
|
-
## Rules
|
|
136
|
-
- Branch: `test-hardening-[date]`
|
|
137
|
-
- When fixing flaky tests, DO NOT change the test's intent — only fix the non-determinism
|
|
138
|
-
- If a flaky test reveals that the underlying code has a race condition, document it as a bug — don't hide it by making the test more tolerant
|
|
139
|
-
- For contract tests, test against the actual running app, not mocks
|
|
140
|
-
- Don't generate contract tests for endpoints you can't actually call (missing auth setup, etc.) — document them as gaps instead
|
|
141
|
-
- Match existing test framework and conventions
|
|
142
|
-
- You have all night. Be thorough.
|
|
143
|
-
```
|
|
144
|
-
|
|
145
|
-
## Chat Output Requirement
|
|
146
|
-
|
|
147
|
-
In addition to writing the full report file, you MUST print a summary directly in the conversation when you finish. Do not make the user open the report to get the highlights. The chat summary should include:
|
|
148
|
-
|
|
149
|
-
### 1. Status Line
|
|
150
|
-
One sentence: what you did, how long it took, and whether all tests still pass.
|
|
151
|
-
|
|
152
|
-
### 2. Key Findings
|
|
153
|
-
The most important things discovered — bugs, risks, wins, or surprises. Each bullet should be specific and actionable, not vague. Lead with severity or impact.
|
|
154
|
-
|
|
155
|
-
**Good:** "CRITICAL: No backup configuration found for the primary Postgres database — total data loss risk."
|
|
156
|
-
**Bad:** "Found some issues with backups."
|
|
157
|
-
|
|
158
|
-
### 3. Changes Made (if applicable)
|
|
159
|
-
Bullet list of what was actually modified, added, or removed. Skip this section for read-only analysis runs.
|
|
160
|
-
|
|
161
|
-
### 4. Recommendations
|
|
162
|
-
|
|
163
|
-
If there are legitimately beneficial recommendations worth pursuing right now, present them in a table. Do **not** force recommendations — if the audit surfaced no actionable improvements, simply state that no recommendations are warranted at this time and move on.
|
|
164
|
-
|
|
165
|
-
When recommendations exist, use this table format:
|
|
166
|
-
|
|
167
|
-
| # | Recommendation | Impact | Risk if Ignored | Worth Doing? | Details |
|
|
168
|
-
|---|---|---|---|---|---|
|
|
169
|
-
| *Sequential number* | *Short description (≤10 words)* | *What improves if addressed* | *Low / Medium / High / Critical* | *Yes / Probably / Only if time allows* | *1–3 sentences explaining the reasoning, context, or implementation guidance* |
|
|
170
|
-
|
|
171
|
-
Order rows by risk descending (Critical → High → Medium → Low). Be honest in the "Worth Doing?" column — not everything flagged is worth the engineering time. If a recommendation is marginal, say so.
|
|
172
|
-
|
|
173
|
-
### 5. Report Location
|
|
174
|
-
State the full path to the detailed report file for deeper review.
|
|
175
|
-
|
|
176
|
-
---
|
|
177
|
-
|
|
178
|
-
**Formatting rules for chat output:**
|
|
179
|
-
- Use markdown headers, bold for severity labels, and bullet points for scannability.
|
|
180
|
-
- Do not duplicate the full report contents — just the highlights and recommendations.
|
|
181
|
-
- If you made zero findings in a phase, say so in one line rather than omitting it silently.
|
|
1
|
+
# Test Hardening
|
|
2
|
+
|
|
3
|
+
## Prompt
|
|
4
|
+
|
|
5
|
+
```
|
|
6
|
+
You are running an overnight test hardening pass. You have several hours. Your job is to make the existing test suite more reliable and more complete in two specific areas: flaky test diagnosis/repair and API contract testing.
|
|
7
|
+
|
|
8
|
+
Work on a branch called `test-hardening-[date]`.
|
|
9
|
+
|
|
10
|
+
## Your Mission
|
|
11
|
+
|
|
12
|
+
### Phase 1: Flaky Test Diagnosis & Repair
|
|
13
|
+
|
|
14
|
+
Flaky tests are tests that sometimes pass and sometimes fail without code changes. They erode trust in the test suite and train developers to ignore failures. Your job is to find and fix them.
|
|
15
|
+
|
|
16
|
+
**Detection:**
|
|
17
|
+
- Run the full test suite 3-5 times in sequence
|
|
18
|
+
- Note any tests that produce different results across runs
|
|
19
|
+
- Look for tests that have been skipped/disabled with comments like "flaky", "intermittent", "timing issue", "TODO: fix"
|
|
20
|
+
- Search git history for tests that have been re-run in CI (if CI config is visible)
|
|
21
|
+
- Look for common flaky patterns even in currently-passing tests:
|
|
22
|
+
- Tests that depend on wall clock time or `Date.now()`
|
|
23
|
+
- Tests that depend on execution order (shared mutable state between tests)
|
|
24
|
+
- Tests that use `setTimeout` or arbitrary delays instead of proper async waiting
|
|
25
|
+
- Tests that depend on database auto-increment IDs or insertion order
|
|
26
|
+
- Tests that depend on file system state, network availability, or external services without mocking
|
|
27
|
+
- Tests that use random/non-deterministic data without seeding
|
|
28
|
+
- Tests with race conditions in async setup/teardown
|
|
29
|
+
- Tests that assert on floating point equality without tolerance
|
|
30
|
+
- Tests that depend on object key ordering or array sort stability
|
|
31
|
+
|
|
32
|
+
**For each flaky or potentially flaky test found:**
|
|
33
|
+
1. Diagnose the root cause — explain WHY it's flaky
|
|
34
|
+
2. Fix it:
|
|
35
|
+
- Replace time-dependent assertions with deterministic alternatives (mock clocks, inject time)
|
|
36
|
+
- Isolate shared state — each test gets its own setup
|
|
37
|
+
- Replace arbitrary delays with proper async waiting (waitFor, polling, event-based)
|
|
38
|
+
- Mock external dependencies that introduce non-determinism
|
|
39
|
+
- Use deterministic test data with explicit seeds if randomness is needed
|
|
40
|
+
- Fix setup/teardown ordering issues
|
|
41
|
+
3. Run the test 5 times to verify the fix holds
|
|
42
|
+
4. Commit: `fix: resolve flaky test in [module] — [root cause]`
|
|
43
|
+
|
|
44
|
+
**For currently-disabled flaky tests:**
|
|
45
|
+
- Attempt to fix and re-enable them
|
|
46
|
+
- If you can fix them, commit with: `fix: re-enable previously flaky test [name]`
|
|
47
|
+
- If you can't fix them, document why in the report
|
|
48
|
+
|
|
49
|
+
### Phase 2: API Contract Testing
|
|
50
|
+
|
|
51
|
+
Verify that the actual API behavior matches what consumers expect. This catches drift between documentation, types, and reality.
|
|
52
|
+
|
|
53
|
+
**Step 1: Map all API endpoints**
|
|
54
|
+
- Crawl the routing layer to find every endpoint
|
|
55
|
+
- For each endpoint, document:
|
|
56
|
+
- Method (GET/POST/PUT/DELETE/PATCH)
|
|
57
|
+
- Path (including URL parameters)
|
|
58
|
+
- Expected request body schema
|
|
59
|
+
- Expected response body schema for each status code
|
|
60
|
+
- Required headers / authentication
|
|
61
|
+
- Query parameters
|
|
62
|
+
|
|
63
|
+
**Step 2: Compare against documentation**
|
|
64
|
+
- If OpenAPI/Swagger docs exist, compare the actual code against the spec
|
|
65
|
+
- If TypeScript types/interfaces exist for request/response, compare against actual behavior
|
|
66
|
+
- Flag any discrepancies:
|
|
67
|
+
- Endpoints that exist in code but not in docs (undocumented)
|
|
68
|
+
- Endpoints in docs but not in code (stale docs)
|
|
69
|
+
- Response fields that exist in code but not in types
|
|
70
|
+
- Required fields in types that are actually optional in practice
|
|
71
|
+
- Status codes returned that aren't documented
|
|
72
|
+
|
|
73
|
+
**Step 3: Write contract tests**
|
|
74
|
+
For each endpoint, write tests that verify:
|
|
75
|
+
- Correct response status code for valid requests
|
|
76
|
+
- Correct response body structure (all expected fields present, correct types)
|
|
77
|
+
- Correct error response format for invalid requests (400, 401, 403, 404, 422)
|
|
78
|
+
- Required fields are actually required (omitting them returns appropriate error)
|
|
79
|
+
- Optional fields work when omitted
|
|
80
|
+
- Pagination behavior if applicable (correct page size, next/prev links, total count)
|
|
81
|
+
- Content-Type headers are correct
|
|
82
|
+
- CORS headers are present if expected
|
|
83
|
+
|
|
84
|
+
**Contract test quality standards:**
|
|
85
|
+
- Tests should validate STRUCTURE and TYPES, not specific values (unless values are constants)
|
|
86
|
+
- Use schema validation where possible (JSON Schema, Zod, Joi — match what the project uses)
|
|
87
|
+
- Test against a running instance of the app with a test database — not mocked responses
|
|
88
|
+
- Each endpoint gets its own test file or describe block
|
|
89
|
+
- Include authentication setup in test fixtures
|
|
90
|
+
|
|
91
|
+
**Step 4: Identify undocumented behavior**
|
|
92
|
+
As you write contract tests, you'll discover behavior that isn't documented anywhere:
|
|
93
|
+
- Default values for optional parameters
|
|
94
|
+
- Implicit filtering or sorting
|
|
95
|
+
- Hidden query parameters that work but aren't documented
|
|
96
|
+
- Rate limiting behavior
|
|
97
|
+
- Error message formats and codes
|
|
98
|
+
|
|
99
|
+
Document all of this. It's valuable even if you don't write tests for all of it.
|
|
100
|
+
|
|
101
|
+
## Output Requirements
|
|
102
|
+
|
|
103
|
+
Create the `audit-reports/` directory in the project root if it doesn't already exist. Save the report as `audit-reports/03_TEST_HARDENING_REPORT_[run-number]_[date]_[time in user's local time].md` (e.g., `03_TEST_HARDENING_REPORT_01_2026-02-16_2129.md`). Increment the run number based on any existing reports with the same name prefix in that folder.
|
|
104
|
+
|
|
105
|
+
### Report Structure
|
|
106
|
+
|
|
107
|
+
1. **Summary**
|
|
108
|
+
- Flaky tests found and fixed: X
|
|
109
|
+
- Flaky tests found but couldn't fix: X
|
|
110
|
+
- Previously disabled tests re-enabled: X
|
|
111
|
+
- API endpoints found: X
|
|
112
|
+
- Contract tests written: X
|
|
113
|
+
- Documentation discrepancies found: X
|
|
114
|
+
|
|
115
|
+
2. **Flaky Tests Fixed**
|
|
116
|
+
- Table: | Test Name | File | Root Cause | Fix Applied |
|
|
117
|
+
|
|
118
|
+
3. **Flaky Tests Unresolved**
|
|
119
|
+
- Table: | Test Name | File | Root Cause | Why It Couldn't Be Fixed |
|
|
120
|
+
|
|
121
|
+
4. **API Endpoint Map**
|
|
122
|
+
- Complete table of all endpoints with method, path, auth requirement, and test status
|
|
123
|
+
|
|
124
|
+
5. **Documentation Discrepancies**
|
|
125
|
+
- Every mismatch between docs/types and actual behavior
|
|
126
|
+
- Include what the docs say vs. what the code does
|
|
127
|
+
|
|
128
|
+
6. **Undocumented Behavior**
|
|
129
|
+
- Behavior you discovered that isn't documented anywhere
|
|
130
|
+
|
|
131
|
+
7. **Recommendations**
|
|
132
|
+
- Patterns that are causing flakiness that the team should stop using
|
|
133
|
+
- Suggestions for preventing future documentation drift
|
|
134
|
+
|
|
135
|
+
## Rules
|
|
136
|
+
- Branch: `test-hardening-[date]`
|
|
137
|
+
- When fixing flaky tests, DO NOT change the test's intent — only fix the non-determinism
|
|
138
|
+
- If a flaky test reveals that the underlying code has a race condition, document it as a bug — don't hide it by making the test more tolerant
|
|
139
|
+
- For contract tests, test against the actual running app, not mocks
|
|
140
|
+
- Don't generate contract tests for endpoints you can't actually call (missing auth setup, etc.) — document them as gaps instead
|
|
141
|
+
- Match existing test framework and conventions
|
|
142
|
+
- You have all night. Be thorough.
|
|
143
|
+
```
|
|
144
|
+
|
|
145
|
+
## Chat Output Requirement
|
|
146
|
+
|
|
147
|
+
In addition to writing the full report file, you MUST print a summary directly in the conversation when you finish. Do not make the user open the report to get the highlights. The chat summary should include:
|
|
148
|
+
|
|
149
|
+
### 1. Status Line
|
|
150
|
+
One sentence: what you did, how long it took, and whether all tests still pass.
|
|
151
|
+
|
|
152
|
+
### 2. Key Findings
|
|
153
|
+
The most important things discovered — bugs, risks, wins, or surprises. Each bullet should be specific and actionable, not vague. Lead with severity or impact.
|
|
154
|
+
|
|
155
|
+
**Good:** "CRITICAL: No backup configuration found for the primary Postgres database — total data loss risk."
|
|
156
|
+
**Bad:** "Found some issues with backups."
|
|
157
|
+
|
|
158
|
+
### 3. Changes Made (if applicable)
|
|
159
|
+
Bullet list of what was actually modified, added, or removed. Skip this section for read-only analysis runs.
|
|
160
|
+
|
|
161
|
+
### 4. Recommendations
|
|
162
|
+
|
|
163
|
+
If there are legitimately beneficial recommendations worth pursuing right now, present them in a table. Do **not** force recommendations — if the audit surfaced no actionable improvements, simply state that no recommendations are warranted at this time and move on.
|
|
164
|
+
|
|
165
|
+
When recommendations exist, use this table format:
|
|
166
|
+
|
|
167
|
+
| # | Recommendation | Impact | Risk if Ignored | Worth Doing? | Details |
|
|
168
|
+
|---|---|---|---|---|---|
|
|
169
|
+
| *Sequential number* | *Short description (≤10 words)* | *What improves if addressed* | *Low / Medium / High / Critical* | *Yes / Probably / Only if time allows* | *1–3 sentences explaining the reasoning, context, or implementation guidance* |
|
|
170
|
+
|
|
171
|
+
Order rows by risk descending (Critical → High → Medium → Low). Be honest in the "Worth Doing?" column — not everything flagged is worth the engineering time. If a recommendation is marginal, say so.
|
|
172
|
+
|
|
173
|
+
### 5. Report Location
|
|
174
|
+
State the full path to the detailed report file for deeper review.
|
|
175
|
+
|
|
176
|
+
---
|
|
177
|
+
|
|
178
|
+
**Formatting rules for chat output:**
|
|
179
|
+
- Use markdown headers, bold for severity labels, and bullet points for scannability.
|
|
180
|
+
- Do not duplicate the full report contents — just the highlights and recommendations.
|
|
181
|
+
- If you made zero findings in a phase, say so in one line rather than omitting it silently.
|
|
@@ -1,130 +1,130 @@
|
|
|
1
|
-
# Test Architecture & Antipattern Audit
|
|
2
|
-
|
|
3
|
-
You are running an overnight test architecture audit. Test Coverage checks quantity. Test Hardening fixes flakiness. Your job is different: determine whether the tests are actually *good* — whether they catch real regressions or just produce green checkmarks.
|
|
4
|
-
|
|
5
|
-
**READ-ONLY analysis.** Do not modify any code or create a branch.
|
|
6
|
-
|
|
7
|
-
---
|
|
8
|
-
|
|
9
|
-
## Global Rules
|
|
10
|
-
|
|
11
|
-
- Evaluate tests as a *regression safety net*, not as documentation or coverage metrics.
|
|
12
|
-
- For every antipattern found, include: file, test name, what's wrong, why it matters, and a concrete fix suggestion.
|
|
13
|
-
- Be honest. A 95% coverage suite full of antipatterns is worse than 60% coverage of well-written behavioral tests. Say so.
|
|
14
|
-
- You have all night. Read every test file.
|
|
15
|
-
|
|
16
|
-
---
|
|
17
|
-
|
|
18
|
-
## Phase 1: Test Inventory & Classification
|
|
19
|
-
|
|
20
|
-
**Catalog every test file.** For each, record: file path, test count, what it tests (unit/integration/E2E), framework, approximate runtime, and the source module it covers.
|
|
21
|
-
|
|
22
|
-
**Classify the suite:**
|
|
23
|
-
- Ratio of unit : integration : E2E tests. Is the testing pyramid inverted (too many E2E, too few unit)?
|
|
24
|
-
- Which modules have tests? Which have none? Which have tests that don't match current behavior?
|
|
25
|
-
- Are test file locations consistent (co-located vs. separate `__tests__` directory vs. mixed)?
|
|
26
|
-
|
|
27
|
-
---
|
|
28
|
-
|
|
29
|
-
## Phase 2: Antipattern Detection
|
|
30
|
-
|
|
31
|
-
Scan every test file for each category below. Be exhaustive — count every instance.
|
|
32
|
-
|
|
33
|
-
### Implementation Coupling
|
|
34
|
-
- Tests asserting on internal method calls, private state, or execution order rather than inputs → outputs
|
|
35
|
-
- Tests that mock the module under test (testing the mock, not the code)
|
|
36
|
-
- Tests that break when you refactor internals without changing behavior
|
|
37
|
-
- Tests asserting exact function call counts on non-critical mocks (`expect(mock).toHaveBeenCalledTimes(3)` where 3 is an implementation detail)
|
|
38
|
-
|
|
39
|
-
### Misleading Tests
|
|
40
|
-
- Test name says one thing, assertions check another ("should validate email" but only checks the function doesn't throw)
|
|
41
|
-
- Tests with zero assertions (run code but verify nothing — `expect` never called)
|
|
42
|
-
- Tests where every assertion is on a mock, not on actual output
|
|
43
|
-
- Tautological assertions (`expect(true).toBe(true)`, `expect(mock).toHaveBeenCalled()` on a mock called unconditionally in setup)
|
|
44
|
-
- `expect` inside callbacks or async blocks that never execute (test passes because the assertion is never reached)
|
|
45
|
-
|
|
46
|
-
### Fragile Snapshots
|
|
47
|
-
- Snapshot tests on large objects, full HTML trees, or API responses (any change = blind update)
|
|
48
|
-
- Snapshot files with frequent, large diffs in git history
|
|
49
|
-
- Inline snapshots that are clearly auto-updated without review (formatting artifacts, irrelevant fields)
|
|
50
|
-
|
|
51
|
-
### Mock Overuse
|
|
52
|
-
- Mocks more complex than the code they replace (mock setup longer than the function body)
|
|
53
|
-
- Mocks that re-implement business logic (now you have two things to maintain)
|
|
54
|
-
- Mocks of things that should just be called (pure utility functions, simple data transforms)
|
|
55
|
-
- Deep mock chains (`mockService.mockMethod.mockReturnValue(...)` 5+ levels deep)
|
|
56
|
-
- Tests that only verify mock interactions with no behavioral assertion
|
|
57
|
-
|
|
58
|
-
### Wrong Test Level
|
|
59
|
-
- "Unit" tests that spin up databases, HTTP servers, or read files (integration tests in disguise)
|
|
60
|
-
- "Integration" tests that mock every dependency (unit tests in disguise)
|
|
61
|
-
- E2E tests checking implementation details that a unit test should cover
|
|
62
|
-
- Unit tests duplicating exact E2E test coverage with no additional edge cases
|
|
63
|
-
|
|
64
|
-
### Shared & Leaking State
|
|
65
|
-
- Global `beforeAll` setup shared across unrelated tests (test order dependence)
|
|
66
|
-
- Mutable module-level variables modified by tests without reset
|
|
67
|
-
- Database/file state not cleaned up between tests
|
|
68
|
-
- Tests that pass individually but fail when run together (or vice versa)
|
|
69
|
-
|
|
70
|
-
### Duplication & Bloat
|
|
71
|
-
- Near-identical tests with one parameter changed (should be parameterized/table-driven)
|
|
72
|
-
- The same setup code copy-pasted across 10+ test files
|
|
73
|
-
- Test helper functions that duplicate production code instead of calling it
|
|
74
|
-
- Tests for trivially simple code (getters, one-line pass-throughs) consuming maintenance effort
|
|
75
|
-
|
|
76
|
-
### Test Helper Bugs
|
|
77
|
-
- Shared test utilities, factories, or builders — read them as carefully as production code
|
|
78
|
-
- Helpers that silently swallow errors, supply wrong defaults, or produce invalid test data
|
|
79
|
-
- Factory functions that don't match current schema (added fields missing, removed fields still present)
|
|
80
|
-
|
|
81
|
-
---
|
|
82
|
-
|
|
83
|
-
## Phase 3: Regression Effectiveness Assessment
|
|
84
|
-
|
|
85
|
-
**For each major module**, answer: "If a developer introduced a subtle bug in this module tomorrow, would the tests catch it?"
|
|
86
|
-
|
|
87
|
-
- Assess whether tests check *behavior* (given X input, expect Y output) or just *execution* (the function ran without crashing)
|
|
88
|
-
- Cross-reference with mutation testing results if a Test Coverage run exists — functions with high line coverage but low mutation scores are the worst offenders
|
|
89
|
-
- Identify the most dangerous gaps: code that has tests but whose tests wouldn't catch common bug types (off-by-one, null handling, boundary conditions, wrong status codes)
|
|
90
|
-
|
|
91
|
-
**Rate each module:** Strong (would catch most regressions) / Weak (covers happy path only) / Decorative (tests exist but catch almost nothing) / None
|
|
92
|
-
|
|
93
|
-
---
|
|
94
|
-
|
|
95
|
-
## Phase 4: Structural Assessment
|
|
96
|
-
|
|
97
|
-
- **Test organization**: Consistent? Discoverable? Can you find the tests for a given module without searching?
|
|
98
|
-
- **Test naming conventions**: Descriptive (`should return 404 when user not found`) or vague (`test1`, `works correctly`)?
|
|
99
|
-
- **Setup/teardown patterns**: Consistent? Appropriate scope? Unnecessarily broad?
|
|
100
|
-
- **Custom matchers/utilities**: Well-maintained? Documented? Actually used?
|
|
101
|
-
- **Test configuration**: Reasonable timeouts? Appropriate parallelism? Sensible defaults?
|
|
102
|
-
|
|
103
|
-
---
|
|
104
|
-
|
|
105
|
-
## Output
|
|
106
|
-
|
|
107
|
-
Save as `audit-reports/04_TEST_ARCHITECTURE_REPORT_[run-number]_[date]_[time in user's local time].md`.
|
|
108
|
-
|
|
109
|
-
### Report Structure
|
|
110
|
-
|
|
111
|
-
1. **Executive Summary** — Suite health rating (decorative / fragile / adequate / strong / excellent), antipattern count by category, regression effectiveness score, one-line verdict: "This test suite [would / would not] catch a subtle billing bug introduced on a Friday afternoon."
|
|
112
|
-
2. **Test Inventory** — Classification table, pyramid ratio, coverage distribution.
|
|
113
|
-
3. **Antipattern Findings** — Per category: count, worst examples (file + test name + what's wrong), fix pattern. Table: | File | Test | Antipattern | Severity | Suggested Fix |
|
|
114
|
-
4. **Regression Effectiveness** — Per-module rating table: | Module | Test Count | Coverage | Effectiveness Rating | Why |
|
|
115
|
-
5. **Structural Assessment** — Organization, naming, conventions, configuration.
|
|
116
|
-
6. **Recommendations** — Priority-ordered. Focus on: which antipatterns to fix first (highest regression risk), which modules need test rewrites vs. additions, conventions to adopt, and whether the team should invest in better test infrastructure (factories, custom matchers, test database management).
|
|
117
|
-
|
|
118
|
-
## Chat Output Requirement
|
|
119
|
-
|
|
120
|
-
Print a summary in conversation:
|
|
121
|
-
|
|
122
|
-
1. **Status Line** — What you analyzed.
|
|
123
|
-
2. **Key Findings** — Specific bullets with severity. "42 tests have zero assertions — they pass even if the code returns garbage." Not "found some test quality issues."
|
|
124
|
-
3. **Recommendations** table (if warranted):
|
|
125
|
-
|
|
126
|
-
| # | Recommendation | Impact | Risk if Ignored | Worth Doing? | Details |
|
|
127
|
-
|---|---|---|---|---|---|
|
|
128
|
-
| | ≤10 words | What improves | Low–Critical | Yes/Probably/If time | 1–3 sentences |
|
|
129
|
-
|
|
130
|
-
4. **Report Location** — Full path.
|
|
1
|
+
# Test Architecture & Antipattern Audit
|
|
2
|
+
|
|
3
|
+
You are running an overnight test architecture audit. Test Coverage checks quantity. Test Hardening fixes flakiness. Your job is different: determine whether the tests are actually *good* — whether they catch real regressions or just produce green checkmarks.
|
|
4
|
+
|
|
5
|
+
**READ-ONLY analysis.** Do not modify any code or create a branch.
|
|
6
|
+
|
|
7
|
+
---
|
|
8
|
+
|
|
9
|
+
## Global Rules
|
|
10
|
+
|
|
11
|
+
- Evaluate tests as a *regression safety net*, not as documentation or coverage metrics.
|
|
12
|
+
- For every antipattern found, include: file, test name, what's wrong, why it matters, and a concrete fix suggestion.
|
|
13
|
+
- Be honest. A 95% coverage suite full of antipatterns is worse than 60% coverage of well-written behavioral tests. Say so.
|
|
14
|
+
- You have all night. Read every test file.
|
|
15
|
+
|
|
16
|
+
---
|
|
17
|
+
|
|
18
|
+
## Phase 1: Test Inventory & Classification
|
|
19
|
+
|
|
20
|
+
**Catalog every test file.** For each, record: file path, test count, what it tests (unit/integration/E2E), framework, approximate runtime, and the source module it covers.
|
|
21
|
+
|
|
22
|
+
**Classify the suite:**
|
|
23
|
+
- Ratio of unit : integration : E2E tests. Is the testing pyramid inverted (too many E2E, too few unit)?
|
|
24
|
+
- Which modules have tests? Which have none? Which have tests that don't match current behavior?
|
|
25
|
+
- Are test file locations consistent (co-located vs. separate `__tests__` directory vs. mixed)?
|
|
26
|
+
|
|
27
|
+
---
|
|
28
|
+
|
|
29
|
+
## Phase 2: Antipattern Detection
|
|
30
|
+
|
|
31
|
+
Scan every test file for each category below. Be exhaustive — count every instance.
|
|
32
|
+
|
|
33
|
+
### Implementation Coupling
|
|
34
|
+
- Tests asserting on internal method calls, private state, or execution order rather than inputs → outputs
|
|
35
|
+
- Tests that mock the module under test (testing the mock, not the code)
|
|
36
|
+
- Tests that break when you refactor internals without changing behavior
|
|
37
|
+
- Tests asserting exact function call counts on non-critical mocks (`expect(mock).toHaveBeenCalledTimes(3)` where 3 is an implementation detail)
|
|
38
|
+
|
|
39
|
+
### Misleading Tests
|
|
40
|
+
- Test name says one thing, assertions check another ("should validate email" but only checks the function doesn't throw)
|
|
41
|
+
- Tests with zero assertions (run code but verify nothing — `expect` never called)
|
|
42
|
+
- Tests where every assertion is on a mock, not on actual output
|
|
43
|
+
- Tautological assertions (`expect(true).toBe(true)`, `expect(mock).toHaveBeenCalled()` on a mock called unconditionally in setup)
|
|
44
|
+
- `expect` inside callbacks or async blocks that never execute (test passes because the assertion is never reached)
|
|
45
|
+
|
|
46
|
+
### Fragile Snapshots
|
|
47
|
+
- Snapshot tests on large objects, full HTML trees, or API responses (any change = blind update)
|
|
48
|
+
- Snapshot files with frequent, large diffs in git history
|
|
49
|
+
- Inline snapshots that are clearly auto-updated without review (formatting artifacts, irrelevant fields)
|
|
50
|
+
|
|
51
|
+
### Mock Overuse
|
|
52
|
+
- Mocks more complex than the code they replace (mock setup longer than the function body)
|
|
53
|
+
- Mocks that re-implement business logic (now you have two things to maintain)
|
|
54
|
+
- Mocks of things that should just be called (pure utility functions, simple data transforms)
|
|
55
|
+
- Deep mock chains (`mockService.mockMethod.mockReturnValue(...)` 5+ levels deep)
|
|
56
|
+
- Tests that only verify mock interactions with no behavioral assertion
|
|
57
|
+
|
|
58
|
+
### Wrong Test Level
|
|
59
|
+
- "Unit" tests that spin up databases, HTTP servers, or read files (integration tests in disguise)
|
|
60
|
+
- "Integration" tests that mock every dependency (unit tests in disguise)
|
|
61
|
+
- E2E tests checking implementation details that a unit test should cover
|
|
62
|
+
- Unit tests duplicating exact E2E test coverage with no additional edge cases
|
|
63
|
+
|
|
64
|
+
### Shared & Leaking State
|
|
65
|
+
- Global `beforeAll` setup shared across unrelated tests (test order dependence)
|
|
66
|
+
- Mutable module-level variables modified by tests without reset
|
|
67
|
+
- Database/file state not cleaned up between tests
|
|
68
|
+
- Tests that pass individually but fail when run together (or vice versa)
|
|
69
|
+
|
|
70
|
+
### Duplication & Bloat
|
|
71
|
+
- Near-identical tests with one parameter changed (should be parameterized/table-driven)
|
|
72
|
+
- The same setup code copy-pasted across 10+ test files
|
|
73
|
+
- Test helper functions that duplicate production code instead of calling it
|
|
74
|
+
- Tests for trivially simple code (getters, one-line pass-throughs) consuming maintenance effort
|
|
75
|
+
|
|
76
|
+
### Test Helper Bugs
|
|
77
|
+
- Shared test utilities, factories, or builders — read them as carefully as production code
|
|
78
|
+
- Helpers that silently swallow errors, supply wrong defaults, or produce invalid test data
|
|
79
|
+
- Factory functions that don't match current schema (added fields missing, removed fields still present)
|
|
80
|
+
|
|
81
|
+
---
|
|
82
|
+
|
|
83
|
+
## Phase 3: Regression Effectiveness Assessment
|
|
84
|
+
|
|
85
|
+
**For each major module**, answer: "If a developer introduced a subtle bug in this module tomorrow, would the tests catch it?"
|
|
86
|
+
|
|
87
|
+
- Assess whether tests check *behavior* (given X input, expect Y output) or just *execution* (the function ran without crashing)
|
|
88
|
+
- Cross-reference with mutation testing results if a Test Coverage run exists — functions with high line coverage but low mutation scores are the worst offenders
|
|
89
|
+
- Identify the most dangerous gaps: code that has tests but whose tests wouldn't catch common bug types (off-by-one, null handling, boundary conditions, wrong status codes)
|
|
90
|
+
|
|
91
|
+
**Rate each module:** Strong (would catch most regressions) / Weak (covers happy path only) / Decorative (tests exist but catch almost nothing) / None
|
|
92
|
+
|
|
93
|
+
---
|
|
94
|
+
|
|
95
|
+
## Phase 4: Structural Assessment
|
|
96
|
+
|
|
97
|
+
- **Test organization**: Consistent? Discoverable? Can you find the tests for a given module without searching?
|
|
98
|
+
- **Test naming conventions**: Descriptive (`should return 404 when user not found`) or vague (`test1`, `works correctly`)?
|
|
99
|
+
- **Setup/teardown patterns**: Consistent? Appropriate scope? Unnecessarily broad?
|
|
100
|
+
- **Custom matchers/utilities**: Well-maintained? Documented? Actually used?
|
|
101
|
+
- **Test configuration**: Reasonable timeouts? Appropriate parallelism? Sensible defaults?
|
|
102
|
+
|
|
103
|
+
---
|
|
104
|
+
|
|
105
|
+
## Output
|
|
106
|
+
|
|
107
|
+
Save as `audit-reports/04_TEST_ARCHITECTURE_REPORT_[run-number]_[date]_[time in user's local time].md`.
|
|
108
|
+
|
|
109
|
+
### Report Structure
|
|
110
|
+
|
|
111
|
+
1. **Executive Summary** — Suite health rating (decorative / fragile / adequate / strong / excellent), antipattern count by category, regression effectiveness score, one-line verdict: "This test suite [would / would not] catch a subtle billing bug introduced on a Friday afternoon."
|
|
112
|
+
2. **Test Inventory** — Classification table, pyramid ratio, coverage distribution.
|
|
113
|
+
3. **Antipattern Findings** — Per category: count, worst examples (file + test name + what's wrong), fix pattern. Table: | File | Test | Antipattern | Severity | Suggested Fix |
|
|
114
|
+
4. **Regression Effectiveness** — Per-module rating table: | Module | Test Count | Coverage | Effectiveness Rating | Why |
|
|
115
|
+
5. **Structural Assessment** — Organization, naming, conventions, configuration.
|
|
116
|
+
6. **Recommendations** — Priority-ordered. Focus on: which antipatterns to fix first (highest regression risk), which modules need test rewrites vs. additions, conventions to adopt, and whether the team should invest in better test infrastructure (factories, custom matchers, test database management).
|
|
117
|
+
|
|
118
|
+
## Chat Output Requirement
|
|
119
|
+
|
|
120
|
+
Print a summary in conversation:
|
|
121
|
+
|
|
122
|
+
1. **Status Line** — What you analyzed.
|
|
123
|
+
2. **Key Findings** — Specific bullets with severity. "42 tests have zero assertions — they pass even if the code returns garbage." Not "found some test quality issues."
|
|
124
|
+
3. **Recommendations** table (if warranted):
|
|
125
|
+
|
|
126
|
+
| # | Recommendation | Impact | Risk if Ignored | Worth Doing? | Details |
|
|
127
|
+
|---|---|---|---|---|---|
|
|
128
|
+
| | ≤10 words | What improves | Low–Critical | Yes/Probably/If time | 1–3 sentences |
|
|
129
|
+
|
|
130
|
+
4. **Report Location** — Full path.
|