Skip to content

Add direct unit tests for app/services/tracer_client/tracer_tools.py#975

Merged
muddlebee merged 3 commits intoTracer-Cloud:mainfrom
gitsofaryan:test/add-tracer-tools-unit-tests
Apr 28, 2026
Merged

Add direct unit tests for app/services/tracer_client/tracer_tools.py#975
muddlebee merged 3 commits intoTracer-Cloud:mainfrom
gitsofaryan:test/add-tracer-tools-unit-tests

Conversation

@gitsofaryan
Copy link
Copy Markdown
Contributor

Fixes #889

Describe the changes you have made in this PR -

Added direct unit tests for TracerToolsMixin in app/services/tracer_client/tracer_tools.py. The implementation uses a fake subclass to stub out the _get() method, allowing for fully offline testing of the task processing logic. The tests verify:

  • Correct task counting (total, failed, completed).
  • Accurate extraction of failure details including extra fields like tool_cmd and explanation.
  • Robust handling of various exit code formats (strings, numbers, None, empty strings).
  • Proper behavior for unsuccessful API responses and empty payloads.

Demo/Screenshot for feature changes and bug fixes -

tests/services/tracer_client/test_tracer_tools.py::test_get_run_tasks_all_success PASSED [ 20%]
tests/services/tracer_client/test_tracer_tools.py::test_get_run_tasks_mixed_failure PASSED [ 40%]
tests/services/tracer_client/test_tracer_tools.py::test_get_run_tasks_empty_payload PASSED [ 60%]
tests/services/tracer_client/test_tracer_tools.py::test_get_run_tasks_unsuccessful_response PASSED [ 80%]
tests/services/tracer_client/test_tracer_tools.py::test_get_run_tasks_exit_code_handling PASSED [100%]

============================== 5 passed in 1.78s ==============================

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:
I implemented a FakeTracerClient that inherits from the mixin and stubs the _get method. This approach avoids complex mocking of the httpx client while still ensuring that the core logic of get_run_tasks is exercised against realistic JSON payloads. I explicitly tested edge cases for exit_code as specified in the issue scope to ensure that the logic correctly distinguishes between success and failure across different representation styles.

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!

Comment thread tests/services/tracer_client/test_tracer_tools.py Fixed
Comment thread tests/services/tracer_client/test_tracer_tools.py Fixed
@greptile-apps
Copy link
Copy Markdown
Contributor

greptile-apps Bot commented Apr 26, 2026

Greptile Summary

Adds a new test file covering TracerToolsMixin.get_run_tasks using a FakeTracerClient stub. The five test cases address success, mixed failure, empty payload, unsuccessful API response, and exit_code format variations. All prior thread concerns (unused import, inline thinking comments, manual loop vs parametrize, missing type hints, and from __future__ import annotations) are resolved in this revision.

Confidence Score: 5/5

Safe to merge; all prior review concerns are resolved and no new issues were found.

All P1 concerns from previous review rounds (unused import, debug comments, manual loop, missing type hints) are addressed in this revision. Remaining feedback would be P2 at most. Tests correctly model source behaviour, use parametrize, and are fully offline.

No files require special attention.

Important Files Changed

Filename Overview
tests/services/tracer_client/test_tracer_tools.py New test file for TracerToolsMixin; all previous review concerns (unused import, debug comments, manual loop, type hints) addressed; tests correctly reflect source behaviour including integer and None exit codes.

Sequence Diagram

sequenceDiagram
    participant Test
    participant FakeTracerClient
    participant TracerToolsMixin
    participant _get (stub)

    Test->>FakeTracerClient: set _get_response
    Test->>FakeTracerClient: get_run_tasks(run_id)
    FakeTracerClient->>TracerToolsMixin: get_run_tasks(run_id)
    TracerToolsMixin->>_get (stub): _get("/api/tools/{run_id}", params)
    _get (stub)-->>TracerToolsMixin: _get_response dict
    TracerToolsMixin->>TracerToolsMixin: check success + data
    TracerToolsMixin->>TracerToolsMixin: classify each exit_code
    TracerToolsMixin-->>Test: TracerTaskResult(found, total, failed, ...)
Loading

Reviews (2): Last reviewed commit: "fix: remove unused MagicMock import" | Re-trigger Greptile

Comment thread tests/services/tracer_client/test_tracer_tools.py Outdated
Comment thread tests/services/tracer_client/test_tracer_tools.py Outdated
Comment thread tests/services/tracer_client/test_tracer_tools.py Outdated
Comment thread tests/services/tracer_client/test_tracer_tools.py Outdated
Comment thread tests/services/tracer_client/test_tracer_tools.py Fixed
@gitsofaryan
Copy link
Copy Markdown
Contributor Author

@greptileai

@muddlebee
Copy link
Copy Markdown
Collaborator

@gitsofaryan thank you. Looks good!

@muddlebee muddlebee merged commit 7a9d8e7 into Tracer-Cloud:main Apr 28, 2026
7 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.

Add direct unit tests for app/services/tracer_client/tracer_tools.py

3 participants