@massu/core 0.1.2 → 0.4.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.
- package/commands/_shared-preamble.md +76 -0
- package/commands/massu-audit-deps.md +211 -0
- package/commands/massu-changelog.md +174 -0
- package/commands/massu-cleanup.md +315 -0
- package/commands/massu-commit.md +481 -0
- package/commands/massu-create-plan.md +752 -0
- package/commands/massu-dead-code.md +131 -0
- package/commands/massu-debug.md +484 -0
- package/commands/massu-deploy.md +91 -0
- package/commands/massu-deps.md +374 -0
- package/commands/massu-doc-gen.md +279 -0
- package/commands/massu-docs.md +364 -0
- package/commands/massu-estimate.md +313 -0
- package/commands/massu-golden-path.md +973 -0
- package/commands/massu-guide.md +167 -0
- package/commands/massu-hotfix.md +480 -0
- package/commands/massu-loop-playwright.md +837 -0
- package/commands/massu-loop.md +775 -0
- package/commands/massu-new-feature.md +511 -0
- package/commands/massu-parity.md +214 -0
- package/commands/massu-plan.md +456 -0
- package/commands/massu-push-light.md +207 -0
- package/commands/massu-push.md +434 -0
- package/commands/massu-refactor.md +410 -0
- package/commands/massu-release.md +363 -0
- package/commands/massu-review.md +238 -0
- package/commands/massu-simplify.md +281 -0
- package/commands/massu-status.md +278 -0
- package/commands/massu-tdd.md +201 -0
- package/commands/massu-test.md +516 -0
- package/commands/massu-verify-playwright.md +281 -0
- package/commands/massu-verify.md +667 -0
- package/dist/cli.js +12521 -0
- package/dist/hooks/cost-tracker.js +80 -5
- package/dist/hooks/post-edit-context.js +72 -6
- package/dist/hooks/post-tool-use.js +234 -57
- package/dist/hooks/pre-compact.js +144 -5
- package/dist/hooks/pre-delete-check.js +141 -11
- package/dist/hooks/quality-event.js +80 -5
- package/dist/hooks/security-gate.js +29 -0
- package/dist/hooks/session-end.js +83 -8
- package/dist/hooks/session-start.js +153 -7
- package/dist/hooks/user-prompt.js +166 -5
- package/package.json +6 -5
- package/src/backfill-sessions.ts +5 -4
- package/src/cli.ts +6 -1
- package/src/commands/doctor.ts +193 -6
- package/src/commands/init.ts +235 -6
- package/src/commands/install-commands.ts +137 -0
- package/src/config.ts +68 -2
- package/src/db.ts +115 -2
- package/src/docs-tools.ts +8 -6
- package/src/hooks/post-edit-context.ts +1 -1
- package/src/hooks/post-tool-use.ts +130 -0
- package/src/hooks/pre-compact.ts +23 -1
- package/src/hooks/pre-delete-check.ts +92 -4
- package/src/hooks/security-gate.ts +32 -0
- package/src/hooks/session-start.ts +97 -4
- package/src/hooks/user-prompt.ts +46 -1
- package/src/import-resolver.ts +2 -1
- package/src/knowledge-db.ts +169 -0
- package/src/knowledge-indexer.ts +704 -0
- package/src/knowledge-tools.ts +1413 -0
- package/src/license.ts +482 -0
- package/src/memory-db.ts +14 -1
- package/src/observation-extractor.ts +11 -4
- package/src/page-deps.ts +3 -2
- package/src/python/coupling-detector.ts +124 -0
- package/src/python/domain-enforcer.ts +83 -0
- package/src/python/impact-analyzer.ts +95 -0
- package/src/python/import-parser.ts +244 -0
- package/src/python/import-resolver.ts +135 -0
- package/src/python/migration-indexer.ts +115 -0
- package/src/python/migration-parser.ts +332 -0
- package/src/python/model-indexer.ts +70 -0
- package/src/python/model-parser.ts +279 -0
- package/src/python/route-indexer.ts +58 -0
- package/src/python/route-parser.ts +317 -0
- package/src/python-tools.ts +629 -0
- package/src/sentinel-db.ts +2 -1
- package/src/server.ts +29 -6
- package/src/session-archiver.ts +4 -5
- package/src/tools.ts +283 -31
- package/README.md +0 -40
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: massu-tdd
|
|
3
|
+
description: Test-driven development cycle — RED (failing test) -> GREEN (minimal impl) -> IMPROVE (refactor)
|
|
4
|
+
allowed-tools: Bash(*), Read(*), Write(*), Edit(*), Grep(*), Glob(*)
|
|
5
|
+
---
|
|
6
|
+
name: massu-tdd
|
|
7
|
+
|
|
8
|
+
> **Shared rules apply.** Read `.claude/commands/_shared-preamble.md` before proceeding. CR-9 enforced.
|
|
9
|
+
|
|
10
|
+
# Massu TDD: Test-Driven Development Cycle
|
|
11
|
+
|
|
12
|
+
## Objective
|
|
13
|
+
|
|
14
|
+
Implement features or fix bugs using strict test-first development. Write the test BEFORE the implementation. The test defines the contract; the code fulfills it.
|
|
15
|
+
|
|
16
|
+
**This is NOT `/massu-test`** (which audits existing coverage). `/massu-tdd` is for writing NEW code test-first.
|
|
17
|
+
|
|
18
|
+
---
|
|
19
|
+
|
|
20
|
+
## NON-NEGOTIABLE RULES
|
|
21
|
+
|
|
22
|
+
- **Tests BEFORE implementation** - writing code first violates TDD
|
|
23
|
+
- **Minimal implementation** - in GREEN phase, write ONLY enough to pass the test
|
|
24
|
+
- **Refactor ONLY when green** - never refactor with failing tests
|
|
25
|
+
- **VR-proof at every step** - show test output proving RED/GREEN status
|
|
26
|
+
- **Pattern compliance** - IMPROVE phase must apply CLAUDE.md patterns
|
|
27
|
+
- **FIX ALL ISSUES ENCOUNTERED (CR-9)** - if tests reveal other bugs, fix them
|
|
28
|
+
|
|
29
|
+
---
|
|
30
|
+
|
|
31
|
+
## COMMAND DISTINCTION
|
|
32
|
+
|
|
33
|
+
| Command | Purpose | When to Use |
|
|
34
|
+
|---------|---------|-------------|
|
|
35
|
+
| `/massu-tdd` | Write NEW code test-first | New features, bug fixes |
|
|
36
|
+
| `/massu-test` | Audit EXISTING test coverage | Coverage analysis, gap detection |
|
|
37
|
+
|
|
38
|
+
---
|
|
39
|
+
|
|
40
|
+
## TDD CYCLE
|
|
41
|
+
|
|
42
|
+
### Step 0: SCOPE
|
|
43
|
+
|
|
44
|
+
User provides feature description or bug report. Identify:
|
|
45
|
+
- **Test file location**: `packages/core/src/__tests__/[name].test.ts`
|
|
46
|
+
- **Target source file**: The file that will be implemented/modified
|
|
47
|
+
- **Vitest config**: `packages/core/vitest.config.ts`
|
|
48
|
+
|
|
49
|
+
### Step 1: RED (Write Failing Test)
|
|
50
|
+
|
|
51
|
+
Write the test file FIRST. The test defines expected behavior.
|
|
52
|
+
|
|
53
|
+
```bash
|
|
54
|
+
# Write test with assertions for expected behavior
|
|
55
|
+
# Then run it -- it MUST FAIL
|
|
56
|
+
cd packages/core && npx vitest run src/__tests__/[test-file] --reporter=verbose
|
|
57
|
+
```
|
|
58
|
+
|
|
59
|
+
**Verification**:
|
|
60
|
+
- Test output shows FAIL status
|
|
61
|
+
- Failure is for the RIGHT reason (missing function/feature, not syntax error)
|
|
62
|
+
- If test PASSES: the test is wrong (testing nothing) or the feature already exists
|
|
63
|
+
|
|
64
|
+
**VR-proof**: Show test output with FAIL status.
|
|
65
|
+
|
|
66
|
+
### Step 2: GREEN (Minimal Implementation)
|
|
67
|
+
|
|
68
|
+
Write ONLY the minimum code to make the failing test pass.
|
|
69
|
+
|
|
70
|
+
Rules:
|
|
71
|
+
- No refactoring
|
|
72
|
+
- No extra features
|
|
73
|
+
- No cleanup
|
|
74
|
+
- No pattern compliance yet
|
|
75
|
+
- Just make the test pass
|
|
76
|
+
|
|
77
|
+
```bash
|
|
78
|
+
# Run the test again -- it MUST PASS
|
|
79
|
+
cd packages/core && npx vitest run src/__tests__/[test-file] --reporter=verbose
|
|
80
|
+
```
|
|
81
|
+
|
|
82
|
+
**VR-proof**: Show test output with PASS status.
|
|
83
|
+
|
|
84
|
+
### Step 3: IMPROVE (Refactor)
|
|
85
|
+
|
|
86
|
+
Now improve code quality while keeping tests green:
|
|
87
|
+
- Apply CLAUDE.md patterns (config-driven, getConfig(), ESM imports, etc.)
|
|
88
|
+
- Improve naming, readability, structure
|
|
89
|
+
- Add error handling
|
|
90
|
+
- Extract reusable functions
|
|
91
|
+
|
|
92
|
+
```bash
|
|
93
|
+
# Run test after refactoring -- MUST STILL PASS
|
|
94
|
+
cd packages/core && npx vitest run src/__tests__/[test-file] --reporter=verbose
|
|
95
|
+
```
|
|
96
|
+
|
|
97
|
+
**VR-proof**: Show test output with PASS status.
|
|
98
|
+
|
|
99
|
+
### Step 4: REPEAT or COMPLETE
|
|
100
|
+
|
|
101
|
+
If more scenarios needed (edge cases, error handling, additional features):
|
|
102
|
+
- Return to Step 1 with the next test case
|
|
103
|
+
- Each cycle adds one scenario
|
|
104
|
+
|
|
105
|
+
If complete:
|
|
106
|
+
```bash
|
|
107
|
+
# Run full test suite to confirm no regressions
|
|
108
|
+
npm test
|
|
109
|
+
```
|
|
110
|
+
|
|
111
|
+
**VR-TEST proof**: Full suite passes.
|
|
112
|
+
|
|
113
|
+
---
|
|
114
|
+
|
|
115
|
+
## TDD CYCLE DIAGRAM
|
|
116
|
+
|
|
117
|
+
```
|
|
118
|
+
+-------------------------+
|
|
119
|
+
| Step 0: SCOPE |
|
|
120
|
+
| Define test + target |
|
|
121
|
+
+--------+----------------+
|
|
122
|
+
|
|
|
123
|
+
+--------v----------------+
|
|
124
|
+
| Step 1: RED |
|
|
125
|
+
| Write failing test |<----+
|
|
126
|
+
| VR: test FAILS | |
|
|
127
|
+
+--------+----------------+ |
|
|
128
|
+
| |
|
|
129
|
+
+--------v----------------+ |
|
|
130
|
+
| Step 2: GREEN | |
|
|
131
|
+
| Minimal implementation | | More
|
|
132
|
+
| VR: test PASSES | | scenarios?
|
|
133
|
+
+--------+----------------+ |
|
|
134
|
+
| |
|
|
135
|
+
+--------v----------------+ |
|
|
136
|
+
| Step 3: IMPROVE | |
|
|
137
|
+
| Refactor + patterns |-----+
|
|
138
|
+
| VR: test STILL PASSES |
|
|
139
|
+
+--------+----------------+
|
|
140
|
+
|
|
|
141
|
+
+--------v----------------+
|
|
142
|
+
| Step 4: COMPLETE |
|
|
143
|
+
| Full suite passes |
|
|
144
|
+
| VR-TEST: npm test |
|
|
145
|
+
+-------------------------+
|
|
146
|
+
```
|
|
147
|
+
|
|
148
|
+
---
|
|
149
|
+
|
|
150
|
+
## TEST PATTERNS
|
|
151
|
+
|
|
152
|
+
### Unit Test Template
|
|
153
|
+
```typescript
|
|
154
|
+
import { describe, it, expect, vi } from 'vitest';
|
|
155
|
+
|
|
156
|
+
describe('[Feature]', () => {
|
|
157
|
+
describe('[Scenario]', () => {
|
|
158
|
+
it('should [expected behavior] when [condition]', () => {
|
|
159
|
+
// Arrange
|
|
160
|
+
// Act
|
|
161
|
+
// Assert
|
|
162
|
+
expect(result).toBe(expected);
|
|
163
|
+
});
|
|
164
|
+
});
|
|
165
|
+
});
|
|
166
|
+
```
|
|
167
|
+
|
|
168
|
+
### MCP Tool Test Template
|
|
169
|
+
```typescript
|
|
170
|
+
import { describe, it, expect, vi } from 'vitest';
|
|
171
|
+
|
|
172
|
+
describe('[ToolName]', () => {
|
|
173
|
+
it('should return correct result for valid input', () => {
|
|
174
|
+
// Arrange: set up mock database, config
|
|
175
|
+
// Act: call handleToolCall with tool name and args
|
|
176
|
+
// Assert: verify content[0].text contains expected output
|
|
177
|
+
});
|
|
178
|
+
|
|
179
|
+
it('should handle missing arguments gracefully', () => {
|
|
180
|
+
// Test error handling
|
|
181
|
+
});
|
|
182
|
+
});
|
|
183
|
+
```
|
|
184
|
+
|
|
185
|
+
---
|
|
186
|
+
|
|
187
|
+
## SESSION STATE UPDATE
|
|
188
|
+
|
|
189
|
+
After TDD cycle, update `session-state/CURRENT.md`:
|
|
190
|
+
|
|
191
|
+
```markdown
|
|
192
|
+
## TDD SESSION
|
|
193
|
+
- **Feature**: [description]
|
|
194
|
+
- **Test file**: [path]
|
|
195
|
+
- **Cycles**: [N]
|
|
196
|
+
- **Status**: COMPLETE / IN_PROGRESS
|
|
197
|
+
```
|
|
198
|
+
|
|
199
|
+
---
|
|
200
|
+
|
|
201
|
+
**Remember: The test is the specification. Write it first, then make it pass.**
|
|
@@ -0,0 +1,516 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: massu-test
|
|
3
|
+
description: Intelligent test runner with failure analysis, coverage gaps, and test generation
|
|
4
|
+
allowed-tools: Bash(*), Read(*), Write(*), Edit(*), Grep(*), Glob(*)
|
|
5
|
+
---
|
|
6
|
+
name: massu-test
|
|
7
|
+
|
|
8
|
+
> **Shared rules apply.** Read `.claude/commands/_shared-preamble.md` before proceeding. CR-9, CR-35 enforced.
|
|
9
|
+
|
|
10
|
+
# CS Test: Intelligent Test Runner
|
|
11
|
+
|
|
12
|
+
## Objective
|
|
13
|
+
|
|
14
|
+
Run tests intelligently, analyze failures, detect coverage gaps, and generate missing tests. Supports multiple modes for targeted testing workflows.
|
|
15
|
+
|
|
16
|
+
**Usage**: `/massu-test` (run all) or `/massu-test [--affected | --coverage | --generate [module] | --fix]`
|
|
17
|
+
|
|
18
|
+
## Workflow Position
|
|
19
|
+
|
|
20
|
+
```
|
|
21
|
+
/massu-test (standalone test runner)
|
|
22
|
+
/massu-test --fix (test + auto-fix failures)
|
|
23
|
+
/massu-test --generate [mod] (generate missing tests)
|
|
24
|
+
/massu-test --coverage (coverage analysis)
|
|
25
|
+
/massu-test --affected (only tests for changed files)
|
|
26
|
+
```
|
|
27
|
+
|
|
28
|
+
---
|
|
29
|
+
|
|
30
|
+
## NON-NEGOTIABLE RULES
|
|
31
|
+
|
|
32
|
+
- Always capture FULL test output (do not truncate)
|
|
33
|
+
- Never modify source code unless in `--fix` or `--generate` mode
|
|
34
|
+
- In `--fix` mode: understand WHY before applying any fix
|
|
35
|
+
- In `--generate` mode: follow vitest patterns from existing tests exactly
|
|
36
|
+
- Report ALL failures, not just the first one
|
|
37
|
+
- **FIX ALL ISSUES ENCOUNTERED (CR-9)** — in `--fix` mode, fix every failing test, not just one
|
|
38
|
+
- **VR-TEST verification** — `npm test` must pass before commit
|
|
39
|
+
- **Critical paths first** — Tool handlers, config parsing, DB operations need tests
|
|
40
|
+
- **Isolation** — Tests must not depend on external state
|
|
41
|
+
- **Deterministic** — Same code = same result
|
|
42
|
+
|
|
43
|
+
---
|
|
44
|
+
|
|
45
|
+
## ZERO-GAP AUDIT LOOP
|
|
46
|
+
|
|
47
|
+
**Test audit does NOT complete until a SINGLE COMPLETE AUDIT finds ZERO issues.**
|
|
48
|
+
|
|
49
|
+
### The Rule
|
|
50
|
+
|
|
51
|
+
```
|
|
52
|
+
TEST AUDIT LOOP:
|
|
53
|
+
1. Run ALL test coverage and quality checks
|
|
54
|
+
2. Count gaps and issues found
|
|
55
|
+
3. IF issues > 0:
|
|
56
|
+
- Fix ALL issues (add tests, fix anti-patterns)
|
|
57
|
+
- Re-run ENTIRE audit from Step 1
|
|
58
|
+
4. IF issues == 0:
|
|
59
|
+
- TEST COVERAGE VERIFIED
|
|
60
|
+
```
|
|
61
|
+
|
|
62
|
+
### Completion Requirement
|
|
63
|
+
|
|
64
|
+
| Scenario | Action |
|
|
65
|
+
|----------|--------|
|
|
66
|
+
| Audit finds 3 untested critical paths | Add tests, re-run ENTIRE audit |
|
|
67
|
+
| Re-audit finds 1 test quality issue | Fix it, re-run ENTIRE audit |
|
|
68
|
+
| Re-audit finds 0 issues | **NOW** test coverage verified |
|
|
69
|
+
|
|
70
|
+
**Partial re-checks are NOT valid. The ENTIRE test audit must pass in a SINGLE run.**
|
|
71
|
+
|
|
72
|
+
---
|
|
73
|
+
|
|
74
|
+
## STEP 1: DETERMINE MODE
|
|
75
|
+
|
|
76
|
+
Parse `$ARGUMENTS` to determine the execution mode:
|
|
77
|
+
|
|
78
|
+
| Argument | Mode | Description |
|
|
79
|
+
|----------|------|-------------|
|
|
80
|
+
| (none) | FULL_RUN | Run all tests, report results with analysis |
|
|
81
|
+
| `--affected` | AFFECTED | Run only tests affected by current git diff |
|
|
82
|
+
| `--coverage` | COVERAGE | Run tests + analyze which modules have no test coverage |
|
|
83
|
+
| `--generate [module]` | GENERATE | Generate test file for specified module |
|
|
84
|
+
| `--fix` | FIX | Run tests, auto-fix failing tests |
|
|
85
|
+
|
|
86
|
+
```
|
|
87
|
+
IF no arguments:
|
|
88
|
+
MODE = FULL_RUN
|
|
89
|
+
ELSE IF arguments contain "--affected":
|
|
90
|
+
MODE = AFFECTED
|
|
91
|
+
ELSE IF arguments contain "--coverage":
|
|
92
|
+
MODE = COVERAGE
|
|
93
|
+
ELSE IF arguments contain "--generate":
|
|
94
|
+
MODE = GENERATE
|
|
95
|
+
TARGET_MODULE = [module name from arguments]
|
|
96
|
+
ELSE IF arguments contain "--fix":
|
|
97
|
+
MODE = FIX
|
|
98
|
+
ELSE:
|
|
99
|
+
OUTPUT: "Unknown mode. Usage: /massu-test [--affected | --coverage | --generate [module] | --fix]"
|
|
100
|
+
ABORT
|
|
101
|
+
```
|
|
102
|
+
|
|
103
|
+
---
|
|
104
|
+
|
|
105
|
+
## STEP 2: RUN TESTS
|
|
106
|
+
|
|
107
|
+
```bash
|
|
108
|
+
# Run the full test suite with output capture
|
|
109
|
+
npm test 2>&1
|
|
110
|
+
```
|
|
111
|
+
|
|
112
|
+
**For AFFECTED mode, skip to STEP 6 first, then run only affected tests.**
|
|
113
|
+
|
|
114
|
+
---
|
|
115
|
+
|
|
116
|
+
## STEP 3: ANALYZE RESULTS
|
|
117
|
+
|
|
118
|
+
Parse vitest output to extract metrics:
|
|
119
|
+
|
|
120
|
+
```markdown
|
|
121
|
+
### Test Results
|
|
122
|
+
|
|
123
|
+
| Metric | Value |
|
|
124
|
+
|--------|-------|
|
|
125
|
+
| Total tests | [N] |
|
|
126
|
+
| Passing | [N] |
|
|
127
|
+
| Failing | [N] |
|
|
128
|
+
| Skipped | [N] |
|
|
129
|
+
| Duration | [N]s |
|
|
130
|
+
| Test files | [N] |
|
|
131
|
+
```
|
|
132
|
+
|
|
133
|
+
**If all tests pass and mode is FULL_RUN:** Proceed to STEP 5 (coverage gap analysis) then COMPLETION REPORT.
|
|
134
|
+
|
|
135
|
+
**If any tests fail:** Proceed to STEP 4.
|
|
136
|
+
|
|
137
|
+
---
|
|
138
|
+
|
|
139
|
+
## STEP 4: FAILURE ANALYSIS
|
|
140
|
+
|
|
141
|
+
**For each failing test:**
|
|
142
|
+
|
|
143
|
+
1. **Read the test file** — Understand what the test expects
|
|
144
|
+
2. **Read the source module** it tests — Understand what the code actually does
|
|
145
|
+
3. **Identify root cause** — Compare expected vs actual behavior
|
|
146
|
+
|
|
147
|
+
### Classification
|
|
148
|
+
|
|
149
|
+
For each failure, classify as one of:
|
|
150
|
+
|
|
151
|
+
| Classification | Meaning | Fix Target |
|
|
152
|
+
|----------------|---------|------------|
|
|
153
|
+
| TEST_BUG | Test assertion is incorrect or outdated | Test file |
|
|
154
|
+
| CODE_BUG | Source code has an actual bug | Source file |
|
|
155
|
+
| STALE | Test references removed/renamed code | Test file |
|
|
156
|
+
| MOCK_ISSUE | Mock is incorrect or missing | Test file |
|
|
157
|
+
| ENV_ISSUE | Environment/setup problem | Test config |
|
|
158
|
+
|
|
159
|
+
```markdown
|
|
160
|
+
### Failure Analysis
|
|
161
|
+
|
|
162
|
+
| Test | File | Classification | Root Cause | Fix Target |
|
|
163
|
+
|------|------|---------------|------------|------------|
|
|
164
|
+
| [test name] | [file:line] | [class] | [description] | [file] |
|
|
165
|
+
```
|
|
166
|
+
|
|
167
|
+
### FIX Mode (if `--fix`)
|
|
168
|
+
|
|
169
|
+
For each failing test (ordered by classification priority: CODE_BUG > TEST_BUG > STALE > MOCK_ISSUE):
|
|
170
|
+
|
|
171
|
+
1. **Apply the minimal correct fix** following CLAUDE.md patterns
|
|
172
|
+
2. **Re-run the specific test file** to verify the fix:
|
|
173
|
+
```bash
|
|
174
|
+
npx vitest run [specific test file] 2>&1
|
|
175
|
+
```
|
|
176
|
+
3. **If still failing:** Re-analyze and retry (max 3 attempts per test)
|
|
177
|
+
4. **After all fixes applied:** Run the full suite to verify no regressions:
|
|
178
|
+
```bash
|
|
179
|
+
npm test 2>&1
|
|
180
|
+
```
|
|
181
|
+
|
|
182
|
+
```
|
|
183
|
+
FIX LOOP:
|
|
184
|
+
FOR EACH failing_test:
|
|
185
|
+
attempts = 0
|
|
186
|
+
WHILE test fails AND attempts < 3:
|
|
187
|
+
- Read test + source
|
|
188
|
+
- Apply fix
|
|
189
|
+
- Re-run specific test
|
|
190
|
+
- attempts++
|
|
191
|
+
IF still failing after 3 attempts:
|
|
192
|
+
- Mark as MANUAL_FIX_NEEDED
|
|
193
|
+
- Continue to next test
|
|
194
|
+
AFTER all fixes:
|
|
195
|
+
- Run full suite: npm test
|
|
196
|
+
- IF new failures introduced: REVERT last fix, investigate
|
|
197
|
+
```
|
|
198
|
+
|
|
199
|
+
---
|
|
200
|
+
|
|
201
|
+
## STEP 5: COVERAGE GAP ANALYSIS
|
|
202
|
+
|
|
203
|
+
**Runs in FULL_RUN and COVERAGE modes.**
|
|
204
|
+
|
|
205
|
+
### Core Package Coverage
|
|
206
|
+
|
|
207
|
+
```bash
|
|
208
|
+
# List all source modules (excluding tests, hooks, type-only files)
|
|
209
|
+
ls packages/core/src/*.ts
|
|
210
|
+
|
|
211
|
+
# List all test files
|
|
212
|
+
ls packages/core/src/__tests__/*.test.ts
|
|
213
|
+
```
|
|
214
|
+
|
|
215
|
+
Cross-reference: for each source module, check if a corresponding test file exists.
|
|
216
|
+
|
|
217
|
+
```markdown
|
|
218
|
+
### Core Package Coverage
|
|
219
|
+
|
|
220
|
+
| Source Module | Test File | Status |
|
|
221
|
+
|--------------|-----------|--------|
|
|
222
|
+
| analytics.ts | analytics.test.ts | COVERED / MISSING |
|
|
223
|
+
| config.ts | config.test.ts | COVERED / MISSING |
|
|
224
|
+
| ... | ... | ... |
|
|
225
|
+
|
|
226
|
+
**Coverage: [X]/[Y] modules ([Z]%)**
|
|
227
|
+
```
|
|
228
|
+
|
|
229
|
+
### Package Coverage (other packages)
|
|
230
|
+
|
|
231
|
+
```bash
|
|
232
|
+
# List other package modules
|
|
233
|
+
ls packages/plugin/src/*.ts 2>/dev/null
|
|
234
|
+
ls packages/shared/src/*.ts 2>/dev/null
|
|
235
|
+
```
|
|
236
|
+
|
|
237
|
+
```markdown
|
|
238
|
+
### Package Coverage
|
|
239
|
+
|
|
240
|
+
| Source Module | Test File | Status |
|
|
241
|
+
|--------------|-----------|--------|
|
|
242
|
+
| [module] | [test] | COVERED / MISSING |
|
|
243
|
+
|
|
244
|
+
**Coverage: [X]/[Y] modules ([Z]%)**
|
|
245
|
+
```
|
|
246
|
+
|
|
247
|
+
### Coverage Verdict
|
|
248
|
+
|
|
249
|
+
| Threshold | Status |
|
|
250
|
+
|-----------|--------|
|
|
251
|
+
| >= 80% modules covered | GOOD |
|
|
252
|
+
| 50-79% modules covered | NEEDS IMPROVEMENT |
|
|
253
|
+
| < 50% modules covered | POOR |
|
|
254
|
+
|
|
255
|
+
---
|
|
256
|
+
|
|
257
|
+
## STEP 6: AFFECTED TEST DETECTION
|
|
258
|
+
|
|
259
|
+
**Runs in AFFECTED mode only.**
|
|
260
|
+
|
|
261
|
+
### 6a. Get Changed Files
|
|
262
|
+
|
|
263
|
+
```bash
|
|
264
|
+
# Get files changed vs HEAD (unstaged + staged)
|
|
265
|
+
git diff --name-only HEAD
|
|
266
|
+
git diff --cached --name-only
|
|
267
|
+
```
|
|
268
|
+
|
|
269
|
+
### 6b. Trace to Test Files
|
|
270
|
+
|
|
271
|
+
For each changed source file in `packages/core/src/`:
|
|
272
|
+
|
|
273
|
+
```bash
|
|
274
|
+
# Find test files that import or reference this module
|
|
275
|
+
grep -rl "[module-name]" packages/core/src/__tests__/ --include="*.test.ts"
|
|
276
|
+
```
|
|
277
|
+
|
|
278
|
+
### 6c. Run Affected Tests Only
|
|
279
|
+
|
|
280
|
+
```bash
|
|
281
|
+
# Run only the affected test files
|
|
282
|
+
npx vitest run [affected-test-file-1] [affected-test-file-2] ... 2>&1
|
|
283
|
+
```
|
|
284
|
+
|
|
285
|
+
```markdown
|
|
286
|
+
### Affected Test Detection
|
|
287
|
+
|
|
288
|
+
| Changed File | Affected Tests | Result |
|
|
289
|
+
|-------------|---------------|--------|
|
|
290
|
+
| [source file] | [test files] | PASS/FAIL |
|
|
291
|
+
|
|
292
|
+
**[N] changed files -> [M] affected test files -> [P] passing, [F] failing**
|
|
293
|
+
```
|
|
294
|
+
|
|
295
|
+
---
|
|
296
|
+
|
|
297
|
+
## STEP 7: TEST GENERATION
|
|
298
|
+
|
|
299
|
+
**Runs in GENERATE mode only.**
|
|
300
|
+
|
|
301
|
+
### 7a. Read the Target Module
|
|
302
|
+
|
|
303
|
+
```bash
|
|
304
|
+
# Read the module to be tested
|
|
305
|
+
cat packages/core/src/[module].ts
|
|
306
|
+
```
|
|
307
|
+
|
|
308
|
+
Understand:
|
|
309
|
+
- All exported functions
|
|
310
|
+
- Function signatures and return types
|
|
311
|
+
- Dependencies (imports)
|
|
312
|
+
- Database usage (which DB: CodeGraph, Data, Memory)
|
|
313
|
+
|
|
314
|
+
### 7b. Read a Pattern Reference Test
|
|
315
|
+
|
|
316
|
+
Find and read an existing test for a similar module:
|
|
317
|
+
|
|
318
|
+
```bash
|
|
319
|
+
# Find a test for a module of similar type
|
|
320
|
+
ls packages/core/src/__tests__/*.test.ts
|
|
321
|
+
```
|
|
322
|
+
|
|
323
|
+
**For 3-function tool modules** (analytics, cost-tracker, etc.): use `observability-tools.test.ts` as pattern reference.
|
|
324
|
+
**For utility modules**: use `config.test.ts` or similar as pattern reference.
|
|
325
|
+
|
|
326
|
+
### 7c. Generate the Test File
|
|
327
|
+
|
|
328
|
+
Generate following vitest patterns:
|
|
329
|
+
- `import { describe, it, expect, beforeEach, afterEach } from 'vitest'`
|
|
330
|
+
- `describe('[module name]', () => { ... })`
|
|
331
|
+
- `it('should [behavior]', () => { ... })`
|
|
332
|
+
- In-memory database setup in `beforeEach` / cleanup in `afterEach`
|
|
333
|
+
|
|
334
|
+
**For 3-function tool modules, test all three functions:**
|
|
335
|
+
|
|
336
|
+
```typescript
|
|
337
|
+
// 1. Test getXToolDefinitions()
|
|
338
|
+
describe('getXToolDefinitions', () => {
|
|
339
|
+
it('should return tool definitions with correct names', () => { ... });
|
|
340
|
+
it('should include required input schemas', () => { ... });
|
|
341
|
+
});
|
|
342
|
+
|
|
343
|
+
// 2. Test isXTool()
|
|
344
|
+
describe('isXTool', () => {
|
|
345
|
+
it('should return true for matching tool names', () => { ... });
|
|
346
|
+
it('should return false for non-matching tool names', () => { ... });
|
|
347
|
+
});
|
|
348
|
+
|
|
349
|
+
// 3. Test handleXToolCall()
|
|
350
|
+
describe('handleXToolCall', () => {
|
|
351
|
+
it('should handle [action] correctly', () => { ... });
|
|
352
|
+
it('should return error for unknown tool', () => { ... });
|
|
353
|
+
});
|
|
354
|
+
```
|
|
355
|
+
|
|
356
|
+
### 7d. Write and Verify
|
|
357
|
+
|
|
358
|
+
```bash
|
|
359
|
+
# Write the test file
|
|
360
|
+
# Path: packages/core/src/__tests__/[module].test.ts
|
|
361
|
+
|
|
362
|
+
# Run the new test
|
|
363
|
+
npx vitest run packages/core/src/__tests__/[module].test.ts 2>&1
|
|
364
|
+
```
|
|
365
|
+
|
|
366
|
+
**If the new test fails:**
|
|
367
|
+
1. Read the error output carefully
|
|
368
|
+
2. Fix the test (NOT the source code — unless it reveals an actual bug)
|
|
369
|
+
3. Re-run until passing
|
|
370
|
+
4. Run full suite to verify no regressions: `npm test`
|
|
371
|
+
|
|
372
|
+
---
|
|
373
|
+
|
|
374
|
+
## VERIFICATION GATES
|
|
375
|
+
|
|
376
|
+
After any modifications (--fix or --generate modes):
|
|
377
|
+
|
|
378
|
+
### Gate 1: All Tests Pass (VR-TEST)
|
|
379
|
+
```bash
|
|
380
|
+
npm test
|
|
381
|
+
# MUST exit 0, all tests pass
|
|
382
|
+
```
|
|
383
|
+
|
|
384
|
+
### Gate 2: Type Safety (VR-TYPE)
|
|
385
|
+
```bash
|
|
386
|
+
cd packages/core && npx tsc --noEmit
|
|
387
|
+
# MUST show 0 errors
|
|
388
|
+
```
|
|
389
|
+
|
|
390
|
+
### Gate 3: Pattern Compliance (VR-PATTERN)
|
|
391
|
+
```bash
|
|
392
|
+
bash scripts/massu-pattern-scanner.sh
|
|
393
|
+
# MUST exit 0
|
|
394
|
+
```
|
|
395
|
+
|
|
396
|
+
**If ANY gate fails:** Fix the issue, re-run ALL gates. Repeat until clean.
|
|
397
|
+
|
|
398
|
+
---
|
|
399
|
+
|
|
400
|
+
## TEST QUALITY AUDIT
|
|
401
|
+
|
|
402
|
+
### Check for Anti-Patterns
|
|
403
|
+
```bash
|
|
404
|
+
# Find tests without assertions
|
|
405
|
+
grep -rn "it(.*{" packages/core/src/__tests__/ | grep -v "expect\|assert" | head -10
|
|
406
|
+
|
|
407
|
+
# Find tests with only console.log
|
|
408
|
+
grep -rn "console.log" packages/core/src/__tests__/ | head -10
|
|
409
|
+
|
|
410
|
+
# Find flaky patterns (setTimeout, random)
|
|
411
|
+
grep -rn "setTimeout\|Math.random" packages/core/src/__tests__/ | head -10
|
|
412
|
+
```
|
|
413
|
+
|
|
414
|
+
### Test Quality Matrix
|
|
415
|
+
```markdown
|
|
416
|
+
### Test Quality Audit
|
|
417
|
+
|
|
418
|
+
| Issue | Files Affected | Severity | Fix |
|
|
419
|
+
|-------|---------------|----------|-----|
|
|
420
|
+
| No assertions | N | HIGH | Add expects |
|
|
421
|
+
| Flaky patterns | N | MEDIUM | Refactor |
|
|
422
|
+
| console.log in tests | N | LOW | Remove |
|
|
423
|
+
```
|
|
424
|
+
|
|
425
|
+
---
|
|
426
|
+
|
|
427
|
+
## SESSION STATE UPDATE
|
|
428
|
+
|
|
429
|
+
After test audit, update `session-state/CURRENT.md`:
|
|
430
|
+
|
|
431
|
+
```markdown
|
|
432
|
+
## TEST AUDIT SESSION
|
|
433
|
+
|
|
434
|
+
### Audit
|
|
435
|
+
- **Date**: [timestamp]
|
|
436
|
+
- **Scope**: Full / [specific area]
|
|
437
|
+
- **Mode**: [FULL_RUN / AFFECTED / COVERAGE / GENERATE / FIX]
|
|
438
|
+
|
|
439
|
+
### Findings
|
|
440
|
+
- Total test files: [N]
|
|
441
|
+
- Total tests: [N]
|
|
442
|
+
- Coverage: [X]% modules with tests
|
|
443
|
+
- Quality issues: [N]
|
|
444
|
+
|
|
445
|
+
### Tests Added/Fixed
|
|
446
|
+
[List or "None - audit only"]
|
|
447
|
+
|
|
448
|
+
### Status
|
|
449
|
+
- VR-TEST: PASS/FAIL
|
|
450
|
+
- Coverage target: MET/NOT MET
|
|
451
|
+
```
|
|
452
|
+
|
|
453
|
+
---
|
|
454
|
+
|
|
455
|
+
## AUTO-LEARNING PROTOCOL (MANDATORY after every fix/finding)
|
|
456
|
+
|
|
457
|
+
After EVERY fix or finding during test audit:
|
|
458
|
+
|
|
459
|
+
### Step 1: Record the Pattern
|
|
460
|
+
Update `.claude/session-state/CURRENT.md` with:
|
|
461
|
+
- What was wrong (the incorrect pattern or missing test)
|
|
462
|
+
- What fixed it (the correct pattern)
|
|
463
|
+
- File(s) affected
|
|
464
|
+
|
|
465
|
+
### Step 2: Add to Pattern Scanner (if grep-able)
|
|
466
|
+
If the bad pattern is detectable by grep, consider adding it to `scripts/massu-pattern-scanner.sh`.
|
|
467
|
+
|
|
468
|
+
### Step 3: Search Codebase-Wide (CR-9)
|
|
469
|
+
```bash
|
|
470
|
+
grep -rn "[bad_pattern]" packages/core/src/ --include="*.ts"
|
|
471
|
+
```
|
|
472
|
+
Fix ALL instances found, not just the one that was reported.
|
|
473
|
+
|
|
474
|
+
---
|
|
475
|
+
|
|
476
|
+
## COMPLETION REPORT
|
|
477
|
+
|
|
478
|
+
```markdown
|
|
479
|
+
## CS TEST COMPLETE
|
|
480
|
+
|
|
481
|
+
### Mode: [FULL_RUN / AFFECTED / COVERAGE / GENERATE / FIX]
|
|
482
|
+
|
|
483
|
+
### Test Results
|
|
484
|
+
| Metric | Value |
|
|
485
|
+
|--------|-------|
|
|
486
|
+
| Total tests | [N] |
|
|
487
|
+
| Passing | [N] |
|
|
488
|
+
| Failing | [N] |
|
|
489
|
+
| Duration | [N]s |
|
|
490
|
+
|
|
491
|
+
### Failure Analysis (if any)
|
|
492
|
+
| Test | Classification | Root Cause | Fixed? |
|
|
493
|
+
|------|---------------|------------|--------|
|
|
494
|
+
| [name] | [class] | [cause] | YES/NO/MANUAL |
|
|
495
|
+
|
|
496
|
+
### Coverage Gaps (if analyzed)
|
|
497
|
+
| Area | Covered | Total | Percentage |
|
|
498
|
+
|------|---------|-------|------------|
|
|
499
|
+
| Core | [N] | [N] | [N]% |
|
|
500
|
+
| Website | [N] | [N] | [N]% |
|
|
501
|
+
|
|
502
|
+
### Generated Tests (if any)
|
|
503
|
+
| Module | Test File | Tests | Status |
|
|
504
|
+
|--------|-----------|-------|--------|
|
|
505
|
+
| [module] | [file] | [N] tests | PASSING |
|
|
506
|
+
|
|
507
|
+
### Verification Gates (if modifications made)
|
|
508
|
+
| Gate | Status |
|
|
509
|
+
|------|--------|
|
|
510
|
+
| Tests (VR-TEST) | PASS |
|
|
511
|
+
| Types (VR-TYPE) | PASS |
|
|
512
|
+
| Patterns (VR-PATTERN) | PASS |
|
|
513
|
+
|
|
514
|
+
### Next Steps
|
|
515
|
+
- [Actionable recommendations based on findings]
|
|
516
|
+
```
|