@@ -135,3 +135,39 @@ def test_missing_subdir_forces_refresh_when_meta_is_fresh(tmp_path: Path) -> Non
135135
136136 updated = download_repository (src , cache_root = cache , refresh = "stale" )
137137 assert (updated / "extensions" / "all-github-setup" / "ok.txt" ).is_file ()
138+
139+
140+ def test_read_cache_meta_empty_dir (tmp_path : Path ) -> None :
141+ from create_python_app_core .git_cache import read_cache_meta
142+
143+ assert read_cache_meta (tmp_path / "missing" ) is None
144+
145+
146+ def test_read_cache_meta_corrupt_json (tmp_path : Path ) -> None :
147+ from create_python_app_core .errors import CpaError
148+ from create_python_app_core .git_cache import meta_path , read_cache_meta
149+
150+ entry = tmp_path / "e"
151+ entry .mkdir ()
152+ 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.
155+ read_cache_meta (entry )
156+
157+
158+ def test_refresh_after_hours_invalid_env (monkeypatch : pytest .MonkeyPatch ) -> None :
159+ from create_python_app_core .git_cache import refresh_after_hours
160+
161+ monkeypatch .setenv ("CPA_REFRESH_AFTER_HOURS" , "not-a-number" )
162+ assert refresh_after_hours () == 24.0
163+
164+
165+ def test_should_refresh_modes () -> None :
166+ from create_python_app_core .git_cache import CacheMeta , _should_refresh
167+
168+ meta = CacheMeta (url = "u" , ref = "main" , fetched_at = time .time (), commit = "abc" )
169+ assert _should_refresh (None , "stale" ) is True
170+ assert _should_refresh (meta , "manual" ) is False
171+ assert _should_refresh (meta , "always" ) is True
172+ old = CacheMeta (url = "u" , ref = "main" , fetched_at = time .time () - 100_000 , commit = "abc" )
173+ assert _should_refresh (old , "stale" ) is True
0 commit comments