Skip to content

test: add direct unit tests for app/services/honeycomb/client.py #974

Merged
muddlebee merged 5 commits intoTracer-Cloud:mainfrom
gitsofaryan:test/add-honeycomb-unit-tests
Apr 28, 2026
Merged

test: add direct unit tests for app/services/honeycomb/client.py #974
muddlebee merged 5 commits intoTracer-Cloud:mainfrom
gitsofaryan:test/add-honeycomb-unit-tests

Conversation

@gitsofaryan
Copy link
Copy Markdown
Contributor

Fixes #883

Describe the changes you have made in this PR -

Added direct unit tests for the Honeycomb service client in app/services/honeycomb/client.py. These tests cover key behaviors including authentication validation, query creation, and query result retrieval (polling). The implementation uses unittest.mock to ensure no network access is required, and covers both success paths and error handling for HTTP failures and generic exceptions.

Demo/Screenshot for feature changes and bug fixes -

tests/services/test_honeycomb_client.py::test_is_configured PASSED      [  7%]
tests/services/test_honeycomb_client.py::test_validate_access_success PASSED [ 14%]
tests/services/test_honeycomb_client.py::test_validate_access_http_error PASSED [ 21%]
tests/services/test_honeycomb_client.py::test_validate_access_generic_exception PASSED [ 28%]
tests/services/test_honeycomb_client.py::test_create_query_success PASSED [ 35%]
tests/services/test_honeycomb_client.py::test_create_query_no_id PASSED   [ 42%]
tests/services/test_honeycomb_client.py::test_create_query_http_error PASSED [ 50%]
tests/services/test_honeycomb_client.py::test_create_query_result_success PASSED [ 57%]
tests/services/test_honeycomb_client.py::test_create_query_result_http_error PASSED [ 64%]
tests/services/test_honeycomb_client.py::test_get_query_result_success PASSED [ 71%]
tests/services/test_honeycomb_client.py::test_get_query_result_http_error PASSED [ 78%]
tests/services/test_honeycomb_client.py::test_get_query_result_generic_exception PASSED [ 85%]
tests/services/test_honeycomb_client.py::test_run_query_full_flow PASSED  [ 92%]
tests/services/test_honeycomb_client.py::test_query_traces_success PASSED [100%]

============================= 14 passed in 3.82s ==============================

Code Understanding and AI Usage

Did you use AI assistance (ChatGPT, Claude, Copilot, etc.) to write any part of this code?

  • Yes, I used AI assistance (Antigravity)

If you used AI assistance:

  • I have reviewed every single line of the AI-generated code
  • I can explain the purpose and logic of each function/component I added
  • I have tested edge cases and understand how the code handles them
  • I have modified the AI output to follow this project's coding standards and conventions

Explain your implementation approach:
The tests use pytest and unittest.mock to isolate the HoneycombClient from the external API and the httpx library. I focused on covering all branch points in the exception handling logic to ensure that HTTP errors (4xx/5xx) and network-level failures are handled consistently and return the expected error structure. High-level methods like run_query and query_traces are also tested to ensure correct internal logic and payload formatting.

Checklist before requesting a review

  • I have added proper PR title and linked to the issue
  • I have performed a self-review of my code
  • I can explain the purpose of every function, class, and logic block I added
  • I understand why my changes work and have tested them thoroughly
  • I have considered potential edge cases and how my code handles them
  • If it is a core feature, I have added thorough tests
  • My code follows the project's style guidelines and conventions

@gitsofaryan
Copy link
Copy Markdown
Contributor Author

cc : @VaibhavUpreti @rrajan94 PTAL!

@greptile-apps
Copy link
Copy Markdown
Contributor

greptile-apps Bot commented Apr 26, 2026

Greptile Summary

This PR adds 14 unit tests for app/services/honeycomb/client.py, covering authentication validation, query creation, query result retrieval, and the high-level run_query and query_traces helpers. Error branches for HTTP status errors and generic exceptions are well covered across all lower-level methods, but a few branches in the orchestration layer are missing.

Confidence Score: 5/5

Safe to merge; all findings are P2 coverage gaps with no production-code changes.

The PR only adds test code and all identified issues are missing test cases (P2), not correctness bugs. No production code is modified, so there is no merge risk.

tests/services/test_honeycomb_client.py — polling loop, run_query failure propagation, and query_traces empty-filter branch need additional test cases.

Important Files Changed

Filename Overview
tests/services/test_honeycomb_client.py Adds 14 unit tests for HoneycombClient; covers happy paths and HTTP/generic error branches well, but misses the polling retry loop, the for/else timeout path in run_query, the create_query_result failure propagation in run_query, and the no-filter guard in query_traces.

Flowchart

%%{init: {'theme': 'neutral'}}%%
flowchart TD
    A[run_query] --> B[create_query]
    B -->|success=False| Z1[return error]
    B -->|success=True| C[create_query_result]
    C -->|success=False| Z2[return error ⚠️ no test]
    C -->|success=True| D{complete?}
    D -->|Yes — break| E[extract results]
    D -->|No| F[time.sleep + get_query_result]
    F -->|success=False| Z3[return error]
    F -->|success=True| D
    D -->|loop exhausted for/else| Z4[timeout error ⚠️ no test]
    E --> G[return success]

    style Z2 fill:#ffe0b2
    style Z4 fill:#ffe0b2
Loading

Reviews (1): Last reviewed commit: "fix: resolve ruff lint and format issues..." | Re-trigger Greptile

Comment thread tests/services/test_honeycomb_client.py
Comment on lines +208 to +224
"result": {"id": "r1", "complete": True, "data": {"results": [{"data": {"val": 10}}]}},
}
)

# We also need to mock time.sleep to speed up tests if it ever hits it
with patch("time.sleep"):
result = client.run_query({"calculations": []})

assert result["success"] is True
assert result["query_id"] == "q1"
assert result["query_result_id"] == "r1"
assert result["results"] == [{"val": 10}]


def test_query_traces_success(client: HoneycombClient) -> None:
client.run_query = MagicMock(return_value={"success": True, "results": []})

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.

P2 query_traces empty-filter branch not tested

When query_traces is called with no service_name and no trace_id, the client returns {"success": False, "error": "Honeycomb trace queries require a service_name or trace_id."}. This guard branch has no test. Adding a simple case like client.query_traces() asserting result["success"] is False would close the gap.

Context Used: Testing conventions and patterns (source)

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

@gitsofaryan not addressed yet

Comment thread tests/services/test_honeycomb_client.py
@gitsofaryan
Copy link
Copy Markdown
Contributor Author

@muddlebee PTAL!

@muddlebee
Copy link
Copy Markdown
Collaborator

@gitsofaryan pls fix the greptile review points?

@gitsofaryan
Copy link
Copy Markdown
Contributor Author

@muddlebee addressed!

@muddlebee
Copy link
Copy Markdown
Collaborator

@gitsofaryan CI still failing

@gitsofaryan
Copy link
Copy Markdown
Contributor Author

@muddlebee fixed!

@muddlebee muddlebee merged commit 8779304 into Tracer-Cloud:main Apr 28, 2026
7 checks passed
@muddlebee
Copy link
Copy Markdown
Collaborator

@gitsofaryan great work. thank you 🎸

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.

Add direct unit tests for app/services/honeycomb/client.py

2 participants