Skip to content

Coverage imports map pytest contexts to live test files - #872

Merged
zlareb1 merged 1 commit into
mainfrom
fix/pytest-coverage-contexts
Nov 18, 2026
Merged

zlareb1 merged 1 commit into
mainfrom
fix/pytest-coverage-contexts

Conversation

@zlareb1

@zlareb1 zlareb1 commented Nov 18, 2026 •

Copy link
Copy Markdown
Member

Changelog category (leave one):

  • Bug Fix (user-visible misbehavior in a release)

Changelog entry (one or two sentences a user of Loom can read without the diff; the release pull request collects these into the release notes):

Measured coverage imports accept pytest node IDs and setup, run and teardown contexts in repository test layouts. Contexts from the same test file contribute their combined executed lines.

Why

A test name such as tests/test_example.py::test_create|run was compared with indexed file paths without removing its context. That left the test unmapped. Names outside the integration and query layouts also lacked a repository-relative candidate.

Several function contexts can resolve to one source/test-file pair. Assigning each context to that pair discarded the earlier ranges. The import keeps their full union before applying the evidence range cap, counts overlapping lines once, and retains the strongest measured specificity score.

Scope and risk

This changes coverage-name resolution and in-memory import aggregation. A candidate must still match a live indexed file exactly in the selected namespace. Existing integration and query layout candidates remain available. The import retains the union's ranges while planning; stored evidence keeps its existing range cap and format.

Compatibility, rollout and rollback

  • Wire: no op, field, setting or default changes.
  • Operator steps: run loom code coverage-import --namespace <namespace> --dry-run to check unmapped names, then import without --dry-run to rebuild pairs from the coverage source. A server update alone does not rebuild stored coverage.
  • Rollback: reverting restores the prior importer. Imported rows use the existing schema and remain readable.

Tests

  • Regression tests failed before the fix for pytest function, class, parameter and phase contexts; generic test locations; same-file range unions in either input order; and aggregation before the evidence cap.
  • python -m pytest tests/unit/test_code_coverage_import.py tests/unit/test_doc_links.py tests/unit/test_public_copy.py -q: 298 passed.
  • Mypy passed for both changed source modules. Ruff, Markdown formatting, the function-length gate and git diff --check passed.
  • Validation uses focused unit tests locally. Repository-wide checks run in CI. The import planner is covered with in-memory source and repository fixtures.

AI assistance in the code (leave one; writing this description with AI is fine):

  • AI-generated (Codex); checked the import path, reproduced the failing cases, and ran the focused regression and static checks.

  • I can explain every line of this diff and how it interacts with the rest of Loom.

Checklist

  • Full CI passes on the reviewed head: 47 successful checks, two conditional publication skips and all five workflows successful, including formatting, lint, type checking, unit and integration suites.
  • Generated files are regenerated in this PR, not by hand: no generated files change.
  • A new migration is additive and numbered after the latest on main: no migration.
  • A behaviour change to any file a plugin ships bumps both plugin versions: no plugin files change.
  • The frontend builds and its tests pass, if frontend/ changed: no frontend files change.
  • Docs under docs/ describe the system as it is, including operator steps and wire changes.
  • Repository text has no dates, people, host names, internal namespaces, ticket or decision numbers.
  • Commits are signed off (git commit -s).

Normalize repository-relative test names before layout resolution and union the executed ranges of contexts that map to one file. Count their union once and retain the strongest measured specificity score; existing stored pairs require an explicit reimport.

Signed-off-by: zlareb1 <[email protected]>
@zlareb1
zlareb1 merged commit a4cab73 into main Nov 18, 2026
49 checks passed
@zlareb1 zlareb1 mentioned this pull request Nov 18, 2026
6 tasks done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant