Commit 38f700d
fix(tests): use consistent @/lib/db specifier to avoid CI module-identity drift
Two new tests landed with 5d92fc5 (cc-switch credential bridge) passed
locally but failed on the v0.50.2 CI run:
not ok - DB provider WITHOUT api_key → returns false even when settings.json has creds
not ok - resolves ${...} env placeholders against CodePilot DB settings
Root cause: the tests imported lib/db via relative specifier
`../../lib/db` while the prod callers they exercise (runtime/registry.ts,
mcp-loader.ts) import via mixed specifiers. Under tsx + node 20 on Linux,
these can resolve as separate module instances with separate db handles —
setSetting() in the test writes to one DB, getSetting() inside the prod
function reads from another, so the values never line up. macOS tsx 4.x
happens to dedupe by absolute path, which is why local didn't reproduce.
Fix:
- Unified all test imports to `@/lib/db`
- Unified runtime/registry.ts to `@/lib/db` / `@/lib/claude-settings` so
it matches mcp-loader.ts (the rest of the codebase is already on the
alias)
- Added ANTHROPIC_* env var scrub + legacy DB token reset in the
hasCredentialsForRequest describe's beforeEach so inherited CI env
can't short-circuit the function past the branch we're testing
No prod behavior change — production imports still resolve to the same
compiled module in Next.js. This only normalizes the test-time specifier
shape so tsx's module cache sees one instance everywhere.
1030/1030 tests pass.
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>1 parent dc5a6c5 commit 38f700d
3 files changed
Lines changed: 30 additions & 5 deletions
File tree
- src
- __tests__/unit
- lib/runtime
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
260 | 260 | | |
261 | 261 | | |
262 | 262 | | |
| 263 | + | |
| 264 | + | |
| 265 | + | |
| 266 | + | |
| 267 | + | |
| 268 | + | |
| 269 | + | |
| 270 | + | |
| 271 | + | |
| 272 | + | |
| 273 | + | |
| 274 | + | |
| 275 | + | |
| 276 | + | |
| 277 | + | |
| 278 | + | |
| 279 | + | |
| 280 | + | |
| 281 | + | |
| 282 | + | |
| 283 | + | |
| 284 | + | |
| 285 | + | |
| 286 | + | |
| 287 | + | |
263 | 288 | | |
264 | 289 | | |
265 | 290 | | |
| |||
277 | 302 | | |
278 | 303 | | |
279 | 304 | | |
280 | | - | |
| 305 | + | |
281 | 306 | | |
282 | 307 | | |
283 | 308 | | |
| |||
296 | 321 | | |
297 | 322 | | |
298 | 323 | | |
299 | | - | |
| 324 | + | |
300 | 325 | | |
301 | 326 | | |
302 | 327 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
120 | 120 | | |
121 | 121 | | |
122 | 122 | | |
123 | | - | |
| 123 | + | |
124 | 124 | | |
125 | 125 | | |
126 | 126 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
6 | 6 | | |
7 | 7 | | |
8 | 8 | | |
9 | | - | |
10 | | - | |
| 9 | + | |
| 10 | + | |
11 | 11 | | |
12 | 12 | | |
13 | 13 | | |
| |||
0 commit comments