Skip to content

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

Open

Description

@pszymkowiak

Context

Follow-up from #1181 which added the new rtk telemetry {status|enable|disable|forget} subcommands implementing GDPR consent and erasure flow.

The implementation in src/core/telemetry_cmd.rs (~165 lines) merged without unit tests. Given the sensitivity of the code path (consent management, data erasure, GDPR compliance), this should be addressed before the next release.

Scope

At minimum, the following tests should be added:

maybe_ping() consent guard

  • Returns no-op when consent_given is None
  • Returns no-op when consent_given is Some(false)
  • Only sends when consent_given == Some(true) AND enabled == true

send_erasure_request()

  • Includes the X-RTK-Token header when RTK_TELEMETRY_TOKEN is set at compile time
  • Returns error on 4xx/5xx HTTP response
  • Times out cleanly after 5s
  • Handles empty/malformed server response

run_forget()

  • Deletes .device_salt if present
  • Deletes history.db if present
  • Preserves device hash for erasure HTTP call (even after salt deletion)
  • Displays full hash (not truncated) in fallback error message
  • Works correctly when salt file does not exist (no panic)

prompt_telemetry_consent()

  • Returns Ok(()) immediately when consent_given == Some(true) or Some(false) (no re-ask)
  • Returns Ok(()) silently when stdin is not a TTY (CI/CD mode) — no prompt output
  • Only prompts when consent_given == None AND TTY is interactive

save_telemetry_consent()

  • Writes consent_given, consent_date, and enabled atomically
  • Preserves other config fields on save

Notes

  • Follow the pattern in src/core/tracking.rs::tests for DB fixture setup.
  • Use a TempDir for isolation and point RTK_DATA_DIR at it for tests that touch the filesystem.
  • Mock HTTP with a simple local server (or use the approach already used elsewhere in the codebase if one exists).

Priority: medium — the code is working correctly (manually verified during #1181 review), but regression risk is high given GDPR implications.

Activity

  1. added
    bug
    effort-small
    effort-medium
    enhancement
    good first issue
    on Apr 12, 2026
  2. pszymkowiak commented on Apr 12, 2026

    @pszymkowiak
    CollaboratorAuthor

    wshm · Automated triage by AI

    🔍 Automated Triage

    ✨ Category feature
    🟡 Priority medium
    🎯 Confidence 88%

    Summary

    Well-scoped request to add unit tests for telemetry_cmd.rs (GDPR consent/erasure); PR #1270 already in progress — monitor for completion and watch #2106 for a related regression introduced by that PR.

    📁 Relevant files
    • src/core/telemetry_cmd.rs
    • src/core/tracking.rs

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

  3. a22407332FilipeMonteiro commented on Apr 13, 2026

    @a22407332FilipeMonteiro

    Hi! I'd like to work on this issue.

    Could you assign this to me? I'll have a draft PR up shortly.

  4. added 3 commits that reference this issue on Jun 27, 2026
    6bb1997
    f5256f0
    45036ab
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    area:testingbugeffort-mediumeffort-smallenhancementgood first issuehelp wantedpriority:medium

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions