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

samuv added 3 commits January 30, 2026 18:07
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
@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.

- 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
@codecov
Copy link

codecov bot commented Jan 30, 2026

Codecov Report

❌ Patch coverage is 69.91150% with 34 lines in your changes missing coverage. Please review.
✅ Project coverage is 65.38%. Comparing base (d3c579d) to head (26b6c82).

Files with missing lines Patch % Lines
pkg/desktop/validation.go 75.94% 11 Missing and 8 partials ⚠️
pkg/desktop/marker.go 55.88% 13 Missing and 2 partials ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #3535      +/-   ##
==========================================
+ Coverage   65.34%   65.38%   +0.04%     
==========================================
  Files         403      405       +2     
  Lines       39206    39319     +113     
==========================================
+ Hits        25618    25709      +91     
- Misses      11607    11614       +7     
- Partials     1981     1996      +15     

☔ 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
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.

2 participants