Skip to content

Add tracer integration service tests#1035

Merged
muddlebee merged 4 commits intoTracer-Cloud:mainfrom
rameshkumarkoyya:issue/891-tracer-integrations-tests
Apr 28, 2026
Merged

Add tracer integration service tests#1035
muddlebee merged 4 commits intoTracer-Cloud:mainfrom
rameshkumarkoyya:issue/891-tracer-integrations-tests

Conversation

@rameshkumarkoyya
Copy link
Copy Markdown
Contributor

Fixes #891

Describe the changes you have made in this PR -

Added direct unit tests for app/services/tracer_client/tracer_integrations.py in:

  • tests/services/tracer_client/test_tracer_integrations.py

The new coverage includes:

  • a fake DummyTracerClient subclass that stubs _get()
  • direct tests for get_integration_credentials()
  • direct tests for get_all_integrations()
  • direct tests for get_grafana_credentials()

The tests specifically cover:

  • JSON credential parsing when credentials are stored as a string
  • preserving credentials when they are already a dict
  • malformed JSON fallback to an empty dict
  • active Grafana integration preference over inactive records
  • request parameter construction for integration fetches

Demo/Screenshot for feature changes and bug fixes -

Terminal proof:

  • ruff check tests/services/tracer_client/test_tracer_integrations.py passed
  • branch pushed successfully: issue/891-tracer-integrations-tests

Note: full local project validation was limited in this environment because the available machine runtime is Python 3.9, while this repository targets Python 3.11+.


Code Understanding and AI Usage

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

  • No, I wrote all the code myself
  • Yes, I used AI assistance (continue below)

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:
This PR adds direct unit coverage for TracerIntegrationsMixin, which contains JSON parsing and integration selection logic that should not regress.

I followed the existing service test style used under tests/services/tracer_client/ and created a minimal fake client that stubs _get() while recording the endpoint and params passed to it. This keeps the tests focused on the mixin behavior rather than HTTP details.

The implementation covers the three methods requested in the issue:

  • get_integration_credentials() verifies service filtering and empty-result behavior
  • get_all_integrations() verifies JSON string parsing, dict preservation, and malformed JSON fallback
  • get_grafana_credentials() verifies active-record preference and malformed JSON handling for Grafana credentials

The tests are intentionally narrow and direct so they document the service contract clearly and protect the parsing/selection logic from regressions.


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

@greptile-apps
Copy link
Copy Markdown
Contributor

greptile-apps Bot commented Apr 28, 2026

Greptile Summary

Adds direct unit tests for TracerIntegrationsMixin covering JSON credential parsing, dict preservation, malformed JSON fallback, and active-integration preference — all correct and matching the source's behaviour. All three findings are non-blocking P2 style suggestions.

Confidence Score: 5/5

Safe to merge; all existing tests are logically correct and no production code is changed.

All findings are P2: missing coverage paths, a mutable-reference fragility that doesn't affect current runs, and an unscoped caplog. None represent present defects or broken behaviour.

No files require special attention.

Important Files Changed

Filename Overview
tests/services/tracer_client/test_tracer_integrations.py New test file covering the three TracerIntegrationsMixin methods; tests are correct and pass, but missing coverage for get_grafana_credentials(found=False) and the all-inactive fallback path, _payload is returned by mutable reference, and caplog is not scoped to the specific logger.

Sequence Diagram

sequenceDiagram
    participant Test
    participant DummyTracerClient
    participant TracerIntegrationsMixin

    Test->>DummyTracerClient: get_integration_credentials("Grafana")
    DummyTracerClient->>TracerIntegrationsMixin: delegates (mixin)
    TracerIntegrationsMixin->>DummyTracerClient: _get("/api/integrations", {orgId, service})
    DummyTracerClient-->>TracerIntegrationsMixin: _payload (by reference)
    TracerIntegrationsMixin-->>Test: list[dict] or []

    Test->>DummyTracerClient: get_all_integrations()
    DummyTracerClient->>TracerIntegrationsMixin: delegates (mixin)
    TracerIntegrationsMixin->>DummyTracerClient: _get("/api/integrations", {orgId})
    DummyTracerClient-->>TracerIntegrationsMixin: _payload (by reference, mutated in-place)
    TracerIntegrationsMixin-->>Test: list[dict] with parsed credentials

    Test->>DummyTracerClient: get_grafana_credentials()
    DummyTracerClient->>TracerIntegrationsMixin: delegates (mixin)
    TracerIntegrationsMixin->>TracerIntegrationsMixin: get_integration_credentials("Grafana")
    TracerIntegrationsMixin->>DummyTracerClient: _get("/api/integrations", {orgId, service})
    DummyTracerClient-->>TracerIntegrationsMixin: _payload
    TracerIntegrationsMixin-->>Test: GrafanaIntegrationCredentials
Loading

Reviews (1): Last reviewed commit: "Format tracer integration service tests" | Re-trigger Greptile

Comment thread tests/services/tracer_client/test_tracer_integrations.py
Comment thread tests/services/tracer_client/test_tracer_integrations.py Outdated
Comment thread tests/services/tracer_client/test_tracer_integrations.py
Copy link
Copy Markdown
Contributor Author

Addressed the review feedback.

Changes made:

  • added coverage for get_grafana_credentials() when no integrations are returned
  • added coverage for the fallback path when no Grafana integration is active
  • updated the fake client to return a deep copy of _payload so tests are not coupled to in-place mutation
  • scoped caplog to app.services.tracer_client.tracer_integrations for more precise warning assertions

Comment thread tests/services/tracer_client/test_tracer_integrations.py Fixed
@muddlebee
Copy link
Copy Markdown
Collaborator

@rameshkumarkoyya nicely done. let use check the CI run then if its green, ready to merge

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

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_integrations.py

3 participants