Skip to content

Conversation

@samuv
Copy link
Contributor

@samuv samuv commented Jan 30, 2026

Summary

Add CLI validation to detect when ToolHive Desktop manages CLI installation, preventing version conflicts that cause API incompatibilities.

When the Desktop app installs the CLI, it creates a marker file at ~/.toolhive/.cli-source. This PR adds validation that runs before every CLI command to detect conflicts between standalone CLI and Desktop-managed installations.

Validation Flow

flowchart TD
    A[CLI Command Invoked] --> B[Read ~/.toolhive/.cli-source]
    B -->|Not Found| C[Proceed Normally]
    B -->|Found| D[Check symlink_target exists]
    D -->|Missing| C
    D -->|Exists| E{Current CLI matches target?}
    E -->|Yes| C
    E -->|No| F[Hard Stop with Error]
Loading

Key Changes

  • New pkg/desktop/ package - Types, marker file reading, and validation logic
  • Root command integration - PersistentPreRunE hook validates desktop alignment before every command
  • Skip override - TOOLHIVE_SKIP_DESKTOP_CHECK=1 bypasses validation for debugging

Scenarios Handled

Scenario Behavior
No marker file Proceed normally
Marker exists, target binary missing Proceed (Desktop uninstalled, stale marker)
Marker exists, current CLI matches target Proceed (we are the Desktop CLI)
Marker exists, current CLI differs Hard stop with actionable error

Related

Large PR Justification

  • e2e tests and unit tests
  • new module

@github-actions github-actions bot added the size/XL Extra large PR: 1000+ lines changed label Jan 30, 2026
Copy link
Contributor

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Large PR Detected

This PR exceeds 1000 lines of changes and requires justification before it can be reviewed.

How to unblock this PR:

Add a section to your PR description with the following format:

## Large PR Justification

[Explain why this PR must be large, such as:]
- Generated code that cannot be split
- Large refactoring that must be atomic
- Multiple related changes that would break if separated
- Migration or data transformation

Alternative:

Consider splitting this PR into smaller, focused changes (< 1000 lines each) for easier review and reduced risk.

See our Contributing Guidelines for more details.


This review will be automatically dismissed once you add the justification section.

@codecov
Copy link

codecov bot commented Jan 30, 2026

Codecov Report

❌ Patch coverage is 73.80952% with 33 lines in your changes missing coverage. Please review.
✅ Project coverage is 65.53%. Comparing base (fa56a01) to head (724b170).
⚠️ Report is 3 commits behind head on main.

Files with missing lines Patch % Lines
pkg/desktop/validation.go 71.73% 18 Missing and 8 partials ⚠️
pkg/desktop/marker.go 79.41% 4 Missing and 3 partials ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #3535      +/-   ##
==========================================
- Coverage   65.54%   65.53%   -0.01%     
==========================================
  Files         404      406       +2     
  Lines       39873    39999     +126     
==========================================
+ Hits        26133    26212      +79     
- Misses      11715    11756      +41     
- Partials     2025     2031       +6     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@github-actions github-actions bot added size/XL Extra large PR: 1000+ lines changed and removed size/XL Extra large PR: 1000+ lines changed labels Jan 30, 2026
@samuv samuv force-pushed the feat/cli-desktop-validation branch from 26b6c82 to 688cf25 Compare February 2, 2026 10:55
@github-actions github-actions bot added size/XL Extra large PR: 1000+ lines changed and removed size/XL Extra large PR: 1000+ lines changed labels Feb 2, 2026
@samuv samuv force-pushed the feat/cli-desktop-validation branch from 3efd173 to 2003b23 Compare February 3, 2026 09:31
@github-actions github-actions bot added size/XL Extra large PR: 1000+ lines changed and removed size/XL Extra large PR: 1000+ lines changed labels Feb 3, 2026
@samuv samuv marked this pull request as ready for review February 3, 2026 09:57
@samuv samuv force-pushed the feat/cli-desktop-validation branch from 2003b23 to f0f52e0 Compare February 3, 2026 10:20
@github-actions github-actions bot added size/XL Extra large PR: 1000+ lines changed and removed size/XL Extra large PR: 1000+ lines changed labels Feb 3, 2026
@github-actions github-actions bot dismissed their stale review February 3, 2026 10:21

Large PR justification has been provided. Thank you!

@github-actions
Copy link
Contributor

github-actions bot commented Feb 3, 2026

✅ Large PR justification has been provided. The size review has been dismissed and this PR can now proceed with normal review.

@github-actions github-actions bot added size/XL Extra large PR: 1000+ lines changed and removed size/XL Extra large PR: 1000+ lines changed labels Feb 3, 2026
@samuv samuv force-pushed the feat/cli-desktop-validation branch from ebc4c19 to 4dfa8c1 Compare February 3, 2026 15:39
@github-actions github-actions bot added size/XL Extra large PR: 1000+ lines changed and removed size/XL Extra large PR: 1000+ lines changed labels Feb 3, 2026
@github-actions github-actions bot added size/XL Extra large PR: 1000+ lines changed and removed size/XL Extra large PR: 1000+ lines changed labels Feb 3, 2026
@samuv samuv force-pushed the feat/cli-desktop-validation branch from ab12a43 to 4316a0e Compare February 3, 2026 17:45
@github-actions github-actions bot added size/XL Extra large PR: 1000+ lines changed and removed size/XL Extra large PR: 1000+ lines changed labels Feb 3, 2026
@samuv
Copy link
Contributor Author

samuv commented Feb 3, 2026

@dmjb I think I’ve addressed your feedback on keeping anything that doesn’t need to be shared private

samuv and others added 8 commits February 4, 2026 10:03
Add pkg/desktop/ package to detect and validate when ToolHive Desktop
manages CLI installation via marker file at ~/.toolhive/.cli-source.

- types.go: CliSourceMarker and ValidationResult structs
- marker.go: marker file reading and path utilities
- validation.go: path comparison and conflict detection logic

Related to: toolhive-studio#1512
RFC: THV-0020
Add PersistentPreRunE hook to validate desktop alignment before
every CLI command. Returns hard stop error when conflict detected
between standalone CLI and Desktop-managed installation.
- Unit tests for marker file parsing, path comparison, symlink resolution
- E2E tests for conflict scenarios, stale markers, and skip override
- Simplify if-return in commands.go (revive)
- Add gosec nolint for marker file read (G304)
- Add paralleltest nolint for tests that modify HOME env
- Add goconst nolint for platform checks
- Fix gci import ordering and struct formatting
Add additional unit tests to improve coverage from ~70% to ~87%:
- Test MarkerFileExists() function
- Test ReadMarkerFile() function
- Test GetMarkerFilePath() function
- Test ValidateDesktopAlignment() with actual conflict
- Test CheckDesktopAlignment() with copy method
- Test buildConflictMessage() without desktop version
- Test ReadMarkerFileFromPath() with read error
- Test resolvePath() with relative paths
- Test pathsEqual() on both case-sensitive and case-insensitive platforms

Remaining uncovered lines are OS error paths that require mocking.
@samuv samuv force-pushed the feat/cli-desktop-validation branch from 4316a0e to 724b170 Compare February 4, 2026 09:03
@github-actions github-actions bot added size/XL Extra large PR: 1000+ lines changed and removed size/XL Extra large PR: 1000+ lines changed labels Feb 4, 2026
@samuv samuv self-assigned this Feb 4, 2026
@samuv samuv linked an issue Feb 4, 2026 that may be closed by this pull request
@samuv samuv merged commit 60ecf3f into main Feb 4, 2026
37 of 39 checks passed
@samuv samuv deleted the feat/cli-desktop-validation branch February 4, 2026 10:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size/XL Extra large PR: 1000+ lines changed

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add CLI validation for Desktop app alignment

3 participants