Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion docs/roadmap/alternatives.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,9 @@ Once for a run that checks an item of no skip class, the check reads the invento

1. The SPDX SBOM that the dependency graph of the repository exports (`GET /repos/{owner}/{repo}/dependency-graph/sbom`), with one request. It holds the package URL of each package of a manifest, a lock file or a workflow. A PyPI package matches by its canonical name, an action by its repository (`pkg:githubactions/github/codeql-action/init` is `github/codeql-action`), and the npm package `@<owner>/<name>` by the repository of the same name. A dependency graph that is off gives an empty SBOM.
2. The files under `roadmap.alternatives.inventory_paths` of a clone (`k8s`, `tf`, `.devcontainer`, `src/devops_cli/config/commands.py`, `src/devops_cli/roadmap/runner_tools.py` and `src/devops_cli/infra/ansible_facts.py` by default). They name the services, images and CLIs that no manifest holds, such as LiteLLM, Grafana or kubectl. The three source files name, with no version, the commands that devops-cli starts, each program that a Job needs or leaves out, and the Ansible commands; they take the place of the tools lock (#4363). The name of the repository or of the package counts as a whole word in any case, as `git grep -i -w -F` finds it. The Service row uses the clone of its lane. On a workstation, `--source <clone>` gives the clone, and with no clone the check uses the other two sources.
3. deps.dev, which links a GitHub project to the packages whose source it is (`GET https://api.deps.dev/v3/projects/<project>:packageversions`). The repository `modelcontextprotocol/python-sdk` is the PyPI package `mcp` of the SBOM. The check asks deps.dev only when the SBOM holds a package and the other two sources do not hold the tool, and one run asks once for each project. The answer comes from the same fact cache for 24 hours. A failed read skips the item, and the run takes it again after `roadmap.alternatives.retry_days`.
3. deps.dev, which links a GitHub project to the packages whose source it is (`GET https://api.deps.dev/v3/projects/<project>:packageversions`). The repository `modelcontextprotocol/python-sdk` is the PyPI package `mcp` of the SBOM. The check asks deps.dev only when the SBOM holds a package and the earlier checks do not match, and one run asks once for each project. The answer comes from the same fact cache for 24 hours. A failed read skips the item, and the run takes it again after `roadmap.alternatives.retry_days`.

Before asking deps.dev, the check matches a language's standard library repository (`python/cpython`, `golang/go`, `rust-lang/rust`, `ruby/ruby`, `dotnet/runtime`, or `nodejs/node`) if the SBOM holds a package of that type or if a deployed file uses a suffix of that language (#6347).

The inventory lives for one run.

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
schema: spec-driven
created: 2026-11-25
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
## Context

`src/devops_cli/roadmap/alternatives.py` evaluates `inventory.uses(tool.url, tool.project)` inside `_verdict_of` after ADR confirmation. When `inventory.uses(...)` returns `True`, `_verdict_of` returns `Verdict.IN_USE` with automatic inventory override (`True`). Today `Inventory` (`src/devops_cli/roadmap/inventory.py`) checks:
1. Exact PURL key matches (`_tool_keys(url, project) & self.packages`).
2. Whole-word matches for `_tool_names(url)` inside `self.deployed`.
3. `deps.dev` linked packages (`_linked_packages(project) & self.packages`).

For standard library repositories like `github.com/python/cpython` or `github.com/golang/go`, none of these three checks fire when the repository only holds ecosystem packages such as `pkg:pypi/httpx` or source files such as `.py`.

## Goals / Non-Goals

**Goals:**
- Recognize standard library repositories for languages used in the repository from either SBOM PURL types or deployed file suffixes.
- Short-circuit inside `Inventory.uses` before querying `deps.dev`.
- Keep third-party tools in the same ecosystem unaffected (`covers` stays `covers`).
- Keep repositories with no matching language signal unaffected (`covers` stays `covers`).

**Non-Goals:**
- Running external language classifiers or modifying `ProjectProfile`.
- Querying `deps.dev` or GitHub APIs at runtime for language detection.

## Decisions

1. **Static `_STDLIB_LANGUAGES` table in `inventory.py`**:
Map canonical `github.com/<owner>/<repo>` project identifiers to `(purl_type, frozenset_of_suffixes)`:
- `github.com/python/cpython`: `("pypi", frozenset({".py"}))`
- `github.com/golang/go`: `("golang", frozenset({".go"}))`
- `github.com/rust-lang/rust`: `("cargo", frozenset({".rs"}))`
- `github.com/ruby/ruby`: `("gem", frozenset({".rb"}))`
- `github.com/dotnet/runtime`: `("nuget", frozenset({".cs"}))`
- `github.com/nodejs/node`: `("npm", frozenset({".js", ".mjs", ".cjs", ".ts"}))`
2. **`suffixes` field on `Inventory`**:
Extend `_read_files` (or helper `_read_deployed`) to collect lowercased `file.suffix.lower()` alongside the file contents and pass `suffixes` into `Inventory(packages, deployed, suffixes)`. Keep `suffixes: frozenset[str] = frozenset()` defaulted so existing unit tests building `Inventory(packages, deployed)` continue working without changes.
3. **Evaluation order in `Inventory.uses`**:
Evaluate `_stdlib_in_use(project, self.packages, self.suffixes)` after direct PURL and deployed-word checks and before `if project is None or not self.packages: return False` and `_linked_packages(project)`. Checking before `not self.packages` ensures an empty SBOM with a `.py` deployed file still detects `python/cpython` without calling `deps.dev`.

## Risks / Trade-offs

- If `self.deployed` literally contains the word `"cpython"`, `_tool_names` already matches it as a whole word; testing the empty-signal and deployed-suffix scenarios uses paths/contents without that literal word.
- If a third-party package like `sqlalchemy/sqlalchemy` is evaluated when only `pkg:pypi/httpx` is in the SBOM, it is not in `_STDLIB_LANGUAGES`, so it does not trigger the stdlib rule.
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
## Why

`roadmap alternatives` uses the repository SBOM and deployed file text in `Inventory` to turn an existing-tool match into `in-use`. When the LLM names a language's standard library repository such as `python/cpython`, neither the SBOM PURL (`pkg:pypi/...`) nor package links on `deps.dev` match `cpython` directly, so the verdict stays `covers` (issue #6347).

## Feasibility

Feasible in one pull request. Adding a static mapping of standard library GitHub projects to their SBOM PURL type and deployed file suffixes inside `src/devops_cli/roadmap/inventory.py` fits cleanly into the existing `Inventory.uses` flow with zero new external dependencies.

## Existing Tool Considered

No existing open tool in our dependency graph maps our SBOM PURL types and deployed file extensions to upstream standard library GitHub projects inside `Inventory.uses`. Adding this static mapping in `src/devops_cli/roadmap/inventory.py` costs ~60k tokens and ~2 hours, which avoids unnecessary `deps.dev` HTTP lookups and custom heuristic classifiers.

## What Changes

- Map standard library GitHub projects (`github.com/python/cpython`, `github.com/golang/go`, `github.com/rust-lang/rust`, `github.com/ruby/ruby`, `github.com/dotnet/runtime`, `github.com/nodejs/node`) to their SBOM PURL type and deployed file suffixes in `src/devops_cli/roadmap/inventory.py`.
- Collect deployed file suffixes in `_read_files` and store `suffixes: frozenset[str]` on `Inventory` (defaulting to `frozenset()` so existing 2-argument callers keep working).
- Check the standard library mapping in `Inventory.uses` against `self.packages` and `self.suffixes` before calling `_linked_packages(project)`.
- Update `docs/roadmap/alternatives.md` (`### The tools in use`) and add unit + end-to-end fake-model tests.

## Capabilities

### New Capabilities

- None.

### Modified Capabilities

- `roadmap-alternatives`: Mark a language's standard library as `in-use` when the repository SBOM holds a package of that ecosystem or its deployed paths include a file suffix of that language.

## Impact

- Code: `src/devops_cli/roadmap/inventory.py`
- Docs: `docs/roadmap/alternatives.md`
- Tests: `tests/roadmap/test_roadmap_alternatives_project_facts.py`, `tests/roadmap/test_roadmap_alternatives.py`
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
## ADDED Requirements

### Requirement: Standard library of a used language counts as in-use

`Inventory.uses` MUST return `True` when a tool's upstream project is the standard library of a language signaled either by a package PURL type in the repository SBOM or by a deployed file suffix under `config.inventory_paths`, without calling `deps.dev`. Third-party packages in that ecosystem MUST NOT match through this rule, and a repository with no matching package PURL or deployed suffix MUST NOT mark the standard library as in use.

#### Scenario: Standard library of a used language gets in-use
- **WHEN** the repository SBOM holds `pkg:pypi/httpx` and the model proposes `https://github.com/python/cpython` (`covers` or `partly`)
- **THEN** `Inventory.uses` returns `True` without calling `deps.dev` and the verdict becomes `in-use`

#### Scenario: Standard library gets in-use from a deployed suffix with empty SBOM
- **WHEN** the repository SBOM is empty, a deployed path holds a `.py` file, and the model proposes `https://github.com/python/cpython`
- **THEN** `Inventory.uses` returns `True` without calling `deps.dev` and the verdict becomes `in-use`

#### Scenario: Third-party tool keeps covers
- **WHEN** the repository SBOM holds only `pkg:pypi/httpx` and the model proposes `https://github.com/sqlalchemy/sqlalchemy` as `covers`
- **THEN** the standard library rule does not match and the verdict stays `covers`

#### Scenario: No standard-library rule without a language signal
- **WHEN** the repository SBOM is empty, no deployed path has a matching suffix, and the model proposes `https://github.com/python/cpython` as `covers`
- **THEN** `Inventory.uses` returns `False` and the verdict stays `covers`
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
## 1. Specification & Design

- [x] 1.1 Write OpenSpec proposal, design, tasks, and `roadmap-alternatives` spec delta for `#6347`

## 2. Tests First (RED)

- [x] 2.1 Add RED tests in `tests/roadmap/test_roadmap_alternatives_project_facts.py` and `tests/roadmap/test_roadmap_alternatives.py` covering SBOM PURL signal, deployed suffix signal, third-party tool, empty inventory, non-Python stdlib, and zero `deps.dev` HTTP lookups
- [x] 2.2 Run targeted `pytest` on `origin/main` code and verify the new tests fail

## 3. Implementation & Documentation (GREEN)

- [x] 3.1 Add `_STDLIB_LANGUAGES`, `suffixes` collection from deployed files, and `_stdlib_in_use` check in `src/devops_cli/roadmap/inventory.py`
- [x] 3.2 Update `docs/roadmap/alternatives.md` (`### The tools in use`) to document standard library language matching
- [x] 3.3 Run `ruff format`, `ruff check`, `mypy src/`, and targeted `pytest` suites to verify GREEN

## 4. Verification & Archive

- [x] 4.1 Archive the OpenSpec change with `devops openspec archive`
- [x] 4.2 Run `devops ci --check --no-cache --skip test,outdated` and `devops ci fail-to-pass --base origin/main`
22 changes: 22 additions & 0 deletions openspec/specs/roadmap-alternatives/spec.md
Original file line number Diff line number Diff line change
Expand Up @@ -1029,6 +1029,7 @@ A fenced code block or an HTML block that no close ends runs to the end of the b
- **THEN** the first write closes the fence at the end of the body and adds the block after it
- **AND** the quote keeps each of its lines, and only the first run checks the item

<<<<<<< HEAD
### Requirement: ADR rejection ignores link targets
`rejects()` SHALL ignore Markdown link targets when matching a tool name in an ADR.

Expand Down Expand Up @@ -1061,3 +1062,24 @@ The verdict check SHALL return `in-use` for the item's own repository first, SHA
#### Scenario: Genuine ADR 0018 rejection stays ahead of inventory
- **WHEN** `validate_reply` checks an item with ADR 0018 cited for `bubblewrap` and an inventory containing `bubblewrap`
- **THEN** the verdict is `rejected`

### Requirement: Standard library of a used language counts as in-use

`Inventory.uses` MUST return `True` when a tool's upstream project is the standard library of a language signaled either by a package PURL type in the repository SBOM or by a deployed file suffix under `config.inventory_paths`, without calling `deps.dev`. Third-party packages in that ecosystem MUST NOT match through this rule, and a repository with no matching package PURL or deployed suffix MUST NOT mark the standard library as in use.

#### Scenario: Standard library of a used language gets in-use
- **WHEN** the repository SBOM holds `pkg:pypi/httpx` and the model proposes `https://github.com/python/cpython` (`covers` or `partly`)
- **THEN** `Inventory.uses` returns `True` without calling `deps.dev` and the verdict becomes `in-use`

#### Scenario: Standard library gets in-use from a deployed suffix with empty SBOM
- **WHEN** the repository SBOM is empty, a deployed path holds a `.py` file, and the model proposes `https://github.com/python/cpython`
- **THEN** `Inventory.uses` returns `True` without calling `deps.dev` and the verdict becomes `in-use`

#### Scenario: Third-party tool keeps covers
- **WHEN** the repository SBOM holds only `pkg:pypi/httpx` and the model proposes `https://github.com/sqlalchemy/sqlalchemy` as `covers`
- **THEN** the standard library rule does not match and the verdict stays `covers`

#### Scenario: No standard-library rule without a language signal
- **WHEN** the repository SBOM is empty, no deployed path has a matching suffix, and the model proposes `https://github.com/python/cpython` as `covers`
- **THEN** `Inventory.uses` returns `False` and the verdict stays `covers`
>>>>>>> 50e1865e0 (fix(roadmap): mark a used language's stdlib as in-use (#6347))
61 changes: 45 additions & 16 deletions src/devops_cli/roadmap/inventory.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,16 @@
"NUGET": "nuget",
"RUBYGEMS": "gem",
}

# Standard library GitHub projects mapped to their SBOM PURL type and deployed file suffixes.
_STDLIB_LANGUAGES: dict[str, tuple[str, frozenset[str]]] = {
"github.com/python/cpython": (_PYPI, frozenset({".py"})),
"github.com/golang/go": ("golang", frozenset({".go"})),
"github.com/rust-lang/rust": ("cargo", frozenset({".rs"})),
"github.com/ruby/ruby": ("gem", frozenset({".rb"})),
"github.com/dotnet/runtime": ("nuget", frozenset({".cs"})),
"github.com/nodejs/node": (_NPM, frozenset({".js", ".mjs", ".cjs", ".ts"})),
}
# The relation of a package version to a project that makes the project its source.
_SOURCE_REPO = "SOURCE_REPO"

Expand Down Expand Up @@ -172,19 +182,34 @@ def _whole_word(name: str) -> re.Pattern[str]:
return re.compile(rf"(?<!\w){re.escape(name)}(?!\w)", re.IGNORECASE)


def _read_files(root: Path, paths: Sequence[str]) -> str:
"""The text of each file under the deployed `paths` of the clone at `root`. A path that the
clone does not hold is left out, and a symbolic link is not followed."""
def _read_files(root: Path, paths: Sequence[str]) -> tuple[str, frozenset[str]]:
"""The text and lower-cased suffixes of each file under the deployed `paths` of the clone at
`root`. A path that the clone does not hold is left out, and a symbolic link is not
followed."""
texts: list[str] = []
suffixes: set[str] = set()
for path in paths:
target = safe_resolve_subpath(root, path)
files = [target] if target.is_file() else sorted(target.rglob("*"))
texts += [
file.read_text(encoding="utf-8", errors="ignore")
for file in files
if file.is_file() and not file.is_symlink()
]
return "\n".join(texts)
for file in files:
if file.is_file() and not file.is_symlink():
texts.append(file.read_text(encoding="utf-8", errors="ignore"))
if file.suffix:
suffixes.add(file.suffix.lower())
return "\n".join(texts), frozenset(suffixes)


def _stdlib_in_use(project: str | None, packages: frozenset[str], suffixes: frozenset[str]) -> bool:
"""Whether `project` is the standard library of a language that the SBOM packages or deployed
file `suffixes` signal as in use."""
if project is None:
return False
signal = _STDLIB_LANGUAGES.get(project.lower())
if signal is None:
return False
purl_type, lang_suffixes = signal
prefix = f"{purl_type}:"
return bool(lang_suffixes & suffixes) or any(package.startswith(prefix) for package in packages)


# The packages that deps.dev links to each project, in the process and in the cache Valkey, by
Expand Down Expand Up @@ -221,23 +246,27 @@ def _linked_packages(project: str) -> frozenset[str]:
@dataclass
class Inventory:
"""The tools in use of one repository at HEAD: the keys of the packages of its SBOM, and the
text of the deployed files of a clone. One run reads it once, and keeps what deps.dev said
of each project it asked about."""
text and suffixes of the deployed files of a clone. One run reads it once, and keeps what
deps.dev said of each project it asked about."""

packages: frozenset[str] = frozenset()
deployed: str = ""
suffixes: frozenset[str] = frozenset()
_linked: dict[str, frozenset[str]] = field(default_factory=dict, init=False, repr=False)

def uses(self, url: str, project: str | None) -> bool:
"""Whether the repository uses the tool at `url`, whose GitHub project is `project`:
the SBOM holds its package, the deployed files name it, or the SBOM holds a package that
deps.dev links to its project. deps.dev is asked only when the SBOM holds a package.
Raises as deps.dev raises."""
the SBOM holds its package, the deployed files name it, the repository uses its
language's standard library, or the SBOM holds a package that deps.dev links to its
project. deps.dev is asked only when the SBOM holds a package and the earlier checks do
not match. Raises as deps.dev raises."""
project = project or project_of(url)
if _tool_keys(url, project) & self.packages:
return True
if any(_whole_word(name).search(self.deployed) for name in _tool_names(url)):
return True
if _stdlib_in_use(project, self.packages, self.suffixes):
return True
if project is None or not self.packages:
return False
if project not in self._linked:
Expand All @@ -248,8 +277,8 @@ def uses(self, url: str, project: str | None) -> bool:
def read_inventory(store: RoadmapStore, source: Path | None, paths: Sequence[str]) -> Inventory:
"""The inventory of the repository of `store`: one read of its SBOM, and the deployed `paths`
of the clone at `source` when the run has one."""
deployed = _read_files(source, paths) if source is not None else ""
return Inventory(package_keys(store.dependency_purls()), deployed)
deployed, suffixes = _read_files(source, paths) if source is not None else ("", frozenset())
return Inventory(package_keys(store.dependency_purls()), deployed, suffixes)


__all__ = [
Expand Down
Loading