Skip to content

refactor(ci): github ci runs the gate through devops ci from one check table #843

Closed

Description

@dan-petty

Problem Statement

GitHub CI and the local gate (uv run devops ci) define their checks separately, and the copies have drifted. Check argv lives in three places at HEAD (9c879ae):

  • the aggregate gate, _run_all_checks_async (src/devops_cli/commands/ci.py:312-485);
  • the per-check subcommands (ci.py:798-1074), which run through _run → run_subprocess (ci.py:172-185, synchronous, output streamed by default) while the gate runs through run_subprocess_async with output captured (ci.py:275-280); both insert uv --preview-features malware-check,check-command (ci.py:180-181, :271-272);
  • the static and test jobs in .github/workflows/ci.yml:25-97.

Drift at HEAD:

  • Bandit. CI runs bandit -r src/ -ll -ii (ci.yml:60). The gate runs -ll -s B608 (ci.py:431), and so does devops ci security (ci.py:984). The scanner adapters also skip B608 (security/bandit.py:69,75,85, ai/tools/builtin_tools.py:321). build_bandit_cmd (config/commands.py:126-128) passes B608 to -x, which excludes paths, not tests. Only its own test calls it (tests/test_command_builders.py:77).
  • This drift has already failed a PR. Run 35455994333 (2026-09-19) failed CI's Bandit step on three B608 MEDIUM/MEDIUM findings in ai/spend/ledger.py. The local gate's -s B608 had skipped them.
  • devcontainer. devops devcontainer validate runs only in CI (ci.yml:69). Run 35944910698 (2026-09-24) failed on that step.
  • pytest.
    • The gate runs -n auto --maxprocesses=<min(cpus, 8)> --durations=10 --cov=src --cov-report=term-missing (ci.py:376-389).
    • CI runs pytest --cov=src --cov-report=xml (ci.yml:97) with addopts = "-n logical" (pyproject.toml:105). That writes .data/coverage.xml (pyproject.toml:124-125).
  • docs fix. In fix mode the gate runs devops docs generate --sync-readme on its own, before the concurrent phase (ci.py:357-364, since 15bf983), and then devops docs check inside it (ci.py:442-448). devops ci docs --fix runs generate and then check in sequence (ci.py:1021-1025). So the fixer sits on the gate's critical path, and the two paths order the work differently.

Measured with bandit 1.9.4 (uv.lock:260-261) at HEAD: uv run bandit -r src -ll -f json -q reports 2 findings. Both are B608, MEDIUM severity, LOW confidence. CI's -ii and the gate's -s B608 both hide them.

  • ai/instruction_generator.py:221 is an f-string of Markdown. The string ends at :409.
  • commands/k8s/stack_lifecycle.py:296 is a Python script that runs in the Open WebUI pod (finding range :296-318). Its SQL is parameterised, but it embeds repr() of the admin credentials (:309-312).

Two hand-written roadmap entries ask for this. Neither has an issue, and docs/ROADMAP.md is now rendered from GitHub at each cut (#739, shipped in v0.2.25 as 6948e1c; docs/ROADMAP.md:3-4), so they are not edited here:

  • "Single-Source CI Gate Definitions" (docs/ROADMAP.md:1055, P2). This item delivers its steps 1, 3 and 4: a ci.yml parity test, one argv source for the gate and the subcommands with CI calling it, and -ll everywhere with a reasoned # nosec B608 per finding. [tool.bandit] cannot hold level or confidence (:1058).
  • "Gate Calibration Drill" (docs/ROADMAP.md:935, P1). This item delivers the part of its registry that is the one argv source for devops ci and CI, and its ci.yml parity case. It does not deliver the rest of that entry: the registry's claim, asserting-line, fixture and corpus columns; its entries for the structural hook, scan complexity and the --fail-on scans; its later steps. Its proposal to move B608 into [tool.bandit] skips is superseded by the per-finding nosec.

The owner moved this item into v0.2.26 in place of #408 (2026-10-01). v0.2.26 ships the unattended roadmap service (#741, #752, #753, #1083, #981), which should merge behind GitHub CI that runs the same checks as the local gate.

Proposed Solution

One ordered table of check specs in commands/ci.py. Each row has a name, a check argv and an optional fix argv.

  • Rows, in today's order (ci.py:374-470): test, lint, format, typecheck, audit, security, actionlint, docs, uv-check, lockfile, outdated.
  • A new devcontainer row runs uv run devops devcontainer validate --workspace .. It is an offline JSON parse plus file-existence checks (commands/devcontainer.py:220-345).
  • The test row adds --cov-report=xml, so local and CI runs both write .data/coverage.xml. _clean_coverage_artifacts (ci.py:222-243) removes .coverage* and a root coverage.xml, not .data/coverage.xml, so the report survives the run.
  • The name uv_check becomes uv-check everywhere (row, summary, metric step), so each check has one spelling. Today only ci.py:450-454, lang/en/messages.py:720, lang/en/help.py:521 and tests/test_ci.py:168-178,207-214,257 read the old name.

The table feeds:

  • the aggregate gate: all_checks (ci.py:677-731) and run (ci.py:1127-1145). run keeps its --fix/--no-fix and --dry-run, gains no --only or --skip, and stays uncached as today (it never calls _handle_ci_results);
  • each subcommand that runs one row: lint, format, typecheck, audit, security, actionlint, docs, uv-check, lockfile, outdated, and coverage, which runs the test row.
    • In check mode, each one runs exactly its row's check argv.
    • In fix mode (the default for lint and format, --fix for docs), each one runs its row's fix argv. Docs then runs its check argv.
  • new --only and --skip options on the aggregate callback:
    • Both take row names, comma-separated or repeated.
    • An unknown name exits 2 and lists the valid names. So does passing both options.
    • python_version always runs. The coverage result appears only when test runs.

Hangs and timeouts:

  • A run that selects exactly one row streams that row's output instead of capturing it (capture_output=False on run_subprocess_async, core/process.py:405-406; today always True at ci.py:275-280). Tests & Coverage then shows pytest's progress live, as it does today. With streaming, the captured stdout is empty, so _warn_when_over_budget (ci.py:633-649) prints the warning without a slowest-tests list; the live --durations=10 output already holds it.
  • _execute_check_async (ci.py:259-298) turns TimeoutExpired (raised without output by run_subprocess_async, core/process.py:419-423) into a failed result that names the check and its limit. The other rows and the summary still print. Every row keeps DEFAULT_SUBPROCESS_TIMEOUT_SECONDS (1800 s, config/defaults.py:299); both CI jobs' timeout-minutes (15 and 30, ci.yml:29,75) end at or before that, so this path serves local runs. In CI, streaming covers Tests & Coverage and a hung Static Analysis row is the one without a pass or fail line.

Remove devops ci coverage --xml (ci.py:843, HELP.ci.xml_report at lang/en/help.py:507, the dry-run case at tests/test_ci_dry_run.py:83, docs/commands/ci.md:52), since the row always writes the XML report.

One bandit rule set:

  • The security row is uv run bandit -r src -ll.
  • The scanner adapters (security/bandit.py:69,75,85, ai/tools/builtin_tools.py:321) keep their target, severity and output flags, and drop -s B608.
  • Each of the two findings gets # nosec B608 # <reason> on a line inside the finding's range. Bandit 1.9.4 ignores a nosec on the line above the statement and honours one on the closing """ line or on a middle line of parenthesised adjacent literals (verified offline with scratch files). At instruction_generator.py, the only such place is after the closing """ (:409); at stack_lifecycle.py it goes on one of the credential lines (:309-312).
  • The stack_lifecycle reason names the embedded credentials, not "not SQL".
  • Delete build_bandit_cmd (config/commands.py:126-128), its re-export (config/__init__.py:32,858), its test (tests/test_command_builders.py:77) and DEFAULT_BANDIT_EXCLUDE (config/defaults.py:425).
  • docs/ROUTINE_TASKS.md:298 names only uv run devops ci security.
  • docs/cheatsheets/security_and_ssh.md:12 drops -ii.

ci.yml, with job ids and names unchanged:

  • Static Analysis: after toolchain setup, one step runs uv run devops ci --check --no-cache --skip test,outdated.
  • Tests & Coverage: one step runs uv run devops ci --check --no-cache --only test. Its setup-toolchain step keeps tooling-cache-paths: .pytest_cache (tests/test_ci.py:596-598 asserts it).
  • Dependency Freshness (scheduled): uv run devops ci outdated.
  • static, test and devcontainer keep no needs between them (tests/test_ci.py:600-613).
  • The workflow_dispatch trigger (ci.yml:16) and the if: github.event_name != 'schedule' condition on both gate jobs (ci.yml:27,73) stay as they are: feat(ci): devops pr update --dispatch-ci starts ci.yml on each branch it updates, and only update-prs.yml may hold actions: write #984 pins them and dispatches this workflow.

A parity test in tests/test_ci.py, beside the existing ci.yml tests (:538-630). It:

Regenerate the CLI docs. They drop --xml. The generator does not render group-callback options yet: docs/commands/ci.md lists no devops ci --check or --no-cache. --only and --skip appear once #854 lands. Do not fix the generator here.

Existing tests to carry over. tests/test_ci.py:28-220 patch subprocess.run per subcommand; :227-305 and :489-516 patch _execute_check_async with its current 6-parameter signature (ci.py:259-266). They are rewritten against the table, not kept beside it.

Scope

One pull request. It edits src/devops_cli/commands/ci.py, src/devops_cli/lang/en/{help,messages}.py, src/devops_cli/security/bandit.py, src/devops_cli/ai/tools/builtin_tools.py, src/devops_cli/ai/instruction_generator.py, src/devops_cli/commands/k8s/stack_lifecycle.py, src/devops_cli/config/{commands,__init__,defaults}.py, .github/workflows/ci.yml, tests/test_ci.py, tests/test_ci_dry_run.py, tests/test_command_builders.py, docs/commands/ci.md, docs/ROUTINE_TASKS.md, docs/cheatsheets/security_and_ssh.md, a task file and changelog.d/843.md.

Constraints:

Key Questions

  • Does the gate's isolated environment, which drops UV_* (core/process.py:27-84, applied at :121-146), still run uv run inside Actions? Answered: expected yes. setup-uv sets UV_PYTHON=3.14, UV_CACHE_DIR and UV_PYTHON_INSTALL_DIR. setup-toolchain runs uv sync --all-groups --all-extras (.github/actions/setup-toolchain/action.yml:46) with uv 0.12.16 and Python 3.14 (:33-34), creating .venv with CPython 3.14.7, which matches .python-version. So uv run should find an in-sync .venv without those variables. If it does not, uv run rebuilds the environment rather than failing, and the CI timing criterion catches that. The fix is then for the gate to pass the UV_* keys it finds through extra_allowed_env (core/process.py:230,356,535), where the deny patterns still apply. Isolation is never turned off.
  • Which names do --only and --skip take? Answered: the row names, spelled like the subcommands. uv_check becomes uv-check in the summary too. devcontainer gets no devops ci subcommand, because devops devcontainer validate already exists.
  • How do narrowed runs use the cache? Answered: they never read or write it. ci_options holds only fix and check (ci.py:714), and every passing run is saved (_handle_ci_results, ci.py:652-674). Otherwise a narrowed pass could certify the full gate. CI also passes --no-cache.
  • Which fixers run in a narrowed fix-mode run? Answered: only the selected rows' fix argvs. devops ci --only typecheck rewrites nothing.
  • Does devops ci test run the test row? Answered: no. It is the narrowed runner that the pre-commit hook calls with staged files (.pre-commit-config.yaml:62-68), and it takes -k, -x and -n (_build_test_cmd, ci.py:778-795). It runs without coverage, because fail_under = 90 (pyproject.toml:113) would fail any narrowed run. devops ci coverage and --only test run the test row.
  • Where do fix argvs run? Answered: the ruff fixers rewrite Python files that every other check reads, so they run one at a time before the concurrent phase, as today (ci.py:341-356, format then lint). The docs fixer writes only Markdown, so it moves from the serial pre-phase (ci.py:357-364) into the docs task, followed by docs check. That matches devops ci docs --fix and takes the fixer off the critical path.
  • Do the scanner adapters drop -s B608 too? Answered: yes. They scan reviewed code, where a blanket skip hides SQL injection. A false positive gets a nosec, as it does here. If the owner keeps their skip, the bandit criterion covers only the gate and ci.yml.
  • Does the test row write coverage XML on every local run? Answered: yes. Local and CI then run one argv, and feat(ci): changed-line coverage on pull requests (diff-cover) #850 can read the coverage.xml that CI already writes, as owner decision D4 requires. The before/after timing includes its cost.
  • Does devops ci security --severity stay? Answered: yes, as an explicit override for ad-hoc runs. With its default (medium, config/defaults.py:424), the subcommand runs the row.
  • Does this item edit docs/ROADMAP.md? Answered: no. feat(github): github-sourced roadmap, migration and generated roadmap view (devops roadmap migrate, render) #739 shipped in v0.2.25 (6948e1c); the file is rendered from GitHub at the cut and item PRs never edit it. The remainders of the two hand-written entries (:1055 steps 2 and 5, and the rest of :935) are named in the PR description as candidates for intake.
  • What is on the allowlist at landing? Answered: nothing, once refactor(ci): ci installs nothing on the runner, and live bubblewrap tests skip where bwrap is missing #832 has landed. Toolchain setup lives in the composite action (uses:), so every gate-job run: step is uv run devops ci .... The allowlist exists for later steps such as feat(ci): changed-line coverage on pull requests (diff-cover) #850's diff-cover and feat(release): production service image for scheduled jobs and webhook handlers #753's service-image job, each added with a reason.
  • What does CI show when a check fails or hangs? Answered: at least what it shows today. Today the test step streams pytest output, so a hang shows the last test that ran. Through the gate, output is captured (ci.py:275-280). On a timeout, run_subprocess_async kills the process and raises TimeoutExpired without its output (core/process.py:419-423), and _execute_check_async does not catch it (ci.py:259-298). Both jobs' timeout-minutes (15 and 30, ci.yml:29,75) end at or before the 1800 s check limit (config/defaults.py:299), so the runner would kill the job before anything prints. Hence: a single-row run streams, which covers Tests & Coverage, and a timeout becomes a failed result, which covers local runs. In Static Analysis each check prints its pass or fail line as it finishes (ci.py:288-289); a hung check is the one without a line. A failing check prints its full stdout and stderr; passing checks' output (_print_failures, ci.py:499-508) is not shown, which is acceptable. A per-row timeout column is not part of this item; if a shorter test-row limit is wanted later, it is a separate candidate.
  • What does devops ci run become? Answered: it is fed by the table like all_checks, keeps --fix/--no-fix and --dry-run, gains no --only or --skip (the issue places those on the aggregate callback), and stays uncached (ci.py:1127-1145 never calls _handle_ci_results). Folding it into the callback or deleting it is a separate candidate.
  • Which ci.yml properties must the rewrite preserve for the items that land after it? Answered: the job names Static Analysis and Tests & Coverage (ci.yml:26,72; required checks in chore(github): required CI checks bind merges into release and main, and ADR 0004 records the verification policy #842, pinned by feat(ci): devops pr update --dispatch-ci starts ci.yml on each branch it updates, and only update-prs.yml may hold actions: write #984's invariant), the workflow_dispatch trigger (ci.yml:16; feat(ci): devops pr update --dispatch-ci starts ci.yml on each branch it updates, and only update-prs.yml may hold actions: write #984 dispatches it) and the if: github.event_name != 'schedule' condition on both gate jobs (ci.yml:27,73; feat(ci): devops pr update --dispatch-ci starts ci.yml on each branch it updates, and only update-prs.yml may hold actions: write #984 requires a dispatched run to produce both checks). The parity test pins the names; the trigger and the conditions are not edited.

Acceptance Criteria

  • One bandit policy. uv run bandit -r src -ll exits 0. git grep -c "nosec B608" -- src totals 2. git grep -n -e '"B608"' -e '-ii' -- src .github ':!src/devops_cli/ai/knowledge_base' prints nothing (at HEAD it prints 8 lines). The PR description quotes all three outputs.
  • Parity. The parity test in tests/test_ci.py passes on the real ci.yml. Test cases that mutate the parsed workflow make it fail in each of these cases: a raw uv run ruff check . step is added to static; security is added to the static job's --skip, so no job reaches it; either pinned job is renamed. It runs in at most 1 s, checked with uv run pytest tests/test_ci.py --durations=0.
  • Selection, checked with CliRunner and run_subprocess_async patched (ci.py:276) in tests/test_ci.py: devops ci --only test runs only python_version, test and coverage, and invokes the aggregate rather than the test subcommand; --skip test,outdated runs every other row, devcontainer included; --only tset, and --only test --skip lint, exit 2 and list the valid names.
  • Subcommands match their rows. A test in tests/test_ci.py runs with run_subprocess patched (ci.py:182) and is parametrised over the rows. In check mode it checks each subcommand's argv against its row's check argv; in fix mode, against its row's fix argv, for rows that have one. coverage must equal the test row. The comparison is made on the same side of the --preview-features insertion (ci.py:180-181, :271-272) for both paths.
  • Fix order. With the runner patched, fix mode runs ruff format . and then ruff check --fix . before any check starts, and the docs task runs docs generate --sync-readme and then docs check. A test in tests/test_ci.py asserts the call order.
  • Hangs. With run_subprocess_async patched: --only test calls it with capture_output=False, and a full run calls it with capture_output=True; a runner that raises TimeoutExpired for typecheck makes the run exit 1, the summary marks typecheck failed with its limit, and every other row still reports. Tests in tests/test_ci.py.
  • Cache. A narrowed run neither reads nor saves the cache. A unit test in tests/test_ci.py with a tmp cache root checks both directions: after a passing --only lint run, a plain devops ci is not a cache hit; after a cached full pass, --only lint still calls the runner for lint.
  • --xml is gone. uv run devops ci coverage --xml exits 2, docs/commands/ci.md no longer lists it, and tests/test_ci_dry_run.py:83 no longer passes it.
  • ci.yml keeps what feat(ci): devops pr update --dispatch-ci starts ci.yml on each branch it updates, and only update-prs.yml may hold actions: write #984 reads. uv run pytest tests/test_ci.py passes with the existing ci.yml tests (tests/test_ci.py:538-630) kept, and the new file still has workflow_dispatch under on: and if: github.event_name != 'schedule' on static and test, checked by grep -n "workflow_dispatch\|github.event_name != 'schedule'" .github/workflows/ci.yml printing those three lines.
  • CI. The PR's own CI passes Static Analysis and Tests & Coverage. The PR description lists the Static Analysis job time and the Tests & Coverage test-step time, for its own run and for the last 5 successful runs. Each is no higher than the slowest of those 5. At ef21785, 6 successful runs took 42-64 s for the job and 123-177 s for the test step.
  • Local timing. The task file records uv run devops ci --no-cache wall-clock time, 3 runs before and 3 after, on the same machine and filesystem (ext4 if available). The median after the change is no higher than the slowest run before it.
  • Coverage XML. Pending a person: rm -f .data/coverage.xml && uv run devops ci --check --no-cache --only test && test -s .data/coverage.xml exits 0.
  • uv run devops ci passes, including docs, within its 5-minute budget; uv run actionlint passes on the new ci.yml.

Out of Scope

Dependencies

Order in v0.2.26: #832 → #843 → #406; #753 on either side of #843. After v0.2.26: #885 → #838 → #858 and #984 → #842 in v0.2.27, each after #843.

Activity

  1. added
    type/refactor
    scope/cli
    priority/p1-high
    on Oct 1, 2026
  2. added this to the v0.2.26 milestone on Oct 1, 2026
  3. dan-petty commented on Oct 1, 2026

    @dan-petty
    OwnerAuthor

    Moved into v0.2.26 in place of #408, by the owner's decision (2026-10-01). v0.2.26 ships the unattended roadmap service (#741, #752, #753), which should merge behind GitHub CI that runs the same checks as the local gate. Depends on #832.

  4. dan-petty commented on Oct 3, 2026

    @dan-petty
    OwnerAuthor

    #753 now merges first in v0.2.26, so this item, landing second, allowlists the service-image raw run: steps. #1083 joins the service this CI protects.

  5. dan-petty commented on Oct 4, 2026

    @dan-petty
    OwnerAuthor

    Closed by #1157, merged into release/v0.2.26.

    GitHub only acts on closing keywords when a pull request merges into the default branch, so this was closed by devops gh issues close-merged.

  6. added a commit that references this issue on Oct 4, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    priority/p1-highscope/clitype/refactor

    Type

    No type

    Projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions