diff --git a/openspec/changes/2166-the-unused-run-subprocess-re-import/.openspec.yaml b/openspec/changes/2166-the-unused-run-subprocess-re-import/.openspec.yaml index 25002a8e81..5849f5c860 100644 --- a/openspec/changes/2166-the-unused-run-subprocess-re-import/.openspec.yaml +++ b/openspec/changes/2166-the-unused-run-subprocess-re-import/.openspec.yaml @@ -1,2 +1,3 @@ schema: spec-driven created: 2026-11-01 +skip_specs: true diff --git a/openspec/changes/2166-the-unused-run-subprocess-re-import/design.md b/openspec/changes/2166-the-unused-run-subprocess-re-import/design.md index 59c825eea7..9300f1d949 100644 --- a/openspec/changes/2166-the-unused-run-subprocess-re-import/design.md +++ b/openspec/changes/2166-the-unused-run-subprocess-re-import/design.md @@ -2,13 +2,13 @@ ## Decisions -- **Use ruff check --select F401 --ignore-noqa as the check command**: ruff is already the project linter and the command is confirmed to report the 15 findings at b170358e. No new tool is needed. -- **Set the ceiling at 14**: This issue removes the 15th site (ruff.py:23), leaving 14 sites owned by #1332. The ceiling goes to zero when #1332 removes those sites. -- **Add the check as a devops ci row, not a pytest test**: docs/TESTING.md states: 'A check of committed files or of tool configuration is a row of devops ci, not a pytest test.' -- **Remove the alias rather than deprecate it**: The project is pre-1.0 and docs/TESTING.md forbids tests from importing private names. The alias exists only for a test fake, which is updated in the same change. +- **Remove the alias and keep the public name**: `_prepare_cmd` has no caller in `src/`. The project is before 1.0 and keeps no shim. `docs/TESTING.md` forbids a test to import a private name, so the fake and the test move to `prepare_tool_cmd`. +- **Lower the existing ceiling, and add no row**: the ratchet `src noqa: F401` already fails on a new site once its ceiling equals the count. The count is 0 on `main` (see the Feasibility section of the proposal). A new row would count the same sites with a second tool and would need a subcommand, a message, help text and documents (the `test-settings` row of #2173 changed the command, its message, `README.md` and two generated documents). +- **Show the failure by a probe file, not by a new test**: the ratchet already has a test. A new test that writes a file into `src/` would break `docs/TESTING.md`, which says a check of committed files is not a test that starts a program. Group 2 holds numbered steps that a person or an agent can repeat. ## Rejected alternatives -- **Add a pytest invariant test for the F401 ceiling**: docs/TESTING.md states: 'A check of committed files or of tool configuration is a row of devops ci, not a pytest test.' -- **Use a custom script to count noqa F401 imports**: ruff already reports these with --select F401 --ignore-noqa. A custom script adds tokens to build, keep and fix, and duplicates ruff's parser. -- **Keep the _prepare_cmd alias with a deprecation warning**: The project is pre-1.0. docs/TESTING.md forbids tests from importing private names. The alias has no production use. +- **A `devops ci` row `ruff check --select F401 --ignore-noqa src` that counts findings against a ceiling of 14**: the 14 sites are gone (`ruff` reports 0), so a ceiling of 14 would let 14 new sites in. A row with a ceiling of 0 duplicates the ratchet at 0. +- **A `devops ci` row `ruff check --select F401 --ignore-noqa src` that fails on any finding, as an addition to the `lint` row**: it works, but it checks the same sites as the ratchet. The `lint` subcommand runs only the `cmd` of its row, so the check would run in `devops ci` and not in `devops ci lint`. If a person wants it, it is a follow-up change. +- **A pytest test that runs `ruff` and asserts on its output**: `docs/TESTING.md` says a test of `src/` starts no system program, and a check of committed files is a row of `devops ci`. +- **Keep the alias with a deprecation warning**: the alias has no production use, and the project keeps no shim before 1.0. diff --git a/openspec/changes/2166-the-unused-run-subprocess-re-import/proposal.md b/openspec/changes/2166-the-unused-run-subprocess-re-import/proposal.md index d573689441..eb930e1911 100644 --- a/openspec/changes/2166-the-unused-run-subprocess-re-import/proposal.md +++ b/openspec/changes/2166-the-unused-run-subprocess-re-import/proposal.md @@ -2,38 +2,48 @@ ## Why -#2166: Two test accommodations reached the code after #1309 and #1332 were filed, and no check stopped them. The unused run_subprocess re-import in security/ruff.py and the private _prepare_cmd alias in core/process.py violate docs/TESTING.md. No check prevents a new # noqa: F401 re-import from entering src/. +Issue #2166: two accommodations for tests reached the code, and no check stopped a third from entering `src/`. Most of the issue is done on `main`. Two parts remain: + +- The private alias `_prepare_cmd = prepare_tool_cmd` in `src/devops_cli/core/process.py` still stands. The shared process fake imports it, and a test imports it. `docs/TESTING.md` says no test imports a private name from `devops_cli`. +- The ceiling of the ratchet for `# noqa: F401` in `src/` is 15, and the real count is 0. The ratchet lets 15 new unused re-imports in with no failure. ## What Changes -- Remove the unused run_subprocess import from src/devops_cli/security/ruff.py -- Remove the _prepare_cmd alias from src/devops_cli/core/process.py and update tests/support/fakes/process.py and tests/core/test_process.py to use prepare_tool_cmd -- Add a devops ci row that runs ruff check --select F401 --ignore-noqa src and fails when the finding count exceeds 14 +- Remove the alias `_prepare_cmd` from `src/devops_cli/core/process.py`. The process fake and `tests/core/test_process.py` use the public `prepare_tool_cmd`. +- Set the ceiling `src noqa: F401` of the existing suppression ratchet to 0. - The change fits one pull request. +- The change has no spec delta and sets `skip_specs: true`. It alters no command, option, message, manifest or service behavior. The alias had no caller in `src/`, and the ratchet is a test. -## Capabilities +## Acceptance -### New Capabilities +The criteria of #2166, and the group that delivers each: -None. +- `src/devops_cli/security/ruff.py` imports no name it does not use, and its tests patch no `devops_cli` name: already true on `main`, so no group (see Feasibility). +- `rg -n "_prepare_cmd" src tests` prints nothing: group 1. +- A `devops ci` row fails on a new unused `# noqa: F401` import in `src/`, and shows it failing on an added re-import: group 2. The check is the existing suppression ratchet, which runs in the `test` row of `devops ci`. Group 2 holds its ceiling at 0 and shows the failure on an added import. This replaces the new row that the issue names, because the ratchet already counts this kind (see Feasibility). Pending a person: confirm that the ratchet at 0 meets the criterion, or ask for the extra `ruff --ignore-noqa` row. +- The check runs on the stock runner with no install, and its job stays under 5 minutes: group 2. The ratchet runs in the `test` row that CI already runs, so it adds no job and no install. +- `uv run devops ci` passes: the checks of the pull request, run by CI. Group 1 and group 2 each end with the narrow test run that covers their files. -### Modified Capabilities +## Feasibility -- `ci-gate-admission`: F401 re-import ceiling check +Each fact below comes from a run on `origin/main` at 1c20865a, on 2026-11-01. -## Impact +- The re-import in `src/devops_cli/security/ruff.py` is gone. `grep -n "run_subprocess\|noqa" src/devops_cli/security/ruff.py` prints nothing. Commit a1950694 (#1332, merged 2026-10-30) removed it; `git log -S run_subprocess -- src/devops_cli/security/ruff.py` lists that commit last. +- No site is left. `git grep -n "noqa: F401" -- src` prints nothing (exit 1), and `uv run ruff check --select F401 --ignore-noqa src` prints `All checks passed!` (ruff 0.16.8). The issue counted 15 at b170358e. +- No test of the ruff scanner patches a `devops_cli` name. `git grep -n patch -- tests/security/test_review_ruff_mypy_evidence.py` prints nothing. The one `patch.object(ci_module, "run_subprocess", ...)` in `tests/commands/test_ci.py:1938` is a test of `ci.py`. +- The alias stands. `git grep -n "_prepare_cmd" -- src tests` prints 8 lines: `src/devops_cli/core/process.py:482`, `tests/core/test_process.py:583,585,592,598` and `tests/support/fakes/process.py:23,272,361`. No other file in `src/` uses it. `prepare_tool_cmd` (`src/devops_cli/core/process.py:474`) is the public function. `ci.py` already calls it. +- The ratchet exists. `DEFAULT_SUPPRESSION_CEILINGS` in `tests/invariants/test_architectural_invariants.py:176` holds `"src noqa: F401": 15`. `_collect_suppressions` counts every `# noqa` comment in `src/` by code, and a bare `# noqa` counts under the kind `src noqa`, which has no ceiling and so a ceiling of 0. The collector gives 0 for `src noqa: F401`, so the ceiling is 15 above the count. +- The gap is real. A probe file `src/devops_cli/f401_probe.py` with the line `import os # noqa: F401` makes `uv run ruff check --select F401 --ignore-noqa src` report `Found 1 error`, while `uv run devops ci test tests/invariants/test_architectural_invariants.py -k suppressions_stay_under_their_ceilings` prints `1 passed`. The probe file was removed after the run. +- Nothing newer does this work. `uv run devops gh api repos/dan-petty/devops-cli/issues/1332 --jq .state` prints `closed`, and the same call for #1309 prints `closed`. #1336 is open: it turns ratchets into bans, and does not touch this ceiling. `git grep -ln "_prepare_cmd" -- openspec/changes` outside this folder prints nothing. -- Code: `src/devops_cli/security/ruff.py`, `src/devops_cli/core/process.py`, `src/devops_cli/commands/ci.py` -- Tests: `tests/support/fakes/process.py`, `tests/core/test_process.py` +## Existing Tool Considered -## Feasibility +The suppression ratchet of #849 (`tests/invariants/test_architectural_invariants.py`) already counts `# noqa: F401` in `src/` and fails when the count passes its ceiling. It needs a ceiling of 0 and no new code. Ruff with `--select F401 --ignore-noqa` is the other open tool. It reports the same sites as the ratchet, so a second guard for the same sites has no extra value now. #1336 turns the ratchets into bans, so a second guard would also be one more thing to remove. -- The re-import at src/devops_cli/security/ruff.py:23 is confirmed by the issue body and the context shows the file in the directory tree. -- The alias at src/devops_cli/core/process.py:482 is confirmed by identifier matches showing _prepare_cmd = prepare_tool_cmd. -- The test references at tests/core/test_process.py:583-598 are confirmed by identifier matches. -- The command uv run ruff check --select F401 --ignore-noqa src is stated to report 15 findings at b170358e, all in security/. -- First checks the implementation runs: rg -n 'noqa: F401' src/devops_cli/security/ruff.py to confirm the import exists; rg -n '_prepare_cmd' src tests to confirm the alias and its references; uv run ruff check --select F401 --ignore-noqa src to confirm the count is 15 before removal. +The change deletes one name, `_prepare_cmd`, and one private import in each of the process fake and `tests/core/test_process.py`. -## Existing Tool Considered +## Impact -ruff is already the project linter and is available via uv run. No new tool or library is needed. The check uses the existing ruff binary with --select F401 --ignore-noqa flags. +- Code: `src/devops_cli/core/process.py` (the alias line). +- Tests: `tests/support/fakes/process.py`, `tests/core/test_process.py`, `tests/invariants/test_architectural_invariants.py`. +- Existing code to keep passing: `prepare_tool_cmd` and its callers in `src/devops_cli/commands/ci.py` and `src/devops_cli/core/process.py`; the 128 test files that use the process fake; `test_suppressions_stay_under_their_ceilings`. diff --git a/openspec/changes/2166-the-unused-run-subprocess-re-import/specs/ci-gate-admission/spec.md b/openspec/changes/2166-the-unused-run-subprocess-re-import/specs/ci-gate-admission/spec.md deleted file mode 100644 index 1c7758029e..0000000000 --- a/openspec/changes/2166-the-unused-run-subprocess-re-import/specs/ci-gate-admission/spec.md +++ /dev/null @@ -1,12 +0,0 @@ -## ADDED Requirements - -### Requirement: F401 re-import ceiling check -The CI gate SHALL include a check that runs ruff check --select F401 --ignore-noqa over src/ and fails when the finding count exceeds the ceiling of 14. - -#### Scenario: New re-import exceeds ceiling -- **WHEN** A # noqa: F401 import is added to a file in src/ and the finding count becomes 15 -- **THEN** The check fails with a message naming the new site - -#### Scenario: Count at ceiling passes -- **WHEN** The finding count is 14 or fewer -- **THEN** The check passes with exit code 0 diff --git a/openspec/changes/2166-the-unused-run-subprocess-re-import/tasks.md b/openspec/changes/2166-the-unused-run-subprocess-re-import/tasks.md index 1998ad9530..48f37644fd 100644 --- a/openspec/changes/2166-the-unused-run-subprocess-re-import/tasks.md +++ b/openspec/changes/2166-the-unused-run-subprocess-re-import/tasks.md @@ -1,29 +1,22 @@ # Tasks -## 1. Remove unused re-import in security/ruff.py +## 1. Remove the `_prepare_cmd` alias -Reads: none. Changes: `src/devops_cli/security/ruff.py`. +Reads: `src/devops_cli/core/process.py` lines 470 to 482, `tests/core/test_process.py` lines 575 to 600, `tests/support/fakes/process.py` lines 18 to 26, 240 to 275 and 355 to 365. Changes: `src/devops_cli/core/process.py`, `tests/core/test_process.py`, `tests/support/fakes/process.py`. -- [ ] 1.1 Write a test that runs uv run ruff check --select F401 src/devops_cli/security/ruff.py and asserts exit code 0 with no findings, and verify that `uv run ruff check --select F401 src/devops_cli/security/ruff.py` fails on the base -- [ ] 1.2 Remove the run_subprocess import line (line 23) from src/devops_cli/security/ruff.py. The module does not use the name and no test patches it, and verify that `uv run ruff check --select F401 src/devops_cli/security/ruff.py` passes -- [ ] 1.3 Change no document, run `uv run devops docs generate --sync-readme`, and verify that `uv run devops ci docs` passes +This group keeps behavior, so it adds no test. The repeatable check is `git grep -n "_prepare_cmd" -- src tests`. It prints 8 lines on the base and nothing when the group is done. -## 2. Remove _prepare_cmd alias and update tests +- [ ] 1.1 Run `git grep -n "_prepare_cmd" -- src tests` and note the 8 lines. In `tests/support/fakes/process.py`, import `prepare_tool_cmd` at the top in place of `_prepare_cmd`, call it in the two places that call `_prepare_cmd(cmd)`, and make the method `prepare_cmd` use the top-level import and not a local one. Verify with `uv run devops ci test tests/core/test_process_contract.py tests/core/test_process_hardening.py` +- [ ] 1.2 In `tests/core/test_process.py`, import and call `prepare_tool_cmd` in `test_uv_preview_flags_injection`, with the same expected values. Verify with `uv run devops ci test tests/core/test_process.py` +- [ ] 1.3 Delete the line `_prepare_cmd = prepare_tool_cmd` and its blank lines from `src/devops_cli/core/process.py`. Verify that `git grep -n "_prepare_cmd" -- src tests` prints nothing and that `uv run devops ci test tests/core/test_process.py tests/core/test_process_contract.py tests/core/test_process_hardening.py tests/commands/test_ci.py` passes. The full suite, which holds the 128 files that use the process fake, runs in CI -Reads: none. Changes: `src/devops_cli/core/process.py`, `tests/support/fakes/process.py`, `tests/core/test_process.py`. +## 2. Set the `src noqa: F401` ceiling to 0 -- [ ] 2.1 Write a test that asserts rg -n '_prepare_cmd' src tests prints nothing, and verify that `uv run devops ci test tests/core/test_process.py` fails on the base -- [ ] 2.2 Remove the line _prepare_cmd = prepare_tool_cmd from src/devops_cli/core/process.py (line 482). In tests/support/fakes/process.py, change the import of _prepare_cmd to prepare_tool_cmd. In tests/core/test_process.py, change all references from _prepare_cmd to prepare_tool_cmd (lines 583, 585, 592, 598), and verify that `uv run devops ci test tests/core/test_process.py` passes -- [ ] 2.3 Change no document, run `uv run devops docs generate --sync-readme`, and verify that `uv run devops ci docs` passes +Reads: `tests/invariants/test_architectural_invariants.py` lines 176 to 196 and 2505 to 2525. Changes: `tests/invariants/test_architectural_invariants.py`. -## 3. Add F401 re-import ceiling CI row +This group changes a test constant and no behavior, so it adds no test. The repeatable check is the probe in 2.1 to 2.4. It shows that a new unused `# noqa: F401` import in `src/` passes the ratchet at 15 and fails it at 0. -Reads: none. Changes: `src/devops_cli/commands/ci.py`. - -- [ ] 3.1 Write a test that adds a # noqa: F401 import to a temporary file in src/, runs the new CI row, and asserts it fails. Remove the import and assert the row passes at the ceiling of 14, and verify that `uv run devops ci` fails on the base -- [ ] 3.2 Add a new row to devops ci that runs ruff check --select F401 --ignore-noqa src, counts the findings, and fails with a message naming the new sites when the count exceeds 14. The row runs on the stock runner with no install step, and verify that `uv run devops ci` passes -- [ ] 3.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 ..HEAD). +- [ ] 2.1 Confirm the count: `git grep -n "noqa: F401" -- src` prints nothing, and `uv run ruff check --select F401 --ignore-noqa src` prints `All checks passed!` +- [ ] 2.2 Probe the base. Write the line `import os # noqa: F401` to the new file `src/devops_cli/f401_probe.py`. Run `uv run devops ci test tests/invariants/test_architectural_invariants.py -k suppressions_stay_under_their_ceilings`. It passes, which is the gap. Delete the probe file +- [ ] 2.3 In `DEFAULT_SUPPRESSION_CEILINGS`, change `"src noqa: F401": 15` to `"src noqa: F401": 0` +- [ ] 2.4 Repeat the probe of 2.2. The run now fails with `src noqa: F401: 1 > ceiling 0`. Delete the probe file, and verify with `git status --short` that no file under `src/` is changed and with `uv run devops ci test tests/invariants/test_architectural_invariants.py` that the file passes. Put the output of 2.2 and 2.4 in a comment on the pull request