aboutsummaryrefslogtreecommitdiffstats
path: root/packages/meshbay-cli/tests/fake_node.py
diff options
context:
space:
mode:
authorChristophe Besson <cbesson@gmail.com>2026-10-16 10:41:17 +0200
committerChristophe Besson <cbesson@gmail.com>2026-10-16 10:41:17 +0200
commit4802be13580de1529b7824a2337d132d64849801 (patch)
tree6dd77bcc00a0d8e494cf687918c86b9fd8e77051 /packages/meshbay-cli/tests/fake_node.py
parentd74d371bd7c0ed25f60754e475a78975bf2dc4ee (diff)
downloadmeshbay-4802be13580de1529b7824a2337d132d64849801.tar.gz
fix(cli): apply index updates in place instead of fetching the whole index
The interactive mode fetched and re-parsed the full index on every index_delta, on the loop receiving the download: 67 times in 80 s while a node enriched a library. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Diffstat (limited to 'packages/meshbay-cli/tests/fake_node.py')
-rw-r--r--packages/meshbay-cli/tests/fake_node.py22
1 files changed, 21 insertions, 1 deletions
diff --git a/packages/meshbay-cli/tests/fake_node.py b/packages/meshbay-cli/tests/fake_node.py
index c618ee4..47f82b3 100644
--- a/packages/meshbay-cli/tests/fake_node.py
+++ b/packages/meshbay-cli/tests/fake_node.py
@@ -79,6 +79,8 @@ class FakeNode:
self.members: dict[str, Identity] = {} # sender → the device it signs with
self.unresponsive = False # pings go unanswered, as a dead link's
self.admin_ops: dict[str, dict] = {}
+ self.channels: list[FakeChannel] = []
+ self.index_syncs = 0 # full indexes asked for
def add(self, path: str, name: str, data: bytes, uploader_id: str = "") -> dict:
fid = hashlib.blake2b(data + path.encode() + name.encode(), digest_size=32).hexdigest()
@@ -92,9 +94,26 @@ class FakeNode:
return entry
def session(self) -> GroupSession:
- return GroupSession(None, FakeChannel(self), GROUP_ID, "node-1", NODE_PK, self.gek,
+ ch = FakeChannel(self)
+ self.channels.append(ch)
+ return GroupSession(None, ch, GROUP_ID, "node-1", NODE_PK, self.gek,
dict(self.ack), self.identity, self.nonce, self.role)
+ def push_delta(self, *, additions=(), updates=(), deletions=()) -> None:
+ """An `index_delta` to every session, sealed as the node seals one. The
+ entries are applied here first, so a later `index_sync` agrees."""
+ for e in (*additions, *updates):
+ self.files[e["id"]] = e
+ for fid in deletions:
+ self.files.pop(fid, None)
+ wire = lambda es: [{k: v for k, v in e.items() if k != "data"} for e in es] # noqa: E731
+ payload = {"base_version": 1, "version": 1, "additions": wire(additions),
+ "deletions": list(deletions), "updates": wire(updates)}
+ msg = {"type": "index_delta", "group_id": GROUP_ID,
+ **seal(self.gek, PURPOSE_INDEX, "index_delta", GROUP_ID, payload)}
+ for ch in self.channels:
+ ch._emit(msg)
+
def list_device(self, sender: str, device: Identity, *,
countersigned_by: Identity | None = None, proof: bool = True) -> None:
"""A roster row for `sender`'s device: a root, or countersigned by another
@@ -189,6 +208,7 @@ class FakeChannel:
def _index_sync(self, msg):
n = self.node
+ n.index_syncs += 1
payload = {"version": 1, "roots": n.roots, "dirs": sorted(n.dirs),
"entries": [{k: v for k, v in e.items() if k != "data"}
for e in n.files.values()]}