From 328b01a2dd545d70a078db8df1e91b02d65bfc9c Mon Sep 17 00:00:00 2001 From: Christophe Besson Date: Wed, 23 Sep 2026 22:25:28 +0200 Subject: test: read the WebRTC transport's source as a set of files Source-reading tests take their text from node_source (node) and node_tree (hub): webrtc_server.py plus anything under transport/webrtc/, so a check for something's absence keeps reading the code it guards if that code moves. test_node_source_scope holds the boundary. Co-Authored-By: Claude Opus 5.5 --- packages/meshbay-node/tests/node_source.py | 52 ++++++++++++++++++++++++++++++ 1 file changed, 52 insertions(+) create mode 100644 packages/meshbay-node/tests/node_source.py (limited to 'packages/meshbay-node/tests/node_source.py') diff --git a/packages/meshbay-node/tests/node_source.py b/packages/meshbay-node/tests/node_source.py new file mode 100644 index 0000000..df63773 --- /dev/null +++ b/packages/meshbay-node/tests/node_source.py @@ -0,0 +1,52 @@ +""" +The node's source text, for the tests that have to read it. + +A test that reads source to prove something is *absent* — no bare +`ensure_future`, no exception text sent to a peer, no GEK unwrapped over MNP — +goes on passing when the code it guards moves to another file: it simply stops +looking at that code. So every such test takes its text from here, and the +file sets below are derived from the tree rather than listed, so that a module +added later is read without anybody having to remember it. +""" + +import inspect +import textwrap +from pathlib import Path + +SRC = Path(__file__).resolve().parents[1] / "src" / "meshbay_node" +TRANSPORT = SRC / "transport" + +# The WebRTC transport is `webrtc_server.py` and whatever has been split out of +# it into `transport/webrtc/`. The other modules beside them are not part of it +# and are not held to its rules by these tests: QUIC is a transport of its own +# and not at parity (docs/MESHBAY_DESIGN.md §15.3), and `wire.py`, `tls_cert.py` +# and the ICE helpers serve both or neither. +WEBRTC_PACKAGE = TRANSPORT / "webrtc" + + +def webrtc_files() -> list[Path]: + """Every module of the WebRTC transport, however it is split up.""" + files = [TRANSPORT / "webrtc_server.py"] + if WEBRTC_PACKAGE.is_dir(): + files += sorted(p for p in WEBRTC_PACKAGE.rglob("*.py") + if "__pycache__" not in p.parts) + return files + + +def webrtc_source() -> str: + return "\n".join(p.read_text(encoding="utf-8") for p in webrtc_files()) + + +def session_source() -> str: + """The body of WebRTCPeerSession, including every class it is built from.""" + from meshbay_node.transport.webrtc_server import WebRTCPeerSession + + return "\n".join(inspect.getsource(k) for k in WebRTCPeerSession.__mro__ + if k.__module__.startswith("meshbay_node.")) + + +def session_method(name: str) -> str: + """One method of WebRTCPeerSession, wherever it is defined.""" + from meshbay_node.transport.webrtc_server import WebRTCPeerSession + + return textwrap.dedent(inspect.getsource(getattr(WebRTCPeerSession, name))) -- cgit v1.2.3