tests.test_cache module

Tests for the global cache of binaries, HTTP responses and tool configs.

tests.test_cache.test_cache_dir_env_override(monkeypatch, tmp_path)[source]

REPOMATIC_CACHE_DIR env var overrides platform default.

tests.test_cache.test_cache_dir_env_override_tilde(monkeypatch)[source]

REPOMATIC_CACHE_DIR with ~ expands to home directory.

tests.test_cache.test_cache_dir_darwin(monkeypatch)[source]

macOS uses ~/Library/Caches/repomatic.

tests.test_cache.test_cache_dir_linux_xdg(monkeypatch)[source]

Linux with XDG_CACHE_HOME uses $XDG_CACHE_HOME/repomatic.

tests.test_cache.test_cache_dir_linux_default(monkeypatch)[source]

Linux without XDG_CACHE_HOME uses ~/.cache/repomatic.

tests.test_cache.test_cache_dir_windows_localappdata(monkeypatch)[source]

Windows uses %LOCALAPPDATA%/repomatic/Cache.

tests.test_cache.test_cache_dir_from_config(monkeypatch, tmp_path)[source]

cache.dir in [tool.repomatic] overrides platform default.

tests.test_cache.test_cache_dir_env_beats_config(monkeypatch, tmp_path)[source]

REPOMATIC_CACHE_DIR env var takes precedence over config.

tests.test_cache.test_max_age_days_from_config(monkeypatch)[source]

cache.max-age in [tool.repomatic] overrides field default.

tests.test_cache.test_max_age_days_env_beats_config(monkeypatch)[source]

REPOMATIC_CACHE_MAX_AGE env var takes precedence over config.

tests.test_cache.test_cached_binary_path_structure(cache_env)[source]

Cache path follows bin/{tool}/{version}/{platform}/{executable}.

tests.test_cache.test_get_cached_binary_not_cached(cache_env)[source]

Returns None when the binary is not in the cache.

tests.test_cache.test_get_cached_binary_exists(cache_env)[source]

Returns the path when the binary exists and is executable.

tests.test_cache.test_get_cached_binary_not_executable(cache_env)[source]

Returns None when the file exists but is not executable.

tests.test_cache.test_store_binary_creates_cache_entry(tmp_path, cache_env)[source]

store_binary copies the source file into the cache.

tests.test_cache.test_store_binary_overwrites_existing(tmp_path, cache_env)[source]

store_binary replaces an existing cached binary atomically.

tests.test_cache.test_store_binary_triggers_auto_purge(tmp_path, cache_env)[source]

store_binary calls auto_purge after storing.

tests.test_cache.test_store_binary_stamps_store_time(monkeypatch, tmp_path, cache_env)[source]

A source carrying an old archive mtime is not self-purged on store.

shutil.copy2 preserves the source mtime, which for a binary extracted from a release archive is the upstream build date. auto_purge ages entries by mtime, so without a fresh timestamp the auto_purge call inside store_binary would delete the entry it just stored.

tests.test_cache.test_store_binary_unwritable_cache_returns_none(tmp_path, cache_env)[source]

An unwritable cache root degrades to None instead of raising.

Matches the fail-soft contract of store_response and store_config: the caller falls back to its staging copy.

tests.test_cache.test_cache_info_empty(cache_env)[source]

Returns empty list when cache is empty.

tests.test_cache.test_cache_info_lists_entries(tmp_path, cache_env)[source]

Returns all cached entries with correct metadata.

tests.test_cache.test_clear_cache_all(tmp_path, cache_env)[source]

A clear with no filter removes every binary.

tests.test_cache.test_clear_cache_specific_tool(tmp_path, cache_env)[source]

A scoped clear removes only the binaries of that tool.

tests.test_cache.test_clear_cache_max_age(tmp_path, cache_env)[source]

An age-limited clear removes only old binaries.

tests.test_cache.test_clear_cache_prunes_empty_dirs(tmp_path, cache_env)[source]

A clear removes the directories it empties.

tests.test_cache.test_auto_purge_removes_old_entries(monkeypatch, tmp_path, cache_env)[source]

auto_purge removes entries older than REPOMATIC_CACHE_MAX_AGE.

tests.test_cache.test_auto_purge_disabled_when_zero(tmp_path, cache_env)[source]

auto_purge does nothing when REPOMATIC_CACHE_MAX_AGE=0.

tests.test_cache.test_auto_purge_keeps_fresh_entries(monkeypatch, tmp_path, cache_env)[source]

auto_purge keeps entries newer than the threshold.

tests.test_cache.test_max_age_days_default(monkeypatch)[source]

Returns CacheConfig.max_age when env var is not set.

tests.test_cache.test_max_age_days_custom(monkeypatch)[source]

Reads integer from REPOMATIC_CACHE_MAX_AGE.

tests.test_cache.test_max_age_days_zero_disables(monkeypatch)[source]

REPOMATIC_CACHE_MAX_AGE=0 disables auto-purge.

tests.test_cache.test_max_age_days_invalid_fallback(monkeypatch)[source]

Invalid value falls back to default with a warning.

tests.test_cache.test_prune_empty_dirs(tmp_path)[source]

Removes empty nested directories but preserves root.

tests.test_cache.test_prune_empty_dirs_preserves_nonempty(tmp_path)[source]

Preserves directories that contain files.

tests.test_cache.test_store_and_get_cached_response(cache_env)[source]

Round-trip: store a response, then retrieve it.

tests.test_cache.test_get_cached_response_zero_ttl(cache_env)[source]

TTL=0 bypasses cache entirely.

tests.test_cache.test_get_cached_response_negative_ttl(cache_env)[source]

Negative TTL bypasses cache entirely.

tests.test_cache.test_get_cached_response_missing(cache_env)[source]

Returns None when no cached response exists.

tests.test_cache.test_get_cached_response_stale(cache_env)[source]

Returns None when cached response is older than max_age_seconds.

tests.test_cache.test_store_response_nested_key(cache_env)[source]

Keys with slashes create nested directories.

tests.test_cache.test_http_cache_info_lists_entries(cache_env)[source]

Every cached response is listed.

tests.test_cache.test_http_cache_info_empty(cache_env)[source]

Returns empty list when HTTP cache is empty.

tests.test_cache.test_clear_http_cache_all(cache_env)[source]

A clear with no filter removes every HTTP entry.

tests.test_cache.test_clear_http_cache_by_namespace(cache_env)[source]

A scoped clear removes only the entries of that namespace.

tests.test_cache.test_clear_http_cache_by_age(cache_env)[source]

An age-limited clear removes only old HTTP entries.

tests.test_cache.test_store_config_keys_the_file_on_its_content(cache_env)[source]

Different content lands on different files; the same content on one.

Two checkouts generating different configs for one tool used to overwrite each other’s file, so a run could read the config of the other.

tests.test_cache.test_config_entries_list_both_layouts(cache_env)[source]

A config with no digest directory is listed too, so a clean reaches it.

tests.test_cache.test_store_config_triggers_auto_purge(cache_env)[source]

A stored config ages like every other entry, so a store sweeps the cache.

tests.test_cache.test_clean_reaches_the_caches_its_filters_apply_to(tmp_path, cache_env, options, left)[source]

A scope filter narrows only the caches it names, and spares the rest.

tests.test_cache.test_auto_purge_reaches_configs(monkeypatch, tmp_path, cache_env)[source]

A stale config is purged with the binaries and the HTTP responses.

tests.test_cache.test_cache_rows_lists_every_cache_in_order(tmp_path, cache_env)[source]

Binaries come first, then HTTP responses, then tool configs.

tests.test_cache.test_lock_files_stay_out_of_listings_and_cleans(cache_env)[source]

A lock file another run may hold is never listed nor deleted.