diff options
| author | Christophe Besson <cbesson@gmail.com> | 2026-09-25 01:17:32 +0200 |
|---|---|---|
| committer | Christophe Besson <cbesson@gmail.com> | 2026-09-25 01:17:32 +0200 |
| commit | 320620a18399eb43c4d9056e9fe4c3ffac8fcfd4 (patch) | |
| tree | a7eb9f0c0c3428fcb20a245d2a5b2b828a8a1a8e /packages/meshbay-node/tests | |
| parent | 387138410532daad174ed602fd03f4f979cd3d81 (diff) | |
| download | meshbay-320620a18399eb43c4d9056e9fe4c3ffac8fcfd4.tar.gz | |
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 <noreply@anthropic.com>
Diffstat (limited to 'packages/meshbay-node/tests')
| -rw-r--r-- | packages/meshbay-node/tests/node_source.py | 17 | ||||
| -rw-r--r-- | packages/meshbay-node/tests/test_ops.py | 15 |
2 files changed, 26 insertions, 6 deletions
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?" |