feat: Add analytics opt-out environment variable tests (#1118)#1189
Conversation
Greptile SummaryThis PR adds two unit tests verifying that Confidence Score: 4/5Safe 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
Sequence DiagramsequenceDiagram
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() ✓
Reviews (1): Last reviewed commit: "feat: Add analytics opt-out environment ..." | Re-trigger Greptile |
|
@Diwansu-pilania pls follow the contribution guidlines properly lile linking the issue to the PR etc. |
|
🧑💻 @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. |

#1118
Code Understanding and AI Usage
Did you use AI assistance (ChatGPT, Claude, Copilot, etc.) to write any part of this code?
If you used AI assistance:
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 viaOPENSRE_ANALYTICS_DISABLED=1orDO_NOT_TRACK=1environment variables. For each scenario, the tests instantiate theAnalyticsprovider and assert that its internal_disabledflag is set toTrue. Furthermore, they verify that calling thecapture()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
Note: Please check Allow edits from maintainers if you would like us to assist in the PR.