Skip to content

The agent that grows with you

fix(update): drop the _IS_WINDOWS test flag; prove the read-only sweep on a real Windows host

teknium1d767bfabdad0
diff --git a/hermes_cli/gitlock.py b/hermes_cli/gitlock.py
index 1f3a7f39faf..a342f75c79d 100644
--- a/hermes_cli/gitlock.py
+++ b/hermes_cli/gitlock.py
@@ -14,9 +14,6 @@ from typing import Callable, Iterable, List, Optional
logger = logging.getLogger(__name__)
-# Module-level (not inline) so tests can flip it without breaking pathlib's os.name check.
-_IS_WINDOWS = os.name == "nt"
-
# Files younger than this are presumed live (a fetch may be in flight) and are never removed. Lock
# files live for seconds and a healthy fetch completes in minutes; 10 minutes is abandoned.
STALE_LOCK_MIN_AGE_SECONDS = 10 * 60
@@ -61,7 +58,7 @@ def _sweep_stale(directory: Path, candidates: Callable[[], Iterable[Path]], *, m
for entry in candidates():
try:
if entry.is_file() and (st := entry.stat()).st_mtime < cutoff:
- if _IS_WINDOWS:
+ if os.name == "nt":
# git renames its transfer temps into place read-only; Windows refuses to
# unlink a read-only file (EACCES/13), so without clearing the write bit
# this sweep silently removes nothing on real debris (#116384).
diff --git a/tests/hermes_cli/test_gitlock_tmp_packs.py b/tests/hermes_cli/test_gitlock_tmp_packs.py
index da9cfd4665e..d471c1b36b9 100644
--- a/tests/hermes_cli/test_gitlock_tmp_packs.py
+++ b/tests/hermes_cli/test_gitlock_tmp_packs.py
@@ -13,6 +13,8 @@ import os
import time
from pathlib import Path
+import pytest
+
from hermes_cli.gitlock import (
STALE_TMP_PACK_MIN_AGE_SECONDS,
clear_stale_tmp_packs,
@@ -102,14 +104,13 @@ def test_never_raises_on_unlink_failure(tmp_path, monkeypatch):
assert clear_stale_tmp_packs(repo) == [] # skipped, not raised
def test_windows_readonly_debris_is_cleared(tmp_path, monkeypatch):
"""git renames its transfer temps into place read-only, and Windows refuses to unlink a
read-only file with EACCES — the exact rule that let aborted-fetch debris survive this
- sweep for months (#116384). Path.unlink is faked to that Windows rule so the regression
- is exercised on POSIX CI too."""
+ sweep for months (#116384). Runs on a real Windows host: no faked unlink, no faked OS."""
repo = _mkrepo(tmp_path)
monkeypatch.setattr("hermes_cli.gitlock._git_proc_running", lambda: False)
- monkeypatch.setattr("hermes_cli.gitlock._IS_WINDOWS", True)
pack = repo / ".git" / "objects" / "pack"
debris = pack / "tmp_pack_ReadOnly"
@@ -117,15 +118,6 @@ def test_windows_readonly_debris_is_cleared(tmp_path, monkeypatch):
_age(debris, STALE_TMP_PACK_MIN_AGE_SECONDS + 60)
os.chmod(debris, 0o444) # read-only, as git writes its pack temps
- real_unlink = Path.unlink
-
- def windows_unlink(self, *a, **k):
- if not self.stat().st_mode & 0o222: # Windows: no write bit -> EACCES
- raise PermissionError(13, "Permission denied")
- return real_unlink(self, *a, **k)
-
- monkeypatch.setattr(Path, "unlink", windows_unlink)
-
removed = clear_stale_tmp_packs(repo)
assert removed == [str(debris)] # write bit cleared first, then unlinked
assert not debris.exists()