Skip to content

Commit c3fceb0

Browse files
committed
fix(config): clamp negative cache age to 0 (fresh, not stale)
The previous strict guard rejected negative ages outright, but a negative age means the cache file was just written (Windows mtime skew puts it slightly in the future of time.time()). Treating it as miss broke test_from_url_uses_cache_when_fresh on Windows. Correct semantic: negative age = 'just written' = max(0, age) = 0 = fresh (passes the < max_age check for any positive max_age). With max_age=0 we still get 0 < 0 = False = miss, so the cache-bypass test still passes.
1 parent c1963c3 commit c3fceb0

1 file changed

Lines changed: 7 additions & 6 deletions

File tree

src/get_installer/config.py

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -273,13 +273,14 @@ def from_url(
273273
key = _hashlib.sha256(url.encode("utf-8")).hexdigest()[:32]
274274
cache_path = cd / f"registry-{key}.json"
275275
if cache_path.is_file():
276-
age = _time.time() - cache_path.stat().st_mtime
277-
# Reject negative ages: on Windows (and some FUSE mounts)
276+
# Clamp age to 0: on Windows (and some FUSE mounts)
278277
# st_mtime can land slightly in the future after a rename
279-
# because of filesystem-time vs wall-clock precision skew.
280-
# `cache_max_age_seconds=0` must always bypass the cache,
281-
# so guard the comparison from below.
282-
if 0 <= age < cache_max_age_seconds:
278+
# because of filesystem-time vs wall-clock precision skew,
279+
# producing a negative age. A just-written cache is fresh,
280+
# not stale; treat negatives as 0. `cache_max_age_seconds=0`
281+
# still correctly bypasses (0 < 0 is False).
282+
age = max(0.0, _time.time() - cache_path.stat().st_mtime)
283+
if age < cache_max_age_seconds:
283284
try:
284285
data = json.loads(cache_path.read_text(encoding="utf-8"))
285286
return cls.from_dict(data, source_path=cache_path)

0 commit comments

Comments
 (0)