From 7aa322da35e377fb7344f953aca667bcfc4e00f3 Mon Sep 17 00:00:00 2001 From: Pouzor Date: Mon, 7 Sep 2026 17:49:29 +0200 Subject: [PATCH] test(migrations): stop the pre-split backup test tracking the app version MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit `_backup_db` names its copy `homelab.db.back-`, so the 3.4.1 bump renamed the backup `init_db` takes from `back-3.3.2` to `back-3.4.1`. The test hardcoded its post-split copies as `back-3.3.1` / `back-3.3.2`, which happened to overwrite that backup while the version was 3.3.2; at 3.4.1 it survives, still carrying the columns this very boot is about to drop, and wins the newest-first scan in `_pre_split_backup`. The fixture was also unlike a real install, where the current version's backup is taken after the columns are already gone — they went in the 3.3.0 boot, not this one. Copy a post-split database over it too, under whatever the version is, and the test stops breaking on every bump. `_pre_split_backup` is unchanged: preferring the newest backup that still holds the columns is right, the drop boot's own backup included. ha-relevant: no --- backend/tests/migrations/test_legacy_node_columns.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/backend/tests/migrations/test_legacy_node_columns.py b/backend/tests/migrations/test_legacy_node_columns.py index 150ef5e..1a9a760 100644 --- a/backend/tests/migrations/test_legacy_node_columns.py +++ b/backend/tests/migrations/test_legacy_node_columns.py @@ -19,6 +19,7 @@ from sqlalchemy.ext.asyncio import create_async_engine import app.db.database as database import app.services.inventory_sync as inventory_sync +from app.core.config import APP_VERSION # `create_all` under v3.2.0. NOT NULL is reproduced exactly where it was. _NODES_320 = ( @@ -412,8 +413,10 @@ async def test_the_newest_backup_that_still_has_the_columns_is_the_one_read(db_3 shutil.copy2(db_path, pre_split) await database.init_db() # drops the columns, and backs up under this version - # Post-split backups: newer, and unable to say who drew what. - for name in ("back-3.3.1", "back-3.3.2"): + # Post-split backups: newer, and unable to say who drew what. On a real + # install the current version's own backup is one of them — the columns went + # in an earlier boot, not this one — so overwrite the one `init_db` took. + for name in ("back-3.3.1", "back-3.3.2", f"back-{APP_VERSION}"): shutil.copy2(db_path, db_path.parent / f"{db_path.name}.{name}") assert database._pre_split_backup() == pre_split