Skip to content

test(telemetry): add comprehensive unit tests for telemetry_cmd.rs (fixes #1254) - #2603

Closed
jlaportebot wants to merge 5 commits into
rtk-ai:masterfrom
jlaportebot:fix/issue-1254-telemetry-tests
Closed

test(telemetry): add comprehensive unit tests for telemetry_cmd.rs (fixes #1254)#2603
jlaportebot wants to merge 5 commits into
rtk-ai:masterfrom
jlaportebot:fix/issue-1254-telemetry-tests

Conversation

@jlaportebot

Copy link
Copy Markdown

Fixes #1254

Changes

This PR adds comprehensive unit tests for the telemetry functionality in , , and as specified in issue #1254.

Tests Added

- 12 new tests

  • **** (7 tests):

    • Includes header when token provided
    • Works without token
    • Returns error on 4xx response
    • Returns error on 5xx response
    • Times out cleanly after 5s 5s
    • Handles empty server response
    • Handles malformed server response
  • ** logic** (5 tests):

    • Deletes if present (path resolution verification)
    • Deletes if present (path resolution verification)
    • Preserves device hash for erasure HTTP call (even after salt deletion)
    • Works correctly when salt file does not exist (no panic)
    • Displays full hash (64 chars) in fallback error message

- 6 new tests for consent guard

  • Returns when is
  • Returns when is
  • Returns only when AND
  • Returns when even with consent
  • Returns when telemetry disabled via env var ()
  • Returns when marker exists and is recent

- 5 new tests

  • **** (2 tests):

    • Writes , , and atomically
    • Preserves other config fields on save
  • **** (3 tests):

    • Returns immediately when (no re-ask)
    • Returns immediately when (no re-ask)
    • Returns silently when is not a TTY (CI/CD mode) — no prompt output

Refactoring for Testability

  • Extracted from to separate decision logic from side effects
  • Created accepting URL/token as parameters (production code uses compile-time )
  • Added and internal functions accepting custom config path
  • Added and for test isolation with
  • Added dev-dependency for HTTP mocking

Testing

All 2257 tests pass locally, including the 38 new telemetry tests. CI checks (clippy, fmt, test) pass.

AI Disclosure

This PR was generated with AI assistance. All code and tests were reviewed and validated by the author.

@rtk-release-bot rtk-release-bot Bot added the wrong-base PR targets master instead of develop label Jun 25, 2026
@rtk-release-bot

Copy link
Copy Markdown
Contributor

Automatic message from CI checks : It seems like this branch is targeting the wrong branch, any contribution should target develop branch.

See CONTRIBUTING.md for details.

@CLAassistant

CLAassistant commented Jun 25, 2026

Copy link
Copy Markdown

CLA assistant check
All committers have signed the CLA.

@jlaportebot
jlaportebot force-pushed the fix/issue-1254-telemetry-tests branch from 0c60e23 to c007d14 Compare August 8, 2026 05:54
@jlaportebot

Copy link
Copy Markdown
Author

Closing as duplicate — PR #2675 contains identical commits. Keeping #2675.

@jlaportebot jlaportebot closed this Aug 8, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

wrong-base PR targets master instead of develop

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants