Skip to content

Corrección: fix(cli): refuse relative --target-dir in doctor, update, and uninstall (#388) #390

Closed

Description

@barbatdev

Source PR: #388
Branch: fix/target-dir-shared-validation
Head reviewed: 1227271

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

  • Issue doctor --target-dir accepts relative paths while install refuses them as invalid_target #372 criterion satisfied only for relative/unclean targets; doctor and update still accept absolute targets install refuses as invalid_target (internal/cli/doctor.go:122): Issue doctor --target-dir accepts relative paths while install refuses them as invalid_target #372's Expected direction is explicit: 'a target that install would refuse as invalid_target should be refused the same way by every command that consumes --target-dir, so the directory-target contract stays consistent across the CLI.' At the reviewed head the shared guard validTargetDir (install.go:102) checks only path form (absolute + clean). install additionally refuses any absolute target that is missing or not a directory as error=invalid_target, exit 64 (install.go:119-121). doctor still forwards such a target at doctor.go:122 and reports presence=absent with exit 0 (doctor.go:134); a regular file yields presence=unreadable with exit 3 (exitConflict). update still stats the path at update.go:243 and returns reason=target_absent with exit 2 (writeUpdateRefusal returns exitUnknown=2). docs/operating.md:81, untouched by this PR, documents install's refusal set as 'the path is missing, relative, or not a directory', while the sentence added by this PR at docs/operating.md:82 claims only 'a relative or unclean --target-dir' is refused by doctor, update, and uninstall - the PR narrows the stated scope without reconciling it with the issue criterion or listing it under its Out of Scope section. The new test TestDirectoryTargetCommandsRefuseRelativeTargets exercises only relative and unclean targets, so the divergence is covered by no assertion. Note for triage: doctor's documented contract (docs/operating.md table) is to report a directory target's presence, so the issue criterion as written and the preserved presence=absent behavior are in tension - the intended scope needs an explicit decision rather than the silent narrowing.
    • Failure scenario: Given the absolute path /abs/missing that does not exist: cortex install --target-dir /abs/missing exits 64 with stderr error=invalid_target, but cortex doctor --target-dir /abs/missing exits 0 with stdout target=/abs/missing presence=absent, and cortex update --target-dir /abs/missing --catalog <catalog> --apply exits 2 with stdout ending reason=target_absent - none of them refuses the target the way install would, contradicting the quoted criterion. Given an absolute path that is a regular file: install exits 64 error=invalid_target, doctor exits 3 presence=unreadable, update exits 2 reason=target_absent. The commands still disagree on what a valid target is, which is the exact inconsistency doctor --target-dir accepts relative paths while install refuses them as invalid_target #372 reports.

Acceptance criteria

  • Fixed: Issue doctor --target-dir accepts relative paths while install refuses them as invalid_target #372 criterion satisfied only for relative/unclean targets; doctor and update still accept absolute targets install refuses as invalid_target (internal/cli/doctor.go:122). The scenario below no longer reproduces: Given the absolute path /abs/missing that does not exist: cortex install --target-dir /abs/missing exits 64 with stderr error=invalid_target, but cortex doctor --target-dir /abs/missing exits 0 with stdout target=/abs/missing presence=absent, and cortex update --target-dir /abs/missing --catalog <catalog> --apply exits 2 with stdout ending reason=target_absent - none of them refuses the target the way install would, contradicting the quoted criterion. Given an absolute path that is a regular file: install exits 64 error=invalid_target, doctor exits 3 presence=unreadable, update exits 2 reason=target_absent. The commands still disagree on what a valid target is, which is the exact inconsistency doctor --target-dir accepts relative paths while install refuses them as invalid_target #372 reports.

Activity

  1. barbatjuan commented on Oct 24, 2026

    @barbatjuan
    Contributor

    Status at head ccf3ebf of #388: relative, unclean, trailing-separator, and empty targets are now refused as invalid_target (exit 64) by every --target-dir command. The remaining item here needs your ruling before I change code, because two of your own texts point in different directions:

    Today, with the built binary at ccf3ebf:

    Absolute target install doctor update uninstall
    missing exit 64 invalid_target exit 0 presence=absent exit 2 reason=target_absent exit 0 not_installed
    regular file exit 64 invalid_target exit 3 presence=unreadable exit 2 reason=target_absent exit 70 uninstall_observation_failed

    Options:

    1. Keep it as is, and narrow doctor --target-dir accepts relative paths while install refuses them as invalid_target #372's wording to the path form.
    2. Make update refuse a missing or non-directory target as invalid_target (it has nothing to update), and keep doctor's presence report. This is my recommendation.
    3. Make doctor and update both refuse, as written here. doctor would then never report presence=absent, so its feat: report directory targets in cortex doctor #343 contract and docs change too.

    Once you pick one, I'll push it to fix/target-dir-shared-validation with tests and docs, and fold in the remaining non-blocking suggestions from the latest reviews in the same push (fixture outside the source tree, a duplicate-flag subtest, a runtime-mode control case, and refusing the contradictory --runtime "" --target-dir <dir>).

  2. barbatdev commented on Nov 12, 2026

    @barbatdev
    ContributorAuthor

    Maintainer decision (option 2): update --target-dir refuses an absolute target that is missing or not a directory as invalid_target (exit 64), the same as install. doctor keeps reporting presence=absent without refusing. Note: #358 (PR #430) makes uninstall --target-dir on a missing root fail closed (exit 3); #388 must be rebased on it and keep both behaviors.

  3. barbatdev commented on Nov 12, 2026

    @barbatdev
    ContributorAuthor

    Implemented on #388 in 79102df (option 2).

  4. barbatdev commented on Nov 12, 2026

    @barbatdev
    ContributorAuthor

    Implemented by #388 (merged 46f2870): update --target-dir refuses a missing or non-directory absolute target as invalid_target, exit 64. doctor keeps presence=absent, exit 0. uninstall keeps exit 3 from #358. Covered by TestUpdateDirectoryTargetRefusesMissingOrNonDirectory and TestDoctorDirectoryTargetReportsMissingAsAbsent.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions