Skip to content

fix: isolate completion test from local .pt-snap/focus.json - #53

Merged
codeasier merged 1 commit into
mainfrom
fix/completion-test-returns-empty-for-no-db
Apr 18, 2026
Merged

codeasier merged 1 commit into
mainfrom
fix/completion-test-returns-empty-for-no-db

Conversation

@codeasier

Copy link
Copy Markdown
Owner

📝 Description

test_returns_empty_for_no_db fails when a local .pt-snap/focus.json exists because _resolve_db_for_completion() finds it via upward directory search from Path.cwd().

Fix: use monkeypatch.chdir(tmp_path) to isolate the test in a clean temporary directory with no focus file.

🔗 Related Issue

Fixes #52

🧪 Testing

  • Tests added/updated
  • Manual testing completed
  • Lint checks passed (ruff check ., black --check .)
  • All 226 tests passing (previously 1 failed)

✅ Checklist

  • Code follows project guidelines
  • Documentation updated (if applicable)
  • No new warnings introduced
  • Changes tested locally

📋 Additional Notes

Single file change in tests/test_completion.py.

test_returns_empty_for_no_db fails when a local .pt-snap/focus.json
exists because _resolve_db_for_completion() finds it via upward
directory search. Fix by chdir-ing to a clean tmp_path.

Fixes #52
@codeasier
codeasier force-pushed the fix/completion-test-returns-empty-for-no-db branch from a847f61 to 95d14c9 Compare April 18, 2026 15:39

@codeasier codeasier left a comment

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@codeasier
codeasier merged commit 44a6390 into main Apr 18, 2026
5 checks passed
@codeasier
codeasier deleted the fix/completion-test-returns-empty-for-no-db branch April 18, 2026 15:40
codeasier added a commit that referenced this pull request Sep 17, 2026
…son (#124)

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

Co-authored-by: codeasier <liuyekang@huawei.com>
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.

[BUG] test_returns_empty_for_no_db fails when local .pt-snap/focus.json exists

1 participant