Repository navigation
Keep tests from writing into the committed publications/ and reactome/ caches - #5025
Conversation
- test_fetch_pubmed_data cached PMID_29727692.md into the repo's
publications/ on every integration run (cassette replay included);
it now caches to tmp_path.
- seed_missing_annotations hard-coded Path("publications") for title
fetches, so fetch_gene_data(base_path=tmp) still wrote publications
into the working directory. It takes publications_dir, and
fetch_gene_data passes base_path / "publications" (unchanged for the
CLI, where base_path is the working directory).
- conftest snapshots git status of publications/ and genes/ at session
start and fails the run if any test changed them.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01SfBE3uVPNyHBBofmRvNakd
The BAG6 refresh test replaces seed_missing_annotations with a stub that did not accept the new keyword. It now records publications_dir and asserts fetch_gene_data passes base_path / "publications". Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01SfBE3uVPNyHBBofmRvNakd
A bare `linkml-reference-validator` run from the repo root (no --config) loads .linkml-reference-validator.yaml, which did not set trust_cached_entries, so such a run could still re-fetch and rewrite committed publications/ entries. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01SfBE3uVPNyHBBofmRvNakd
|
Claude finished @cmungall's task in 5m 32s —— View job Review: PR #5025 — keep tests out of the committed caches
This is a test-hygiene / ETL-plumbing PR. The diagnosis is right and the fix is the right shape: a cwd-relative cache default is exactly how
🟡 IMPORTANT — the sibling leak two lines away is still cwd-bound, and the new guard can't see it
# Use reactome directory for cache
cache_dir = Path("reactome")This is inside It's reachable from the exact tests this PR is cleaning up: And because If you'd rather land this PR as-is and do the Reactome half as a follow-up, adding 🔵 SUGGESTION — the guard is inert for
|
There was a problem hiding this comment.
Test-hygiene/plumbing PR; no gene-review YAML changed, so the GO/evidence checklist is n/a.
The diagnosis and fix shape are right, and I verified the load-bearing parts: base_path is normalized to Path.cwd() (gene.py:455, :1656) so the CLI is genuinely unchanged; the new seeding test is non-vacuous (get_cached_title parses the first # heading, and the iterdir() assertion pins that nothing extra was written); --untracked-files=all correctly excludes git-ignored artifacts; and mutating session.exitstatus in pytest_sessionfinish does take effect.
One 🟡 to close: goa_validator.py:1146 still hardcodes cache_dir = Path("reactome") inside _get_reactome_title, called from line 927 — the same fetch_titles block whose PMID branch this PR just parameterized. It writes into the committed reactome/ tree regardless of base_path, and it is reachable from the very tests being cleaned up (test_fetch_gene_data_* pass base_path=tmp with fetch_titles defaulting True, and their cassettes carry Reactome:R- refs). Because PROTECTED_TREES omits reactome, the new tripwire would not report it — so the guard currently gives false reassurance there rather than merely incomplete coverage. Threading a reactome_dir the same way plus adding "reactome" to PROTECTED_TREES closes it; adding just the PROTECTED_TREES entry now and doing the plumbing as a follow-up would be enough to make it visible instead of silent.
Five 🔵s in the full comment, all take-or-leave: the guard is inert for just doctest (pytest --doctest-modules src doesn't load tests/conftest.py as an initial conftest, so pytest_sessionstart never fires — a root-level conftest would cover every invocation); the unconditional TESTS_FAILED clobbers INTERRUPTED/USAGE_ERROR/NO_TESTS_COLLECTED; the red message prints above the terminal summary so the last line still reads green on a tripped run; the porcelain set-diff can't see content edits to already-dirty files; and seed-goa in cli.py:1534/1552 still takes the cwd default.
Note: no uv/virtualenv in this container, so this is a static review — I could not run the suite, the new tests, or ruff. Evidence for each claim is cited in the full comment.
See #5025 (comment) for details.
Review follow-ups on the test-isolation change:
- _get_reactome_title hard-coded Path("reactome"), so fetch_gene_data
with a tmp base_path could still write reactome/R-*.md into the repo.
seed_missing_annotations takes reactome_dir, and fetch_gene_data
passes base_path / "reactome" (unchanged for the CLI).
- Move the protected-tree guard to a root conftest.py so it also covers
invocations that never load tests/conftest.py, such as
`pytest --doctest-modules src`, and protect reactome/ as well.
- Only turn an otherwise passing run into a failure, keeping
interrupted / usage-error / no-tests exit codes, and report the
changed files in the terminal summary.
- Document that the status comparison cannot see further edits to an
already-modified file and attributes concurrent edits to the tests.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01SfBE3uVPNyHBBofmRvNakd
|
Addressed in 8d437d1. 🟡 Reactome cache
🔵 Taken
🔵 Not taken: Checks: the affected test files pass (175 passed); Generated by Claude Code |
|
Claude finished @cmungall's task in 3m 4s —— View job Review: PR #5025 — follow-up pass on
|
There was a problem hiding this comment.
Follow-up pass on 8d437d1: the 🟡 Reactome leak is closed and four of five 🔵s were taken.
Verified statically: _get_reactome_title no longer hard-codes a cache dir and its single call site threads reactome_dir; fetch_gene_data/fetch_gene_data_ncRNA pass base_path / "reactome", with base_path still normalized to cwd so the CLI is unchanged. The new test assertion is non-vacuous — the committed reactome/R-CEL-9856612.md carries a different # heading, which get_cached_title would return without the parameter. The rootdir conftest.py really is an initial conftest for every invocation including pytest --doctest-modules src; tests/conftest.py is back to main byte-for-byte; the ExitCode.OK guard preserves interrupted/usage-error/no-tests codes; and pytest_terminal_summary does fire, since TerminalReporter gates on its hook argument and OK is in summary_exit_codes. No test writes to the real reactome/, so the new PROTECTED_TREES entry shouldn't false-trip.
Two take-or-leave 🔵s in the full comment: gocams/ (plus rules/arba, rules/unirule) are the same cwd-default shape reactome/ was in and are one PROTECTED_TREES entry from being covered; and the two cwd fallbacks could be hoisted out of the per-reference loop. Declining the seed-goa CLI default is the right call for the reason you gave.
Note: no uv/virtualenv in this container, so I could not run the suite, the new test, or ruff — your results and CI are the authority on pass/fail.
See #5025 (comment) for details.
|
Thanks. Both new 🔵s will go into the next code push if one is needed: adding Generated by Claude Code |
Summary
test_fetch_pubmed_data(integration) calledfetch_pubmed_data(pmid)with the default cache dir. Everyjust test-full/pytest -m integrationrun, cassette replay included, rewrote the committedpublications/PMID_29727692.md. It now caches totmp_path.GOAValidator.seed_missing_annotationshard-codedPath("publications")andPath("reactome")for title fetches. As a result,fetch_gene_data(base_path=tmp)still cached PMIDs and Reactome entries into the working directory, which happens when cassettes are recorded.publications_dirandreactome_dir.fetch_gene_dataandfetch_gene_data_ncRNApassbase_path / "publications"andbase_path / "reactome".base_pathdefaults to the working directory.conftest.pyguards the committed data:git statusofpublications/,genes/andreactome/(untracked files included) when a session starts.pytest --doctest-modules src..linkml-reference-validator.yamlnow setstrust_cached_entries: true. Upstream's CLI loads this file when run without--config, so a barelinkml-reference-validatorrun from the repo root could still re-fetch and rewrite reviewed cache entries.conf/reference_validator_config.yamlalready sets it.Replaces the remaining part of the closed #4552, whose LRV upgrade and backport removal are already on
main.Validation
n/a (no gene-review changes)
Test plan
maincheckout in this container (justmissing, shallow-clone snapshot commits). The protected trees were unchanged afterwards.pytest -m integration --vcr-record=none tests/test_publication_etl.pypasses and leaves the working tree clean.test_seed_missing_annotations_uses_given_cache_dirsfails without the parameters: it picks up the committedPMID_12345.mdandR-CEL-9856612.mdtitles.test_bare_cli_default_config_trusts_reviewed_cachefails without the config line.--doctest-modulesrun outsidetests/that writespublications/PMID_*.md, and a test outsidetests/that writesreactome/R-*.md. A clean run exits 0.ruff checkandmypyclean on changed files.🤖 Generated with Claude Code
https://claude.ai/code/session_01SfBE3uVPNyHBBofmRvNakd