Skip to content

test(roadmap): run each implement scenario once with subtests #4722

Open

Description

@dan-petty

Problem or Motivation

81 groups (199 tests) run one identical job scenario and check different facts. The tests have the same arrange, the same run lines and the same branch arcs (measured from coverage contexts). For example, tests/roadmap/implement/test_roadmap_implement_job.py:278, 307, 439, 524 and 545 all run job_world.run(two_groups()).

One run per group saves 499.3 s in a local full run with per-test coverage contexts, which is 60-140 s of CI worker time before the registry fix (estimated). Changed-Test Independence runs each changed file 3 times, so it gains 3 times as much.

Saving: 60-140 s of CI worker time before the registry fix (estimated). The saving is smaller after it.

Found by the CI and test audit of 2026-11-11. The account runs at most 20 hosted jobs at one time (measured), so each job that does no work makes the queue of each pull request longer.

Proposed Solution & Architectural Design

Risk: Low. Test ids change. The reviewer must accept the subtest form (docs/TESTING.md allows consecutive asserts).

Target Subsystem

SDLC, Git & PR Governance (tests/roadmap/implement/).

Existing Tool Considered

The subtests fixture, built into pytest (9.2.0 is the pinned version). It works under xdist (measured: the report names a failing subtest). No new tool. Cost: about 60,000 tokens and 4 hours.

Acceptance Criteria

Dependencies

Depends on #4509.

Alternatives check of 2026-11-30: not-applicable.
Class: test, no model call.
Tool: none found.

Proposed design

Problem statement

The change folds each implement test group into one scenario run with pytest subtests. The package has 81 groups of 199 tests. Each group runs the same job scenario and checks different facts. One run per group saves 499.3 s in a local full run with per-test coverage contexts, and 60-140 s of CI worker time before the registry fix. The change depends on #4509 for the measurement. A test-tree check holds the run count and the subtest form.

Acceptance criteria

Requirement: Folded modules pass

Each folded test module of tests/roadmap/implement/ MUST pass after the fold.

Scenario: The implement test package passes

  • WHEN uv run pytest tests/roadmap/implement/ -q runs
  • THEN the run exits 0 and reports no failure.

Requirement: Run count held at the recorded ceiling

The test-tree check SHALL hold the count of job_world.run( calls in each module of tests/roadmap/implement/ at or below the count in tests/gate/tree_checks/implement_scenario_runs.toml.

Scenario: The check prints the run count of each module

  • WHEN uv run devops ci --check --only test-tree runs
  • THEN the check passes and prints the count of job_world.run( calls of each module of tests/roadmap/implement/.

Requirement: The check refuses a count above the ceiling

The check MUST fail when a module holds more job_world.run( calls than its recorded count.

Scenario: A small tree above the ceiling fails the check

  • WHEN a test of the check gives it a small tree with a count above the recorded count
  • THEN the check fails and names the module and the two counts.

Requirement: Each folded fact is a subtest

Each assert that follows the run call of a test SHALL sit inside a with subtests.test('<behaviour>') block.

Scenario: An assert outside a subtest block fails the check

  • WHEN a test of the check gives it a small tree whose assert after the run call sits outside a with subtests.test( block
  • THEN the check fails and names the file and the line of the assert.

Requirement: Subtest label is a literal

Each subtests.test( call of a folded test MUST take a literal string label.

Scenario: A label that is a variable fails the check

  • WHEN a test of the check gives it a small tree whose subtests.test( call takes a variable
  • THEN the check fails and names the file and the line of the call.

Requirement: Pending a person after the merge

The issue MUST hold the saving measured after #4509 lands.

Scenario: The measured saving is recorded

Existing Tool Considered

The alternatives check of 2026-11-30 in the issue body gives not-applicable: class test, no model call, and no tool found. The subtests fixture of pytest (pinned 9.2.0) covers the need; the issue body records that it works under xdist. It lacks a stable per-fact test id, so test ids change. The change keeps the behaviour name as the literal subtest label. No new dependency. The issue body gives the cost as about 60,000 tokens and 4 hours.

Key questions

  • Which mechanism folds the identical implement job scenarios?: Use the subtests fixture of pytest. One with subtests.test('<behaviour>') block checks each fact after one scenario run. (best practice) [sources: docs/TESTING.md, tests/roadmap/implement/test_roadmap_implement_job.py]
    • Chosen: subtests fixture. Each fact keeps its own label, a failing fact names itself, and the body records that it works under xdist.
    • Rejected: Consecutive asserts. docs/TESTING.md allows them, but the first failure hides the later facts and the report names no fact.
    • Rejected: Parametrized tests. Each case runs the scenario again, so the change saves no run time.
  • How is the saving measured after perf(test): stage gate tests parse every test file per call #4509 lands?: Measure the count of job_world.run( calls and the CPU time of the package with per-test coverage contexts on pinned CPUs. Record the numbers in the issue. Never bound elapsed time in a test. (best practice) [sources: docs/TESTING.md]
    • Chosen: Pinned-CPU run with per-test coverage contexts. The count of runs is deterministic, and docs/TESTING.md refuses a test that bounds elapsed time from above.
    • Rejected: Wall time of a shared host. A loaded host varies more than the change.
    • Rejected: A test that bounds the run time. The test-elapsed-upper-bound rule and docs/TESTING.md refuse it.
  • Should a test-tree check hold the run count and the subtest form?: Yes. A check_* function in tests/gate/tree_checks/ holds the count of job_world.run( calls per module and refuses an assert after the run that sits outside a subtests.test( block. (best practice) [sources: AGENTS.md, docs/TESTING.md, tests/gate/tree_checks/config_values.py]
    • Chosen: Add the test-tree check. AGENTS.md rule 11 asks for a check that fails if the problem returns, and the test-tree row holds the invariants over tests/.
    • Rejected: Review only. A later test can add a second run with no check to refuse it.
    • Rejected: No guard. The fold would regress with no signal.
  • Does the fold add a test?: No. docs/TESTING.md gives no new test to an edit of tests only, so the run of the changed modules is the proof. The new check gets a test of its logic with a small tree. [sources: docs/TESTING.md]
  • Which tests fold first?: Fold the exact two_groups() group of tests/roadmap/implement/test_roadmap_implement_job.py first, then the other exact groups of the package. Fold a test that shares only a prefix after you read it. (best practice) [sources: tests/roadmap/implement/test_roadmap_implement_job.py]
    • Chosen: Exact groups first. The issue names these tests, and they share the same arrange, run lines and branch arcs.
    • Rejected: Every prefix group at once. The issue says to fold a test that shares only a prefix after you read it.

Fit

Fits in one pull request.

Suspected block

None.

Dependencies

#4509

Activity

  1. added
    source/agent
    type/test
    scope/roadmap
    status/new
    value/medium
    effort/medium
    on Nov 11, 2026
  2. dan-petty commented on Nov 11, 2026

    @dan-petty
    OwnerAuthor

    Intake placed this item to the backlog: intake puts every new item in the backlog. A person plans the milestones.

    • Type: type/test. The test prefix of the title gives the type.
    • Scope: scope/roadmap. The (roadmap) scope of the title gives the scope.
    • Priority: P2-Medium. Saves 60-140 s of CI time but depends on #4509 and does not fix a defect.
    • Value: Medium. Reduces CI worker time and queue length without changing test coverage.
    • Effort: Medium. 81 groups to refactor with a mechanical subtests pattern, estimated at about 4 hours.
    • Related: test(roadmap): the four largest roadmap test files split by behaviour #3748, which asks for a different change. Both reorganize roadmap test files, but #3748 splits large files by behaviour while the candidate folds redundant scenario runs into subtests.
  3. added
    priority/p2-medium
    on Nov 11, 2026
  4. devops-cli-service commented on Nov 14, 2026

    @devops-cli-service
    Contributor

    Alternatives check: not-applicable

    Class: test. The check makes no search and no model call for an item of this class.

    Tool: none found

    Checked on 2026-11-14. A person decides what this means for the item. The check changes no label and closes no issue.

  5. added
    status/ready
    and removed
    status/new
    on Nov 15, 2026
  6. devops-cli-service commented on Nov 15, 2026

    @devops-cli-service
    Contributor

    Status set to Ready at a8a99cb (see proposed design in issue body).

  7. dan-petty commented on Nov 20, 2026

    @dan-petty
    OwnerAuthor

    Frozen on 2026-11-20. The stage, implement and fix-checks jobs grade under 60%, so the owner rule asks for a re-architecture before more fixes inside the current design (tracker #6519). This item is incremental work on those jobs, so its Dependencies section now names #6521 first. Stage and implement leave this item while #6521 is open. When the experiments of #6519 decide, a person closes #6521 (this item can then continue) or closes this item as not planned.

  8. added
    status/new
    and removed
    status/ready
    on Nov 26, 2026
  9. devops-cli-service commented on Nov 26, 2026

    @devops-cli-service
    Contributor

    Next step: the open items close, or a person replies in a comment or edits the body. See Dependencies in the section Proposed design of the body.

  10. added
    status/ready
    and removed
    status/new
    on Dec 1, 2026
  11. devops-cli-service commented on Dec 1, 2026

    @devops-cli-service
    Contributor

    Next step: the stage job writes the plan of the item. See the section Proposed design of the body.

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

    effort/mediumpriority/p2-mediumscope/roadmapsource/agentstatus/readytype/testvalue/medium

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions