Add gRPC user agent interceptor - #2172
Conversation
Signed-off-by: Somesh Mal <malsomesh9@gmail.com>
Up to standards ✅🟢 Issues
|
| Metric | Results |
|---|---|
| Complexity | 20 |
TIP This summary will be updated as you push new changes. Give us feedback
WalkthroughThe PR implements a gRPC client interceptor that injects an Changes
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~25 minutes 🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. 📋 Issue PlannerBuilt with CodeRabbit's Coding Plans for faster development and fewer bugs. View plan used: ✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: ASSERTIVE
Plan: Pro
Run ID: bb099e42-243d-4032-8910-378d5693cca1
📒 Files selected for processing (4)
src/hiero_sdk_python/client/client.pysrc/hiero_sdk_python/node.pysrc/hiero_sdk_python/user_agent_interceptor.pytests/unit/user_agent_interceptor_test.py
| ) | ||
|
|
||
|
|
||
| pytestmark = pytest.mark.unit |
There was a problem hiding this comment.
Move the real gRPC server check out of the unit test set.
Line 19 marks the whole module as unit tests, but Line 102 starts a real gRPC server and Line 113 opens a real loopback channel. Keep this coverage, but move it to an integration test module or remove the module-level unit marker and explicitly mark only the pure tests as unit.
Suggested marking split if this test remains in the same file
-pytestmark = pytest.mark.unit
-
+@pytest.mark.unit
def test_get_sdk_version_returns_installed_version():
assert _get_sdk_version()
+@pytest.mark.unit
`@patch`("hiero_sdk_python.user_agent_interceptor.importlib_metadata.version")
def test_get_sdk_version_falls_back_to_dev(mock_version):
mock_version.side_effect = importlib_metadata.PackageNotFoundError
assert _get_sdk_version() == "dev"
+@pytest.mark.unit
`@patch`("hiero_sdk_python.user_agent_interceptor._get_sdk_version", return_value="1.2.3")
def test_unary_unary_interceptor_adds_user_agent_header(mock_get_version):
interceptor = _UserAgentInterceptor()
continuation = Mock(return_value="response")
+@pytest.mark.unit
`@patch`("hiero_sdk_python.user_agent_interceptor._get_sdk_version", return_value="1.2.3")
def test_unary_stream_interceptor_adds_user_agent_header(mock_get_version):
interceptor = _UserAgentInterceptor()
continuation = Mock(return_value=iter(["response"]))
+@pytest.mark.unit
`@patch`("hiero_sdk_python.user_agent_interceptor._get_sdk_version", return_value="1.2.3")
def test_interceptor_preserves_existing_metadata(mock_get_version):
interceptor = _UserAgentInterceptor()
continuation = Mock(return_value="response")
+@pytest.mark.unit
`@patch`("grpc.intercept_channel")
def test_apply_user_agent_interceptor_wraps_channel(mock_intercept_channel):
channel = Mock(spec=grpc.Channel)
intercepted_channel = Mock(spec=grpc.Channel)
+@pytest.mark.integration
def test_interceptor_sends_valid_grpc_metadata():
received_metadata = []As per coding guidelines, "No network calls or external dependencies (unit tests are isolated)."
Also applies to: 95-126
|
Closing this PR for now since the contributor is not assigned to the issue, and there are also some concerns around whether this may be an automated/bot-generated contribution. |
Summary
Details
The interceptor sends
x-user-agent: hiero-sdk-python/{version}. The lowercase metadata key is required by gRPC Python/HTTP2 while preserving the sameX-User-Agentheader semantics expected by the consensus node.Fixes #2169
Validation
/tmp/hiero-sdk-python-venv/bin/python -m pytest tests/unit/user_agent_interceptor_test.py -q/tmp/hiero-sdk-python-venv/bin/python -m pytest tests/unit/ -q/tmp/hiero-sdk-python-venv/bin/python -m ruff check src/hiero_sdk_python/user_agent_interceptor.py src/hiero_sdk_python/node.py src/hiero_sdk_python/client/client.py tests/unit/user_agent_interceptor_test.py/tmp/hiero-sdk-python-venv/bin/python -m ruff format --check src/hiero_sdk_python/user_agent_interceptor.py src/hiero_sdk_python/node.py src/hiero_sdk_python/client/client.py tests/unit/user_agent_interceptor_test.py