Skip to content

fix(ci): coverage index treats module-level and import-time changes as unindexed #884

Closed as not planned

Description

@dan-petty

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:1013 counted 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/cache uses in src.
  • 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_cache or functools.cached_property, or if a session- or module-scoped fixture in tests/ imports it (found by AST scan).
  • select_from_index treats 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.py defines LIMIT = 1, which src/pkg/user.py reads at import. Changing LIMIT makes select_from_index report consts.py as 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_cache function is marked. So is a file imported by a session-scoped fixture. Verified by unit tests.
  • The task file records the share of src files marked on a real gate index. A person runs uv run devops ci --no-cache and 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 src files 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

Strategic Alignment

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.

Activity

  1. added
    type/bug
    scope/cli
    priority/p3-low
    on Oct 1, 2026
  2. added
    scope/ci
    and removed
    scope/cli
    on Oct 2, 2026
  3. added this to the v0.2.32 milestone on Oct 8, 2026
  4. dan-petty commented on Oct 8, 2026

    @dan-petty
    OwnerAuthor

    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.

  5. dan-petty commented on Oct 9, 2026

    @dan-petty
    OwnerAuthor

    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):

    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.

  6. removed this from the v0.2.32 milestone on Oct 9, 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/p3-lowscope/citype/bug

    Type

    No type

    Projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions