Skip to content

πŸš€ The fast, Pythonic way to build MCP servers and clients.

Use portable issue ranking cache filenames (#5314)

nate nowack89b00b7f9780
diff --git a/scripts/rank_issues.py b/scripts/rank_issues.py
index 6a56d80cf..4f6f1a36b 100644
--- a/scripts/rank_issues.py
+++ b/scripts/rank_issues.py
@@ -379,9 +379,8 @@ class Cache:
path.write_text(json.dumps(value, default=str))
def _path(self, key: Sequence[str]) -> Path:
- *dirs, leaf = key
- safe = hashlib.sha256(leaf.encode()).hexdigest()[:24]
- return self.root.joinpath(*dirs, f"{safe}.json")
+ safe = hashlib.sha256(json.dumps(key).encode()).hexdigest()
+ return self.root / f"{safe}.json"
Progress = Callable[[str, int, int], None]
diff --git a/tests/test_issue_ranking.py b/tests/test_issue_ranking.py
index 3946e146b..29cb0ef13 100644
--- a/tests/test_issue_ranking.py
+++ b/tests/test_issue_ranking.py
@@ -243,3 +243,21 @@ def test_previous_public_assessment_reused_without_credentials(
)
== {}
)
+
+
+def test_cache_keys_are_portable_and_keep_boundaries(ranking_module, tmp_path):
+ cache = ranking_module.Cache(tmp_path, enabled=True)
+ keys = [
+ ("judgments", "PrefectHQ/fastmcp", "jev:jev-latest", "1"),
+ ("judgments", "PrefectHQ", "fastmcp/jev:jev-latest", "1"),
+ ]
+ for index, key in enumerate(keys):
+ cache.put({"index": index}, *key)
+ for index, key in enumerate(keys):
+ assert cache.get(*key) == {"index": index}
+ assert cache.get("missing") is None
+ files = list(tmp_path.rglob("*.json"))
+ assert len(files) == 2
+ for file in files:
+ assert file.parent == tmp_path
+ assert not set(file.name) & set('<>:"/\\|?*')