summaryrefslogtreecommitdiffstats
path: root/packages/meshbay-node/tests/node_source.py
diff options
context:
space:
mode:
authorChristophe Besson <cbesson@gmail.com>2026-09-23 22:25:28 +0200
committerChristophe Besson <cbesson@gmail.com>2026-09-24 16:45:37 +0200
commit328b01a2dd545d70a078db8df1e91b02d65bfc9c (patch)
tree9af69d617d9482ba4256f3d7334c9dd6cde0d5e2 /packages/meshbay-node/tests/node_source.py
parent92ea222b7aca6a3eb5f04330f0af6755e6e434e3 (diff)
downloadmeshbay-328b01a2dd545d70a078db8df1e91b02d65bfc9c.tar.gz
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 <noreply@anthropic.com>
Diffstat (limited to 'packages/meshbay-node/tests/node_source.py')
-rw-r--r--packages/meshbay-node/tests/node_source.py52
1 files changed, 52 insertions, 0 deletions
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)))