Commit aaf1936
Overhaul test suite: shared fixtures, deterministic timing, and reduced boilerplate (#17)
This PR was the result of running `roborev analyze refactor --per-file
'*/*/*_test.go'` and `roborev analyze test-fixtures --per-file
'*/*/*_test.go'` and then using `roborev fix` to grind through the
results. This is a very effective pattern for systematic refactoring.
## Summary
Comprehensive overhaul of the test suite across 54 files (~12,600 lines
added, ~12,000 removed). The goal is to make tests more reliable,
readable, and maintainable as the codebase grows. No production code
behavior changes.
### Shared test infrastructure (`internal/testutil/`)
- **`testutil/ptr`** — pointer/date helper functions used across
packages
- **`testutil/email`** — `MakeRawEmail` and slice assertions for MIME
test data
- **`testutil/dbtest`** — shared DB test helpers and typed
`TestDataBuilder` replacing raw SQL fixtures
- **`testutil/storetest`** — `StoreFixture` and `MessageBuilder` for
store-layer tests
- **`querytest.MockEngine`** — centralized `query.Engine` test double
### Deterministic timing
- Introduced a `Clock` interface on `RateLimiter` with a mock clock for
tests
- Replaced all `time.Sleep`-based synchronization with mock-clock timer
polling
- Eliminates flaky failures under CI load
### Test pattern improvements
- Converted many tests to **table-driven** format (search parser,
aggregates, attachments, manifests, MCP error cases, etc.)
- Extracted **fluent builders**: `ManifestBuilder`, `GmailErrorBuilder`,
`MessageBuilder` (MIME), `TestDataBuilder` (Parquet)
- Added **assertion helpers** (`assertLevel`, `assertRow`,
`assertSearchCount`, etc.) to reduce repetitive check-and-fail blocks
- Split the 5,800-line `model_test.go` into domain-specific test files
(selection, search, navigation, view rendering)
### Hardening
- Fixed cross-test state leakage via defensive copies of shared slices
and factory functions
- Added duplicate-key detection in aggregate test helpers
- Guarded `fakeT` against `Fatal`/`FailNow`/`Skip`/`Skipf`/`SkipNow`
bypassing sentinel recovery
- Added missing failure-path tests (nil summaries, DB errors, missing
messages)
- Fixed nondeterministic map iteration and header ordering in test
fixtures
### Developer tooling
- Added `.githooks/pre-commit` hook that runs `gofmt` and
`golangci-lint` on staged Go files
- Enable with `make setup-hooks` — prevents lint failures from reaching
CI
## Test plan
- [x] `make test` — all tests pass
- [x] `make lint` — no new warnings
- [ ] CI passes on all platforms
🤖 Generated with [Claude Code](https://claude.com/claude-code)
---------
Co-authored-by: Claude Opus 4.5 <noreply@anthropic.com>1 parent 9a9924c commit aaf1936
File tree
54 files changed
+12693
-11931
lines changed- .githooks
- cmd/msgvault/cmd
- internal
- chat
- deletion
- export
- gmail
- mcp
- mime
- query
- querytest
- search
- store
- sync
- testutil
- dbtest
- email
- ptr
- storetest
- tui
- update
Some content is hidden
Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.
54 files changed
+12693
-11931
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
166 | 166 | | |
167 | 167 | | |
168 | 168 | | |
169 | | - | |
| 169 | + | |
| 170 | + | |
170 | 171 | | |
171 | 172 | | |
| 173 | + | |
172 | 174 | | |
173 | 175 | | |
174 | 176 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
12 | 12 | | |
13 | 13 | | |
14 | 14 | | |
15 | | - | |
| 15 | + | |
16 | 16 | | |
17 | 17 | | |
18 | 18 | | |
| |||
62 | 62 | | |
63 | 63 | | |
64 | 64 | | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
65 | 70 | | |
66 | 71 | | |
67 | 72 | | |
| |||
87 | 92 | | |
88 | 93 | | |
89 | 94 | | |
| 95 | + | |
90 | 96 | | |
91 | 97 | | |
92 | 98 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
2 | 2 | | |
3 | 3 | | |
4 | 4 | | |
5 | | - | |
6 | 5 | | |
| 6 | + | |
7 | 7 | | |
8 | 8 | | |
9 | 9 | | |
| |||
12 | 12 | | |
13 | 13 | | |
14 | 14 | | |
| 15 | + | |
15 | 16 | | |
16 | 17 | | |
17 | 18 | | |
| |||
20 | 21 | | |
21 | 22 | | |
22 | 23 | | |
23 | | - | |
| 24 | + | |
24 | 25 | | |
25 | 26 | | |
26 | 27 | | |
27 | 28 | | |
28 | | - | |
| 29 | + | |
29 | 30 | | |
30 | 31 | | |
31 | 32 | | |
32 | 33 | | |
33 | | - | |
| 34 | + | |
34 | 35 | | |
35 | 36 | | |
36 | 37 | | |
37 | 38 | | |
38 | | - | |
| 39 | + | |
39 | 40 | | |
40 | 41 | | |
41 | 42 | | |
42 | 43 | | |
43 | | - | |
| 44 | + | |
44 | 45 | | |
45 | 46 | | |
46 | 47 | | |
| |||
54 | 55 | | |
55 | 56 | | |
56 | 57 | | |
57 | | - | |
58 | | - | |
59 | | - | |
| 58 | + | |
60 | 59 | | |
61 | 60 | | |
62 | 61 | | |
63 | 62 | | |
64 | 63 | | |
65 | | - | |
| 64 | + | |
66 | 65 | | |
67 | 66 | | |
68 | 67 | | |
69 | 68 | | |
70 | 69 | | |
71 | 70 | | |
72 | 71 | | |
73 | | - | |
| 72 | + | |
74 | 73 | | |
75 | 74 | | |
76 | 75 | | |
77 | 76 | | |
78 | | - | |
| 77 | + | |
79 | 78 | | |
80 | 79 | | |
81 | 80 | | |
82 | 81 | | |
83 | | - | |
| 82 | + | |
84 | 83 | | |
85 | 84 | | |
86 | 85 | | |
87 | 86 | | |
88 | | - | |
| 87 | + | |
89 | 88 | | |
90 | 89 | | |
91 | 90 | | |
| |||
99 | 98 | | |
100 | 99 | | |
101 | 100 | | |
102 | | - | |
103 | | - | |
104 | | - | |
| 101 | + | |
105 | 102 | | |
106 | 103 | | |
107 | 104 | | |
108 | 105 | | |
109 | 106 | | |
110 | | - | |
111 | | - | |
112 | | - | |
| 107 | + | |
113 | 108 | | |
114 | 109 | | |
115 | 110 | | |
116 | 111 | | |
117 | | - | |
118 | | - | |
119 | | - | |
120 | | - | |
121 | | - | |
122 | | - | |
123 | | - | |
124 | | - | |
125 | | - | |
126 | | - | |
127 | | - | |
128 | | - | |
129 | | - | |
130 | | - | |
131 | | - | |
132 | | - | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
133 | 116 | | |
134 | 117 | | |
135 | 118 | | |
| |||
138 | 121 | | |
139 | 122 | | |
140 | 123 | | |
141 | | - | |
142 | | - | |
143 | | - | |
144 | | - | |
| 124 | + | |
145 | 125 | | |
146 | 126 | | |
147 | 127 | | |
| |||
209 | 189 | | |
210 | 190 | | |
211 | 191 | | |
212 | | - | |
| 192 | + | |
213 | 193 | | |
214 | 194 | | |
215 | 195 | | |
216 | 196 | | |
217 | | - | |
| 197 | + | |
218 | 198 | | |
219 | 199 | | |
220 | 200 | | |
221 | 201 | | |
222 | | - | |
| 202 | + | |
223 | 203 | | |
224 | 204 | | |
225 | 205 | | |
| |||
229 | 209 | | |
230 | 210 | | |
231 | 211 | | |
232 | | - | |
233 | | - | |
234 | | - | |
| 212 | + | |
235 | 213 | | |
236 | 214 | | |
237 | 215 | | |
238 | | - | |
0 commit comments