From db400a438853036cfd3518873ea47beabe304718 Mon Sep 17 00:00:00 2001 From: Christophe Besson Date: Thu, 24 Sep 2026 12:32:56 +0200 Subject: test(node): the dispatch golden covers a type field that is not a string Missing, None, an int, a list, a dict, bytes: recorded on the elif chain before it becomes a table, since a dict lookup would raise on the unhashable ones where the chain found no match. Co-Authored-By: Claude Opus 5.5 --- packages/meshbay-node/tests/golden/dispatch.json | 240 +++++++++++++++++++++ .../meshbay-node/tests/test_dispatch_golden.py | 18 ++ 2 files changed, 258 insertions(+) (limited to 'packages/meshbay-node') diff --git a/packages/meshbay-node/tests/golden/dispatch.json b/packages/meshbay-node/tests/golden/dispatch.json index 63ae5aa..98911f5 100644 --- a/packages/meshbay-node/tests/golden/dispatch.json +++ b/packages/meshbay-node/tests/golden/dispatch.json @@ -258,6 +258,246 @@ } }, "dispatch": { + " | challenged | bare": { + "audit": [], + "log": [], + "sent": [ + { + "detail": "Handshake required", + "req_id": 4242, + "type": "error" + } + ], + "spawned": [] + }, + " | fresh | bare": { + "audit": [], + "log": [], + "sent": [ + { + "detail": "Handshake required", + "req_id": 4242, + "type": "error" + } + ], + "spawned": [] + }, + " | member | bare": { + "audit": [], + "log": [ + "WARNING Unknown MNP message type on DataChannel: %s" + ], + "sent": [], + "spawned": [] + }, + " | operator | bare": { + "audit": [], + "log": [ + "WARNING Unknown MNP message type on DataChannel: %s" + ], + "sent": [], + "spawned": [] + }, + " | challenged | bare": { + "audit": [], + "log": [], + "sent": [ + { + "detail": "Handshake required", + "req_id": 4242, + "type": "error" + } + ], + "spawned": [] + }, + " | fresh | bare": { + "audit": [], + "log": [], + "sent": [ + { + "detail": "Handshake required", + "req_id": 4242, + "type": "error" + } + ], + "spawned": [] + }, + " | member | bare": { + "audit": [], + "log": [ + "WARNING Unknown MNP message type on DataChannel: %s" + ], + "sent": [], + "spawned": [] + }, + " | operator | bare": { + "audit": [], + "log": [ + "WARNING Unknown MNP message type on DataChannel: %s" + ], + "sent": [], + "spawned": [] + }, + " | challenged | bare": { + "audit": [], + "log": [], + "sent": [ + { + "detail": "Handshake required", + "req_id": 4242, + "type": "error" + } + ], + "spawned": [] + }, + " | fresh | bare": { + "audit": [], + "log": [], + "sent": [ + { + "detail": "Handshake required", + "req_id": 4242, + "type": "error" + } + ], + "spawned": [] + }, + " | member | bare": { + "audit": [], + "log": [ + "WARNING Unknown MNP message type on DataChannel: %s" + ], + "sent": [], + "spawned": [] + }, + " | operator | bare": { + "audit": [], + "log": [ + "WARNING Unknown MNP message type on DataChannel: %s" + ], + "sent": [], + "spawned": [] + }, + " | challenged | bare": { + "audit": [], + "log": [], + "sent": [ + { + "detail": "Handshake required", + "req_id": 4242, + "type": "error" + } + ], + "spawned": [] + }, + " | fresh | bare": { + "audit": [], + "log": [], + "sent": [ + { + "detail": "Handshake required", + "req_id": 4242, + "type": "error" + } + ], + "spawned": [] + }, + " | member | bare": { + "audit": [], + "log": [ + "WARNING Unknown MNP message type on DataChannel: %s" + ], + "sent": [], + "spawned": [] + }, + " | operator | bare": { + "audit": [], + "log": [ + "WARNING Unknown MNP message type on DataChannel: %s" + ], + "sent": [], + "spawned": [] + }, + " | challenged | bare": { + "audit": [], + "log": [], + "sent": [ + { + "detail": "Handshake required", + "req_id": 4242, + "type": "error" + } + ], + "spawned": [] + }, + " | fresh | bare": { + "audit": [], + "log": [], + "sent": [ + { + "detail": "Handshake required", + "req_id": 4242, + "type": "error" + } + ], + "spawned": [] + }, + " | member | bare": { + "audit": [], + "log": [ + "WARNING Unknown MNP message type on DataChannel: %s" + ], + "sent": [], + "spawned": [] + }, + " | operator | bare": { + "audit": [], + "log": [ + "WARNING Unknown MNP message type on DataChannel: %s" + ], + "sent": [], + "spawned": [] + }, + " | challenged | bare": { + "audit": [], + "log": [], + "sent": [ + { + "detail": "Handshake required", + "req_id": 4242, + "type": "error" + } + ], + "spawned": [] + }, + " | fresh | bare": { + "audit": [], + "log": [], + "sent": [ + { + "detail": "Handshake required", + "req_id": 4242, + "type": "error" + } + ], + "spawned": [] + }, + " | member | bare": { + "audit": [], + "log": [ + "WARNING Unknown MNP message type on DataChannel: %s" + ], + "sent": [], + "spawned": [] + }, + " | operator | bare": { + "audit": [], + "log": [ + "WARNING Unknown MNP message type on DataChannel: %s" + ], + "sent": [], + "spawned": [] + }, "admin_challenge | challenged | bare": { "audit": [], "log": [], diff --git a/packages/meshbay-node/tests/test_dispatch_golden.py b/packages/meshbay-node/tests/test_dispatch_golden.py index b31b63b..c917208 100644 --- a/packages/meshbay-node/tests/test_dispatch_golden.py +++ b/packages/meshbay-node/tests/test_dispatch_golden.py @@ -144,6 +144,20 @@ def _message_types() -> list[str]: return sorted(names | {"client_diag", "no_such_type"}) +def _odd_types() -> dict[str, dict]: + """A `type` field that is not a string, or no `type` at all. msgpack will + carry any value there, and a dispatch keyed by type has to treat each of + these as the chain of comparisons did — an unhashable one included.""" + return { + "": {}, + "": {"type": None}, + "": {"type": 7}, + "": {"type": [MNP.PING]}, + "": {"type": {"t": MNP.PING}}, + "": {"type": MNP.PING.encode()}, + } + + def _shapes(keys: list[str]) -> dict[str, dict]: return { "bare": {}, @@ -165,6 +179,10 @@ def _record(keys: list[str]) -> dict: for shape, fields in _shapes(keys).items(): msg = {**fields, "type": mtype, "req_id": REQ_ID} out["dispatch"][f"{mtype} | {state} | {shape}"] = _run(_session(state), msg) + for label, fields in _odd_types().items(): + for state in ("fresh", "challenged", "member", "operator"): + msg = {**fields, "req_id": REQ_ID} + out["dispatch"][f"{label} | {state} | bare"] = _run(_session(state), msg) for op in _admin_ops() + ["no_such_op"]: s = _session("operator") s._admin_ops["the-op"] = {"op": op, "subject": "subject", "nonce": b"\x05" * 32, -- cgit v1.2.3