diff --git a/README.md b/README.md index 04c5c50d05..aa83fec553 100644 --- a/README.md +++ b/README.md @@ -71,7 +71,7 @@ devops config set ai.api_key "sk-ant-..." # 4. Verify LLM connectivity and run CI validation devops ai test -devops ci run +devops ci ``` ### Reusable Dev Container Package (GHCR) diff --git a/docs/CLI_REFERENCE.md b/docs/CLI_REFERENCE.md index 4abea65a36..a6eaf6f4ca 100644 --- a/docs/CLI_REFERENCE.md +++ b/docs/CLI_REFERENCE.md @@ -210,11 +210,21 @@ Exits 1 when a row fails or a pod opens a connection. | | | `devops ci deps [OPTIONS]` | Validate dependency hygiene and imports via deptry. | | | `devops ci test-settings [OPTIONS]` | Verify test configuration settings and environment variables. | | | `devops ci maintain [OPTIONS]` | Run automated toolchain, dependency freshness, and lockfile maintenance checks. | -| | `devops ci run [OPTIONS]` | Run full CI and return a single pass/fail status. | | | `devops ci mutate [OPTIONS] ` | Mutation-test functions with mutmut and show each mutant no test killed; never a gate. | | | `devops ci job-time [OPTIONS]` | Fail when the last runs of a CI job took more than the limit on average. Reads the job time of the last completed push runs of a workflow on a branch from GitHub's Actions API. A job that passed, failed or timed out counts, whatever the run concluded. Fails too when fewer runs than asked for could be read. | | | `devops ci durations [OPTIONS]` | Write the mean seconds of each test module to tests/module_durations.json, from the JUnit reports of the test shards of the last push runs of a workflow on a branch. The split of the test shards weighs each module by these seconds. gh downloads the artifacts of each run. A run whose artifacts GitHub no longer holds is left out. | | | `devops ci fail-to-pass [OPTIONS]` | Replay added or modified tests against the merge-base tree to prove a defect fix's tests fail unpatched. A changed module under tests/gate/*_checks/ runs its gate row on the base and head trees: a case of that module that fails on base and passes on head proves the fix. | +| | `devops ci zizmor [OPTIONS]` | Run the zizmor check. | +| | `devops ci constructs [OPTIONS]` | Run the constructs check. | +| | `devops ci openspec [OPTIONS]` | Run the openspec check. | +| | `devops ci git [OPTIONS]` | Run the git check. | +| | `devops ci bwrap [OPTIONS]` | Run the bwrap check. | +| | `devops ci k8s [OPTIONS]` | Run the k8s check. | +| | `devops ci test-tree [OPTIONS]` | Run the test-tree check. | +| | `devops ci startup-imports [OPTIONS]` | Run the startup-imports check. | +| | `devops ci swallowed-failures [OPTIONS]` | Run the swallowed-failures check. | +| | `devops ci domain [OPTIONS]` | Run the domain check. | +| | `devops ci roadmap-stage-eval-commits [OPTIONS]` | Run the roadmap-stage-eval-commits check. | | [**uv**](commands/uv.md) | `devops uv sync [OPTIONS]` | Sync project dependencies into the virtual environment. | | | `devops uv lock [OPTIONS]` | Regenerate the uv lockfile. | | | `devops uv python-install [OPTIONS]` | Install project Python version with uv. | diff --git a/docs/MCP_TOOLS.md b/docs/MCP_TOOLS.md index ce6d52cb6e..7299003302 100644 --- a/docs/MCP_TOOLS.md +++ b/docs/MCP_TOOLS.md @@ -690,8 +690,8 @@ Run tests, linting, formatting, and type-checks. A run that selects test, securi | `check` | `boolean` | No | `False` | Run in check-only mode without automatically applying formatting or lint fixes. | | `cache` | `boolean` | No | `True` | Reuse a cached verdict when the codebase is unchanged. Results are recorded either way. | | `force` | `boolean` | No | `False` | Bypass CI execution cache and force re-execution of all quality gates. | -| `only` | `array[string]` | No | - | Run only the specified check names (comma-separated or repeated). | -| `skip` | `array[string]` | No | - | Skip the specified check names (comma-separated or repeated). | +| `only` | `array[string]` | No | - | Run only the specified check names (test, lint, format, typecheck, audit, security, actionlint, zizmor, docs, uv-check, lockfile, build, outdated, deps, constructs, devcontainer, openspec, git, test-settings, bwrap, k8s, test-tree, startup-imports, swallowed-failures, domain, roadmap-stage-eval-commits). Comma-separated or repeated. | +| `skip` | `array[string]` | No | - | Skip the specified check names (test, lint, format, typecheck, audit, security, actionlint, zizmor, docs, uv-check, lockfile, build, outdated, deps, constructs, devcontainer, openspec, git, test-settings, bwrap, k8s, test-tree, startup-imports, swallowed-failures, domain, roadmap-stage-eval-commits). Comma-separated or repeated. | | `shard` | `integer` | No | `1` | Number of the part of the test suite this run covers, from 1 to --shards. CI runs each part on its own runner. | | `shards` | `integer` | No | `1` | Number of parts the test suite splits into. Above 1, the run covers one part, checks no coverage floor and leaves no cached verdict. | | `dry_run` | `boolean` | No | `False` | Preview execution plan without mutating external state. | diff --git a/docs/ROADMAP_WORKFLOW.md b/docs/ROADMAP_WORKFLOW.md index e234bac6b6..119dc68386 100644 --- a/docs/ROADMAP_WORKFLOW.md +++ b/docs/ROADMAP_WORKFLOW.md @@ -308,6 +308,9 @@ The shell holds no key, and `uv` is allowed, so the agent runs the commands of t | Command | Access | Use | | :--- | :--- | :--- | | `uv run devops ci test` | write | Run the tests of one file: `uv run devops ci test `. It writes cache files in the checkout. | +| `uv run devops ci constructs` | read | Run the constructs row of the CI quality gate. | +| `uv run devops ci docs` | read | Run the docs row of the CI quality gate. | +| `uv run devops ci openspec` | read | Run the openspec row of the CI quality gate. | | `uv run devops ai repomap` | read | Print a compact map of the symbols of the repository. | | `uv run devops ai ast` | write | Parse one source file (`parse`) or build the symbol graph of the repository (`graph`). `graph --output ` writes a file: give it a path in the checkout. | | `uv run devops docs generate` | write | Write the generated documents in the docs directory of the checkout: pass no `--output-dir`. Run it after a change to a command or a setting. | diff --git a/docs/TELEMETRY.md b/docs/TELEMETRY.md index d49ec1b826..2c854e1a24 100644 --- a/docs/TELEMETRY.md +++ b/docs/TELEMETRY.md @@ -100,7 +100,7 @@ writes by name. | `devops_cli_subprocess_duration_seconds` | Histogram | `s` | Wall time of a program that devops-cli ran, by program and status: ok or error. | | `devops_cli_telemetry_tests_total` | Counter | `1` | Test points that devops telemetry test sent, to show that metrics reach the collector. | | `devops_cli_ci_checks_total` | Counter | `1` | Checks that devops ci ran, by step and outcome: pass or fail. | -| `devops_cli_ci_gate_slot_wait_seconds` | Histogram | `s` | Time a devops ci run waited for a free gate slot before its checks started. | +| `devops_cli_ci_gate_slot_wait_seconds` | Histogram | `s` | Time a gate run waited for a free gate slot before its checks started. | | `devops_cli_review_duration_seconds` | Histogram | `s` | Review wall time, by target type. | | `devops_cli_findings_total` | Counter | `1` | Review findings, by producer, severity and status. | | `devops_cli_ai_requests_total` | Counter | `1` | LLM calls and embedding requests, by operation (chat or embeddings), provider, model, server, serving backend, whether the cache answered and row: the job row that sent the request. | diff --git a/docs/commands/ci.md b/docs/commands/ci.md index fe16384173..a6b93f0031 100644 --- a/docs/commands/ci.md +++ b/docs/commands/ci.md @@ -14,8 +14,8 @@ devops ci [OPTIONS] COMMAND [ARGS]... | `--check` | `boolean` | - | Run in check-only mode without automatically applying formatting or lint fixes. | | `--cache` / `--no-cache` | `boolean` | `True` | Reuse a cached verdict when the codebase is unchanged. Results are recorded either way. | | `--force`, `-f` | `boolean` | - | Bypass CI execution cache and force re-execution of all quality gates. | -| `--only` | `string` | - | Run only the specified check names (comma-separated or repeated). | -| `--skip` | `string` | - | Skip the specified check names (comma-separated or repeated). | +| `--only` | `string` | - | Run only the specified check names (test, lint, format, typecheck, audit, security, actionlint, zizmor, docs, uv-check, lockfile, build, outdated, deps, constructs, devcontainer, openspec, git, test-settings, bwrap, k8s, test-tree, startup-imports, swallowed-failures, domain, roadmap-stage-eval-commits). Comma-separated or repeated. | +| `--skip` | `string` | - | Skip the specified check names (test, lint, format, typecheck, audit, security, actionlint, zizmor, docs, uv-check, lockfile, build, outdated, deps, constructs, devcontainer, openspec, git, test-settings, bwrap, k8s, test-tree, startup-imports, swallowed-failures, domain, roadmap-stage-eval-commits). Comma-separated or repeated. | | `--shard` | `integer` | `1` | Number of the part of the test suite this run covers, from 1 to --shards. CI runs each part on its own runner. | | `--shards` | `integer` | `1` | Number of parts the test suite splits into. Above 1, the run covers one part, checks no coverage floor and leaves no cached verdict. | | `--dry-run` | `boolean` | - | Preview execution plan without mutating external state. | @@ -321,23 +321,6 @@ devops ci maintain [OPTIONS] --- -## `devops ci run` - -**Run full CI and return a single pass/fail status.** - -```bash -devops ci run [OPTIONS] -``` - -**Options:** - -| Option / Flag | Type | Default | Description | -|---|---|---|---| -| `--fix` / `--no-fix` | `boolean` | `True` | Auto-fix lint/format before reporting status. | -| `--dry-run` | `boolean` | - | Preview execution plan without mutating external state. | - ---- - ## `devops ci mutate` **Mutation-test functions with mutmut and show each mutant no test killed; never a gate.** @@ -426,3 +409,179 @@ devops ci fail-to-pass [OPTIONS] | `--dry-run` | `boolean` | - | Preview execution plan without mutating external state. | --- + +## `devops ci zizmor` + +**Run the zizmor check.** + +```bash +devops ci zizmor [OPTIONS] +``` + +**Options:** + +| Option / Flag | Type | Default | Description | +|---|---|---|---| +| `--dry-run` | `boolean` | - | Preview execution plan without mutating external state. | + +--- + +## `devops ci constructs` + +**Run the constructs check.** + +```bash +devops ci constructs [OPTIONS] +``` + +**Options:** + +| Option / Flag | Type | Default | Description | +|---|---|---|---| +| `--dry-run` | `boolean` | - | Preview execution plan without mutating external state. | + +--- + +## `devops ci openspec` + +**Run the openspec check.** + +```bash +devops ci openspec [OPTIONS] +``` + +**Options:** + +| Option / Flag | Type | Default | Description | +|---|---|---|---| +| `--dry-run` | `boolean` | - | Preview execution plan without mutating external state. | + +--- + +## `devops ci git` + +**Run the git check.** + +```bash +devops ci git [OPTIONS] +``` + +**Options:** + +| Option / Flag | Type | Default | Description | +|---|---|---|---| +| `--dry-run` | `boolean` | - | Preview execution plan without mutating external state. | + +--- + +## `devops ci bwrap` + +**Run the bwrap check.** + +```bash +devops ci bwrap [OPTIONS] +``` + +**Options:** + +| Option / Flag | Type | Default | Description | +|---|---|---|---| +| `--dry-run` | `boolean` | - | Preview execution plan without mutating external state. | + +--- + +## `devops ci k8s` + +**Run the k8s check.** + +```bash +devops ci k8s [OPTIONS] +``` + +**Options:** + +| Option / Flag | Type | Default | Description | +|---|---|---|---| +| `--dry-run` | `boolean` | - | Preview execution plan without mutating external state. | + +--- + +## `devops ci test-tree` + +**Run the test-tree check.** + +```bash +devops ci test-tree [OPTIONS] +``` + +**Options:** + +| Option / Flag | Type | Default | Description | +|---|---|---|---| +| `--dry-run` | `boolean` | - | Preview execution plan without mutating external state. | + +--- + +## `devops ci startup-imports` + +**Run the startup-imports check.** + +```bash +devops ci startup-imports [OPTIONS] +``` + +**Options:** + +| Option / Flag | Type | Default | Description | +|---|---|---|---| +| `--dry-run` | `boolean` | - | Preview execution plan without mutating external state. | + +--- + +## `devops ci swallowed-failures` + +**Run the swallowed-failures check.** + +```bash +devops ci swallowed-failures [OPTIONS] +``` + +**Options:** + +| Option / Flag | Type | Default | Description | +|---|---|---|---| +| `--dry-run` | `boolean` | - | Preview execution plan without mutating external state. | + +--- + +## `devops ci domain` + +**Run the domain check.** + +```bash +devops ci domain [OPTIONS] +``` + +**Options:** + +| Option / Flag | Type | Default | Description | +|---|---|---|---| +| `--dry-run` | `boolean` | - | Preview execution plan without mutating external state. | + +--- + +## `devops ci roadmap-stage-eval-commits` + +**Run the roadmap-stage-eval-commits check.** + +```bash +devops ci roadmap-stage-eval-commits [OPTIONS] +``` + +**Options:** + +| Option / Flag | Type | Default | Description | +|---|---|---|---| +| `--dry-run` | `boolean` | - | Preview execution plan without mutating external state. | + +--- diff --git a/openspec/changes/5451-each-check-row-is-a-devops/.openspec.yaml b/openspec/changes/archive/2026-11-14-5451-each-check-row-is-a-devops/.openspec.yaml similarity index 100% rename from openspec/changes/5451-each-check-row-is-a-devops/.openspec.yaml rename to openspec/changes/archive/2026-11-14-5451-each-check-row-is-a-devops/.openspec.yaml diff --git a/openspec/changes/5451-each-check-row-is-a-devops/design.md b/openspec/changes/archive/2026-11-14-5451-each-check-row-is-a-devops/design.md similarity index 100% rename from openspec/changes/5451-each-check-row-is-a-devops/design.md rename to openspec/changes/archive/2026-11-14-5451-each-check-row-is-a-devops/design.md diff --git a/openspec/changes/5451-each-check-row-is-a-devops/proposal.md b/openspec/changes/archive/2026-11-14-5451-each-check-row-is-a-devops/proposal.md similarity index 100% rename from openspec/changes/5451-each-check-row-is-a-devops/proposal.md rename to openspec/changes/archive/2026-11-14-5451-each-check-row-is-a-devops/proposal.md diff --git a/openspec/changes/5451-each-check-row-is-a-devops/specs/ci-gate-rows/spec.md b/openspec/changes/archive/2026-11-14-5451-each-check-row-is-a-devops/specs/ci-gate-rows/spec.md similarity index 100% rename from openspec/changes/5451-each-check-row-is-a-devops/specs/ci-gate-rows/spec.md rename to openspec/changes/archive/2026-11-14-5451-each-check-row-is-a-devops/specs/ci-gate-rows/spec.md diff --git a/openspec/changes/5451-each-check-row-is-a-devops/specs/roadmap-implement-step/inputs/spec.md b/openspec/changes/archive/2026-11-14-5451-each-check-row-is-a-devops/specs/roadmap-implement-step/inputs/spec.md similarity index 100% rename from openspec/changes/5451-each-check-row-is-a-devops/specs/roadmap-implement-step/inputs/spec.md rename to openspec/changes/archive/2026-11-14-5451-each-check-row-is-a-devops/specs/roadmap-implement-step/inputs/spec.md diff --git a/openspec/changes/5451-each-check-row-is-a-devops/tasks.md b/openspec/changes/archive/2026-11-14-5451-each-check-row-is-a-devops/tasks.md similarity index 92% rename from openspec/changes/5451-each-check-row-is-a-devops/tasks.md rename to openspec/changes/archive/2026-11-14-5451-each-check-row-is-a-devops/tasks.md index a8546a0f68..4d89e10668 100644 --- a/openspec/changes/5451-each-check-row-is-a-devops/tasks.md +++ b/openspec/changes/archive/2026-11-14-5451-each-check-row-is-a-devops/tasks.md @@ -4,62 +4,62 @@ Kind: behavior. Reads: `src/devops_cli/commands/ci.py`, `tests/commands/test_ci_dry_run.py`, `tests/invariants/test_dry_run_class_ratchet.py`. Changes: `src/devops_cli/commands/ci.py`, `tests/commands/test_ci_row_commands.py` (new). -- [ ] 1.1 The case `test_a_row_command_plans_only_its_row` runs the row constructs and the row test-tree, each with `--dry-run`, and fails on the base, where neither word is a command of the `ci` group; the case `test_the_row_tuple_matches_the_registry` compares `CHECK_ROW_NAMES` with `get_check_specs()` and fails on the base; write `test_a_row_with_a_hand_written_command_runs_dry_run` for `lint --dry-run` +- [x] 1.1 The case `test_a_row_command_plans_only_its_row` runs the row constructs and the row test-tree, each with `--dry-run`, and fails on the base, where neither word is a command of the `ci` group; the case `test_the_row_tuple_matches_the_registry` compares `CHECK_ROW_NAMES` with `get_check_specs()` and fails on the base; write `test_a_row_with_a_hand_written_command_runs_dry_run` for `lint --dry-run` - Verification: `$ uv run devops ci test tests/commands/test_ci_row_commands.py` fails on the base -- [ ] 1.2 Add `CHECK_ROW_NAMES` to `src/devops_cli/commands/ci.py` as the row names in registry order. Extract a shared helper `_run_checks_lifecycle` from `all_checks` that wraps the run in `_until_stopped`, handles `asyncio.CancelledError`, calls `_warn_when_over_budget`, and calls `_handle_ci_results(save_cache=False)`. Add `_row_command(name)`, decorated with `@dry_run_class("request-plan")`, which sets dry run and invokes `_run_checks_lifecycle` inside `_gate_slot(spec.heavy)` for `get_check_spec(name)`. Register each generated command with its own help string showing its row name +- [x] 1.2 Add `CHECK_ROW_NAMES` to `src/devops_cli/commands/ci.py` as the row names in registry order. Extract a shared helper `_run_checks_lifecycle` from `all_checks` that wraps the run in `_until_stopped`, handles `asyncio.CancelledError`, calls `_warn_when_over_budget`, and calls `_handle_ci_results(save_cache=False)`. Add `_row_command(name)`, decorated with `@dry_run_class("request-plan")`, which sets dry run and invokes `_run_checks_lifecycle` inside `_gate_slot(spec.heavy)` for `get_check_spec(name)`. Register each generated command with its own help string showing its row name - Verification: `$ uv run devops ci test tests/commands/test_ci_row_commands.py` passes ## 2. Select rows by name and name them in the option help Kind: behavior. Reads: `src/devops_cli/commands/ci.py`, `src/devops_cli/telemetry/usage_errors.py`, `src/devops_cli/core/cli.py`, `tests/commands/test_ci.py`. Changes: `src/devops_cli/commands/ci.py`, `tests/commands/test_ci.py`, `tests/commands/test_ci_row_commands.py`, `tests/ai/mcp/__snapshots__/test_mcp_tool_listing/test_the_tool_listing_matches_the_snapshot.json`. -- [ ] 2.1 The case `test_a_misspelled_only_name_records_bad_value` runs the root CLI with `ci --only constructz` and fails on the base, where the run exits 2 with no ledger record; the case `test_a_misspelled_skip_name_records_bad_value` runs `ci --skip constructz`; write `test_ci_only_multiple_comma_separated_dry_run` for `ci --only constructs,openspec --dry-run` and `test_ci_only_repeated_option_dry_run` for `ci --only constructs --only openspec --dry-run`; the case `test_the_selection_help_names_the_rows` reads the help of `--only` and `--skip` and fails on the base +- [x] 2.1 The case `test_a_misspelled_only_name_records_bad_value` runs the root CLI with `ci --only constructz` and fails on the base, where the run exits 2 with no ledger record; the case `test_a_misspelled_skip_name_records_bad_value` runs `ci --skip constructz`; write `test_ci_only_multiple_comma_separated_dry_run` for `ci --only constructs,openspec --dry-run` and `test_ci_only_repeated_option_dry_run` for `ci --only constructs --only openspec --dry-run`; the case `test_the_selection_help_names_the_rows` reads the help of `--only` and `--skip` and fails on the base - Verification: `$ uv run devops ci test tests/commands/test_ci_row_commands.py` fails on the base -- [ ] 2.2 Add `_row_name_callback` to `src/devops_cli/commands/ci.py`: it splits each value at commas, checks each name against `CHECK_ROW_NAMES`, raises `typer.BadParameter` with up to 3 close matches and the valid names, and returns the value unchanged. Pass it as `callback=` to `--only` and `--skip` and set their help from `CHECK_ROW_NAMES`. Update `test_ci_cli_runner_only_and_skip_validation` in `tests/commands/test_ci.py` to match the new bad parameter output. Regenerate the MCP tool listing snapshot with `--snapshot-update` +- [x] 2.2 Add `_row_name_callback` to `src/devops_cli/commands/ci.py`: it splits each value at commas, checks each name against `CHECK_ROW_NAMES`, raises `typer.BadParameter` with up to 3 close matches and the valid names, and returns the value unchanged. Pass it as `callback=` to `--only` and `--skip` and set their help from `CHECK_ROW_NAMES`. Update `test_ci_cli_runner_only_and_skip_validation` in `tests/commands/test_ci.py` to match the new bad parameter output. Regenerate the MCP tool listing snapshot with `--snapshot-update` - Verification: `$ uv run devops ci test tests/commands/test_ci_row_commands.py tests/commands/test_ci.py` passes ## 3. Delete the run command and its old test cases Kind: behavior. Reads: `src/devops_cli/commands/ci.py`, `tests/commands/test_ci_dry_run.py`, `tests/commands/test_net_construct_rules.py`, `tests/commands/test_ci.py`, `tests/commands/test_ci_row_commands.py`. Changes: `src/devops_cli/commands/ci.py`, `tests/commands/test_ci.py`, `tests/commands/test_ci_dry_run.py`, `tests/commands/test_net_construct_rules.py`, `tests/commands/test_ci_row_commands.py`. -- [ ] 3.1 The case `test_the_removed_run_command_records_unknown_command` runs the root CLI with `ci run` and fails on the base, where the run exits 0 and starts the gate +- [x] 3.1 The case `test_the_removed_run_command_records_unknown_command` runs the root CLI with `ci run` and fails on the base, where the run exits 0 and starts the gate - Verification: `$ uv run devops ci test tests/commands/test_ci_row_commands.py` fails on the base -- [ ] 3.2 Delete the `run` command from `src/devops_cli/commands/ci.py` with its options and its `@dry_run_class` line. In `tests/commands/test_ci.py`, update `test_ci_additional_subcommands` (line 547), `test_ci_helpers_and_edge_cases` (line 578), and `test_ci_run_docs_fix_when_needed` (line 637) to invoke `app` with `['--fix']` / `['--no-fix']` instead of the removed `run` subcommand. Delete the case `test_ci_run_command_dry_run` from `tests/commands/test_ci_dry_run.py`. Remove the second invocation of the removed command from `test_ci_dry_run_unlinks_nothing`. Reword the docstring of `tests/commands/test_net_construct_rules.py`. Add the case `test_the_removed_run_command_records_unknown_command` to `tests/commands/test_ci_row_commands.py` +- [x] 3.2 Delete the `run` command from `src/devops_cli/commands/ci.py` with its options and its `@dry_run_class` line. In `tests/commands/test_ci.py`, update `test_ci_additional_subcommands` (line 547), `test_ci_helpers_and_edge_cases` (line 578), and `test_ci_run_docs_fix_when_needed` (line 637) to invoke `app` with `['--fix']` / `['--no-fix']` instead of the removed `run` subcommand. Delete the case `test_ci_run_command_dry_run` from `tests/commands/test_ci_dry_run.py`. Remove the second invocation of the removed command from `test_ci_dry_run_unlinks_nothing`. Reword the docstring of `tests/commands/test_net_construct_rules.py`. Add the case `test_the_removed_run_command_records_unknown_command` to `tests/commands/test_ci_row_commands.py` - Verification: `$ uv run devops ci test tests/commands/test_ci_row_commands.py tests/commands/test_ci.py` passes ## 4. Name no removed command in the gate-slot metric description Kind: behavior. Reads: `src/devops_cli/telemetry/instruments.py`, `tests/telemetry/test_telemetry_instruments.py`, `tests/telemetry/test_consolidation_serialization.py`. Changes: `src/devops_cli/telemetry/instruments.py`, `tests/telemetry/test_telemetry_instruments.py`. -- [ ] 4.1 The case `test_the_gate_slot_histogram_description_names_no_command` in `tests/telemetry/test_telemetry_instruments.py` reads the description of `CI_GATE_SLOT_WAIT` and fails on the base, whose text holds the removed command name +- [x] 4.1 The case `test_the_gate_slot_histogram_description_names_no_command` in `tests/telemetry/test_telemetry_instruments.py` reads the description of `CI_GATE_SLOT_WAIT` and fails on the base, whose text holds the removed command name - Verification: `$ uv run devops ci test tests/telemetry/test_telemetry_instruments.py` fails on the base -- [ ] 4.2 Set the description of `CI_GATE_SLOT_WAIT` in `src/devops_cli/telemetry/instruments.py` to `Time a gate run waited for a free gate slot before its checks started`. Add the case `test_the_gate_slot_histogram_description_names_no_command` beside `test_the_roadmap_tool_instruments_are_declared_with_their_kinds_and_units`: it asserts that the description equals that text, so the description names no command and holds no removed command name +- [x] 4.2 Set the description of `CI_GATE_SLOT_WAIT` in `src/devops_cli/telemetry/instruments.py` to `Time a gate run waited for a free gate slot before its checks started`. Add the case `test_the_gate_slot_histogram_description_names_no_command` beside `test_the_roadmap_tool_instruments_are_declared_with_their_kinds_and_units`: it asserts that the description equals that text, so the description names no command and holds no removed command name - Verification: `$ uv run devops ci test tests/telemetry/test_telemetry_instruments.py` passes ## 5. Regenerate the documents after the removal and the new description Kind: other. Reads: `README.md`, `docs/TELEMETRY.md`, `docs/CLI_REFERENCE.md`, `docs/commands/ci.md`, `docs/MCP_TOOLS.md`, `src/devops_cli/ai/knowledge_base/devops_cli/cli_command_reference.md`. Changes: `README.md`, `docs/TELEMETRY.md`, `docs/CLI_REFERENCE.md`, `docs/commands/ci.md`, `docs/MCP_TOOLS.md`, `src/devops_cli/ai/knowledge_base/devops_cli/cli_command_reference.md`. -- [ ] 5.1 Write `devops ci` in place of the removed command in the quick-start block of `README.md`. Delete the row of the removed command from the table of `src/devops_cli/ai/knowledge_base/devops_cli/cli_command_reference.md`. Run `uv run devops docs generate` to regenerate `docs/TELEMETRY.md`, `docs/CLI_REFERENCE.md`, `docs/commands/ci.md` and `docs/MCP_TOOLS.md` from the app and from the instrument descriptions, so that the gate-slot row holds the new description and no document names the removed command, and run this check by hand: Run `uv run devops docs generate`. Run `uv run devops docs check` and confirm that it reports every documentation file as up to date. Run `git grep -n -F -w 'devops ci run' -- README.md docs/ src/` and confirm that it finds no match. Confirm that the row of `devops_cli_ci_gate_slot_wait_seconds` in `docs/TELEMETRY.md` reads the description of `CI_GATE_SLOT_WAIT`. -- [ ] 5.2 Edit `README.md` and `src/devops_cli/ai/knowledge_base/devops_cli/cli_command_reference.md`, and regenerate `docs/TELEMETRY.md`, `docs/CLI_REFERENCE.md`, `docs/commands/ci.md` and `docs/MCP_TOOLS.md` +- [x] 5.1 Write `devops ci` in place of the removed command in the quick-start block of `README.md`. Delete the row of the removed command from the table of `src/devops_cli/ai/knowledge_base/devops_cli/cli_command_reference.md`. Run `uv run devops docs generate` to regenerate `docs/TELEMETRY.md`, `docs/CLI_REFERENCE.md`, `docs/commands/ci.md` and `docs/MCP_TOOLS.md` from the app and from the instrument descriptions, so that the gate-slot row holds the new description and no document names the removed command, and run this check by hand: Run `uv run devops docs generate`. Run `uv run devops docs check` and confirm that it reports every documentation file as up to date. Run `git grep -n -F -w 'devops ci run' -- README.md docs/ src/` and confirm that it finds no match. Confirm that the row of `devops_cli_ci_gate_slot_wait_seconds` in `docs/TELEMETRY.md` reads the description of `CI_GATE_SLOT_WAIT`. +- [x] 5.2 Edit `README.md` and `src/devops_cli/ai/knowledge_base/devops_cli/cli_command_reference.md`, and regenerate `docs/TELEMETRY.md`, `docs/CLI_REFERENCE.md`, `docs/commands/ci.md` and `docs/MCP_TOOLS.md` - Verification: `$ uv run devops ci docs` passes ## 6. Name the scoped rows in the implement prompt table Kind: behavior. Reads: `src/devops_cli/roadmap/implement/implement_shell_policy.py`, `src/devops_cli/config/constants.py`, `docs/ROADMAP_WORKFLOW.md`, `tests/roadmap/implement/test_roadmap_implement_shell_policy.py`. Changes: `src/devops_cli/roadmap/implement/implement_shell_policy.py`, `docs/ROADMAP_WORKFLOW.md`, `tests/roadmap/implement/test_roadmap_implement_shell_policy.py`. -- [ ] 6.1 The case `test_the_local_commands_are_the_eight_commands_of_the_project_and_none_uses_the_network` reads `LOCAL_COMMANDS` and fails on the base, because the table holds no row of `ci` besides `ci test`; `test_the_document_of_the_workflow_holds_the_same_tables` compares the text of `local_commands_table()` with `docs/ROADMAP_WORKFLOW.md`; and `test_each_local_command_is_a_command_of_the_devops_app` runs `--help` for each of the eight commands +- [x] 6.1 The case `test_the_local_commands_are_the_eight_commands_of_the_project_and_none_uses_the_network` reads `LOCAL_COMMANDS` and fails on the base, because the table holds no row of `ci` besides `ci test`; `test_the_document_of_the_workflow_holds_the_same_tables` compares the text of `local_commands_table()` with `docs/ROADMAP_WORKFLOW.md`; and `test_each_local_command_is_a_command_of_the_devops_app` runs `--help` for each of the eight commands - Verification: `$ uv run devops ci test tests/roadmap/implement/test_roadmap_implement_shell_policy.py` fails on the base -- [ ] 6.2 Add `LocalCommand(("ci", "constructs"), ShellAccess.READ, ...)`, `LocalCommand(("ci", "docs"), ShellAccess.READ, ...)` and `LocalCommand(("ci", "openspec"), ShellAccess.READ, ...)` to `LOCAL_COMMANDS` in `src/devops_cli/roadmap/implement/implement_shell_policy.py`, each naming the row that it runs and carrying the argv `ci` with that row name. Replace the table of `docs/ROADMAP_WORKFLOW.md` with the text that `local_commands_table()` renders. Rename the case that counts the five commands to the eight commands and update the cases that hold the old names +- [x] 6.2 Add `LocalCommand(("ci", "constructs"), ShellAccess.READ, ...)`, `LocalCommand(("ci", "docs"), ShellAccess.READ, ...)` and `LocalCommand(("ci", "openspec"), ShellAccess.READ, ...)` to `LOCAL_COMMANDS` in `src/devops_cli/roadmap/implement/implement_shell_policy.py`, each naming the row that it runs and carrying the argv `ci` with that row name. Replace the table of `docs/ROADMAP_WORKFLOW.md` with the text that `local_commands_table()` renders. Rename the case that counts the five commands to the eight commands and update the cases that hold the old names - Verification: `$ uv run devops ci test tests/roadmap/implement/test_roadmap_implement_shell_policy.py` passes -- [ ] 6.3 Edit `docs/ROADMAP_WORKFLOW.md` with the table that `local_commands_table()` renders +- [x] 6.3 Edit `docs/ROADMAP_WORKFLOW.md` with the table that `local_commands_table()` renders - Verification: `$ uv run devops ci docs` passes ## 7. Search the tracked files for the removed command Kind: other. Reads: `README.md`, `docs/TELEMETRY.md`, `docs/CLI_REFERENCE.md`, `docs/commands/ci.md`, `docs/MCP_TOOLS.md`, `src/devops_cli/ai/knowledge_base/devops_cli/cli_command_reference.md`, `src/devops_cli/telemetry/instruments.py`. Changes: `README.md`. -- [ ] 7.1 Verify that no tracked file names the removed command name: run negative search over tracked paths, leaving no stray occurrences after groups 3 to 5 removed the name from code, metric description and documents +- [x] 7.1 Verify that no tracked file names the removed command name: run negative search over tracked paths, leaving no stray occurrences after groups 3 to 5 removed the name from code, metric description and documents - Verification: `$ ! git grep -n -I -F -w 'devops ci run' -- README.md docs/ src/ tests/` passes ## Criteria diff --git a/openspec/specs/ci-gate-rows/spec.md b/openspec/specs/ci-gate-rows/spec.md index 3eb11acb73..247acce390 100644 --- a/openspec/specs/ci-gate-rows/spec.md +++ b/openspec/specs/ci-gate-rows/spec.md @@ -148,3 +148,68 @@ The `test` row of a shard run SHALL stop at `DEFAULT_CI_TEST_SHARD_TIMEOUT_SECON #### Scenario: The index build - **WHEN** `devops ci coverage --build-index` starts the suite - **THEN** the run takes `DEFAULT_CI_COVERAGE_INDEX_TIMEOUT_SECONDS` of 3600 s + +### Requirement: Each row of the check registry is a subcommand +Each row of `get_check_specs()` SHALL be a subcommand of `devops ci` named after the row, and a row with no hand-written command SHALL get a generated command that runs the same path as `devops ci --only `: the same gate slot, the same telemetry and the same request plan of a narrowed run. The list of commands SHALL come from a static tuple of row names, and the module SHALL NOT call `get_check_specs()` while it imports. + +#### Scenario: A row with no hand-written command +- **WHEN** The test runs the row constructs and the row test-tree, each with `--dry-run`. +- **THEN** Each run exits 0, and its request plan holds one request for each command of that row's check spec and no request of another row. + +#### Scenario: A row with a hand-written command +- **WHEN** The test runs the lint row with `--dry-run`. +- **THEN** The run exits 0 and plans the fix command of the lint row, which is its hand-written command. + +### Requirement: The static row tuple matches the registry +The static tuple of row names in `src/devops_cli/commands/ci.py` SHALL hold the same names, in the same order, as `get_check_specs()`, so that a row that is added, renamed or removed fails the test that compares the two lists. + +#### Scenario: A row is added, renamed or removed +- **WHEN** The test compares the static tuple with the names that `get_check_specs()` returns. +- **THEN** The two lists are equal, and the test names the first name that differs. + +### Requirement: `--only` and `--skip` select a set of rows +`--only` and `--skip` SHALL accept a comma-separated list and a repeated option, and SHALL select exactly the named rows, so that the form `--only lint,format,domain` of `.pre-commit-config.yaml` keeps working. + +#### Scenario: A comma-separated list of two rows +- **WHEN** The test runs the `ci` group with `--only constructs,openspec --dry-run`. +- **THEN** The run exits 0, and its request plan holds the commands of both rows and no command of another row. + +#### Scenario: A repeated option +- **WHEN** The test runs the `ci` group with `--only constructs --only openspec --dry-run`. +- **THEN** The run exits 0, and its request plan holds the commands of both rows and no command of another row. + +### Requirement: A wrong row name is a usage error with a close name +A row name that the registry does not hold MUST raise `BadParameter` from the option callback, with up to 3 close row names and the valid row names. The root group MUST record one usage error of kind `bad_value` with command path `ci`, and the run MUST exit 2. + +#### Scenario: A misspelled row name of the only option +- **WHEN** The test runs the root CLI with `ci --only constructz`. +- **THEN** The run exits 2, its error text holds `constructs`, and the usage ledger holds one record of kind `bad_value` and command path `ci`. + +#### Scenario: A misspelled row name of the skip option +- **WHEN** The test runs the root CLI with `ci --skip constructz`. +- **THEN** The run exits 2, and the usage ledger holds one record of kind `bad_value` and command path `ci`. + +### Requirement: The help of the selection options names the rows +The help of `--only` and `--skip` MUST list the row names of the static tuple, so that a caller reads the valid names without a second command. + +#### Scenario: A person reads the help of the group +- **WHEN** The test runs `devops ci --help`. +- **THEN** The help text of `--only` and of `--skip` holds each row name of the static tuple. + +### Requirement: `devops ci run` is removed +`devops ci run` MUST NOT exist. The root group MUST report the word `run` as an unknown command and exit 2. The text of the removed command MUST NOT appear in `README.md`, in a file under `docs/` or `src/`, or in a test module other than the case that searches for it. + +#### Scenario: The removed command +- **WHEN** The test runs the root CLI with `ci run`. +- **THEN** The run exits 2, and the usage ledger holds one record of kind `unknown_command` with command path `ci`. + +#### Scenario: No other file names the removed command +- **WHEN** The test searches the tracked files with `git grep` and leaves its own module out. +- **THEN** The search finds no line. + +### Requirement: The gate-slot metric description names no removed command +The description of the `CI_GATE_SLOT_WAIT` histogram SHALL be `Time a gate run waited for a free gate slot before its checks started`, which names no command and holds no removed command name. + +#### Scenario: The description of the gate-slot histogram +- **WHEN** The test reads the description of `CI_GATE_SLOT_WAIT`. +- **THEN** The description equals `Time a gate run waited for a free gate slot before its checks started`. diff --git a/openspec/specs/roadmap-implement-step/inputs/spec.md b/openspec/specs/roadmap-implement-step/inputs/spec.md index 59fca5d3b2..a6102ef4d8 100644 --- a/openspec/specs/roadmap-implement-step/inputs/spec.md +++ b/openspec/specs/roadmap-implement-step/inputs/spec.md @@ -142,8 +142,8 @@ The step SHALL take a `## . ` heading as the start of a group only whe - **WHEN** `tasks.md` holds a quote `> ## 2. Extra` after the group 1 - **THEN** the parsed groups are the group 1 only -### Requirement: The prompt lists the local devops commands of the catalog -The prompt of the step SHALL list each command of `LOCAL_COMMANDS` in `src/devops_cli/roadmap/implement/implement_shell_policy.py` with its access class and its use, and `docs/ROADMAP_WORKFLOW.md` SHALL hold the same table. `LOCAL_COMMANDS` SHALL hold `ci test`, `ai repomap`, `ai ast`, `docs generate` and `openspec check`, and no command with the access `network`. A call of a listed command through `uv run` SHALL pass the shell policy and SHALL NOT count as a refusal. +### Requirement: The prompt lists the local commands of the catalog +The prompt of the step SHALL list each command of `LOCAL_COMMANDS` with its access class and its use, and `docs/ROADMAP_WORKFLOW.md` SHALL hold the same table. `LOCAL_COMMANDS` SHALL hold `ci test`, `ci constructs`, `ci docs`, `ci openspec`, `ai repomap`, `ai ast`, `docs generate` and `openspec check`, and no `network` command. A listed command run through `uv run` SHALL pass the shell policy and SHALL NOT count as a refusal. #### Scenario: The prompt holds the table - **WHEN** The prompt of the step is built. diff --git a/src/devops_cli/ai/knowledge_base/devops_cli/cli_command_reference.md b/src/devops_cli/ai/knowledge_base/devops_cli/cli_command_reference.md index a940ef354c..aecc05a176 100644 --- a/src/devops_cli/ai/knowledge_base/devops_cli/cli_command_reference.md +++ b/src/devops_cli/ai/knowledge_base/devops_cli/cli_command_reference.md @@ -91,7 +91,6 @@ This document provides an overview of the main command groups implemented in `de | | `devops config audit-keys` | Audit config for unencrypted plaintext keys | | | | `devops config output` | List configuration environment variables | `--export`, `--json` | | **`ci`** | `devops ci` | Run every check of the local quality gate | `--fix/--no-fix`, `--check`, `--cache`, `--force`, `--files` | -| | `devops ci run` | Same as `devops ci` | `--fix` | | | `devops ci audit` | Check dependencies for known CVEs (uv audit, and npm audit of the lockfile of each Node tool) | | | | `devops ci build` | Build the wheel and the sdist via uv build | | | | `devops ci mutate` | Mutation-test changed functions with mutmut and show the survivors; never a gate | `paths`, `--changed`, `--base` | diff --git a/src/devops_cli/commands/ci.py b/src/devops_cli/commands/ci.py index 830258096a..c3a6d8c23f 100644 --- a/src/devops_cli/commands/ci.py +++ b/src/devops_cli/commands/ci.py @@ -116,6 +116,36 @@ def invoke(self, ctx: Any) -> Any: # failure a warning (#5606). _SNAPSHOT_WARN_UNUSED: Final[str] = "--snapshot-warn-unused" +# The names of every row in the check registry, in registry order (#5451). +CHECK_ROW_NAMES: Final[tuple[str, ...]] = ( + "test", + "lint", + "format", + "typecheck", + "audit", + "security", + "actionlint", + "zizmor", + "docs", + "uv-check", + "lockfile", + "build", + "outdated", + "deps", + "constructs", + "devcontainer", + "openspec", + "git", + "test-settings", + "bwrap", + "k8s", + "test-tree", + "startup-imports", + "swallowed-failures", + "domain", + "roadmap-stage-eval-commits", +) + def _get_project_root() -> Path: """The worktree the CI checks verify: the nearest linked worktree, else the workspace root. @@ -1564,6 +1594,69 @@ def _handle_ci_results( raise typer.Exit(1) +def _run_checks_lifecycle( + specs: Sequence[CheckSpec], + root: Path, + *, + ci_options: dict[str, Any] | None = None, + effective_fix: bool = False, + before_fingerprint: str | None = None, + save_cache: bool = False, +) -> None: + """Run selected check specs through the async lifecycle, summary, budget warnings and cache handling.""" + if ci_options is None: + ci_options = {"fix": effective_fix, "check": not effective_fix} + start_time = clock.monotonic() + if not is_dry_run(): + print_info("Executing CI quality gates concurrently...") + sys.stdout.flush() + try: + results = asyncio.run( + _until_stopped( + _run_all_checks_async( + lint_fix=effective_fix, + format_fix=effective_fix, + docs_fix=effective_fix, + specs=specs, + ) + ) + ) + except asyncio.CancelledError: + raise typer.Exit(CONST_EXIT_CANCELLED) from None + _print_failures(results) + _print_summary(results, total_elapsed=clock.monotonic() - start_time) + _warn_when_over_budget(results) + _handle_ci_results( + results, + root, + ci_options, + before_fingerprint=before_fingerprint, + save_cache=save_cache, + ) + + +def _row_name_callback(value: list[str] | str | None) -> list[str] | str | None: + """Validate check row names in --only and --skip options.""" + if not value: + return value + raw_items = [value] if isinstance(value, str) else list(value) + for item in raw_items: + for part in item.split(","): + name = part.strip() + if not name: + continue + if name not in CHECK_ROW_NAMES: + import difflib + + close = difflib.get_close_matches(name, CHECK_ROW_NAMES, n=3) + hint = f" Close matches: {', '.join(close)}." if close else "" + valid_list = ", ".join(CHECK_ROW_NAMES) + raise typer.BadParameter( + f"Unknown check row: {name!r}.{hint} Valid rows: {valid_list}" + ) + return value + + @app.callback(invoke_without_command=True) @dry_run_class("request-plan") def all_checks( @@ -1587,13 +1680,17 @@ def all_checks( only: Annotated[ list[str] | None, typer.Option( - "--only", help="Run only the specified check names (comma-separated or repeated)." + "--only", + callback=_row_name_callback, + help=f"Run only the specified check names ({', '.join(CHECK_ROW_NAMES)}). Comma-separated or repeated.", ), ] = None, skip: Annotated[ list[str] | None, typer.Option( - "--skip", help="Skip the specified check names (comma-separated or repeated)." + "--skip", + callback=_row_name_callback, + help=f"Skip the specified check names ({', '.join(CHECK_ROW_NAMES)}). Comma-separated or repeated.", ), ] = None, shard: Annotated[ @@ -1638,30 +1735,11 @@ def all_checks( return with _gate_slot(any(spec.heavy for spec in selected_specs)): - start_time = clock.monotonic() - if not is_dry_run(): - print_info("Executing CI quality gates concurrently...") - sys.stdout.flush() - try: - results = asyncio.run( - _until_stopped( - _run_all_checks_async( - lint_fix=effective_fix, - format_fix=effective_fix, - docs_fix=effective_fix, - specs=selected_specs, - ) - ) - ) - except asyncio.CancelledError: - raise typer.Exit(CONST_EXIT_CANCELLED) from None - _print_failures(results) - _print_summary(results, total_elapsed=clock.monotonic() - start_time) - _warn_when_over_budget(results) - _handle_ci_results( - results, + _run_checks_lifecycle( + selected_specs, root, - ci_options, + ci_options=ci_options, + effective_fix=effective_fix, before_fingerprint=before_fingerprint, save_cache=(not is_narrowed), ) @@ -2538,30 +2616,6 @@ def maintain( print_success("Toolchain and lockfile maintenance checks passed.") -@app.command() -@dry_run_class("request-plan") -def run( - fix: Annotated[ - bool, - typer.Option("--fix/--no-fix", help=HELP.ci.fix_all), - ] = True, - dry_run: Annotated[ - bool, - typer.Option("--dry-run", help=HELP.options.dry_run), - ] = False, -) -> None: - """Run full CI and return a single pass/fail status.""" - if dry_run: - set_dry_run(True) - start_time = time.perf_counter() - results = asyncio.run(_run_all_checks_async(lint_fix=fix, format_fix=fix, docs_fix=fix)) - _print_failures(results) - _print_summary(results, total_elapsed=time.perf_counter() - start_time) - if not is_dry_run() and not any(res.dry_run for res in results): - if not all(res.passed for res in results): - raise typer.Exit(1) - - _MUTMUT = ["uv", "run", "mutmut"] _MUTMUT_RESULTS = [*_MUTMUT, "results", "--all", "true"] @@ -2902,3 +2956,39 @@ def fail_to_pass( write_stderr(f"{output}\n") raise typer.Exit(1) print_info(output, prefix=False, safe=True) + + +def _row_command(name: str) -> Callable[..., None]: + """Generate a subcommand callback for one row of the check registry.""" + + @dry_run_class("request-plan") + def command( + dry_run: Annotated[ + bool, + typer.Option("--dry-run", help=HELP.options.dry_run), + ] = False, + ) -> None: + if dry_run: + set_dry_run(True) + root = _get_project_root() + spec = get_check_spec(name) + with _gate_slot(spec.heavy): + _run_checks_lifecycle([spec], root, save_cache=False) + + command.__name__ = name.replace("-", "_") + command.__doc__ = f"Run the {name} check." + return command + + +def _register_row_commands() -> None: + """Register one generated subcommand for each row that has no hand-written command.""" + existing = { + c.name or (c.callback.__name__ if c.callback else "") for c in app.registered_commands + } + for name in CHECK_ROW_NAMES: + if name not in existing: + cmd = _row_command(name) + app.command(name=name, help=f"Run the {name} check.")(cmd) + + +_register_row_commands() diff --git a/src/devops_cli/roadmap/implement/implement_shell_policy.py b/src/devops_cli/roadmap/implement/implement_shell_policy.py index 7f68af2ebd..834097ddf4 100644 --- a/src/devops_cli/roadmap/implement/implement_shell_policy.py +++ b/src/devops_cli/roadmap/implement/implement_shell_policy.py @@ -168,6 +168,21 @@ class ShellRefusal: "Run the tests of one file: `uv run devops ci test <file>`. It writes cache files in the " "checkout.", ), + LocalCommand( + ("ci", "constructs"), + ShellAccess.READ, + "Run the constructs row of the CI quality gate.", + ), + LocalCommand( + ("ci", "docs"), + ShellAccess.READ, + "Run the docs row of the CI quality gate.", + ), + LocalCommand( + ("ci", "openspec"), + ShellAccess.READ, + "Run the openspec row of the CI quality gate.", + ), LocalCommand( ("ai", "repomap"), ShellAccess.READ, diff --git a/src/devops_cli/telemetry/instruments.py b/src/devops_cli/telemetry/instruments.py index a92a5af988..617ed49b7f 100644 --- a/src/devops_cli/telemetry/instruments.py +++ b/src/devops_cli/telemetry/instruments.py @@ -79,7 +79,7 @@ class Instrument: "devops_cli_ci_gate_slot_wait_seconds", InstrumentKind.HISTOGRAM, "s", - "Time a devops ci run waited for a free gate slot before its checks started", + "Time a gate run waited for a free gate slot before its checks started", ) REVIEW_DURATION = Instrument( "devops_cli_review_duration_seconds", diff --git a/tests/ai/mcp/__snapshots__/test_mcp_tool_listing/test_the_tool_listing_matches_the_snapshot.json b/tests/ai/mcp/__snapshots__/test_mcp_tool_listing/test_the_tool_listing_matches_the_snapshot.json index 963ef7cd06..578414c0f1 100644 --- a/tests/ai/mcp/__snapshots__/test_mcp_tool_listing/test_the_tool_listing_matches_the_snapshot.json +++ b/tests/ai/mcp/__snapshots__/test_mcp_tool_listing/test_the_tool_listing_matches_the_snapshot.json @@ -1394,7 +1394,7 @@ } ], "default": null, - "description": "Run only the specified check names (comma-separated or repeated)." + "description": "Run only the specified check names (test, lint, format, typecheck, audit, security, actionlint, zizmor, docs, uv-check, lockfile, build, outdated, deps, constructs, devcontainer, openspec, git, test-settings, bwrap, k8s, test-tree, startup-imports, swallowed-failures, domain, roadmap-stage-eval-commits). Comma-separated or repeated." }, "shard": { "default": 1, @@ -1421,7 +1421,7 @@ } ], "default": null, - "description": "Skip the specified check names (comma-separated or repeated)." + "description": "Skip the specified check names (test, lint, format, typecheck, audit, security, actionlint, zizmor, docs, uv-check, lockfile, build, outdated, deps, constructs, devcontainer, openspec, git, test-settings, bwrap, k8s, test-tree, startup-imports, swallowed-failures, domain, roadmap-stage-eval-commits). Comma-separated or repeated." } }, "type": "object" diff --git a/tests/commands/test_ci.py b/tests/commands/test_ci.py index 8b5cf4a913..1757739a73 100644 --- a/tests/commands/test_ci.py +++ b/tests/commands/test_ci.py @@ -542,9 +542,9 @@ def test_ci_additional_subcommands(process_fake: ProcessFake) -> None: res_docs = runner.invoke(app, ["docs"]) assert res_docs.exit_code == 0 - # 4. run subcommand with --fix + # 4. gate with --fix process_fake.reset() - res_run_fix = runner.invoke(app, ["run", "--fix"]) + res_run_fix = runner.invoke(app, ["--fix"]) assert res_run_fix.exit_code == 0 assert any("generate" in c for c in _started(process_fake)) @@ -573,9 +573,9 @@ def test_ci_helpers_and_edge_cases(ci_root: Path, process_fake: ProcessFake) -> "Total Elapsed:" in said, ) == (1, True, True, True, True) - # 3. the run command executes every check and gives one status + # 3. the gate executes every check and gives one status process_fake.reset() - res_run = runner.invoke(app, ["run", "--no-fix"]) + res_run = runner.invoke(app, ["--no-fix"]) assert (res_run.exit_code, len(process_fake.calls) >= 1) == (0, True) # 4. test command with invalid -k filter @@ -634,7 +634,7 @@ def test_ci_clean_coverage_and_extended_options(ci_root: Path, process_fake: Pro @pytest.mark.usefixtures("ci_root", "ci_head") def test_ci_run_docs_fix_when_needed(process_fake: ProcessFake) -> None: """Verify that CI fix pipeline triggers doc generation when docs check fails.""" - result = runner.invoke(app, ["run", "--fix"]) + result = runner.invoke(app, ["--fix"]) called = _started(process_fake) assert result.exit_code == 0 @@ -2221,9 +2221,9 @@ def test_ci_cli_runner_only_and_skip_validation() -> None: res_both.exit_code, "Cannot combine --only and --skip" in res_both.output, res_invalid_only.exit_code, - "Invalid check name(s): 'invalid_gate'" in res_invalid_only.output, + "Unknown check row: 'invalid_gate'" in res_invalid_only.output, res_invalid_skip.exit_code, - "Invalid check name(s): 'invalid_gate'" in res_invalid_skip.output, + "Unknown check row: 'invalid_gate'" in res_invalid_skip.output, ) == (2, True, 2, True, 2, True) diff --git a/tests/commands/test_ci_dry_run.py b/tests/commands/test_ci_dry_run.py index b92f6b4478..c09579c97e 100644 --- a/tests/commands/test_ci_dry_run.py +++ b/tests/commands/test_ci_dry_run.py @@ -101,22 +101,8 @@ def test_ci_all_checks_dry_run(recorder: list[list[str]]) -> None: assert ("✓ pass" in res.stdout, "CI Summary" in res.stdout) == (False, False) -def test_ci_run_command_dry_run(recorder: list[list[str]]) -> None: - """devops ci run --dry-run prints fix steps and checks and exits 0.""" - res = runner.invoke(app, ["run", "--dry-run"]) - assert (res.exit_code, len(recorder), is_dry_run()) == (0, 0, True) - assert ( - "1. uv --preview-features malware-check,check-command run ruff format ." in res.stdout, - "2. uv --preview-features malware-check,check-command run ruff check --config pyproject.toml --fix ." - in res.stdout, - "3. uv --preview-features malware-check,check-command run devops docs generate" - in res.stdout, - ) == (True, True, True) - assert ("✓ pass" in res.stdout, "CI Summary" in res.stdout) == (False, False) - - def test_ci_dry_run_unlinks_nothing(recorder: list[list[str]], ci_root: Path) -> None: - """devops ci --dry-run and devops ci run --dry-run unlink no coverage files.""" + """devops ci --dry-run unlinks no coverage files.""" cov_worker = ci_root / ".coverage.sample" cov_xml = ci_root / "coverage.xml" cov_worker.write_text("worker data") @@ -125,15 +111,13 @@ def test_ci_dry_run_unlinks_nothing(recorder: list[list[str]], ci_root: Path) -> os.utime(cov_worker, (two_hours_ago, two_hours_ago)) res_ci = runner.invoke(app, ["--dry-run"]) - res_run = runner.invoke(app, ["run", "--dry-run"]) assert ( res_ci.exit_code, - res_run.exit_code, cov_worker.exists(), cov_xml.exists(), len(recorder), - ) == (0, 0, True, True, 0) + ) == (0, True, True, 0) @pytest.mark.usefixtures("ci_root") diff --git a/tests/commands/test_ci_row_commands.py b/tests/commands/test_ci_row_commands.py new file mode 100644 index 0000000000..f902fcef88 --- /dev/null +++ b/tests/commands/test_ci_row_commands.py @@ -0,0 +1,180 @@ +"""Tests for generated and hand-written row commands of the ci group.""" + +from __future__ import annotations + +import json +import platform +from collections.abc import Callable +from pathlib import Path +from typing import Any + +import pytest +from typer.testing import CliRunner + +from devops_cli.commands.ci import ( + CHECK_ROW_NAMES, + _planned_requests, + app, + get_check_spec, + get_check_specs, +) +from tests.support.agent_markers import agent_marker_names +from tests.support.fakes.process import ProcessAnswer, ProcessCall, ProcessFake + +platform.processor() + +runner = CliRunner() + +_LEDGER = "usage-errors.jsonl" +Ledger = Callable[[], list[dict[str, Any]]] + + +@pytest.fixture +def ledger(tmp_path: Path, monkeypatch: pytest.MonkeyPatch) -> Ledger: + """A user data root of the test's own, and a caller with no agent or CI marker: a person.""" + for name in agent_marker_names(): + monkeypatch.delenv(name, raising=False) + root = tmp_path / "data" + monkeypatch.setenv("DEVOPS_CLI_USER_DATA_ROOT", str(root)) + + def read() -> list[dict[str, Any]]: + path = root / _LEDGER + lines = path.read_text(encoding="utf-8").splitlines() if path.exists() else [] + return [{k: v for k, v in json.loads(line).items() if k != "at"} for line in lines] + + return read + + +@pytest.fixture +def recorder(process_fake: ProcessFake) -> list[list[str]]: + """Capture the programs the runner is asked to start, answering each with success.""" + calls: list[list[str]] = [] + + def record(call: ProcessCall) -> ProcessAnswer: + calls.append(list(call.argv)) + return ProcessAnswer() + + process_fake.answer(lambda _call: True, record) + return calls + + +def test_a_row_command_plans_only_its_row(recorder: list[list[str]]) -> None: + """A row with no hand-written command runs dry-run and plans only its requests.""" + res_constructs = runner.invoke(app, ["constructs", "--dry-run"]) + assert res_constructs.exit_code == 0 + constructs_spec = get_check_spec("constructs") + for req in _planned_requests(constructs_spec): + assert req.line() in res_constructs.stdout + + test_tree_spec = get_check_spec("test-tree") + for req in _planned_requests(test_tree_spec): + assert req.line() not in res_constructs.stdout + + res_tree = runner.invoke(app, ["test-tree", "--dry-run"]) + assert res_tree.exit_code == 0 + for req in _planned_requests(test_tree_spec): + assert req.line() in res_tree.stdout + for req in _planned_requests(constructs_spec): + assert req.line() not in res_tree.stdout + + +def test_the_row_tuple_matches_the_registry() -> None: + """The static row tuple in ci.py equals the check specs in registry order.""" + expected = tuple(spec.name for spec in get_check_specs()) + assert CHECK_ROW_NAMES == expected + + +def test_a_row_with_a_hand_written_command_runs_dry_run(recorder: list[list[str]]) -> None: + """A row with a hand-written command plans its command under dry-run.""" + res = runner.invoke(app, ["lint", "--dry-run"]) + assert res.exit_code == 0 + expected_cmd = "uv --preview-features malware-check,check-command run ruff check --config pyproject.toml --fix ." + assert f"1. {expected_cmd}" in res.stdout + + +def test_a_misspelled_only_name_records_bad_value(cli: Callable[..., Any], ledger: Ledger) -> None: + """A misspelled row name in --only raises bad parameter and records bad_value.""" + res = cli("ci", "--only", "constructz") + assert res.exit_code == 2 + assert "constructs" in res.output + records = ledger() + assert len(records) == 1 + assert records[0]["kind"] == "bad_value" + assert records[0]["command_path"] == "ci" + + +def test_a_misspelled_skip_name_records_bad_value(cli: Callable[..., Any], ledger: Ledger) -> None: + """A misspelled row name in --skip raises bad parameter and records bad_value.""" + res = cli("ci", "--skip", "constructz") + assert res.exit_code == 2 + records = ledger() + assert len(records) == 1 + assert records[0]["kind"] == "bad_value" + assert records[0]["command_path"] == "ci" + + +def test_ci_only_multiple_comma_separated_dry_run(recorder: list[list[str]]) -> None: + """Comma-separated check rows in --only plan exactly those rows.""" + res = runner.invoke(app, ["--only", "constructs,openspec", "--dry-run"]) + assert res.exit_code == 0 + constructs_spec = get_check_spec("constructs") + openspec_spec = get_check_spec("openspec") + test_tree_spec = get_check_spec("test-tree") + for req in _planned_requests(constructs_spec): + assert req.line() in res.stdout + for req in _planned_requests(openspec_spec): + assert req.line() in res.stdout + for req in _planned_requests(test_tree_spec): + assert req.line() not in res.stdout + + +def test_ci_only_repeated_option_dry_run(recorder: list[list[str]]) -> None: + """Repeated --only options plan exactly those rows.""" + res = runner.invoke(app, ["--only", "constructs", "--only", "openspec", "--dry-run"]) + assert res.exit_code == 0 + constructs_spec = get_check_spec("constructs") + openspec_spec = get_check_spec("openspec") + test_tree_spec = get_check_spec("test-tree") + for req in _planned_requests(constructs_spec): + assert req.line() in res.stdout + for req in _planned_requests(openspec_spec): + assert req.line() in res.stdout + for req in _planned_requests(test_tree_spec): + assert req.line() not in res.stdout + + +def test_the_selection_help_names_the_rows() -> None: + """The help of --only and --skip lists each row name.""" + res = runner.invoke(app, ["--help"]) + assert res.exit_code == 0 + lines = res.stdout.splitlines() + only_lines: list[str] = [] + skip_lines: list[str] = [] + target: list[str] | None = None + for line in lines: + if "--only" in line: + target = only_lines + elif "--skip" in line: + target = skip_lines + elif target is not None and line.strip().startswith("--"): + target = None + if target is not None: + target.append(line) + only_block = " ".join(only_lines) + skip_block = " ".join(skip_lines) + for name in CHECK_ROW_NAMES: + assert name in only_block + assert name in skip_block + + +def test_the_removed_run_command_records_unknown_command( + cli: Callable[..., Any], ledger: Ledger +) -> None: + """The removed 'run' subcommand exits 2 and records unknown_command with command path 'ci'.""" + res = cli("ci", "run") + assert res.exit_code == 2 + records = ledger() + assert len(records) == 1 + assert records[0]["kind"] == "unknown_command" + assert records[0]["command_path"] == "ci" + assert records[0]["name"] == "run" diff --git a/tests/commands/test_net_construct_rules.py b/tests/commands/test_net_construct_rules.py index d1b3810ef0..0b15eff6d4 100644 --- a/tests/commands/test_net_construct_rules.py +++ b/tests/commands/test_net_construct_rules.py @@ -13,7 +13,7 @@ def test_ci_constructs_row_matches_constants() -> None: - """The constructs row in devops ci runs the scan with CONST_AST_GREP_SCAN_ARGS.""" + """The constructs row of devops ci executes the scan with CONST_AST_GREP_SCAN_ARGS.""" spec = get_check_spec("constructs") assert spec.cmd == ["uv", "run", "ast-grep", *CONST_AST_GREP_SCAN_ARGS] assert len(CONST_BANNED_HAND_ROLLED_APIS) == 4 diff --git a/tests/roadmap/implement/test_roadmap_implement_shell_policy.py b/tests/roadmap/implement/test_roadmap_implement_shell_policy.py index 31b510b05a..ce04aca9e6 100644 --- a/tests/roadmap/implement/test_roadmap_implement_shell_policy.py +++ b/tests/roadmap/implement/test_roadmap_implement_shell_policy.py @@ -503,11 +503,14 @@ def test_the_shell_section_of_the_document_names_the_directory_tool_and_the_scra # ── The local devops commands ───────────────────────────────────────────────────────────── -def test_the_local_commands_are_the_five_commands_of_the_project_and_none_uses_the_network() -> ( +def test_the_local_commands_are_the_eight_commands_of_the_project_and_none_uses_the_network() -> ( None ): assert [(c.words, str(c.access)) for c in LOCAL_COMMANDS] == [ (("ci", "test"), "write"), + (("ci", "constructs"), "read"), + (("ci", "docs"), "read"), + (("ci", "openspec"), "read"), (("ai", "repomap"), "read"), (("ai", "ast"), "write"), (("docs", "generate"), "write"), diff --git a/tests/telemetry/test_telemetry_instruments.py b/tests/telemetry/test_telemetry_instruments.py index e855df9f92..f3c0c1cac4 100644 --- a/tests/telemetry/test_telemetry_instruments.py +++ b/tests/telemetry/test_telemetry_instruments.py @@ -642,6 +642,16 @@ def test_the_roadmap_tool_instruments_are_declared_with_their_kinds_and_units() } == expected +def test_the_gate_slot_histogram_description_names_no_command() -> None: + """The gate-slot histogram description names no command (#5451).""" + from devops_cli.telemetry.instruments import CI_GATE_SLOT_WAIT + + assert ( + CI_GATE_SLOT_WAIT.description + == "Time a gate run waited for a free gate slot before its checks started" + ) + + def test_the_telemetry_document_lists_each_roadmap_tool_instrument_with_its_kind_and_unit() -> None: document = (REPO_ROOT / "docs" / "TELEMETRY.md").read_text(encoding="utf-8")