test: real-DB migration test (#14) #15

Merged
padreug merged 1 commit from test/14-migration-db into main 2026-07-19 22:23:21 +00:00
Owner

Closes #14. Adds tests/test_migrations.py — the regression guard for the class of bug that #13 was.

What it does

Runs the full m0NN migration chain against a fresh temp SQLite via the lnbits Database, then round-trips a room + booking through crud:

  • exercises the m002 checkin_instructions column, big_int amount columns, and is_available on real rows (not monkeypatched).
  • if any migration statement is invalid on SQLite, the test raises there.

Isolation (the wrinkle, solved)

Database binds its sqlite path + engine at construction from settings.lnbits_data_folder, and crud.db is built at import — so late env vars don't help. Approach: monkeypatch settings.lnbits_data_foldertmp_path, build a fresh ext_chatelet Database, and swap it into crud for the test. Import-order-independent, per-test isolation, no live server.

It has teeth

Verified by reintroducing the #13 bad-index syntax (CREATE INDEX ... ON chatelet.<table>) → the test fails with sqlite3.OperationalError: near ".": syntax error. Restored; 23 pass (22 + this).

Why PR

Test-only, but on a money-adjacent extension → PR category. Handing off merge to you via the Forgejo UI.

🤖 Generated with Claude Code

Closes #14. Adds `tests/test_migrations.py` — the regression guard for the class of bug that #13 was. ## What it does Runs the full `m0NN` migration chain against a **fresh temp SQLite** via the lnbits `Database`, then round-trips a room + booking through `crud`: - exercises the `m002` `checkin_instructions` column, `big_int` amount columns, and `is_available` on **real rows** (not monkeypatched). - if any migration statement is invalid on SQLite, the test raises there. ## Isolation (the wrinkle, solved) `Database` binds its sqlite path + engine at construction from `settings.lnbits_data_folder`, and `crud.db` is built at import — so late env vars don't help. Approach: monkeypatch `settings.lnbits_data_folder` → `tmp_path`, build a fresh `ext_chatelet` `Database`, and swap it into `crud` for the test. Import-order-independent, per-test isolation, no live server. ## It has teeth Verified by reintroducing the #13 bad-index syntax (`CREATE INDEX ... ON chatelet.<table>`) → the test **fails** with `sqlite3.OperationalError: near ".": syntax error`. Restored; **23 pass** (22 + this). ## Why PR Test-only, but on a money-adjacent extension → PR category. Handing off merge to you via the Forgejo UI. 🤖 Generated with [Claude Code](https://claude.com/claude-code)
Runs the full m0NN migration chain against a fresh temp SQLite via the
lnbits Database, then round-trips a room + booking through crud (exercising
the m002 checkin_instructions column, big_int amounts, and is_available on
real rows). Closes the gap that let the #13 SQLite-index bug ship: the rest
of the suite monkeypatches crud, so migrations were never executed.

Isolation is import-order-independent: monkeypatch settings.lnbits_data_folder
to tmp_path, build a fresh ext_chatelet Database, swap it into crud for the
test. Verified it fails (sqlite3 OperationalError) if the #13 bad-index syntax
is reintroduced.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_019VUQCfdqiLSsFS2jcGnaFD
padreug deleted branch test/14-migration-db 2026-07-19 22:23:21 +00:00
Sign in to join this conversation.
No reviewers
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!15
No description provided.