Commit 233fa6c
authored
fix: repair pagination_cursors composite PK and isolate test suites (#265)
## What
Two fixes found during post-merge testing of #262:
### CLI-72: `pagination_cursors` wrong primary key
Migration 4→5 used `CREATE TABLE IF NOT EXISTS`, so any DB that already
had `pagination_cursors` from an earlier code path kept a single-column
PK (`command_key TEXT PRIMARY KEY`) instead of the required composite PK
(`PRIMARY KEY (command_key, context)`). This caused a runtime crash on
the first `--cursor last` use:
```
SQLiteError: ON CONFLICT clause does not match any PRIMARY KEY or UNIQUE constraint
```
**Fix:**
- Schema version bumped to 6 with a migration that detects the wrong PK,
drops the table, and recreates it correctly. Cursor data loss is safe
(5-min TTL).
- `repairWrongPrimaryKeys()` added to `repairSchema()` so auto-repair
also catches this.
- `isSchemaError()` extended to recognise the ON CONFLICT error and
trigger auto-repair.
- New `wrong_primary_key` `SchemaIssue` variant surfaced in
`getSchemaIssues()` and `sentry cli fix`.
### Test isolation: `bun test` caused ~130 spurious failures locally
`"test": "bun test"` ran all files in one process.
`test/isolated/resolve-target.test.ts` uses `mock.module()` which leaks
global module state across files, poisoning `api-client.js`,
`db/defaults.js`, and others for all subsequent tests.
**Fix:** Change the `test` script to `bun run test:unit && bun run
test:isolated` so each suite runs in a separate Bun process. The split
was already documented in `AGENTS.md`; the top-level script just wasn't
using it.
## Result
`bun run test`: 1931 tests, 0 failures (was 130 failures).1 parent 995fd40 commit 233fa6c
File tree
5 files changed
+323
-19
lines changed- src
- commands/cli
- lib/db
- test
- commands/cli
- lib/db
5 files changed
+323
-19
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
17 | 17 | | |
18 | 18 | | |
19 | 19 | | |
20 | | - | |
| 20 | + | |
21 | 21 | | |
22 | 22 | | |
23 | 23 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
24 | 24 | | |
25 | 25 | | |
26 | 26 | | |
27 | | - | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
28 | 31 | | |
29 | 32 | | |
30 | 33 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
14 | 14 | | |
15 | 15 | | |
16 | 16 | | |
17 | | - | |
| 17 | + | |
18 | 18 | | |
19 | 19 | | |
20 | 20 | | |
| |||
330 | 330 | | |
331 | 331 | | |
332 | 332 | | |
| 333 | + | |
| 334 | + | |
| 335 | + | |
| 336 | + | |
| 337 | + | |
| 338 | + | |
| 339 | + | |
| 340 | + | |
| 341 | + | |
| 342 | + | |
| 343 | + | |
| 344 | + | |
| 345 | + | |
| 346 | + | |
| 347 | + | |
| 348 | + | |
| 349 | + | |
| 350 | + | |
| 351 | + | |
| 352 | + | |
| 353 | + | |
| 354 | + | |
| 355 | + | |
| 356 | + | |
| 357 | + | |
333 | 358 | | |
334 | 359 | | |
335 | 360 | | |
| |||
345 | 370 | | |
346 | 371 | | |
347 | 372 | | |
348 | | - | |
| 373 | + | |
| 374 | + | |
| 375 | + | |
| 376 | + | |
| 377 | + | |
| 378 | + | |
| 379 | + | |
| 380 | + | |
| 381 | + | |
| 382 | + | |
| 383 | + | |
| 384 | + | |
| 385 | + | |
| 386 | + | |
| 387 | + | |
| 388 | + | |
| 389 | + | |
| 390 | + | |
| 391 | + | |
| 392 | + | |
| 393 | + | |
| 394 | + | |
| 395 | + | |
| 396 | + | |
| 397 | + | |
| 398 | + | |
| 399 | + | |
349 | 400 | | |
350 | 401 | | |
351 | 402 | | |
| |||
360 | 411 | | |
361 | 412 | | |
362 | 413 | | |
363 | | - | |
364 | | - | |
365 | | - | |
366 | | - | |
367 | | - | |
368 | | - | |
369 | | - | |
370 | | - | |
371 | | - | |
372 | | - | |
373 | | - | |
374 | | - | |
| 414 | + | |
| 415 | + | |
375 | 416 | | |
376 | 417 | | |
377 | 418 | | |
| |||
421 | 462 | | |
422 | 463 | | |
423 | 464 | | |
424 | | - | |
425 | | - | |
| 465 | + | |
| 466 | + | |
| 467 | + | |
| 468 | + | |
| 469 | + | |
| 470 | + | |
| 471 | + | |
| 472 | + | |
| 473 | + | |
| 474 | + | |
| 475 | + | |
| 476 | + | |
| 477 | + | |
| 478 | + | |
| 479 | + | |
| 480 | + | |
| 481 | + | |
| 482 | + | |
| 483 | + | |
| 484 | + | |
| 485 | + | |
| 486 | + | |
| 487 | + | |
| 488 | + | |
| 489 | + | |
| 490 | + | |
| 491 | + | |
| 492 | + | |
| 493 | + | |
| 494 | + | |
| 495 | + | |
| 496 | + | |
| 497 | + | |
| 498 | + | |
| 499 | + | |
| 500 | + | |
426 | 501 | | |
427 | 502 | | |
428 | 503 | | |
| |||
432 | 507 | | |
433 | 508 | | |
434 | 509 | | |
| 510 | + | |
435 | 511 | | |
436 | 512 | | |
437 | 513 | | |
| |||
458 | 534 | | |
459 | 535 | | |
460 | 536 | | |
461 | | - | |
| 537 | + | |
| 538 | + | |
462 | 539 | | |
463 | 540 | | |
464 | 541 | | |
| |||
615 | 692 | | |
616 | 693 | | |
617 | 694 | | |
| 695 | + | |
| 696 | + | |
| 697 | + | |
| 698 | + | |
| 699 | + | |
| 700 | + | |
| 701 | + | |
| 702 | + | |
| 703 | + | |
| 704 | + | |
| 705 | + | |
| 706 | + | |
| 707 | + | |
| 708 | + | |
| 709 | + | |
| 710 | + | |
618 | 711 | | |
619 | 712 | | |
620 | 713 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
367 | 367 | | |
368 | 368 | | |
369 | 369 | | |
| 370 | + | |
| 371 | + | |
| 372 | + | |
| 373 | + | |
| 374 | + | |
| 375 | + | |
| 376 | + | |
| 377 | + | |
| 378 | + | |
| 379 | + | |
| 380 | + | |
| 381 | + | |
| 382 | + | |
| 383 | + | |
| 384 | + | |
| 385 | + | |
| 386 | + | |
| 387 | + | |
| 388 | + | |
| 389 | + | |
| 390 | + | |
| 391 | + | |
| 392 | + | |
| 393 | + | |
| 394 | + | |
| 395 | + | |
| 396 | + | |
| 397 | + | |
| 398 | + | |
| 399 | + | |
| 400 | + | |
| 401 | + | |
| 402 | + | |
| 403 | + | |
| 404 | + | |
| 405 | + | |
| 406 | + | |
| 407 | + | |
| 408 | + | |
| 409 | + | |
| 410 | + | |
| 411 | + | |
| 412 | + | |
| 413 | + | |
| 414 | + | |
| 415 | + | |
| 416 | + | |
| 417 | + | |
| 418 | + | |
| 419 | + | |
| 420 | + | |
| 421 | + | |
| 422 | + | |
| 423 | + | |
| 424 | + | |
370 | 425 | | |
0 commit comments