Skip to content

test(ci): the suite's slowest tests run on recorded scanner and installer results, not real semgrep, gitleaks, bandit, uv audit, uv pip sync or sudo #1666

Closed

Description

@dan-petty

Friction

  • After the page-cap test, the slowest tests in every full run are the ones that start real external tools. Together they cost about 186 worker-seconds per full run at load 27, and they grow 2-6x as load rises.
  • Several of them reach the network from a child process, which the in-process network guard does not see. The gate then depends on PyPI, OSV and the Semgrep registry being up, against the owner's rule that tests never touch the network or real scanners.
  • They also run on pre-commit whenever a change selects them.

Evidence

Checked at release/v0.2.37 30b8fdd with strace and a PATH-shim sweep of a gate-shaped full run.

Remedy

  • test_ci_maintain_live: also patch devops_cli.commands.ci._returncode, as the neighbouring test does.
  • The six scanner-running tests: patch run_semgrep_scan and run_gitleaks_scan (and bandit in the gateway tests) as tests/test_review_path_routing.py:204-205 does, and feed recorded outputs where a test needs findings.
  • test_devcontainer_post_create_scaffolds_agent_instructions: pass --skip-tools or patch devops_cli.commands.install_tools.install_managed_tools.
  • test_ensure_path_ownership_and_mount_edge_cases: stub the chown subprocess.
  • The test conventions say the no-network rule covers every process a test starts, and that the gate's uv audit, uv tree --outdated and uv check are its intended network checks. They go in docs/TESTING.md if docs(cli): docs/TESTING.md holds the test conventions, ADR 0005 records that tests double only process edges, and AGENTS.md and the contributor docs point to them #1308 has created it by then (AGENTS.md:111 already links it, but it does not exist at 30b8fdd), otherwise in docs/SDLC.md Phase 2 beside its mock-isolation rule (docs/SDLC.md:105).
  • Every test and assertion stays.

Acceptance criteria

  • Tests first, offline: an autouse guard in tests/conftest.py wraps run_subprocess and fails a test that would start a scanner binary. It reads the binaries from the binary_name of every BaseSecurityScanner subclass (src/devops_cli/security/base.py:415), not from a hand-kept list. It does not use every BIN_* constant in src/devops_cli/config/commands.py, which also names git, uv, find and kustomize that tests run legitimately. It fails on today's tree for the scanner-running tests above and passes after the patches. The same guard fails a test that would start the real gh (CONST_GH_CLI) through the process edge run_gh uses; a test that needs gh output scripts it with the existing gh fakes. Any other test it catches, for example one that starts ruff or mypy through a scanner class, is named in the PR and patched the same way.
  • test(cli): the hermetic floor fails a test that reaches an edge without a fake and resets all process-wide state after every test #1310's hermetic floor, when it lands, denies processes in general and replaces this guard; the guard says so in its docstring.
  • Each changed test keeps its assertions and passes with no network (run under unshare -n or with the guard).
  • In a full run, --durations shows none of the named tests above 5 s at load under 20.

Activity

  1. added
    source/agent
    type/test
    on Oct 18, 2026
  2. dan-petty commented on Oct 18, 2026

    @dan-petty
    OwnerAuthor

    Intake placed this item to the backlog: at intake only a critical fix goes into a release; a release start pulls Ready items in, P0 features first.

    • Type: type/test. The candidate is about improving test performance and reliability by patching external tool calls.
    • Priority: P2-Medium. Improves CI performance and test stability, but does not block other work or introduce critical issues.
    • Value: Medium. Improves developer experience and CI speed for a subset of tests that currently run slow external tools.
    • Effort: High. Requires patching multiple test files, updating mock setups, and ensuring recorded outputs work correctly.
  3. dan-petty commented on Oct 20, 2026

    @dan-petty
    OwnerAuthor

    Intake marked #1725 a duplicate of this item on 2026-10-20 and folded it. That was a misjudgement: #1725 holds v0.2.38 to the owner's timing targets (gate at most 2 minutes, PR CI at most 3, no test over 5 seconds, no test touching the network, real tools or localhost services) and lists every measured cost with its owner. This item owns one row of that table, the real semgrep, gitleaks and bandit runs (6 tests, about 82s, with semgrep downloading p/default from inside tests). #1725 was created directly and links back here.

  4. added this to the v0.2.38 milestone on Oct 20, 2026
  5. added 2 commits that reference this issue on Oct 20, 2026
    63951cc
    84ee9ca
  6. dan-petty commented on Oct 20, 2026

    @dan-petty
    OwnerAuthor

    What changed

    #1738, merged into release/v0.2.38 as 84ee9ca.

    Closes #1666

    This counts toward the v0.2.38 CI time budget in #1725: it removes the "real scanners" row (semgrep, gitleaks and bandit in six tests).

    15 file(s) changed.

    How it was verified

    Check runs at 63951cc:

    • Prune PR DevContainer Images: pass
    • Audit Defect PR Hardening: skipping
    • devops-cli: pass
    • zizmor: pass
    • bandit: pass
    • CodeQL: pass
    • Dependency Freshness: skipping
    • Static Analysis: pass
    • Tests & Coverage: pass
    • Rule Pack Tests: pass
    • Changed-Test Independence: pass
    • Fail-to-Pass Self-Check: pass
    • Analyze (python): pass
    • Fail-to-Pass Check: pass
    • Analyze (actions): pass
    • Service Image: skipping
    • DevContainer Image: skipping

    Acceptance Criteria of docs/agent/tasks/task-1666-recorded-scanner-results.md:

    • Tests first, offline: the refusal fails a test that would start a scanner binary or gh. It sits on subprocess.Popen rather than wrapping run_subprocess, so it also covers run_gh, a direct subprocess.run and asyncio, and reads the names from the scanner registry rather than from every BaseSecurityScanner subclass, which would refuse the ruff the swallowed-failures ratchet runs. Before the refusal existed, every refusal case in tests/test_suite_refuses_real_programs.py failed (FileNotFoundError for each program named at /usr/local/bin, DID NOT RAISE for the shell command and the handler of every exception), and the git case passed. Under the refusal and before the fake, the six scanner tests failed, each naming the real Bandit or Gitleaks it started; with scanner_fake they pass. No test started gh. One full run under a stricter list that also named uv and sudo caught one other test, tests/test_release.py::test_uv_lock_check_offline_passes_after_bump, which runs uv lock --check --offline on purpose.
    • The refusal's docstring says test(cli): the hermetic floor fails a test that reaches an edge without a fake and resets all process-wide state after every test #1310's hermetic floor replaces it.
    • Each changed test keeps its assertions and passes with no network: the six tests, the contract suite and the refusal's tests passed under unshare -rn.
    • The named tests, alone with -n 0 beside other agents' work (load average 12-25 on 16 CPUs): test_a_branch_cannot_loosen_its_own_review 14.66 s to 2.15 s, test_review_pipeline_admit_inline_suppression_added_by_change 11.89 s to 0.74 s, test_five_personas_with_one_transient_503_sees_exactly_six_calls 7.42 s to 0.86 s, test_pipeline_multi_scanner_aggregation 7.34 s to 0.77 s, test_transport_answers_400_once_fails_without_second_attempt_and_reports_status 7.30 s to 0.59 s and test_routed_files_only_branch_diff_makes_no_model_calls 1.00 s to 0.06 s: 49.6 s to 5.2 s. In a full run at load average 41-52, none of them was among the 60 slowest (7.35 s and up).
    • Pending a person: the full-run check at load under 20. On a quiet host, run uv run pytest -q --durations=0 tests | grep -E 'loosen_its_own_review|admit_inline_suppression|multi_scanner_aggregation|five_personas_with_one_transient|400_once_fails|routed_files_only_branch'; each should show under 5 s.
  7. added 3 commits that reference this issue on Oct 21, 2026
    1a8b26c
    f92399e
    64e74dd
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

    source/agenttype/test

    Type

    No type

    Projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions