Skip to content

Use synthetic paths in test_dir.py to avoid Windows CI failures#1909

Merged
nathanjmcdougall merged 2 commits into
mainfrom
copilot/fix-os-specific-directory-names
Apr 9, 2026
Merged

Use synthetic paths in test_dir.py to avoid Windows CI failures#1909
nathanjmcdougall merged 2 commits into
mainfrom
copilot/fix-os-specific-directory-names

Conversation

Copilot AI commented Apr 9, 2026

Copy link
Copy Markdown
Contributor

get_project_name_from_dir() only reads Path.name — it never touches the filesystem. Tests were unnecessarily creating real directories via tmp_path, which fails on Windows where "..." is interpreted as ../.. traversal and trailing dots are silently stripped.

  • tests/usethis/_file/test_dir.py: Replace all tmp_path-based paths with string paths ("/fake/...") since no filesystem access is needed
  • usethis-python-test skill (v1.5 → v1.6): Add guidance on preferring synthetic paths when testing pure path-metadata logic
# Before: fails on Windows when dir_name is OS-special
def test_leading_dots(self, tmp_path: Path):
    with usethis_config.set(project_dir=tmp_path / "..hidden"):
        assert get_project_name_from_dir() == "hidden"

# After: no filesystem dependency
def test_leading_dots(self):
    with usethis_config.set(project_dir="/fake/..hidden"):
        assert get_project_name_from_dir() == "hidden"

…issues

Replace tmp_path-based paths with string paths in TestGetProjectNameFromDir
since get_project_name_from_dir() only reads .name and never touches the
filesystem. This avoids Windows-specific failures where directory names like
"..." are interpreted as parent traversal.

Agent-Logs-Url: https://github.com/usethis-python/usethis-python/sessions/c5cf2c22-5f12-46c3-a10e-ee4f3dd165a7

Co-authored-by: nathanjmcdougall <18602289+nathanjmcdougall@users.noreply.github.com>
Copilot AI changed the title [WIP] Fix filesystem directory creation with OS-special names in tests Use synthetic paths in test_dir.py to avoid Windows CI failures Apr 9, 2026
Copilot AI requested a review from nathanjmcdougall April 9, 2026 20:50
@nathanjmcdougall nathanjmcdougall marked this pull request as ready for review April 9, 2026 21:13
@codecov

codecov Bot commented Apr 9, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ All tests successful. No failed tests found.

📢 Thoughts on this report? Let us know!

@codspeed-hq

codspeed-hq Bot commented Apr 9, 2026

Copy link
Copy Markdown

Merging this PR will not alter performance

✅ 3 untouched benchmarks


Comparing copilot/fix-os-specific-directory-names (f3e61e7) with main (fe3b8a6)

Open in CodSpeed

@nathanjmcdougall nathanjmcdougall merged commit 6dfa9eb into main Apr 9, 2026
20 checks passed
@nathanjmcdougall nathanjmcdougall deleted the copilot/fix-os-specific-directory-names branch April 9, 2026 22:28
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.

agent: avoid creating filesystem directories with OS-special names in tests

2 participants