Skip to content

test(mesh): pin session config-resolution helpers (_max_peers, endpoint-scheme gate, PeerInfo repr)#984

Merged
cagataycali merged 1 commit into
strands-labs:mainfrom
cagataycali:test/mesh-session-config-helpers
Jul 2, 2026
Merged

test(mesh): pin session config-resolution helpers (_max_peers, endpoint-scheme gate, PeerInfo repr)#984
cagataycali merged 1 commit into
strands-labs:mainfrom
cagataycali:test/mesh-session-config-helpers

Conversation

@cagataycali

Copy link
Copy Markdown
Member

What

Adds focused regression coverage for the pure-Python configuration helpers in strands_robots/mesh/session.py that resolve operator env vars and validate endpoint schemes before any transport is opened. These are contracts callers depend on but that had no direct coverage, so a regression in the fallback ordering or the scheme gate would have slipped through.

New file tests/mesh/test_session_config_helpers.py pins:

  • _max_peers() clamps a non-integer STRANDS_MESH_MAX_PEERS (e.g. not-a-number, 10.5) and a non-positive value (0, -1) to MAX_PEERS_DEFAULT instead of raising or accepting a bound that would disable/invert the peer-flood cap; a valid positive value is honoured.
  • _validate_endpoint_schemes() accepts TLS-bearing schemes under mtls, rejects a plaintext tcp endpoint under mtls with an actionable ValueError naming the env var and offending endpoint, accepts tcp under none, rejects wss under none, defers on an unknown auth mode without raising (that is resolve_auth_mode's error to raise), skips empty CSV entries, and normalises scheme case.
  • PeerInfo.__repr__ renders a stable identity string (peer_id, type, age).

Why

These helpers gate mesh security posture (which transports are allowed under which auth mode) and bound peer bookkeeping. The env-var fallbacks and the auth-mode/empty-entry branches of the scheme validator were exercised only indirectly. The tests assert observable outputs (returned value / raised type / repr text), not internal state.

Testing

Test-only change; no runtime behaviour is modified.

pytest tests/mesh/test_session_config_helpers.py -q   # 18 passed
pytest tests/mesh/ -q                                 # 1939 passed, 2 skipped

strands_robots/mesh/session.py line coverage 97% -> 99% (closes the _max_peers non-int fallback, PeerInfo.__repr__, and both _validate_endpoint_schemes deferral branches; the two remaining uncovered lines are best-effort except: pass session-teardown race paths). hatch run lint clean (ruff + format + mypy).

@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 PR (+119/-0, one new file tests/mesh/test_session_config_helpers.py) adding focused regression coverage for three pure-Python config helpers in strands_robots/mesh/session.py: _max_peers() env clamping, _validate_endpoint_schemes() auth-mode/scheme gating, and PeerInfo.__repr__. The assertions match the implementation exactly — non-int/non-positive STRANDS_MESH_MAX_PEERS falls back to MAX_PEERS_DEFAULT (session.py:82-89), the mtls/none scheme allowlists (_MTLS_OK_SCHEMES / _NONE_OK_SCHEMES, session.py:282-285) gate as tested, the unknown-auth-mode deferral branch (session.py:306-308) is exercised, and empty CSV segments are skipped (session.py:310-311). No runtime behaviour is modified.

What's good

  • Assertions are on observable outputs (returned value / raised type / repr text), not internal state — matches AGENTS.md "Test behavior, not implementation".
  • Uses monkeypatch.setenv/delenv for env manipulation rather than mutating os.environ directly, per AGENTS.md > Review Learnings (#86) > Testing Patterns.
  • Tight scope: no host paths, no emojis, no touch on Zenoh/torch/MuJoCo import chains.
  • The error-message assertions on _validate_endpoint_schemes pin the actionable-ValueError contract (env var name + offending endpoint present in the message).

@cagataycali
cagataycali merged commit 12abb99 into strands-labs:main Jul 2, 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.

3 participants