Skip to content

test(telemetry_cmd): add unit tests for telemetry subcommands - #1270

Closed
a22407332FilipeMonteiro wants to merge 1 commit into
rtk-ai:developfrom
a22407332FilipeMonteiro:develop
Closed

a22407332FilipeMonteiro wants to merge 1 commit into
rtk-ai:developfrom
a22407332FilipeMonteiro:develop

Conversation

@a22407332FilipeMonteiro

Copy link
Copy Markdown

Closes #1254

Description

This PR adds unit tests for src/core/telemetry_cmd.rs, as requested in #1254 (follow-up from #1181).

Given the GDPR sensitivity of this code path, the goal was to cover the core behaviours of the telemetry subcommands with isolated, deterministic tests.

Tests added

save_telemetry_consent

  • test_save_consent_accepted_sets_correct_fields — verifies that consent_given, enabled, and consent_date are correctly set when consent is accepted
  • test_save_consent_rejected_sets_correct_fields — verifies the same fields are correctly set when consent is rejected

run_forget

  • test_run_forget_deletes_salt_if_present — verifies that .device_salt is deleted when present
  • test_run_forget_no_panic_when_salt_missing — verifies no panic occurs when salt file does not exist
  • test_run_forget_deletes_history_db_if_present — verifies that history.db is deleted when present

send_erasure_request

  • test_send_erasure_request_fails_without_url — verifies that the function returns an error with a clear message when no telemetry endpoint is configured at compile time

Notes

Some tests described in #1254 (HTTP mocking, TTY detection) require the code to be structured differently to be fully testable (e.g. injectable config paths, mockable HTTP client). These are not included in this PR to avoid scope creep, but could be addressed in a follow-up if the maintainers want to refactor those paths.

After adding and testing the new tests, i also tested the existing tests and all 1452 existing tests continue to pass.

@pszymkowiak pszymkowiak added the effort-small Quelques heures, 1 fichier label Apr 13, 2026
@pszymkowiak

Copy link
Copy Markdown
Collaborator

[w] wshm · Automated triage by AI

📊 Automated PR Analysis

🔧 Type chore
🟢 Risk low

Summary

Adds unit tests for telemetry subcommands in telemetry_cmd.rs, covering consent saving, the forget/erasure flow, and error handling when no telemetry endpoint is configured. However, several tests don't actually call the functions under test — they manually replicate the logic inline, which significantly reduces their value as regression tests.

Review Checklist

  • Tests present
  • Breaking change
  • Docs updated

Linked issues: #1254


Analyzed automatically by wshm · This is an automated analysis, not a human review.

@CLAassistant

CLAassistant commented Apr 13, 2026 •

Copy link
Copy Markdown

CLA assistant check
All committers have signed the CLA.

@a22407332FilipeMonteiro

Copy link
Copy Markdown
Author

Thanks for the automated analysis — the feedback is fair.

The run_forget tests don't call the function directly because run_forget() relies on hardcoded paths via dirs::data_local_dir() and the RTK_DATA_DIR / HISTORY_DB constants, with no way to inject a custom path for testing. Calling it directly in tests would risk touching real system files.

To fix this properly, run_forget() would need to accept the paths as parameters (or use an injectable config), which is a small refactor of the production code.

Happy to do that refactor if you'd like — just wanted to check before touching the production code without maintainer input.

@a22407332FilipeMonteiro

Copy link
Copy Markdown
Author

Hi! Just following up on this PR — happy to make any changes if needed. Let me know if you'd like me to address the inline logic issue flagged by the automated analysis, or if there's anything else to adjust. Thanks!

@rtk-release-bot

Copy link
Copy Markdown
Contributor

This pull request has been automatically marked as stale due to 90 days of inactivity. If this pull request is still relevant, please leave any comment (for example, "bump"), and we'll keep it open. Your contribution is very much appreciated — we're sorry we haven't been able to review it yet.

@rtk-release-bot rtk-release-bot Bot added the stale label Sep 3, 2026
@KuSh

KuSh commented Sep 6, 2026

Copy link
Copy Markdown
Collaborator

Closing in favour of #2880, which covers the same issue with tests that call the telemetry functions directly. The tests here assert on values set inside the test body rather than on anything run_forget or save_telemetry_consent does, so they would still pass with that code removed. If there is a case you wanted covered that #2880 misses, please raise it there.

@KuSh KuSh closed this Sep 6, 2026
@KuSh KuSh added the duplicate This issue or pull request already exists label Sep 6, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

duplicate This issue or pull request already exists effort-small Quelques heures, 1 fichier stale

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add unit tests for telemetry_cmd.rs (follow-up from #1181)

4 participants