Skip to content

Corrección: feat(doctor): report directory target presence, writability, and ownership (#355) #360

Closed

Description

@barbatdev

Source PR: #355
Branch: feat/issue-343-doctor
Head reviewed: 1202f79

Push the fixes to the branch above; do not open a new pull request. Comment on the PR and on this issue when done.

Blocking findings

  • An empty --target-dir value is treated as "flag absent" and silently selects the canonical-roots mode (internal/cli/doctor.go): Both new dispatchers parse --target-dir by assigning targetDir = args[index+1] and then branch on if targetDir == "", but "" is also the sentinel for "no flag was given". A caller passing an empty value — the ordinary case of an unset shell variable — therefore lands in the wrong mode instead of being refused with error=invalid_target (exit 64, as the stack's own docs promise for a missing path). runUninstallCommand is the dangerous one: it falls through to runUninstall, which resolves and uninstalls every canonical root. The fix is a separate seen boolean (the pattern update.go's parseUpdateArgs already avoids by rejecting an empty value in the same branch), so an empty value fails closed.
    • Failure scenario: An operator runs cortex uninstall --target-dir "$SKILLS_DIR" in a shell where SKILLS_DIR is unset. args = ["--target-dir", ""], targetDir stays "", the if targetDir == "" branch calls runUninstall, and the command removes every verified Cortex-owned file from the pi, opencode and claude-code canonical roots — three installations the operator never named. cortex doctor --target-dir "$SKILLS_DIR" with the same unset variable prints the host runtimematrix and exits 0, so an automation precheck reports a healthy target it never inspected. Neither path is reachable by the tests, which only pass a non-empty directory.

Acceptance criteria

  • Fixed: An empty --target-dir value is treated as "flag absent" and silently selects the canonical-roots mode (internal/cli/doctor.go). The scenario below no longer reproduces: An operator runs cortex uninstall --target-dir "$SKILLS_DIR" in a shell where SKILLS_DIR is unset. args = ["--target-dir", ""], targetDir stays "", the if targetDir == "" branch calls runUninstall, and the command removes every verified Cortex-owned file from the pi, opencode and claude-code canonical roots — three installations the operator never named. cortex doctor --target-dir "$SKILLS_DIR" with the same unset variable prints the host runtimematrix and exits 0, so an automation precheck reports a healthy target it never inspected. Neither path is reachable by the tests, which only pass a non-empty directory.

Activity

  1. added
    status:approved
    on Oct 21, 2026
  2. barbatdev commented on Nov 12, 2026

    @barbatdev
    ContributorAuthor

    Fixed by #388 (merged 46f2870): an empty --target-dir is refused as invalid_target (exit 64) for install, doctor, update and uninstall, without touching the directory or canonical roots. Covered by TestDirectoryTargetCommandsRefuseRelativeTargets (directory_lifecycle_test.go:224, plus the duplicate-flag case at :332), which passes on main.

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

    fleet-qastatus:approved

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions