fix: stop vuln-scan tests polluting shared clean_app fixture (#83)#88
Merged
Conversation
Tests in TestScanVulnerabilitiesCacheInfo called scan_vulnerabilities() directly on the shared benchmarks/fixtures/clean_app (and vulnerable_app) directory. This wrote .codelens/osv_cache.db permanently into the fixture. When tests/test_architecture.py::TestArchitectureBasic::test_auto_scans_on_fresh_workspace later copied the (now-polluted) fixture into a temp dir and asserted that .codelens/ did not exist there, the assertion failed — intermittently, depending on whether vuln-staleness tests had run first. Root cause: side-effect (.codelens/) written to a fixture directory that is shared across many tests, instead of to a per-test temp copy. Fix: introduce an app_fixture_copy fixture that copies a named app fixture into a fresh temp dir (cleaned up on teardown) and route the four affected tests through it. The shared fixture directory is now never written to, so the assertion in test_auto_scans_on_fresh_workspace holds regardless of test run order. The assertion in test_auto_scans_on_fresh_workspace is intentionally left unchanged — the test's contract (no .codelens/ in a fresh workspace) is correct; the bug was that the fixture was pre-polluted.
|
You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard. |
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.



Root cause
tests/test_vuln_staleness.py::TestScanVulnerabilitiesCacheInforanscan_vulnerabilities(fixture, offline=True)directly on the sharedbenchmarks/fixtures/clean_app(andvulnerable_app) directory — not on a temp copy.scan_vulnerabilitieswrites its OSV cache to<workspace>/.codelens/osv_cache.db, so this permanently polluted the shared fixture withbenchmarks/fixtures/clean_app/.codelens/osv_cache.db.Later,
tests/test_architecture.py::TestArchitectureBasic::test_auto_scans_on_fresh_workspacecopies the (now-polluted)clean_appfixture into a fresh temp dir and asserts:That assertion failed intermittently — specifically when
test_vuln_staleness.pyhad run beforetest_architecture.pyin the same session, leaving.codelens/behind in the fixture.Reproduction (before fix):
Fix chosen and why
The root cause is a side-effect (
.codelens/) being written into a fixture directory that is shared across many tests. The fix removes the side-effect at the source: the shared fixture is never written to.Concretely, a new
app_fixture_copypytest fixture (factory pattern) is added totests/test_vuln_staleness.py. It copies a named app fixture (clean_app/vulnerable_app) into a fresh temp dir, tracks it, and tears it down on test completion. The four affected tests inTestScanVulnerabilitiesCacheInfoare routed through this fixture, soscan_vulnerabilitiesnow writes its.codelens/osv_cache.dbinto the temp copy — never into the shared fixture.This was chosen over the alternatives explicitly rejected in the issue:
.codelens/underbenchmarks/fixtures/— rejected. It only hides the symptom; the file is still on disk and the test still fails depending on run order.test_auto_scans_on_fresh_workspaceassertion to tolerate a pre-existing.codelens/— rejected. That would defeat the test's whole purpose (verifying auto-scan fires on a truly fresh workspace).The assertion in
test_auto_scans_on_fresh_workspaceis intentionally left unchanged — its contract (no.codelens/in a fresh workspace) is correct; the bug was that the fixture was pre-polluted.Files changed
tests/test_vuln_staleness.pyapp_fixture_copyfixture (factory pattern) that copies a named app fixture into a fresh temp dir and removes it on teardown.TestScanVulnerabilitiesCacheInfo(test_clean_app_no_deps_has_cache_info,test_vulnerable_app_has_stale_cache_info,test_cache_info_shape,test_cache_info_is_additive) to takeapp_fixture_copyand run against a temp copy instead of the shared fixture path.No production code under
scripts/is touched. No assertions are weakened. No.gitignorechanges.Definition of Done — verification
1. Full test suite 3× consecutively (no manual cleanup between runs)
Command run 3× back-to-back (no
rmin between):Results (verbose, per-test output captured via
--override-ini="addopts="):test_auto_scans_on_fresh_workspaceExplicit per-test line from each run:
Tail of each run:
2. Ordered run that originally triggered the bug —
test_vuln_staleness.pythentest_architecture.pyOutput:
Both files pass — including
test_auto_scans_on_fresh_workspace. Before the fix, the second invocation failed on that test.3.
benchmarks/fixtures/clean_app/stays cleanAfter the full 3× run + the ordered run, the fixture directory has no
.codelens/:The only working-tree change is the test file edit:
Closes
Closes #83.