From 889873f8dc89c412dc1de915feb7b8812d41ff05 Mon Sep 17 00:00:00 2001 From: Krzysztof kuhy Rudnicki Date: Sun, 22 Nov 2026 16:37:32 +0100 Subject: [PATCH] Zero all download counters in the manifest C18: settle_download_counters wrote equal pairs (1000/1000) from a broken manifest. Write all four counters as 0, like the from-scratch skeleton. Co-Authored-By: Claude Opus 5.5 --- .../steam_installer/manifest_write.py | 17 +++++------ _installer_import/tests/test_cli.py | 3 +- _installer_import/tests/test_cli_finish.py | 28 +++++++++++++++++++ .../tests/test_manifest_finish.py | 6 ++-- 4 files changed, 41 insertions(+), 13 deletions(-) diff --git a/_installer_import/steam_installer/manifest_write.py b/_installer_import/steam_installer/manifest_write.py index bb00d3f..b21b769 100644 --- a/_installer_import/steam_installer/manifest_write.py +++ b/_installer_import/steam_installer/manifest_write.py @@ -213,16 +213,13 @@ def write_atomic(path: Path, text: str) -> None: def settle_download_counters(app_state: dict) -> None: - """Mark the download bookkeeping complete: `Downloaded` == `ToDownload`. + """Zero the download bookkeeping: nothing is queued, nothing is staged. Leaving these at their mid-download values is what made Steam discard a - StateFlags=4 manifest and resume fetching. Real installed manifests keep - these fields (they are not dropped) with the pair values equal. + StateFlags=4 manifest and resume fetching. All four go to "0", the same as + the from-scratch skeleton Steam accepted, rather than merely equal: the + older equal-pair form wrote `1000`/`1000` from a broken manifest, a value + no real install ever had. """ - for total_key, done_key in ( - ("BytesToDownload", "BytesDownloaded"), - ("BytesToStage", "BytesStaged"), - ): - total = app_state.get(total_key) - if total is not None: - app_state[done_key] = total + for key in ("BytesToDownload", "BytesDownloaded", "BytesToStage", "BytesStaged"): + app_state[key] = "0" diff --git a/_installer_import/tests/test_cli.py b/_installer_import/tests/test_cli.py index 0d9a701..6f209ea 100644 --- a/_installer_import/tests/test_cli.py +++ b/_installer_import/tests/test_cli.py @@ -29,7 +29,8 @@ def test_downloaded_content_finishes_the_manifest(steam, monkeypatch): app_state = recognize.read_app_state(library.steamapps / "appmanifest_1771300.acf") assert app_state["StateFlags"] == "4" - assert app_state["BytesDownloaded"] == app_state["BytesToDownload"] + for key in ("BytesToDownload", "BytesDownloaded", "BytesToStage", "BytesStaged"): + assert app_state[key] == "0", key assert recognize.download_counters_settled(app_state) diff --git a/_installer_import/tests/test_cli_finish.py b/_installer_import/tests/test_cli_finish.py index 2942006..f252cf7 100644 --- a/_installer_import/tests/test_cli_finish.py +++ b/_installer_import/tests/test_cli_finish.py @@ -198,3 +198,31 @@ def test_the_install_folder_is_corrected_even_when_the_download_fails( assert cli.main(ARGV) == 1 assert recognize.read_app_state(manifest)["installdir"] == "KingdomComeDeliverance2" + + +def test_wrong_installdir_and_mismatched_counters_end_correct_and_zeroed( + steam, monkeypatch +): + """C18: the live repro (installdir "... WRONG", BytesToDownload 1000, + BytesDownloaded 5) once came out as 1000/1000. The written manifest must + name the real folder, keep its files, and carry every counter at 0.""" + library, install_dir = steam + manifest = library.steamapps / "appmanifest_1771300.acf" + state = recognize.read_app_state(manifest) + state.update( + installdir="KingdomComeDeliverance2 WRONG", + BytesToDownload="1000", + BytesDownloaded="5", + BytesToStage="1000", + BytesStaged="5", + ) + manifest.write_text(vdf.dumps("AppState", state)) + _stub_download(monkeypatch) + + assert cli.main(ARGV) == 0 + + app_state = recognize.read_app_state(manifest) + assert app_state["installdir"] == "KingdomComeDeliverance2" + assert (install_dir / "game.pak").stat().st_size == 1000 + for key in ("BytesToDownload", "BytesDownloaded", "BytesToStage", "BytesStaged"): + assert app_state[key] == "0", key diff --git a/_installer_import/tests/test_manifest_finish.py b/_installer_import/tests/test_manifest_finish.py index 087e999..8d5774c 100644 --- a/_installer_import/tests/test_manifest_finish.py +++ b/_installer_import/tests/test_manifest_finish.py @@ -132,8 +132,10 @@ def test_finish_manifest_settles_download_counters(tmp_path): ) app_state = vdf.parse(manifest_path.read_text())["AppState"] - assert app_state["BytesDownloaded"] == app_state["BytesToDownload"] - assert app_state["BytesStaged"] == app_state["BytesToStage"] + # C18: all four counters at 0, as on a from-scratch manifest. Equal-but- + # nonzero leftovers (1000/1000) are not what Steam writes for an installed app. + for key in ("BytesToDownload", "BytesDownloaded", "BytesToStage", "BytesStaged"): + assert app_state[key] == "0", key assert app_state["StagingSize"] == "0" # DownloadType is present on every real installed manifest -- keep it. assert app_state["DownloadType"] == "1"