Repository navigation
fix: isolate test_api focus resolution from ancestor .pt-snap/focus.json - #124
Merged
Merged
Conversation
Config.resolve_focus() walks up from the current directory looking for .pt-snap/focus.json, but the autouse fixture in tests/test_api.py only neutralized PT_SNAP_DB_PATH and Path.home(). A focus file written to the repository root by `pt-snap focus` or `pt-snap import` therefore leaked into test_set_focus_device_requires_database, which expected no database to be configured. Switch the fixture to monkeypatch and chdir into tmp_path, matching the isolation already used by every other CLI/MCP/service test module since #53, and add a test that pins the invariant that a fresh analyzer sees no inherited focus. Fixes #117
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.
📝 Description
Config.resolve_focus()walks up fromPath.cwd()looking for.pt-snap/focus.json, but the autouse fixture intests/test_api.pyonly neutralizedPT_SNAP_DB_PATHandPath.home(). Any focus file in the repository root (or another ancestor) — exactly whatpt-snap focus/pt-snap importwrite to the current directory — leaked intotest_set_focus_device_requires_database, which then raisedFileNotFoundErrorfor the stale database instead of the expectedRuntimeError("... Set db_path ...").This is the same defect class as #52; #53 fixed
tests/test_completion.pyand every other CLI/MCP/service test module has since adoptedmonkeypatch.chdir(tmp_path).tests/test_api.pywas the last one still using the old fixture.Changes:
_isolate_configwith amonkeypatch-based fixture that alsochdirs intotmp_pathand uses a per-testhomedirectory (the old fixture leaked an uncleanedtempfile.mkdtemp()per test).test_isolated_environment_has_no_inherited_focus, which pins the invariant that a freshSnapshotAnalyzer()in this module resolves tosource == "none"regardless of the developer's machine.osimport.No production code changes.
🔗 Related Issue
Fixes #117
🧪 Testing
Reproduction and verification, run from the branch checkout with a leaked focus file placed at the repository root (
.pt-snap/focus.json→/nonexistent/leaked.db):tests/test_api.pyfrommain1 failed, 17 passed(test_set_focus_device_requires_database)tests/test_api.pyfrom this branch19 passedFull suite on this branch (macOS, Python 3.13.11):
770 passed, 1 xfailed.ruff checkandblack --checkclean.✅ Checklist
Snapshot Runtime Provenance
Snapshot provenance decision: no-update
Snapshot provenance no-update reason: This PR only changes tests/test_api.py; no files under src/pt_snap_cli/snapshot/ are touched.
📋 Additional Notes
AGENTS.mdchange routing: "MCP or Python API behavior" →tests/test_api.py,tests/test_mcp_server.py,tests/test_contract_cli_mcp.py; all three pass.