Add a real-DB migration test (the suite monkeypatches crud, so migrations are unexercised) #14

Closed
opened 2026-07-19 21:18:20 +00:00 by padreug · 0 comments
Owner

Why

The unit suite deliberately isolates the functions under test by monkeypatching crud / create_invoice and driving async with asyncio.run — fast, no DB. The gap: migrations never actually run in tests. This let an install-breaking bug ship to main undetected — CREATE INDEX ... ON chatelet.<table> is invalid SQLite grammar (fixed in #13, caught only by a manual real-DB smoke before tagging v0.1.0).

What

Add a migration test that runs the real migration chain against a real (temp) SQLite via the lnbits Database abstraction, then round-trips through crud to assert the schema:

  • Apply m001 + m002 (and any future m00N) via chatelet.db.connect().
  • Insert a Room (exercises the checkin_instructions column from m002) + a Booking (exercises big_int amount columns + indexes) via crud, read back, assert.
  • Assert is_available overlap behaviour against real rows (not monkeypatched).

A working reference already exists — the manual smoke script used during #13 (migrations m001+m002 applied → room+booking round-trip). It needs adapting into a pytest fixture: set LNBITS_DATA_FOLDER to a temp dir and ensure chatelet.db resolves there. The main unknown is how the lnbits extension test harness wants the ext DB configured — mirror whatever an existing extension (e.g. restaurant, which has schema-qualified indexes) does for DB-touching tests, or a self-contained temp-folder fixture.

Acceptance

  • tests/test_migrations.py applies the full migration chain on a real SQLite temp DB and round-trips a room + booking through crud.
  • Fails if a migration statement is invalid on SQLite (i.e. would have caught the #13 bug).
  • Runs in CI under make test without a live LNbits server.

Low urgency (v0.1.0 migrations are now verified by hand), but this closes the class of bug that #13 was.

## Why The unit suite deliberately isolates the functions under test by monkeypatching `crud` / `create_invoice` and driving async with `asyncio.run` — fast, no DB. The gap: **migrations never actually run in tests.** This let an install-breaking bug ship to `main` undetected — `CREATE INDEX ... ON chatelet.<table>` is invalid SQLite grammar (fixed in #13, caught only by a manual real-DB smoke before tagging v0.1.0). ## What Add a migration test that runs the real migration chain against a real (temp) SQLite via the lnbits `Database` abstraction, then round-trips through `crud` to assert the schema: - Apply `m001` + `m002` (and any future `m00N`) via `chatelet.db.connect()`. - Insert a `Room` (exercises the `checkin_instructions` column from m002) + a `Booking` (exercises `big_int` amount columns + indexes) via `crud`, read back, assert. - Assert `is_available` overlap behaviour against real rows (not monkeypatched). A working reference already exists — the manual smoke script used during #13 (`migrations m001+m002 applied → room+booking round-trip`). It needs adapting into a pytest fixture: set `LNBITS_DATA_FOLDER` to a temp dir and ensure `chatelet.db` resolves there. The main unknown is how the lnbits extension test harness wants the ext DB configured — mirror whatever an existing extension (e.g. `restaurant`, which has schema-qualified indexes) does for DB-touching tests, or a self-contained temp-folder fixture. ## Acceptance - [ ] `tests/test_migrations.py` applies the full migration chain on a real SQLite temp DB and round-trips a room + booking through `crud`. - [ ] Fails if a migration statement is invalid on SQLite (i.e. would have caught the #13 bug). - [ ] Runs in CI under `make test` without a live LNbits server. Low urgency (v0.1.0 migrations are now verified by hand), but this closes the class of bug that #13 was.
Sign in to join this conversation.
No labels
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
aiolabs/chatelet#14
No description provided.