From fdfdbc883b79b59c8aef5f17397d44c41d9a01ae Mon Sep 17 00:00:00 2001 From: thePR0M3TH3AN <53631862+PR0M3TH3AN@users.noreply.github.com> Date: Mon, 4 Aug 2025 11:43:34 -0400 Subject: [PATCH] Use vault migration flag to prompt sync --- src/seedpass/core/manager.py | 13 ++++++++--- src/tests/test_legacy_migration.py | 35 ++++++++++++++++++++++++++++ src/tests/test_nostr_sdk_workflow.py | 1 - 3 files changed, 45 insertions(+), 4 deletions(-) diff --git a/src/seedpass/core/manager.py b/src/seedpass/core/manager.py index 152f6c7..608abbe 100644 --- a/src/seedpass/core/manager.py +++ b/src/seedpass/core/manager.py @@ -1157,8 +1157,14 @@ class PasswordManager: ) migrated = False + index_exists = ( + self.vault.index_file.exists() + or ( + self.vault.fingerprint_dir / "seedpass_passwords_db.json.enc" + ).exists() + ) try: - self.vault.load_index(return_migration_flag=True) + _, migrated = self.vault.load_index(return_migration_flag=True) except RuntimeError as exc: print(colored(str(exc), "red")) sys.exit(1) @@ -1222,9 +1228,10 @@ class PasswordManager: delta_since=self.delta_since or None, ) - if getattr(self.encryption_manager, "last_migration_performed", False): + if migrated and index_exists: print(colored("Local database migration successful.", "green")) - self.encryption_manager.last_migration_performed = False + if self.encryption_manager is not None: + self.encryption_manager.last_migration_performed = False if not self.offline_mode and confirm_action( "Do you want to sync the migrated profile to Nostr now?" ): diff --git a/src/tests/test_legacy_migration.py b/src/tests/test_legacy_migration.py index 667688e..06baefe 100644 --- a/src/tests/test_legacy_migration.py +++ b/src/tests/test_legacy_migration.py @@ -245,3 +245,38 @@ def test_legacy_index_reinit_syncs_once_when_confirmed(monkeypatch, tmp_path: Pa assert calls["sync"] == 1 assert enc_mgr.last_migration_performed is False + + +def test_schema_migration_triggers_sync(monkeypatch, tmp_path: Path): + vault, enc_mgr = create_vault(tmp_path, TEST_SEED, TEST_PASSWORD) + + data = {"schema_version": 3, "entries": {}} + enc_mgr.save_json_data(data, Path("seedpass_entries_db.json.enc")) + enc_mgr.update_checksum(Path("seedpass_entries_db.json.enc")) + assert enc_mgr.last_migration_performed is False + + pm = PasswordManager.__new__(PasswordManager) + pm.encryption_mode = EncryptionMode.SEED_ONLY + pm.encryption_manager = enc_mgr + pm.vault = Vault(enc_mgr, tmp_path) + pm.parent_seed = TEST_SEED + pm.fingerprint_dir = tmp_path + pm.current_fingerprint = tmp_path.name + pm.bip85 = SimpleNamespace() + pm.offline_mode = False + + calls = {"sync": 0} + pm.sync_vault = lambda *a, **k: calls.__setitem__("sync", calls["sync"] + 1) or { + "manifest_id": "m", + "chunk_ids": [], + "delta_ids": [], + } + + monkeypatch.setattr( + "seedpass.core.manager.NostrClient", lambda *a, **k: SimpleNamespace() + ) + monkeypatch.setattr("seedpass.core.manager.confirm_action", lambda *_a, **_k: True) + + pm.initialize_managers() + assert calls["sync"] == 1 + assert enc_mgr.last_migration_performed is False diff --git a/src/tests/test_nostr_sdk_workflow.py b/src/tests/test_nostr_sdk_workflow.py index e601a14..c04b6b5 100644 --- a/src/tests/test_nostr_sdk_workflow.py +++ b/src/tests/test_nostr_sdk_workflow.py @@ -4,7 +4,6 @@ import threading import time from websocket import create_connection -import asyncio import websockets from nostr.key_manager import KeyManager from nostr_sdk import nostr_sdk as sdk