Repository navigation
Description
Context & Rationale
core/coverage_index.py maps each source file to the test files whose coverage contexts executed it. Two kinds of execution never land in a test's own context.
Import-time code
- Module-level statements, decorators, default values and class bodies run during collection under the empty context. So do function bodies called while modules import, such as
new_typer(core/cli.py:170), which 43 command modules call at import (e.g.commands/ci.py:109). - The builder drops the empty context (
coverage_index.py:176). - So when a module-level constant changes, the tests of other modules that imported it are not linked to the file, and are not selected.
- Modules that run only at import are absent from the index, so they already fall back to a full run.
docs/ROADMAP.md:1013counted 24 of them.
First-caller credit
- A session fixture or a memoized function runs once per xdist worker, inside whichever test reached it first. There are 41
lru_cache/cacheuses insrc. register_test_mock_provider(tests/conftest.py:48-54) credits provider registration to whichever few tests the scheduler ran first.- The credited tests change from run to run.
#406 keeps index selection advisory. Any use of the index as the only run needs these cases to fall back first. The watcher entry (docs/ROADMAP.md:1004-1008) is one such use: it allows only an index-backed selection to pass.
Scope & Deliverables
Deliverable
- At build time, record two things for each indexed file:
- a hash of its AST with function and method bodies removed;
- a mark if any line inside a function body ran under the empty context, if it defines a function decorated with
functools.cache,functools.lru_cacheorfunctools.cached_property, or if a session- or module-scoped fixture intests/imports it (found by AST scan).
select_from_indextreats a changed file as unindexed when its AST hash differs from the build or when the file is marked.- Bump
INDEX_FORMAT_VERSION.
Acceptance criteria
- In a fixture repo,
src/pkg/consts.pydefinesLIMIT = 1, whichsrc/pkg/user.pyreads at import. ChangingLIMITmakesselect_from_indexreportconsts.pyas unindexed. Verified by a unit test. - Changing only a function body, in a file with no marks, still selects from the index. Verified by a unit test.
- A file whose function-body line ran under the empty context in the fixture database is marked, and any change to it is unindexed. Verified by a unit test.
- A file with an
lru_cachefunction is marked. So is a file imported by a session-scoped fixture. Verified by unit tests. - The task file records the share of
srcfiles marked on a real gate index. A person runsuv run devops ci --no-cacheand then a scratch count over the saved index. - Building the index, including the AST pass, still takes at most 1 s. Measured by the same person run.
- The new tests take at most 1 s in total, are offline, and use the sqlite fixture.
Key questions
- What if most files end up marked? (proposed) If more than half of
srcfiles are marked, the index rarely answers. Report the share to the owner instead of merging, and propose function-level hashes. - Should function-level hashes be used instead of file-level marks? (proposed) Not at first. File-level marks are simpler, and the recorded share shows whether they cost too much.
Constraint
- No new dependency, and only
astfrom the standard library. - Structural tuple assertions until test(cli): retire the tuple-assert mandate and detect opaque tuple asserts and presence-only tests #851 settles that.
- No shims: an older index reads as absent.
Strategic Alignment
- Milestone: Backlog
- Depends on: feat(cli):
devops ci testselects tests from a coverage index built on demand bydevops ci coverage --build-index#406 - Related: the roadmap entry "Change-Triggered Gate Re-Run With Delta Scorecard" (
docs/ROADMAP.md:1004)
Split off #406 during the v0.2.25/v0.2.26 readiness review (2026-10-01): Found while refining #406. The index gives credit only to code a test runs inside its own context. Import-time code, session fixtures and memoized functions are under-attributed, so the index can select too few tests. #406 keeps selection advisory, because the pre-push gate runs the full suite. This item has to land before anything uses the index as the only run, such as the watcher roadmap entry.
Metadata
Metadata
Assignees
Labels
Type
Projects
- StatusShow more project fieldsDone
Activity
dan-petty commentedon Oct 8, 2026
Placed in v0.2.32 on 2026-10-08 at the owner's request ("Populate 10 security and ci issues into each v0.2.30, v0.2.31, and v0.2.32 milestone"). This is a person's placement. Release theme: URLs and host keys read by the library that dials, ollama hardening, and pull-request test-quality tooling. Position 9 of 10 in the release's planned merge order. Its board Status is set to Ready, so the release-start fill keeps it.
dan-petty commentedon Oct 9, 2026
Closed as not planned (owner decision, 2026-10-09)
The v0.2.32 assessment and its challenge measured the design against release/v0.2.32 (27cf6bd):
devops ci testselects tests from a coverage index built on demand bydevops ci coverage --build-index#406's 5 s budget fail.srcfiles (242/277) and 96% of item PRs (44/46) in v0.2.29 to v0.2.31 as unindexed, so the index would almost never answer.coverageinsrcand cannot see import-time code in lazily imported modules (about 1,170 function-local imports in 217 files).devops ci testselection is advisory, and making it select through one path is test(ci): devops ci, test, devcontainer, workspace, install-tools, uv, branches and pipeline are tested over edge fakes, with no lazy patch targets or PYTEST_CURRENT_TEST checks #1325.When an index-only consumer is planned, that item carries this requirement and measures its own policy first (for example a per-test import-closure rule, or a full run only for changes in modules reached at import time), not file-level marks.