diff options
| author | Christophe Besson <cbesson@gmail.com> | 2026-09-23 22:25:28 +0200 |
|---|---|---|
| committer | Christophe Besson <cbesson@gmail.com> | 2026-09-24 16:45:37 +0200 |
| commit | 328b01a2dd545d70a078db8df1e91b02d65bfc9c (patch) | |
| tree | 9af69d617d9482ba4256f3d7334c9dd6cde0d5e2 /packages/meshbay-node/tests/test_disk_io_off_loop.py | |
| parent | 92ea222b7aca6a3eb5f04330f0af6755e6e434e3 (diff) | |
| download | meshbay-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/test_disk_io_off_loop.py')
| -rw-r--r-- | packages/meshbay-node/tests/test_disk_io_off_loop.py | 31 |
1 files changed, 18 insertions, 13 deletions
diff --git a/packages/meshbay-node/tests/test_disk_io_off_loop.py b/packages/meshbay-node/tests/test_disk_io_off_loop.py index ceaf565..f98eceb 100644 --- a/packages/meshbay-node/tests/test_disk_io_off_loop.py +++ b/packages/meshbay-node/tests/test_disk_io_off_loop.py @@ -36,6 +36,7 @@ from meshbay_node.roots import Root, RootSet from meshbay_node.transfers import LeaselessReads from meshbay_node.transport import webrtc_server from meshbay_node.transport.webrtc_server import WebRTCPeerSession +from node_source import webrtc_files from conftest import one_root, sealed_upload @@ -238,9 +239,10 @@ def test_no_handler_touches_the_disk_on_the_loop(): The whole class, not the calls that were fixed. Every measured test above exercises a handler that exists today; a new one - that stats a root inline would pass all of them. So this walks the module's - syntax tree instead and fails on any filesystem call outside the few - functions written to be run through `off_disk`. + that stats a root inline would pass all of them. So this walks the syntax + tree of every module of the WebRTC transport instead and fails on any + filesystem call outside the few functions written to be run through + `off_disk`. `entry_abs_path` and `safe_subdir` are in the list because both are `Path.resolve()` underneath, and a resolve is syscalls whatever it is @@ -274,14 +276,17 @@ def test_no_handler_touches_the_disk_on_the_loop(): found.append(f"{owner} calls {name}() at line {child.lineno}") visit(child, owner) - tree = ast.parse(Path(webrtc_server.__file__).read_text()) - for node in tree.body: - if isinstance(node, ast.ClassDef): - for member in node.body: - if isinstance(member, (ast.FunctionDef, ast.AsyncFunctionDef)): - visit(member, member.name) - elif isinstance(node, (ast.FunctionDef, ast.AsyncFunctionDef)): - visit(node, node.name) + for path in webrtc_files(): + tree = ast.parse(path.read_text(encoding="utf-8")) + before = len(found) + for node in tree.body: + if isinstance(node, ast.ClassDef): + for member in node.body: + if isinstance(member, (ast.FunctionDef, ast.AsyncFunctionDef)): + visit(member, member.name) + elif isinstance(node, (ast.FunctionDef, ast.AsyncFunctionDef)): + visit(node, node.name) + found[before:] = [f"{path.name}: {f}" for f in found[before:]] assert not found, ( "filesystem calls made from the event loop:\n " @@ -362,8 +367,8 @@ def test_the_scratch_read_is_only_ever_reached_on_a_thread(): handler. Passed to `asyncio.to_thread` it appears in the syntax tree as a name; called inline it appears as a call, which is what this refuses. """ - tree = ast.parse(Path(webrtc_server.__file__).read_text()) - direct = [n.lineno for n in ast.walk(tree) + direct = [f"{path.name}:{n.lineno}" for path in webrtc_files() + for n in ast.walk(ast.parse(path.read_text(encoding="utf-8"))) if isinstance(n, ast.Call) and isinstance(n.func, ast.Name) and n.func.id == "_read_scratch_capped"] |