Skip to content

Commit 5c512c3

Browse files
test: address CodeRabbit feedback on git cache edge cases
Cover empty existing cache dirs separately from missing paths, narrow corrupt-JSON exceptions to JSONDecodeError/CpaError, and assert fresh metadata does not refresh under stale mode.
1 parent 38baf01 commit 5c512c3

1 file changed

Lines changed: 5 additions & 2 deletions

File tree

packages/create-python-app-core/tests/test_git_cache.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,9 @@ def test_missing_subdir_forces_refresh_when_meta_is_fresh(tmp_path: Path) -> Non
140140
def test_read_cache_meta_empty_dir(tmp_path: Path) -> None:
141141
from create_python_app_core.git_cache import read_cache_meta
142142

143+
empty = tmp_path / "empty-entry"
144+
empty.mkdir()
145+
assert read_cache_meta(empty) is None
143146
assert read_cache_meta(tmp_path / "missing") is None
144147

145148

@@ -150,8 +153,7 @@ def test_read_cache_meta_corrupt_json(tmp_path: Path) -> None:
150153
entry = tmp_path / "e"
151154
entry.mkdir()
152155
meta_path(entry).write_text("{not-json", encoding="utf-8")
153-
with pytest.raises((json.JSONDecodeError, CpaError, TypeError, ValueError)):
154-
# Current implementation lets JSONDecodeError propagate; either is acceptable.
156+
with pytest.raises((json.JSONDecodeError, CpaError)):
155157
read_cache_meta(entry)
156158

157159

@@ -168,6 +170,7 @@ def test_should_refresh_modes() -> None:
168170
meta = CacheMeta(url="u", ref="main", fetched_at=time.time(), commit="abc")
169171
assert _should_refresh(None, "stale") is True
170172
assert _should_refresh(meta, "manual") is False
173+
assert _should_refresh(meta, "stale") is False
171174
assert _should_refresh(meta, "always") is True
172175
old = CacheMeta(url="u", ref="main", fetched_at=time.time() - 100_000, commit="abc")
173176
assert _should_refresh(old, "stale") is True

0 commit comments

Comments
 (0)