fix(steam): keep the applied record for a game the client did not report, and apply nothing after a lost write

Review: a game the client briefly refused lost its games_applied record, so its
unchanged request later looked new and overwrote the Steam pick; it now keeps
what was applied before. When the app rewrote games.json during both tries,
the stale second read was applied; that pass now applies no per-game choice
and keeps the record.
This commit is contained in:
The412Banner committed 2026-10-22 22:29:03 +00:00
1 parent 663da2948c
commit 449dc301bd
3 files changed
+38 -8

No files matched your search

@@ -619,7 +619,7 @@ class Helper:
current.pop(app, None)
# The client's pick of a tool the app chose for a game wins once the app's choice was applied.
requests = COMPAT["settled_game_requests"](state, current, catalog)
overrides = COMPAT["requested_games"](requests, catalog, [t["name"] for t in live])
overrides = COMPAT["requested_games"](requests or {}, catalog, [t["name"] for t in live])
overrides = {app: tool for app, tool in overrides.items() if app not in refused}
changes, auto = COMPAT["plan_mapping"](
current, installed, [t["name"] for t in live], default,
@@ -1190,22 +1190,26 @@ def settle_game_requests(requests, state, current, catalog, missing_is_cleared=F
def settled_game_requests(state, current, catalog, missing_is_cleared=False, directory=None):
"""Reads the app's choices, settles them against the client's picks and stores the result. When the
app rewrote the file meanwhile, its newer choices are settled again; they are never overwritten."""
app rewrote the file meanwhile, its newer choices are settled again; they are never overwritten.
None when the app kept rewriting it: this pass then applies no per-game choice and records nothing."""
for _ in range(2):
requests, text = read_game_requests(directory)
settled, moved = settle_game_requests(requests, state, current, catalog, missing_is_cleared)
if not moved or write_game_requests(settled, text, directory):
return settled
return settled
return None
def applied_game_requests(requests, overrides, state):
"""What the app asked for that is now in the mapping; a tool not installed yet stays unapplied."""
"""What the app asked for that is now in the mapping. A tool not installed yet stays unapplied, and a
game this pass did not handle (the client refused to report it) keeps what was applied before."""
recorded = state.get("games_applied")
before = recorded if isinstance(recorded, dict) else {}
return {app: request if overrides.get(app) is not DEFERRED_GAME_TOOL else before.get(app)
for app, request in requests.items() if app in overrides and
(overrides.get(app) is not DEFERRED_GAME_TOOL or app in before)}
if requests is None:
return dict(before)
return {app: request if app in overrides and overrides[app] is not DEFERRED_GAME_TOOL else before[app]
for app, request in requests.items()
if app in overrides and overrides[app] is not DEFERRED_GAME_TOOL or app in before}
def requested_games(requests, catalog, runnable=None):
@@ -1397,7 +1401,7 @@ def register_default(config_path, apps=(), protect=(), default=None, catalog=Non
steam_root = os.path.dirname(os.path.dirname(os.path.abspath(config_path)))
# With the client stopped, config.vdf is what it last kept: an app missing from it has no forced tool.
requests = settled_game_requests(state, current, catalog, not steam_running(), directory)
overrides = requested_games(requests, catalog)
overrides = requested_games(requests or {}, catalog)
managed = state.get("auto", {}).keys() if isinstance(state.get("auto"), dict) else ()
native_choices = state.get("native_choices", ())
native = native_targets(steam_root, set(apps) | set(picks) | set(managed) | set(native_choices))
+26
View File
@@ -707,6 +707,32 @@ class ReconcileTest(unittest.TestCase):
self.assertFalse(COMPAT["write_game_requests"]({}, text))
self.assertEqual(self.games(), {"10": {"valve": True, "dir": "Proton Experimental (ARM64)"}})
def test_an_app_the_client_briefly_refuses_keeps_its_applied_choice_live(self):
page = FakePage({"0": TOOL, "10": TOOL, "11": TOOL}, [TOOL, TOOL_11, COMPAT["FEX_TOOL"]])
self.write_games({"10": {"valve": True, "dir": "Proton 11.0 (ARM64)"}})
self.reconcile(page)
page.refused = {"10"}
state = self.reconcile(page)
self.assertEqual(state["games_applied"], {"10": {"valve": True, "dir": "Proton 11.0 (ARM64)"}})
page.refused = set()
page.sets.clear()
page.mapping["10"] = COMPAT["FEX_TOOL"]
self.reconcile(page)
self.assertEqual(page.sets, [])
self.assertEqual(page.mapping["10"], COMPAT["FEX_TOOL"])
def test_an_app_rewriting_its_choices_during_both_tries_applies_none_of_them_live(self):
page = FakePage({"0": TOOL, "10": TOOL, "11": TOOL}, [TOOL, TOOL_11, COMPAT["FEX_TOOL"]])
self.write_games({"10": {"valve": True, "dir": "Proton 11.0 (ARM64)"}})
self.reconcile(page)
page.sets.clear()
page.mapping["10"] = COMPAT["FEX_TOOL"]
self.write_games({"10": {"valve": True, "dir": "Proton 11.0 (ARM64)"}, "11": None})
with mock.patch.dict(COMPAT["settled_game_requests"].__globals__, write_game_requests=lambda *_: False):
state = self.reconcile(page)
self.assertEqual(page.sets, [])
self.assertEqual(state["games_applied"], {"10": {"valve": True, "dir": "Proton 11.0 (ARM64)"}})
def test_a_steam_pick_is_kept_at_the_next_start(self):
config = self.steam / "config/config.vdf"
config.parent.mkdir(parents=True)