fix(test,agents): WinError 448 pytest symlink fix + AGENTS.md BOM-safe PS rule (#281, #283)#287
Conversation
| def _make_safe(fn): # type: ignore[no-untyped-def] # noqa: ANN001 | ||
| """Wrap a pytest cleanup function to swallow OSError (WinError 448).""" | ||
|
|
||
| def _safe_wrapper(*args, **kwargs): # type: ignore[no-untyped-def] |
Greptile SummaryThis PR delivers two Phase 1 fixes: a Windows 11 24H2+ pytest WinError 448 workaround (via Confidence Score: 5/5Safe to merge; all findings are P2 style/hardening suggestions with no blocking correctness issues. Both changes are minimal and well-contained. The OSError catch being broader than WinError 448 is a hardening suggestion (P2) — in practice these pytest-internal cleanup functions are only called in teardown contexts where suppressing unexpected OS errors is low risk. The AGENTS.md syntax inconsistency is cosmetic. No P0/P1 findings. tests/conftest.py — OSError filter could be narrowed to winerror 448 specifically. Important Files Changed
Flowchart%%{init: {'theme': 'neutral'}}%%
flowchart TD
A[pytest session starts] --> B[conftest.py loaded]
B --> C{sys.platform == win32?}
C -- No --> D[Normal cleanup functions]
C -- Yes --> E[Wrap cleanup_dead_symlinks\nand cleanup_numbered_dir\nwith _make_safe]
E --> F[tmp_path_retention_count=0\npyproject.toml]
F --> G[No old-session dirs retained]
D & G --> H[Tests run]
H --> I[Session finish / atexit]
I --> J[Cleanup called]
J --> K{OSError raised?}
K -- No --> L[Clean exit]
K -- Yes, win32 --> M[Swallow OSError\nlog nothing]
M --> L
Prompt To Fix All With AIThis is a comment left during a code review.
Path: tests/conftest.py
Line: 30-35
Comment:
**Overly broad OSError catch; docstring overpromises specificity**
The wrapper catches _all_ `OSError`, but the PR targets only `WinError 448`. Any unrelated cleanup failure (e.g., disk full, permission denied for a real reason) will now be silently swallowed on every call to `cleanup_dead_symlinks` / `cleanup_numbered_dir`, and the docstring says "WinError 448" when the code is wider than that.
Narrow the filter to the specific winerror value so genuine failures surface:
```suggestion
try:
return fn(*args, **kwargs)
except OSError as exc:
if not (hasattr(exc, "winerror") and exc.winerror == 448):
raise
```
How can I resolve this? If you propose a fix, please make it concise.
---
This is a comment left during a code review.
Path: AGENTS.md
Line: 96
Comment:
**Syntax inconsistency with `scm/github.md` reference**
AGENTS.md prescribes `New-Object System.Text.UTF8Encoding $false`, but every code example in the cross-referenced `scm/github.md` section uses `[System.Text.UTF8Encoding]::new($false)`. Both forms construct the same object, but an agent reading both files sees two different spellings for the canonical pattern, which can introduce variation in generated scripts. Aligning the snippet in AGENTS.md to the scm/github.md form removes the ambiguity.
```suggestion
! When writing files using PowerShell, MUST use `[System.Text.UTF8Encoding]::new($false)` -- never `[System.Text.Encoding]::UTF8` (writes BOM). See `scm/github.md` PS 5.1 section.
```
How can I resolve this? If you propose a fix, please make it concise.Reviews (2): Last reviewed commit: "fix(test,agents): WinError 448 pytest sy..." | Re-trigger Greptile |
… rule (#281, #283) - Add tmp_path_retention_count = 0 to [tool.pytest.ini_options] in pyproject.toml to prevent old-session temp dir retention on Windows 11 24H2+ (#281, t1.18.1) - Add conftest.py monkeypatch wrapping cleanup_dead_symlinks and cleanup_numbered_dir in _pytest.pathlib/_pytest.tmpdir to suppress OSError during session-finish and atexit cleanup (WinError 448 untrusted mount point) - Add ## PowerShell section to AGENTS.md with ! rule requiring New-Object System.Text.UTF8Encoding False for file writes -- never [System.Text.Encoding]::UTF8 which writes a BOM (#283, t1.20.1) - Add CHANGELOG.md entries under [Unreleased] for both fixes
ae3b8b3 to
4ff24f7
Compare
Summary
Two Phase 1 fixes: pytest WinError 448 symlink cleanup (#281) and AGENTS.md BOM-safe PowerShell write rule (#283).
Changes
fix(test): WinError 448 pytest-current symlink cleanup (#281, t1.18.1)
fix(agents): BOM-safe PowerShell file write rule (#283, t1.20.1)
Checklist
Closes #281, Closes #283