From 320620a18399eb43c4d9056e9fe4c3ffac8fcfd4 Mon Sep 17 00:00:00 2001 From: Christophe Besson Date: Fri, 25 Sep 2026 01:17:32 +0200 Subject: test(node): read ops wherever it is split The tests that read ops.py for an absence (fastapi, a TOML path without as_posix, the reference app's name) and the one counting operations by module now take every file of ops.py or the ops package. Co-Authored-By: Claude Opus 5.5 --- packages/meshbay-hub/tests/node_tree.py | 16 ++++++++++++++++ .../tests/test_helloworld_proves_the_plugin_claim.py | 6 ++---- packages/meshbay-node/tests/node_source.py | 17 +++++++++++++++++ packages/meshbay-node/tests/test_ops.py | 15 +++++++++------ 4 files changed, 44 insertions(+), 10 deletions(-) diff --git a/packages/meshbay-hub/tests/node_tree.py b/packages/meshbay-hub/tests/node_tree.py index 8704492..356bc81 100644 --- a/packages/meshbay-hub/tests/node_tree.py +++ b/packages/meshbay-hub/tests/node_tree.py @@ -52,3 +52,19 @@ def method(name: str) -> str: found.append(ast.get_source_segment(text, member, padded=True)) assert len(found) == 1, f"{name}: expected one definition, found {len(found)}" return found[0] + + +def module_files(name: str) -> list[Path]: + """A node module by name — `ops.py`, or every file of the `ops/` package it + becomes — so a test reading it for an absence goes on reading all of it.""" + src = TRANSPORT.parent + files = [src / f"{name}.py"] if (src / f"{name}.py").exists() else [] + if (src / name).is_dir(): + files += sorted(p for p in (src / name).rglob("*.py") + if "__pycache__" not in p.parts) + assert files, f"no module or package named {name} in the node" + return files + + +def module_source(name: str) -> str: + return "\n".join(p.read_text(encoding="utf-8") for p in module_files(name)) diff --git a/packages/meshbay-hub/tests/test_helloworld_proves_the_plugin_claim.py b/packages/meshbay-hub/tests/test_helloworld_proves_the_plugin_claim.py index 7fc9d8e..71a0ea8 100644 --- a/packages/meshbay-hub/tests/test_helloworld_proves_the_plugin_claim.py +++ b/packages/meshbay-hub/tests/test_helloworld_proves_the_plugin_claim.py @@ -35,8 +35,6 @@ import node_tree import pytest STATIC = Path(__file__).resolve().parents[1] / "src" / "meshbay_hub" / "static" -NODE_SRC = (Path(__file__).resolve().parents[2] / "meshbay-node" / "src" - / "meshbay_node") APP = STATIC / "helloworld-app.js" SETTINGS = STATIC / "helloworld-app-settings.js" @@ -69,14 +67,14 @@ def test_no_shared_client_file_mentions_it(name): @pytest.mark.parametrize("name", [ - "ops.py", "roster.py", "config.py", "roots.py", + "ops", "roster", "config", "roots", ]) def test_no_shared_node_module_mentions_it(name): """ Its directories are stored by `ops.set_app_directories`, which keys the row by whatever the app is called. Nothing on the node knows what it is. """ - source = (NODE_SRC / name).read_text(encoding="utf-8") + source = node_tree.module_source(name) assert "helloworld" not in source.lower(), ( f"{name} names the reference app; the generic path was supposed to " f"cover it") diff --git a/packages/meshbay-node/tests/node_source.py b/packages/meshbay-node/tests/node_source.py index 918cf05..46d62ac 100644 --- a/packages/meshbay-node/tests/node_source.py +++ b/packages/meshbay-node/tests/node_source.py @@ -109,3 +109,20 @@ def daemon_call(name: str) -> str: found.append(ast.get_source_segment(text, node)) assert len(found) == 1, f"{len(found)} calls to {name} in the daemon — re-read this test" return found[0] + + +# `ops.py`, or the package it becomes: every file of it either way. +OPS_PACKAGE = SRC / "ops" + + +def ops_files() -> list[Path]: + """Every module of the operations layer, however it is split up.""" + files = [SRC / "ops.py"] if (SRC / "ops.py").exists() else [] + if OPS_PACKAGE.is_dir(): + files += sorted(p for p in OPS_PACKAGE.rglob("*.py") + if "__pycache__" not in p.parts) + return files + + +def ops_source() -> str: + return "\n".join(p.read_text(encoding="utf-8") for p in ops_files()) diff --git a/packages/meshbay-node/tests/test_ops.py b/packages/meshbay-node/tests/test_ops.py index 083f31e..d49d3fa 100644 --- a/packages/meshbay-node/tests/test_ops.py +++ b/packages/meshbay-node/tests/test_ops.py @@ -20,6 +20,7 @@ from meshbay_node import ops from meshbay_node.indexer.group_index import GroupIndex from meshbay_node.roots import RootSet from meshbay_node.transport.quic_server import Denylist +from node_source import ops_source from conftest import one_root @@ -44,13 +45,15 @@ def test_operations_take_state_and_nothing_web_shaped(): second copy. Every public operation therefore takes `state` first and returns plain data. """ - # Defined here, not merely visible here: an async helper imported into the - # module (`off_disk`, say) is not an operation, and reporting it as one says + # Defined in `ops`, not merely visible there: an async helper imported into + # it (`off_disk`, say) is not an operation, and reporting it as one says # nothing about a second implementation appearing. Every real operation is - # written in this module, so nothing is lost by asking. + # written in the module or in the package it is split into, so nothing is + # lost by asking. public = [(n, f) for n, f in vars(ops).items() if inspect.iscoroutinefunction(f) and not n.startswith("_") - and getattr(f, "__module__", None) == ops.__name__] + and (getattr(f, "__module__", "") == ops.__name__ + or getattr(f, "__module__", "").startswith(ops.__name__ + "."))] assert len(public) > 30, "operations have gone missing — did the module move?" for name, fn in public: params = list(inspect.signature(fn).parameters) @@ -82,7 +85,7 @@ def test_the_http_adapter_adds_no_logic(): def test_op_errors_carry_a_status_without_importing_http(): - source = inspect.getsource(ops) + source = ops_source() for forbidden in ("JSONResponse", "fastapi", "starlette", "HTTPException"): assert forbidden not in source, ( f"ops imports {forbidden} — it must not know which adapter called it") @@ -400,7 +403,7 @@ def test_every_path_written_into_node_toml_goes_through_as_posix(): not run on. """ import re - source = inspect.getsource(ops) + source = ops_source() # Every f-string interpolation that lands on the right of a TOML `path =`. writes = re.findall(r'path\s*=\s*\\?"\{([^}]+)\}', source) assert writes, "no TOML path writer found — did the config writer move?" -- cgit v1.2.3