refactor: consolidate load_cache into build.load_stars

load_cache was a duplicate of logic now living in build.load_stars.
Switch the call site to the shared helper and remove the redundant
local function and its tests.

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
Vinta Chen
2026-03-18 17:28:53 +08:00
parent 143abbf201
commit af3baab2ed
2 changed files with 2 additions and 35 deletions
-22
View File
@@ -8,7 +8,6 @@ sys.path.insert(0, os.path.join(os.path.dirname(__file__), ".."))
from fetch_github_stars import (
build_graphql_query,
extract_github_repos,
load_cache,
parse_graphql_response,
save_cache,
)
@@ -65,27 +64,6 @@ class TestExtractGithubRepos:
assert result == {"org/repo"}
class TestLoadCache:
def test_returns_empty_when_missing(self, tmp_path, monkeypatch):
monkeypatch.setattr("fetch_github_stars.CACHE_FILE", tmp_path / "nonexistent.json")
result = load_cache()
assert result == {}
def test_loads_valid_cache(self, tmp_path, monkeypatch):
cache_file = tmp_path / "stars.json"
cache_file.write_text('{"a/b": {"stars": 1}}', encoding="utf-8")
monkeypatch.setattr("fetch_github_stars.CACHE_FILE", cache_file)
result = load_cache()
assert result == {"a/b": {"stars": 1}}
def test_returns_empty_on_corrupt_json(self, tmp_path, monkeypatch):
cache_file = tmp_path / "stars.json"
cache_file.write_text("not json", encoding="utf-8")
monkeypatch.setattr("fetch_github_stars.CACHE_FILE", cache_file)
result = load_cache()
assert result == {}
class TestSaveCache:
def test_creates_directory_and_writes_json(self, tmp_path, monkeypatch):
data_dir = tmp_path / "data"