mirror of
https://github.com/PR0M3TH3AN/SeedPass.git
synced 2025-09-08 07:18:47 +00:00
Add tests for sync and snapshot functionality
This commit is contained in:
@@ -105,3 +105,30 @@ def test_fetch_snapshot_fallback_on_missing_chunk(dummy_nostr_client, monkeypatc
|
||||
)
|
||||
)
|
||||
assert attempts == 3
|
||||
|
||||
|
||||
def test_fetch_snapshot_uses_event_ids(dummy_nostr_client):
|
||||
import os
|
||||
import gzip
|
||||
|
||||
client, relay = dummy_nostr_client
|
||||
|
||||
data = os.urandom(60000)
|
||||
manifest, _ = asyncio.run(client.publish_snapshot(data))
|
||||
|
||||
# Remove identifier keys so chunks can only be fetched via event_id
|
||||
for meta in manifest.chunks:
|
||||
relay.chunks.pop(meta.id, None)
|
||||
|
||||
relay.filters.clear()
|
||||
|
||||
fetched_manifest, chunk_bytes = asyncio.run(client.fetch_latest_snapshot())
|
||||
|
||||
assert gzip.decompress(b"".join(chunk_bytes)) == data
|
||||
|
||||
id_filters = [
|
||||
f.id_called
|
||||
for f in relay.filters
|
||||
if getattr(f, "kind_val", None) == KIND_SNAPSHOT_CHUNK
|
||||
]
|
||||
assert id_filters and all(id_filters)
|
||||
|
@@ -29,3 +29,24 @@ def test_handle_post_failure(capsys):
|
||||
main.handle_post_to_nostr(pm)
|
||||
out = capsys.readouterr().out
|
||||
assert "❌ Sync failed…" in out
|
||||
|
||||
|
||||
def test_handle_post_prints_all_ids(capsys):
|
||||
pm = SimpleNamespace(
|
||||
sync_vault=lambda alt_summary=None: {
|
||||
"manifest_id": "m1",
|
||||
"chunk_ids": ["c1", "c2"],
|
||||
"delta_ids": ["d1", "d2"],
|
||||
}
|
||||
)
|
||||
main.handle_post_to_nostr(pm)
|
||||
out_lines = capsys.readouterr().out.splitlines()
|
||||
expected = [
|
||||
" manifest: m1",
|
||||
" chunk: c1",
|
||||
" chunk: c2",
|
||||
" delta: d1",
|
||||
" delta: d2",
|
||||
]
|
||||
for line in expected:
|
||||
assert any(line in ol for ol in out_lines)
|
||||
|
@@ -85,3 +85,24 @@ def test_sync_index_missing_bad_data(monkeypatch, dummy_nostr_client):
|
||||
assert result is False
|
||||
index_path = dir_path / "seedpass_entries_db.json.enc"
|
||||
assert not index_path.exists()
|
||||
|
||||
|
||||
def test_attempt_initial_sync_incomplete_data(monkeypatch, dummy_nostr_client):
|
||||
client, _relay = dummy_nostr_client
|
||||
with TemporaryDirectory() as tmpdir:
|
||||
dir_path = Path(tmpdir)
|
||||
vault, _enc = create_vault(dir_path)
|
||||
|
||||
pm = PasswordManager.__new__(PasswordManager)
|
||||
pm.fingerprint_dir = dir_path
|
||||
pm.vault = vault
|
||||
pm.nostr_client = client
|
||||
pm.sync_vault = lambda *a, **k: None
|
||||
|
||||
# Simulate relay snapshot retrieval failure due to missing chunks
|
||||
monkeypatch.setattr(client, "fetch_latest_snapshot", lambda: None)
|
||||
|
||||
result = pm.attempt_initial_sync()
|
||||
assert result is False
|
||||
index_path = dir_path / "seedpass_entries_db.json.enc"
|
||||
assert not index_path.exists()
|
||||
|
Reference in New Issue
Block a user