Skip to content

refactor(security): tools are found on PATH and not in tools.lock #4362

Closed as not planned

Description

@dan-petty

Problem

Product code finds some tools through the installer folder of devops install-tools and not through PATH. DEFAULT_LOCAL_BIN_DIR (~/.local/bin) comes first in the search path of the review resolvers of ruff and semgrep (_default_ruff_block_checker in review/analysis.py, _resolve_semgrep_binary in review/rules_pack.py). infra/ansible_facts.py:68-80 also looks in the installer folder first. When an image or a package manager installs a tool in another folder, the lookup misses it or finds a different copy.

Owner decision of 2026-11-19: every tool comes from the devtools image (dan-petty/devtools#1) on PATH, and #4363 removes the installer.

Change

  • Product code finds each tool with shutil.which through devops_cli.core.binaries (check_binary, require_binary). When the tool is missing, it raises DependencyError with an install hint. The hint names the tool and its upstream install source (or the devtools image), not devops install-tools.
  • Remove DEFAULT_LOCAL_BIN_DIR from the review resolvers and the installer-folder lookup of infra/ansible_facts.py:68-80.
  • Rule: no product code calls tool_install_dir or installed_commands. Remove every such call.
  • tests/support/infra.py:101 changes with it.
  • devops install-tools keeps its behavior until chore(tools): remove devops install-tools and tools.lock #4363 removes it.

Renovate. None.

Risk. Low. A host that has a tool only in the installer folder and not on PATH now sees the install hint.

Proof

  • Unit tests with a stand-in on PATH (found) and only in ~/.local/bin (DependencyError).
  • git grep -nE 'tool_install_dir|installed_commands|DEFAULT_LOCAL_BIN_DIR' origin/main -- src returns only the tools_lock package and commands/install_tools.py.

Depends on: none

Proposed design

Problem statement

Code under src/devops_cli/review finds ruff and semgrep through the installer directory DEFAULT_LOCAL_BIN_DIR (~/.local/bin) before it looks on PATH. An image or a package manager that installs a tool in another directory is therefore missed, and the command reports the tool as missing. The change uses the existing check_binary and require_binary helpers, which call shutil.which and raise DependencyError with an install hint. Product code then finds a tool on PATH only.

Acceptance criteria

Requirement: PATH lookup

A command that needs an external tool SHALL find it on PATH through devops_cli.core.binaries.

Scenario: Tool on PATH

  • WHEN A test puts a stand-in semgrep executable on PATH and ~/.local/bin holds no semgrep
  • THEN The resolver of the rule-pack test runner returns the path of the stand-in.

Requirement: Installer directory is not a search path

A tool lookup MUST NOT add DEFAULT_LOCAL_BIN_DIR to the search path.

Scenario: Stand-in only in the installer directory

  • WHEN A test puts a stand-in semgrep executable in ~/.local/bin and no semgrep on PATH
  • THEN The resolver raises DependencyError and never returns the path of the stand-in.

Requirement: Missing tool message

A command that needs an external tool SHALL raise DependencyError through require_binary with an install hint that names the tool and its upstream install source.

Scenario: Tool absent from PATH

  • WHEN PATH holds no ruff binary and a test calls _default_ruff_block_checker
  • THEN The call raises DependencyError with a non-empty install_hint and a message that names ruff.

Requirement: No installer lookup in product code

Product code under src/devops_cli/security, review, k8s and research MUST NOT call tool_install_dir or installed_commands, and MUST NOT use DEFAULT_LOCAL_BIN_DIR to find a tool.

Scenario: Source scan

  • WHEN A test scans the source files of the four packages for the identifiers tool_install_dir, installed_commands and DEFAULT_LOCAL_BIN_DIR
  • THEN The scan reports no match.

Requirement: Install tools command unchanged

devops install-tools and its status subcommand SHALL keep their current behavior until a later item removes them.

Scenario: Install tools tests

  • WHEN The tests of tests/commands/test_install_tools.py run
  • THEN They pass with no change to src/devops_cli/commands/install_tools.py.

Existing Tool Considered

No alternatives check has run. The Python standard library shutil.which covers the need, and the project already wraps it: check_binary and require_binary in src/devops_cli/core/binaries.py return the path or raise DependencyError with an optional install_hint, and docs/SDLC.md requires them instead of raw shutil.which. The wrapper lacks nothing that this change needs, so the change builds no new code. It replaces two PATH-prefix lookups and adds an install hint at each call site. The cost is small: a few thousand tokens and under one hour.

Key questions

  • Which product files find a tool through the installer directory or through tools.lock?: DEFAULT_LOCAL_BIN_DIR prefixes the search path in _default_ruff_block_checker (src/devops_cli/review/analysis.py) and _resolve_semgrep_binary (src/devops_cli/review/rules_pack.py). tool_install_dir and installed_commands appear only in src/devops_cli/commands/install_tools.py, src/devops_cli/tools_lock/init.py and tests/support/tools.py. The other load_tools_lock readers in review, k8s and research read a version pin, not a location. The security package holds no reader, and the implementer still runs the git grep of the issue to confirm it. [sources: src/devops_cli/config/defaults.py, src/devops_cli/review/analysis.py:820, src/devops_cli/review/rules_pack.py:206, src/devops_cli/commands/install_tools.py, src/devops_cli/tools_lock/init.py, tests/support/tools.py, src/devops_cli/k8s/doctor.py, src/devops_cli/research/tool_pins.py]
  • Should each call site call shutil.which directly, or should one helper wrap it?: Use the existing helper require_binary, and check_binary for a yes/no test, from devops_cli.core.binaries. It wraps shutil.which, raises DependencyError with an install hint, and the project rule requires it instead of raw shutil.which. No new helper is written. (best practice) [sources: src/devops_cli/core/binaries.py, src/devops_cli/exceptions/tools.py, docs/SDLC.md]
    • Chosen: Reuse core.binaries require_binary and check_binary. The helper exists, docs/SDLC.md requires it, and it builds on the standard shutil.which.
    • Rejected: Call shutil.which at each call site. docs/SDLC.md forbids raw shutil.which, and it repeats the missing-tool handling.
    • Rejected: Write a new helper in each package. It duplicates core.binaries.
  • What does the install hint say?: The install_hint names the tool and its upstream install source or a package-manager command, such as the tool's documented install page. It does not name devops install-tools, because a later item removes that command. (best practice) [sources: src/devops_cli/exceptions/tools.py, src/devops_cli/core/binaries.py, docs/ERRORS.md:47]
    • Chosen: Name the tool and its upstream install source. It stays valid after the removal of devops install-tools.
    • Rejected: Tell the user to run devops install-tools. The command goes away in a later item.
    • Rejected: Give no install hint. The acceptance criteria require a non-empty hint, and DependencyError supports one.
  • Does a missing tool raise an error, or does the check skip?: The check raises DependencyError through require_binary, with the install hint. The current fallback to the bare command name hides the cause behind a subprocess failure, and a silent skip hides a missing tool. (best practice) [sources: src/devops_cli/core/binaries.py, src/devops_cli/review/analysis.py:820, src/devops_cli/exceptions/tools.py]
    • Chosen: Raise DependencyError with the install hint. The user learns which tool is missing and how to install it, and the error names the tool.
    • Rejected: Fall back to the bare command name and let the subprocess fail. The subprocess error hides the cause, and the command does not say how to install the tool.
    • Rejected: Skip the check and record a coverage gap. A silent skip hides the missing tool, and the issue asks the command to report it.
  • Does this item remove every tools.lock read in product code?: No. This item removes the tool lookup through the installer directory and lock. The version-pin reads stay, and a separate item moves them. The pins are the registry of devops install-tools, and the installer, CI and research use them. (best practice) [sources: src/devops_cli/review/rules_pack.py, src/devops_cli/review/analysis.py, src/devops_cli/k8s/doctor.py, src/devops_cli/research/tool_pins.py]
    • Chosen: Remove the tool lookup only. One pull request stays small, and the pins need a design of their own.
    • Rejected: Remove every tools.lock read in this item. It changes the pins that the installer, CI and research use, and does not fit one pull request.

Fit

Fits in one pull request.

Suspected block

None.

Dependencies

#4359

Alternatives check of 2026-11-19: not-applicable.
Class: refactor, no search.
Tool: none found.

Activity

  1. added
    source/agent
    type/refactor
    scope/security
    status/new
    value/medium
    effort/medium
    on Nov 10, 2026
  2. dan-petty commented on Nov 10, 2026

    @dan-petty
    OwnerAuthor

    Intake placed this item to the backlog: intake puts every new item in the backlog. A person plans the milestones.

    • Type: type/refactor. The refactor prefix of the title gives the type.
    • Scope: scope/security. The (security) scope of the title gives the scope.
    • Priority: P2-Medium. It is a prerequisite for removing devops install-tools and fixes tool lookup in four code areas.
    • Value: Medium. It removes a broken lookup path in security, review, k8s and research code.
    • Effort: Medium. It touches four source areas and replaces a shared lookup helper with shutil.which.
    • Related: fix(devcontainer): the image holds the locked tools in standard locations #4359, which asks for a different change. Both items concern tool discovery on PATH, but #4359 places tools in the image while this item changes code to look them up on PATH.
  3. added
    priority/p2-medium
    on Nov 10, 2026
  4. devops-cli-service commented on Nov 10, 2026

    @devops-cli-service
    Contributor

    Refine cannot set this item to Ready at 273e4c9 while the items below stay open. The next refine round looks at the item again when they close, or when a person replies in a comment or edits the body.

  5. added
    status/ready
    and removed
    status/new
    on Nov 10, 2026
  6. devops-cli-service commented on Nov 10, 2026

    @devops-cli-service
    Contributor

    Status set to Ready at 84d1570 (see proposed design in issue body).

    Moved to new items: #4388.

  7. devops-cli-service commented on Nov 11, 2026

    @devops-cli-service
    Contributor

    Alternatives check: not-applicable

    Class: refactor. The check makes no search and no model call for an item of this class.

    Tool: none found

    Checked on 2026-11-11. A person decides what this means for the item. The check changes no label and closes no issue.

  8. added
    owner/agent
    status/in-progress
    and removed
    status/ready
    on Nov 20, 2026
  9. dan-petty commented on Nov 20, 2026

    @dan-petty
    OwnerAuthor

    Closed as not planned: replaced by #4363. Owner decision of 2026-11-20 (#4363, comment 7047909430): one pull request deletes the tools lock and every reader. The reviewed work of PR #6542 stays on its branch for reuse.

  10. removed
    status/in-progress
    owner/agent
    on Nov 20, 2026
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

    effort/mediumpriority/p2-mediumscope/securitysource/agenttype/refactorvalue/medium

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions