Skip to content

feat(pytest_plugin): Add XDG persistent cache and fixture optimization - #502

Merged
tony merged 6 commits into
masterfrom
pr/cache
Nov 29, 2026
Merged

tony merged 6 commits into
masterfrom
pr/cache

Conversation

@tony

@tony tony commented Dec 30, 2025

Copy link
Copy Markdown
Member

Summary

  • Add XDG-based persistent cache for pytest fixtures (~/.cache/libvcs/pytest/)
  • Add RepoFixtureResult with cache hit/miss tracking
  • Add atomic_init for race-free initialization with pytest-xdist
  • Include FileLock module for atomic operations

Test plan

  • Unit tests for FileLock
  • Fixture performance benchmarks
  • Cache hit/miss tracking verification

@codecov

codecov Bot commented Dec 30, 2025 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 61.94690% with 86 lines in your changes missing coverage. Please review.
✅ Project coverage is 73.14%. Comparing base (a7bd3f2) to head (7bf13cc).

Files with missing lines Patch % Lines
src/libvcs/pytest_plugin.py 64.23% 42 Missing and 7 partials ⚠️
conftest.py 50.66% 36 Missing and 1 partial ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master     #502      +/-   ##
==========================================
- Coverage   73.89%   73.14%   -0.76%     
==========================================
  Files          55       54       -1     
  Lines       12134    12316     +182     
  Branches     1741     1760      +19     
==========================================
+ Hits         8967     9009      +42     
- Misses       2343     2475     +132     
- Partials      824      832       +8     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@tony

tony commented Aug 22, 2026

Copy link
Copy Markdown
Member Author

Automated review finding. Recorded here so it is not lost. Nothing has been pushed to this branch and no fix is applied — this is a note, not a change request.

Vendored file_lock.py carries the stale-lock bug from #501

This PR vendors _internal/file_lock.py verbatim from #501, including its stale-lock handling, which decides staleness from mtime age alone and never checks whether the PID recorded in the lock is still running.

A slow-but-healthy holder therefore has its lock deleted out from under it, and two processes enter the guarded section together. Full detail and the suggested os.kill(pid, 0) liveness check are on #501; whichever lands first should carry the fix so the other does not reintroduce it.

@tony tony mentioned this pull request Nov 28, 2026
17 of 24 tasks
@tony
tony changed the base branch from master to pr/file-lock November 29, 2026 00:34
tony added a commit that referenced this pull request Nov 29, 2026
@tony tony mentioned this pull request Nov 29, 2026
17 of 30 tasks
@tony
tony changed the base branch from pr/file-lock to pr/file-lock-asyncio November 29, 2026 01:55
tony added a commit that referenced this pull request Nov 29, 2026
@tony
tony force-pushed the pr/file-lock-asyncio branch from 179ed93 to 15acdae Compare November 29, 2026 03:01
@tony
tony changed the base branch from pr/file-lock-asyncio to master November 29, 2026 03:06
tony added 5 commits November 28, 2026 21:08
why: Improve test performance with session-scoped caching and atomic
initialization for pytest-xdist compatibility.

what:
- Add XDG-based persistent cache for fixture master copies
- Add RepoFixtureResult dataclass with cache hit/miss tracking
- Add atomic_init for race-free initialization in parallel tests
- Optimize git_repo, hg_repo, svn_repo fixtures with caching
what:
- Add fixture cache hit/miss verification tests
- Add persistent cache version key tests
- Add VCS-native copy vs shutil.copytree benchmarks
what:
- Add performance and benchmark pytest markers to pyproject.toml
- Add fixture cache hit/miss tracking hooks to conftest.py
why: git_repo, hg_repo, and svn_repo return RepoFixtureResult wrappers,
so instantiating a fresh sync instance from the template fixture needs
type(template.repo).

what:
- Unwrap template.repo before constructing the disposable checkout
why: Opt-in benchmark and --run-performance test modules are skipped by
default in CI, skewing project coverage below the 1% Codecov threshold.

what:
- Omit `tests/benchmarks/*` and `tests/test_fixture_performance.py` in
  `[tool.coverage.run].omit`
- Cover `RepoFixtureResult` attribute delegation in
  `tests/test_pytest_plugin.py`
@tony
tony merged commit 968636a into master Nov 29, 2026
9 checks passed
@tony
tony deleted the pr/cache branch November 29, 2026 10:11
tony added a commit that referenced this pull request Nov 29, 2026
why: PR #502 moved sync repo fixtures to shared `*_repo_master` caches
guarded by `atomic_init`, `copytree_reflink`, and `RepoFixtureResult`,
while `async_*_repo` still cloned separate unlocked `*_repo` directories
in the persistent XDG cache.

what:
- Initialize `git_repo_master`, `hg_repo_master`, and `svn_repo_master`
  via `async_atomic_init` and copy checkouts with `copytree_reflink`
- Wrap `async_git_repo`, `async_hg_repo`, and `async_svn_repo` in
  `RepoFixtureResult` with explicit `loop_scope="function"`
- Replace nonexistent `cmd.status()` calls in `async_hg_repo` and
  `async_svn_repo` docstring examples with `get_revision()`
- Add `test_async_repo_fixture_uses_shared_master_cache`
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