Skip to content

test(mesh/session): cover get_session client-fallback + explicit-endpoint paths#601

Merged
cagataycali merged 1 commit into
strands-labs:mainfrom
cagataycali:test/mesh-session-get-session-fallback-paths
Jun 23, 2026
Merged

test(mesh/session): cover get_session client-fallback + explicit-endpoint paths#601
cagataycali merged 1 commit into
strands-labs:mainfrom
cagataycali:test/mesh-session-get-session-fallback-paths

Conversation

@cagataycali

Copy link
Copy Markdown
Member

Problem

strands_robots/mesh/session.py::get_session() had three behavioral branches with no test coverage (lines 628-651, the explicit-endpoint and client-fallback-failure tails). Its sibling _get_zenoh_session_directly already pins the equivalent paths, so the public entry point was the gap. Module coverage sat at 93%.

Change

Adds three behavioral tests to TestSessionLifecycle (zenoh mocked, no broker or install required), asserting outputs/contract rather than internals:

  • listener + client both fail: auto-listener path where the listener open and the client-mode fallback both raise a transport error -> get_session() returns None, caches no session, refcount stays 0, and exactly two open() calls are made.
  • explicit endpoints succeed (ZENOH_CONNECT set): a single direct open(), session cached, refcount = 1, no listener/client dance.
  • explicit endpoints fail (ZENOH_LISTEN set): a transport error on the single explicit open returns None with no silent listener/client retry (loud-on-misconfig contract).

Result

strands_robots/mesh/session.py coverage 93% -> 97% (lines 628-651 now executed). Verified the lines were unexecuted before this change by running the mesh suite against pre-change code. Test-only change; no production behavior altered.

41 passed in 1.27s
strands_robots/mesh/session.py   334   9   97%   87-88, 176, 308, 311, 788-789, 849-850

…oint paths

get_session() lacked behavioral coverage for three branches that its
_get_zenoh_session_directly sibling already pins:

- auto-listener path where BOTH the listener open and the client-mode
  fallback raise (returns None, no cached session, two open() calls)
- explicit-endpoint open success (ZENOH_CONNECT set: single direct open,
  session cached, refcount = 1)
- explicit-endpoint open failure (ZENOH_LISTEN set: transport error
  returns None without a silent listener/client retry)

Lifts strands_robots/mesh/session.py coverage 93% -> 97% (lines 628-651
were previously unexecuted). Tests mock zenoh so no broker or zenoh
install is required.
Comment thread tests/mesh/test_mesh_session.py Dismissed

@yinsong1986 yinsong1986 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Summary

Test-only change (+66/-0 in tests/mesh/test_mesh_session.py) that closes the coverage gap on get_session()'s three untested behavioral tails (lines 628-651): listener+client both failing returns None with no cached session and refcount 0; explicit ZENOH_CONNECT opening directly and caching with refcount 1; and explicit ZENOH_LISTEN failing loudly (no silent listener/client downgrade). Tests mock zenoh (no broker or install required), assert on outputs/contract rather than internals (per AGENTS.md "Test behavior, not implementation"), and sit inside TestSessionLifecycle, whose autouse _reset_session fixture restores _SESSION/_SESSION_REFS before and after each test so there is no module-global state leak.

What's good

  • Scope-disciplined: no production behavior altered; matches the PR title.
  • Env mutation goes through patch.dict("os.environ", ...) rather than raw assignment, so teardown is atomic (AGENTS.md PR #86 testing patterns).
  • Each new test pins a distinct contract branch with a clear docstring; the loud-on-misconfig assertion (open.assert_called_once() for explicit endpoints) is the right behavioral pin.
  • No host paths, no non-ASCII in the diff.

Verification suggestions

python -m pytest tests/mesh/test_mesh_session.py -k TestSessionLifecycle -q (8 passed locally).

@cagataycali
cagataycali merged commit 06f400e into strands-labs:main Jun 23, 2026
6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants