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
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
schema: spec-driven
created: 2026-11-01
12 changes: 12 additions & 0 deletions openspec/changes/2130-the-toolrun-of-osv-scanner-and/design.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# Design

## Decisions

- **Use a streamed SHA-256 over the database files in sorted filename order for the osv-scanner digest.**: The 36 MB database exceeds the file-size cap of a plain file hash. A streamed hash avoids loading the file into memory. Sorting by filename makes the digest deterministic across runs on the same database.
- **Use the SHA-256 of `ruff --show-settings` JSON output for the Ruff digest.**: The issue asks for the resolved configuration, not the raw file. `--show-settings` outputs the final merged configuration as JSON, which is the exact input Ruff uses for the scan.
- **Store both digests as optional string fields on the existing ToolRun record.**: The ToolRun record already lives in the SARIF run property bag (#1983). Adding a field is the minimal change. Optional keeps the record valid for tools that do not produce a digest.

## Rejected alternatives

- **Use the database's modified time combined with a digest of its index.**: The modified time is not content-addressed: a file can be rewritten with the same mtime, or the mtime can change without a content change. A streamed content hash is more robust and matches the acceptance criterion that the digest changes when the database changes.
- **Hash the raw `ruff.toml` or `pyproject.toml` file for the Ruff digest.**: The issue and the proposed design both state the digest covers the resolved configuration, not the raw file. Ruff merges defaults with the project config, so the raw file does not capture the full input.
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
# Proposal

## Why

Issue #2130: the ToolRun of an osv-scanner run records no digest of its advisory database, and the ToolRun of a Ruff run records no digest of the Ruff configuration it read. Without these digests, a user cannot verify which database version or configuration produced a given scan result. The 36 MB PyPI database exceeds the file-size cap of the record's digest step, so a plain file hash is not possible.

## What Changes

- The ToolRun of an osv-scanner run records a `database_digest` field: a streamed SHA-256 over the advisory database files in sorted filename order.
- The ToolRun of a Ruff run records a `config_digest` field: the SHA-256 of the JSON output of `ruff --show-settings` for the target.
- The `review-tool-runs` capability gains two requirements that pin the digest behavior.
- The change fits one pull request.

## Capabilities

### New Capabilities

None.

### Modified Capabilities

- `review-tool-runs`: osv-scanner toolrun records database digest, ruff toolrun records configuration digest

## Impact

- Code: `src/devops_cli/review/scanners/osv_scanner.py`, `src/devops_cli/review/scanners/ruff.py`
- Tests: `tests/test_review_tool_runs.py`

## Feasibility

- The issue states the ToolRun records no digest today and cites #2096 for the 36 MB database and the file-size cap. The capability `review-tool-runs` exists in the spec list, confirming the ToolRun record is a defined concept.
- Python's `hashlib` supports streaming SHA-256 over file objects, so the 36 MB database can be hashed without loading it into memory. This satisfies the file-size cap constraint.
- Ruff's `--show-settings` flag outputs the resolved configuration as JSON to stdout. A test can invoke it on a fixture directory and hash the output offline.
- First checks the implementation runs against the real system: `uv run ruff --show-settings --isolated` to confirm the flag exists and outputs JSON; `uv run devops review scan --help` to confirm the scan command and its flags; `ls` of the osv-scanner database directory to confirm the file layout for the streamed hash.

## Existing Tool Considered

Python's `hashlib` (standard library) provides the streamed SHA-256. Ruff's `--show-settings` flag outputs the resolved configuration. No external library is needed. The change adds two small functions in devops-cli's own scanner adapter code and one field to the ToolRun record. The written cost is roughly 80 lines of code and tests, well within one step's budget. No internal code is deleted.
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
## ADDED Requirements

### Requirement: osv-scanner toolrun records database digest
The ToolRun of an osv-scanner run SHALL record a `database_digest` field that is a SHA-256 hex digest computed by streaming the advisory database files in sorted filename order. The digest SHALL change when the database content changes and SHALL stay the same when it does not.

#### Scenario: digest changes when database changes
- **WHEN** the advisory database files differ between two osv-scanner runs
- **THEN** the `database_digest` in the two ToolRun records is different

#### Scenario: digest stable for unchanged database
- **WHEN** the advisory database files are identical between two osv-scanner runs
- **THEN** the `database_digest` in the two ToolRun records is the same

### Requirement: ruff toolrun records configuration digest
The ToolRun of a Ruff run SHALL record a `config_digest` field that is a SHA-256 hex digest of the resolved configuration that Ruff used for the target. The digest SHALL change when the resolved configuration changes and SHALL stay the same when it does not.

#### Scenario: digest changes when configuration changes
- **WHEN** the Ruff configuration of the target differs between two Ruff runs
- **THEN** the `config_digest` in the two ToolRun records is different

#### Scenario: digest stable for unchanged configuration
- **WHEN** the Ruff configuration of the target is identical between two Ruff runs
- **THEN** the `config_digest` in the two ToolRun records is the same
21 changes: 21 additions & 0 deletions openspec/changes/2130-the-toolrun-of-osv-scanner-and/tasks.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# Tasks

## 1. Add osv-scanner database digest to the ToolRun

Reads: none. Changes: `src/devops_cli/review/scanners/osv_scanner.py`, `tests/test_review_tool_runs.py`.

- [ ] 1.1 Write a test that creates two temporary directories with different file contents, calls the new `database_digest` function on each, and asserts the digests differ. Write a second test that calls the function twice on the same directory and asserts the digests are equal. The test fails because `database_digest` does not exist yet, and verify that `uv run devops ci test tests/test_review_tool_runs.py -k osv_scanner` fails on the base
- [ ] 1.2 Add a `database_digest(db_path: Path) -> str` function to the osv-scanner adapter. It lists the files under `db_path` in sorted order by relative path, opens each file in binary mode, and feeds its bytes into a single `hashlib.sha256` object in 64 KiB chunks. It returns the hex digest. Add a `database_digest: str | None` field to the ToolRun record. In the osv-scanner scan path, call `database_digest` on the database directory and store the result in the ToolRun before the SARIF export, and verify that `uv run devops ci test tests/test_review_tool_runs.py -k osv_scanner` passes
- [ ] 1.3 Change no document, run `uv run devops docs generate --sync-readme`, and verify that `uv run devops ci docs` passes

## 2. Add Ruff configuration digest to the ToolRun

Reads: none. Changes: `src/devops_cli/review/scanners/ruff.py`, `tests/test_review_tool_runs.py`.

- [ ] 2.1 Write a test that creates a temporary project with a `ruff.toml`, calls the new `config_digest` function, and asserts it returns a 64-character hex string. Write a second test that modifies the `ruff.toml` and calls the function again, asserting the digest differs. The test fails because `config_digest` does not exist yet, and verify that `uv run devops ci test tests/test_review_tool_runs.py -k ruff` fails on the base
- [ ] 2.2 Add a `config_digest(target: Path) -> str` function to the Ruff adapter. It runs `ruff --show-settings --isolated <target>` via `subprocess.run`, captures stdout, and returns the SHA-256 hex digest of the JSON bytes. Add a `config_digest: str | None` field to the ToolRun record. In the Ruff scan path, call `config_digest` on the target and store the result in the ToolRun before the SARIF export, and verify that `uv run devops ci test tests/test_review_tool_runs.py -k ruff` passes
- [ ] 2.3 Change no document, run `uv run devops docs generate --sync-readme`, and verify that `uv run devops ci docs` passes

## Workflow follow-up

- Pending a person: review the diff in tuicr (tuicr -r <base>..HEAD).
Loading