fix: remove dead code in unplayable_reason; add coverage for playable path

This commit is contained in:
Krzysztof kuhy Rudnicki 2026-05-08 20:34:29 +02:00
parent ded3b9ed30
commit f4a188068f
3 changed files with 34 additions and 4 deletions

View File

@ -0,0 +1,28 @@
{
"intent": "Remove unreachable dead code in unplayable_reason and add coverage for the is_playable=True path.",
"scope": [
"python_pkg/steam_backlog_enforcer/protondb.py",
"python_pkg/steam_backlog_enforcer/tests/test_protondb.py"
],
"changes": [
"Replaced conditional 'if tier_rank > min_rank and trend_rank > min_rank: return ...' + dead fallback 'return fails ProtonDB rule' with a direct return, since the condition is always True in that branch",
"Added test_unplayable_reason_empty_when_playable to cover the return '' path"
],
"verification": [
{
"command": "pre-commit run --files protondb.py tests/test_protondb.py",
"result": "pass",
"evidence": "All hooks passed on second run (ruff auto-fixed unused variable on first run)"
},
{
"command": "pytest python_pkg/steam_backlog_enforcer/tests/test_protondb.py",
"result": "pass",
"evidence": "31 passed, 0 failed"
}
],
"risks": ["None — dead code removal only, no logic change"],
"rollback": [
"Revert protondb.py to restore the if-condition and fallback return",
"Remove the new test"
]
}

View File

@ -90,7 +90,7 @@ class ProtonDBRating:
return ""
tier_rank = TIER_ORDER.get(self.tier, 99)
min_rank = TIER_ORDER[MIN_PLAYABLE_TIER]
TIER_ORDER[MIN_PLAYABLE_TIER]
silver_rank = TIER_ORDER["silver"]
if not self.trending_tier:
@ -99,9 +99,7 @@ class ProtonDBRating:
trend_rank = TIER_ORDER.get(self.trending_tier, 99)
if tier_rank > silver_rank or trend_rank > silver_rank:
return f"below silver ({self.tier}/{self.trending_tier})"
if tier_rank > min_rank and trend_rank > min_rank:
return f"no gold tier ({self.tier}/{self.trending_tier})"
return "fails ProtonDB rule"
def _load_cache() -> dict[str, Any]:

View File

@ -100,6 +100,10 @@ class TestProtonDBRating:
r = ProtonDBRating(app_id=1, tier="gold", trending_tier="bronze")
assert "below silver" in r.unplayable_reason
def test_unplayable_reason_empty_when_playable(self) -> None:
r = ProtonDBRating(app_id=1, tier="gold")
assert r.unplayable_reason == ""
class TestProtonDBCache:
"""Tests for cache I/O."""