Skip to content

feat: Add analytics opt-out environment variable tests (#1118)#1189

Merged
muddlebee merged 2 commits intoTracer-Cloud:mainfrom
Diwansu-pilania:feature/analytics-opt-out-tests
May 2, 2026
Merged

feat: Add analytics opt-out environment variable tests (#1118)#1189
muddlebee merged 2 commits intoTracer-Cloud:mainfrom
Diwansu-pilania:feature/analytics-opt-out-tests

Conversation

@Diwansu-pilania
Copy link
Copy Markdown
Contributor

@Diwansu-pilania Diwansu-pilania commented May 1, 2026

#1118

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:
The core problem addressed is to guarantee that the OpenSRE CLI respects user preferences for analytics opt-out, which is crucial for privacy and compliance. The chosen approach involves adding dedicated unit tests to tests/analytics/test_provider.py. These tests simulate scenarios where users have opted out via OPENSRE_ANALYTICS_DISABLED=1 or DO_NOT_TRACK=1 environment variables. For each scenario, the tests instantiate the Analytics provider and assert that its internal _disabled flag is set to True. Furthermore, they verify that calling the capture() method does not enqueue or send any events, ensuring no analytics data is transmitted. This approach provides robust, deterministic validation of the opt-out functionality without making network calls, aligning with the requirements outlined in issue #1118.


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

Note: Please check Allow edits from maintainers if you would like us to assist in the PR.

@greptile-apps
Copy link
Copy Markdown
Contributor

greptile-apps Bot commented May 1, 2026

Greptile Summary

This PR adds two unit tests verifying that Analytics is disabled when OPENSRE_ANALYTICS_DISABLED=1 or DO_NOT_TRACK=1 are set, correctly asserting both the _disabled flag and that capture() does not enqueue events. The test logic is sound and the monkeypatch usage ensures proper isolation, but two formatting issues will block CI: duplicate imports (from app.analytics import provider and from app.analytics.events import Event on lines 76–77 are already imported at the top) and a missing trailing newline, both caught by ruff.

Confidence Score: 4/5

Safe to merge after fixing the duplicate imports and trailing newline, which will otherwise cause ruff CI checks to fail.

All findings are P2 style issues, but the duplicate imports will cause a concrete ruff check (F811) failure and the missing newline will fail ruff format --check — both of which block CI per the project's quality standards.

tests/analytics/test_provider.py — duplicate imports and missing trailing newline need to be removed/added before CI passes.

Important Files Changed

Filename Overview
tests/analytics/test_provider.py Adds two tests for analytics opt-out via env vars; duplicate imports and a missing trailing newline will cause ruff lint/format checks to fail in CI.

Sequence Diagram

sequenceDiagram
    participant Test
    participant monkeypatch
    participant Analytics
    participant Queue

    Test->>monkeypatch: setenv("OPENSRE_ANALYTICS_DISABLED", "1")
    Test->>Analytics: Analytics()
    Analytics->>Analytics: _is_opted_out() → True
    Analytics-->>Test: instance (_disabled=True)
    Test->>Analytics: capture(Event.INSTALL_DETECTED)
    Analytics->>Analytics: _disabled check → return early
    Analytics-->>Queue: (no enqueue)
    Test->>Queue: assert _queue.empty() ✓
Loading

Reviews (1): Last reviewed commit: "feat: Add analytics opt-out environment ..." | Re-trigger Greptile

Comment thread tests/analytics/test_provider.py Outdated
Comment thread tests/analytics/test_provider.py Outdated
@muddlebee
Copy link
Copy Markdown
Collaborator

@Diwansu-pilania pls follow the contribution guidlines properly lile linking the issue to the PR etc.

@muddlebee muddlebee merged commit e476f52 into Tracer-Cloud:main May 2, 2026
10 checks passed
@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented May 2, 2026

🧑‍💻 @Diwansu-pilania has entered the contributor hall of fame. Merged. Done. Shipped. Go touch grass (then come back with another PR). 🌱


👋 Join us on Discord - OpenSRE : hang out, contribute, or hunt for features and issues. Everyone's welcome.

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