From 6d110679c53e29d5a3e3bd01a962fe8392a09230 Mon Sep 17 00:00:00 2001 From: thePR0M3TH3AN <53631862+PR0M3TH3AN@users.noreply.github.com> Date: Mon, 4 Aug 2025 09:05:32 -0400 Subject: [PATCH] Prompt sync after migration --- src/seedpass/core/manager.py | 27 ++++++++++++++++++++++++--- src/tests/test_legacy_migration.py | 19 +++++++++++++------ 2 files changed, 37 insertions(+), 9 deletions(-) diff --git a/src/seedpass/core/manager.py b/src/seedpass/core/manager.py index 1b7941d..7e9fe8f 100644 --- a/src/seedpass/core/manager.py +++ b/src/seedpass/core/manager.py @@ -1158,7 +1158,7 @@ class PasswordManager: migrated = False try: - _, migrated = self.vault.load_index(return_migration_flag=True) + self.vault.load_index(return_migration_flag=True) except RuntimeError as exc: print(colored(str(exc), "red")) sys.exit(1) @@ -1222,8 +1222,29 @@ class PasswordManager: delta_since=self.delta_since or None, ) - if migrated and not self.offline_mode: - self.start_background_vault_sync() + if getattr(self.encryption_manager, "last_migration_performed", False): + print(colored("Local database migration successful.", "green")) + 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?" + ): + result = self.sync_vault() + if result: + print( + colored( + "Profile synchronized to Nostr successfully.", + "green", + ) + ) + else: + print(colored("Error: Failed to sync profile to Nostr.", "red")) + elif not self.offline_mode: + print( + colored( + "You can sync the migrated profile later from the main menu.", + "yellow", + ) + ) logger.debug("Managers re-initialized for the new fingerprint.") diff --git a/src/tests/test_legacy_migration.py b/src/tests/test_legacy_migration.py index 1469c47..a71eb54 100644 --- a/src/tests/test_legacy_migration.py +++ b/src/tests/test_legacy_migration.py @@ -105,13 +105,16 @@ def test_migration_triggers_sync(monkeypatch, tmp_path: Path): pm.bip85 = SimpleNamespace() calls = {"sync": 0} - pm.start_background_vault_sync = lambda *a, **k: calls.__setitem__( - "sync", calls["sync"] + 1 - ) + 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 @@ -186,9 +189,13 @@ def test_legacy_index_reinit_triggers_sync_once(monkeypatch, tmp_path: Path): ) calls = {"sync": 0} - pm.start_background_vault_sync = lambda *a, **k: calls.__setitem__( - "sync", calls["sync"] + 1 - ) + 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.confirm_action", lambda *_a, **_k: True) pm.initialize_managers() pm.initialize_managers()