Use vault migration flag to prompt sync

This commit is contained in:
thePR0M3TH3AN
2025-08-04 11:43:34 -04:00
parent 264caff711
commit fdfdbc883b
3 changed files with 45 additions and 4 deletions

View File

@@ -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?"
):

View File

@@ -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

View File

@@ -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