diff --git a/_installer_import/steam_installer/appinfo.py b/_installer_import/steam_installer/appinfo.py index a32c654..236edeb 100644 --- a/_installer_import/steam_installer/appinfo.py +++ b/_installer_import/steam_installer/appinfo.py @@ -9,6 +9,10 @@ from dataclasses import dataclass, field from steam_installer import vdf +# depotdownloader is never given -branch, so it always fetches this one. +PUBLIC_BRANCH = "public" + + class AppInfoError(Exception): pass @@ -34,6 +38,9 @@ class DepotPlan: # depot id -> the DLC app it belongs to. Steam writes that dlcappid into # InstalledDepots, and a DLC depot recorded without it is not credited. dlc: dict[str, str] = field(default_factory=dict) + # depot id -> the manifest gid the public branch ships, for every depot in + # the app's list. A cached depot manifest matching it proves the build. + manifests: dict[str, str] = field(default_factory=dict) @property def all_expected(self) -> set[str]: @@ -147,13 +154,25 @@ def get_depot_plan( for depot_id, entry in depots.items(): if isinstance(entry, dict) and isinstance(entry.get("dlcappid"), str): plan.dlc[depot_id] = entry["dlcappid"] + gid = _public_gid(entry) + if gid is not None: + plan.manifests[depot_id] = gid return plan +def _public_gid(entry: object) -> str | None: + """The manifest gid a depot ships on the public branch, if it ships one.""" + manifests = entry.get("manifests") if isinstance(entry, dict) else None + public = manifests.get(PUBLIC_BRANCH) if isinstance(manifests, dict) else None + gid = public.get("gid") if isinstance(public, dict) else None + return gid if isinstance(gid, str) else None + + def get_dlc_plans( appid: int, language: str = "english", os_name: str = "windows" -) -> dict[int, set[str]]: - """DLC app id -> the depots it installs itself, for DLC with depots of its own. +) -> dict[int, dict[str, str]]: + """DLC app id -> {depot: public gid} it installs itself, for DLC with depots + of its own. Some DLC (Cyberpunk 2077's Phantom Liberty, app 2138330, ~25 GB) keeps its content under its own app id rather than in the game's depot list, so a @@ -168,13 +187,14 @@ def get_dlc_plans( return {} game_depots = app_block.get("depots", {}) game_depot_ids = set(game_depots) if isinstance(game_depots, dict) else set() - plans: dict[int, set[str]] = {} + plans: dict[int, dict[str, str]] = {} for dlc_id, dlc_block in _fetch_app_blocks(dlc_ids).items(): depots = dlc_block.get("depots", {}) if not isinstance(depots, dict): continue - own = _plan_from_depots(dlc_id, depots, language, os_name).required - own -= game_depot_ids + plan = _plan_from_depots(dlc_id, depots, language, os_name) + # Every required depot has a public gid: the plan only takes those. + own = {d: _public_gid(depots[d]) for d in plan.required - game_depot_ids} if own: plans[dlc_id] = own return plans @@ -198,6 +218,10 @@ def _plan_from_depots( dlc_owner = entry.get("dlcappid") if (dlc_owner and dlc_owner != str(appid)) or entry.get("optional") == "1": continue + # A placeholder (BG3 lists 1419654 as `{}`): no manifest on the branch + # depotdownloader fetches means nothing to download, so never missing. + if _public_gid(entry) is None: + continue config = entry.get("config", {}) config = config if isinstance(config, dict) else {} oslist = config.get("oslist") diff --git a/_installer_import/steam_installer/dlc.py b/_installer_import/steam_installer/dlc.py index 11f2c20..bd621f2 100644 --- a/_installer_import/steam_installer/dlc.py +++ b/_installer_import/steam_installer/dlc.py @@ -26,16 +26,17 @@ def download_owned( language: str, max_downloads: int, log: runlog.RunLog, -) -> dict[str, str] | None: +) -> appinfo.DepotPlan | None: """Download every owned DLC of `appid` that has depots of its own. Returns: - depot id -> DLC app id for each DLC depot now downloaded, or None if a - DLC download failed for a reason other than not owning it. + The DLC depots now downloaded -- each credited to its DLC app, with + its public gid -- or None if a DLC download failed for a reason other + than not owning it. """ logger = log.logger plans = appinfo.get_dlc_plans(appid, language) - downloaded: dict[str, str] = {} + downloaded = appinfo.DepotPlan(required=set(), shared=set()) for dlc_appid, depots in sorted(plans.items()): log.section(f"depotdownloader DLC {dlc_appid}") outcome = depotdl.download_dlc( @@ -56,5 +57,7 @@ def download_owned( ) return None logger.info("Downloaded DLC %d (depots %s).", dlc_appid, sorted(depots)) - downloaded.update(dict.fromkeys(depots, str(dlc_appid))) + downloaded.required |= set(depots) + downloaded.dlc.update(dict.fromkeys(depots, str(dlc_appid))) + downloaded.manifests.update(depots) return downloaded diff --git a/_installer_import/steam_installer/finalize.py b/_installer_import/steam_installer/finalize.py index cfff1d1..663ad7a 100644 --- a/_installer_import/steam_installer/finalize.py +++ b/_installer_import/steam_installer/finalize.py @@ -52,6 +52,7 @@ def finish( app_state=app_state, required_depots=depot_plan.required, expected_build_id=expected_build_id, + expected_manifests=depot_plan.manifests, ) if problems: # Fail closed. Writing StateFlags=4 here is what previously turned a @@ -76,6 +77,16 @@ def finish( install_dir=target, now_unix=int(time.time()), dlc_depots=depot_plan.dlc, + # Proven depot by depot, so it outranks whatever the manifest says. + build_id=( + expected_build_id + if finish_check.build_proven( + recognize.discover_cached_depot_manifests(target), + depot_plan.required, + depot_plan.manifests, + ) + else None + ), ) log.file_contents("Manifest after manual finish", written) diff --git a/_installer_import/steam_installer/finish_check.py b/_installer_import/steam_installer/finish_check.py index 50d5694..18e372e 100644 --- a/_installer_import/steam_installer/finish_check.py +++ b/_installer_import/steam_installer/finish_check.py @@ -16,6 +16,7 @@ def check_ready_to_finish( app_state: dict, required_depots: set[str], expected_build_id: str | None, + expected_manifests: dict[str, str] | None = None, ) -> list[str]: """Reasons the manifest must NOT be hand-finished. Empty list means go ahead. @@ -57,6 +58,28 @@ def check_ready_to_finish( f"{install_dir}/{recognize.DEPOTDOWNLOADER_DIR} -- the download did not finish" ) + expected_manifests = expected_manifests or {} + stale = sorted( + depot + for depot in required_depots & set(cached) & set(expected_manifests) + if cached[depot] != expected_manifests[depot] + ) + if stale: + problems.append( + f"depot(s) {', '.join(stale)} hold a manifest the public branch no " + "longer ships -- stale content" + ) + if build_proven(cached, required_depots, expected_manifests): + # The manifest's buildid only ever stood in for this proof. A stub + # (StateFlags 1026, buildid 0) that Steam never got to fill in is no + # reason to refuse content that matches the current build depot by depot. + if expected_build_id is None: + problems.append( + "could not determine the current public build from app info, " + "so there is no buildid to record" + ) + return problems + _content_and_steam_problems(install_dir) + buildid = app_state.get("buildid") target = app_state.get("TargetBuildID") if not (buildid and buildid != "0") and not (target and target != "0"): @@ -78,6 +101,22 @@ def check_ready_to_finish( f"{expected_build_id} -- content is for a different build" ) + return problems + _content_and_steam_problems(install_dir) + + +def build_proven( + cached: dict[str, str], required_depots: set[str], expected: dict[str, str] +) -> bool: + """Whether every required depot holds the manifest the public branch ships.""" + return bool(required_depots) and all( + depot in expected and cached.get(depot) == expected[depot] + for depot in required_depots + ) + + +def _content_and_steam_problems(install_dir: Path) -> list[str]: + """The checks that hold however the build was established.""" + problems: list[str] = [] # Cache *filenames* are not content. Without this, an install dir holding # only `.DepotDownloader/_.manifest` and no game files passes every # other check and gets written as StateFlags=4 with SizeOnDisk=0. diff --git a/_installer_import/steam_installer/flow.py b/_installer_import/steam_installer/flow.py index eab8e8a..3b6fcef 100644 --- a/_installer_import/steam_installer/flow.py +++ b/_installer_import/steam_installer/flow.py @@ -85,6 +85,11 @@ def _download_and_recognize( ) -> int: logger = log.logger + # First thing with Steam closed: whatever happens next, Steam resumes onto + # this field, and a stub written from the display name ("Baldur's Gate 3") + # would point it at a folder the download never fills. + manifest_write.ensure_installdir_correct(library, metadata.appid, install_target) + if staged is not None: log.section("Adopting Steam's staged download") logger.info( @@ -125,16 +130,18 @@ def _download_and_recognize( return 1 logger.info("Checking for owned DLC with depots of its own...") - dlc_depots = dlc.download_owned( + dlc_plan = dlc.download_owned( metadata.appid, install_target, username, language, args.max_downloads, log ) - if dlc_depots is None: + if dlc_plan is None: logger.info("Run log (send this): %s", log.path) return 1 # Downloaded DLC is part of this install now: the finish gate must find its - # depot cached, and the manifest must credit it to its DLC app. - depot_plan.required |= set(dlc_depots) - depot_plan.dlc.update(dlc_depots) + # depot cached at its public gid, and the manifest must credit it to its + # DLC app. + depot_plan.required |= dlc_plan.required + depot_plan.dlc.update(dlc_plan.dlc) + depot_plan.manifests.update(dlc_plan.manifests) log.section("depotdownloader cache") for depot_id, mid in sorted( @@ -142,8 +149,6 @@ def _download_and_recognize( ): logger.debug("depot %s -> manifest %s", depot_id, mid) - manifest_write.ensure_installdir_correct(library, metadata.appid, install_target) - if not args.skip_steamcmd: logger.info("Reconciling with steamcmd (validate)...") log.section("steamcmd app_update validate") diff --git a/_installer_import/steam_installer/manifest_write.py b/_installer_import/steam_installer/manifest_write.py index a746021..307aa15 100644 --- a/_installer_import/steam_installer/manifest_write.py +++ b/_installer_import/steam_installer/manifest_write.py @@ -72,6 +72,7 @@ def finish_manifest_manually( install_dir: Path, now_unix: int, dlc_depots: dict[str, str] | None = None, + build_id: str | None = None, ) -> Path: """Patch appmanifest_.acf to StateFlags=4 using only verified-known values. @@ -81,6 +82,8 @@ def finish_manifest_manually( `dlc_depots` maps a DLC depot to its DLC app id. Steam's own manifests record each DLC depot with that `dlcappid`, so it is written the same way. + `build_id`, when given, is a build the caller proved from the cached depot + manifests; it replaces the one Steam or steamcmd recorded. """ manifest_path = library.steamapps / f"appmanifest_{appid}.acf" if not manifest_path.is_file(): @@ -107,7 +110,7 @@ def finish_manifest_manually( # never falls through to TargetBuildID, leaving a stale/wrong buildid. existing_buildid = app_state.get("buildid") buildid = existing_buildid if existing_buildid and existing_buildid != "0" else None - buildid = buildid or app_state.get("TargetBuildID") or "0" + buildid = build_id or buildid or app_state.get("TargetBuildID") or "0" # A shared depot (e.g. Steamworks Common Redistributables) is installed once # under its owning app and only referenced here. Listing it in diff --git a/_installer_import/tests/test_appinfo.py b/_installer_import/tests/test_appinfo.py index 06ab228..f3317ff 100644 --- a/_installer_import/tests/test_appinfo.py +++ b/_installer_import/tests/test_appinfo.py @@ -7,17 +7,20 @@ def _app_block(monkeypatch, block): monkeypatch.setattr(appinfo, "_fetch_app_block", lambda appid: block) +# Every real depot that has content ships a manifest on the public branch. +_PUB = {"manifests": {"public": {"gid": "1"}}} + # Shape taken from a real `app_info_print 1771300`: 12 depots, of which an # english/windows install only ever fetches three. KCD2_DEPOTS = { - "228989": {"depotfromapp": "228980", "config": {"oslist": "windows"}}, - "1771302": {"config": {"oslist": "windows"}}, - "1771303": {"config": {"oslist": "windows"}}, - "1771304": {"dlcappid": "3406020", "config": {"oslist": "windows"}}, - "1771305": {"config": {"oslist": "windows", "language": "czech"}}, - "1771306": {"config": {"oslist": "windows", "language": "english"}}, - "1771307": {"config": {"oslist": "windows", "language": "french"}}, - "4075290": {"dlcappid": "4075290"}, + "228989": {"depotfromapp": "228980", "config": {"oslist": "windows"}, **_PUB}, + "1771302": {"config": {"oslist": "windows"}, **_PUB}, + "1771303": {"config": {"oslist": "windows"}, **_PUB}, + "1771304": {"dlcappid": "3406020", "config": {"oslist": "windows"}, **_PUB}, + "1771305": {"config": {"oslist": "windows", "language": "czech"}, **_PUB}, + "1771306": {"config": {"oslist": "windows", "language": "english"}, **_PUB}, + "1771307": {"config": {"oslist": "windows", "language": "french"}, **_PUB}, + "4075290": {"dlcappid": "4075290", **_PUB}, "branches": {"public": {"buildid": "23914554"}}, } @@ -42,14 +45,14 @@ def test_get_depot_plan_switches_language(monkeypatch): def test_get_depot_plan_excludes_other_os(monkeypatch): _app_block( monkeypatch, - {"depots": {"10": {"config": {"oslist": "linux"}}, "11": {"config": {}}}}, + {"depots": {"10": {"config": {"oslist": "linux"}, **_PUB}, "11": {"config": {}, **_PUB}}}, ) plan = appinfo.get_depot_plan(1771300, os_name="windows") assert plan.required == {"11"} def test_get_depot_plan_skips_optional_depots(monkeypatch): - _app_block(monkeypatch, {"depots": {"10": {"optional": "1"}, "11": {}}}) + _app_block(monkeypatch, {"depots": {"10": {"optional": "1", **_PUB}, "11": _PUB}}) assert appinfo.get_depot_plan(1771300).required == {"11"} @@ -234,3 +237,4 @@ def test_get_build_id_returns_none_when_buildid_not_a_string(monkeypatch): appinfo.subprocess, "run", lambda cmd, **kw: _FakeCompleted(text) ) assert appinfo.get_build_id(1) is None + diff --git a/_installer_import/tests/test_appinfo_public_manifests.py b/_installer_import/tests/test_appinfo_public_manifests.py new file mode 100644 index 0000000..0e7a1ac --- /dev/null +++ b/_installer_import/tests/test_appinfo_public_manifests.py @@ -0,0 +1,44 @@ +"""Depot plans against what the public branch actually ships. + +Split from test_appinfo.py (250-line cap): these are the depots-without-a- +manifest cases that made a finished BG3 download read as incomplete. +""" + +from steam_installer import appinfo + + +def _app_block(monkeypatch, block): + monkeypatch.setattr(appinfo, "_fetch_app_block", lambda appid: block) + + +# Shape taken from a real `app_info_print 1086940` (Baldur's Gate 3, build +# 25605617): depots listed with no manifest for the public branch are +# placeholders. depotdownloader has nothing to fetch for them, so demanding +# them turned a finished 160 GB download into "the download did not finish". +BG3_DEPOTS = { + "1086941": { + "config": {"oslist": "windows"}, + "manifests": {"public": {"gid": "8253106406752983615"}}, + }, + "1419654": {}, + "1419655": {"config": {"oslist": "windows"}}, + "1419656": {"manifests": {"release_patch_7_hf3": {"gid": "1"}}}, + "2378500": { + "dlcappid": "2378500", + "manifests": {"public": {"gid": "6453229909780803137"}}, + }, +} + + +def test_get_depot_plan_skips_depots_without_a_public_manifest(monkeypatch): + _app_block(monkeypatch, {"depots": BG3_DEPOTS}) + assert appinfo.get_depot_plan(1086940).required == {"1086941"} + + +def test_get_depot_plan_records_every_public_manifest(monkeypatch): + """DLC depots too: the finish check proves the build from these gids.""" + _app_block(monkeypatch, {"depots": BG3_DEPOTS}) + assert appinfo.get_depot_plan(1086940).manifests == { + "1086941": "8253106406752983615", + "2378500": "6453229909780803137", + } diff --git a/_installer_import/tests/test_cli_finish.py b/_installer_import/tests/test_cli_finish.py index 29a2d06..5cf6297 100644 --- a/_installer_import/tests/test_cli_finish.py +++ b/_installer_import/tests/test_cli_finish.py @@ -8,6 +8,7 @@ from steam_installer import ( appinfo, cli, recognize, + vdf, ) from _cli_helpers import ARGV, _stub_download, _stub_steamcmd @@ -116,3 +117,44 @@ def test_module_is_runnable_as_a_script(coverage_subprocess_env): ) assert result.returncode == 0 assert "--skip-steamcmd" in result.stdout + + +def test_a_stub_manifest_is_finished_with_the_proven_build(steam, monkeypatch): + """The enforcer's stub says build 0 and Steam never ran to fill it in. The + cached depot manifest matching the public branch proves the current build, + which is what the finished manifest must record (BG3, 2026-10-23).""" + library, install_dir = steam + manifest = library.steamapps / "appmanifest_1771300.acf" + manifest.write_text( + vdf.dumps("AppState", {"appid": "1771300", "StateFlags": "1026", "buildid": "0"}) + ) + (gid,) = recognize.discover_cached_depot_manifests(install_dir).values() + monkeypatch.setattr( + appinfo, + "get_depot_plan", + lambda appid, language: appinfo.DepotPlan( + {"1771303"}, {"228989"}, manifests={"1771303": gid} + ), + ) + _stub_download(monkeypatch) + + assert cli.main([*ARGV, "--skip-steamcmd"]) == 0 + app_state = vdf.parse(manifest.read_text())["AppState"] + assert (app_state["StateFlags"], app_state["buildid"]) == ("4", "23914554") + + +def test_the_install_folder_is_corrected_even_when_the_download_fails( + steam, monkeypatch +): + """The enforcer's stub names the folder after the display name ("Baldur's + Gate 3", not "Baldurs Gate 3"). Steam resumes onto whatever the manifest + says, so it is fixed as soon as Steam is closed, not only on success.""" + library, _ = steam + manifest = library.steamapps / "appmanifest_1771300.acf" + state = recognize.read_app_state(manifest) + state["installdir"] = "Kingdom Come: Deliverance II" + manifest.write_text(vdf.dumps("AppState", state)) + _stub_download(monkeypatch, returncode=2) + + assert cli.main([*ARGV, "--skip-steamcmd"]) == 1 + assert recognize.read_app_state(manifest)["installdir"] == "KingdomComeDeliverance2" diff --git a/_installer_import/tests/test_dlc.py b/_installer_import/tests/test_dlc.py index 2b49351..0ef3652 100644 --- a/_installer_import/tests/test_dlc.py +++ b/_installer_import/tests/test_dlc.py @@ -15,11 +15,14 @@ from steam_installer import appinfo, cli, depotdl, deps, dlc, recognize, runlog, pytestmark = pytest.mark.usefixtures("cli_logs") +# Every real depot that has content ships a manifest on the public branch. +_PUB = {"manifests": {"public": {"gid": "1"}}} + GAME = { "extended": {"listofdlc": "2060310,2138330,2441600"}, "depots": { - "1091501": {"config": {"oslist": "windows"}}, - "2060310": {"dlcappid": "2060310", "config": {"oslist": "windows"}}, + "1091501": {"config": {"oslist": "windows"}, **_PUB}, + "2060310": {"dlcappid": "2060310", "config": {"oslist": "windows"}, **_PUB}, }, } DLC_BLOCKS = { @@ -28,8 +31,8 @@ DLC_BLOCKS = { # Its own depot, tagged with its own id -- exactly what it installs. 2138330: { "depots": { - "2138330": {"dlcappid": "2138330", "config": {"oslist": "windows"}}, - "2138331": {"config": {"oslist": "windows", "language": "german"}}, + "2138330": {"dlcappid": "2138330", "config": {"oslist": "windows"}, **_PUB}, + "2138331": {"config": {"oslist": "windows", "language": "german"}, **_PUB}, } }, 2441600: {"common": {"name": "Pre-Order Bonus"}}, @@ -45,7 +48,7 @@ def _app_info(monkeypatch, game=GAME, dlc_blocks=DLC_BLOCKS): def test_only_dlc_with_depots_of_its_own_needs_a_run(monkeypatch): _app_info(monkeypatch) - assert appinfo.get_dlc_plans(1091500) == {2138330: {"2138330"}} + assert appinfo.get_dlc_plans(1091500) == {2138330: {"2138330": "1"}} @pytest.mark.parametrize("game", [{}, {"extended": "scalar"}, {"extended": {}}]) @@ -57,7 +60,7 @@ def test_a_game_without_dlc_needs_no_lookup(monkeypatch, game): def test_a_game_with_no_depot_list_still_finds_its_dlc(monkeypatch): _app_info(monkeypatch, game={"extended": {"listofdlc": "2138330"}}) - assert appinfo.get_dlc_plans(1091500) == {2138330: {"2138330"}} + assert appinfo.get_dlc_plans(1091500) == {2138330: {"2138330": "1"}} def test_depot_plan_tags_the_games_own_dlc_depots(monkeypatch): @@ -128,7 +131,9 @@ def run_log(tmp_path, monkeypatch): def _download_owned(monkeypatch, run_log, tmp_path, outcomes): monkeypatch.setattr( - appinfo, "get_dlc_plans", lambda appid, language: {7: {"70"}, 8: {"80"}} + appinfo, + "get_dlc_plans", + lambda appid, language: {7: {"70": "g70"}, 8: {"80": "g80"}}, ) monkeypatch.setattr( depotdl, "download_dlc", lambda dlc_appid, **kw: outcomes[dlc_appid] @@ -137,9 +142,10 @@ def _download_owned(monkeypatch, run_log, tmp_path, outcomes): def test_owned_dlc_is_returned_and_unowned_skipped(monkeypatch, run_log, tmp_path): - assert _download_owned(monkeypatch, run_log, tmp_path, {7: True, 8: None}) == { - "70": "7" - } + plan = _download_owned(monkeypatch, run_log, tmp_path, {7: True, 8: None}) + assert (plan.required, plan.dlc) == ({"70"}, {"70": "7"}) + # Its public gid too, so the finish check can prove the DLC's build. + assert plan.manifests == {"70": "g70"} def test_a_failed_dlc_download_aborts(monkeypatch, run_log, tmp_path): @@ -158,7 +164,7 @@ def test_downloaded_dlc_is_required_and_credited_to_its_app(steam, monkeypatch): manifest.write_text(vdf.dumps("AppState", state)) _stub_download(monkeypatch) _stub_steamcmd(monkeypatch, returncode=8) - monkeypatch.setattr(dlc, "download_owned", lambda *a: {"2138330": "2138330"}) + monkeypatch.setattr(dlc, "download_owned", lambda *a: _dlc_plan("100389")) assert cli.main(ARGV) == 0 @@ -168,17 +174,47 @@ def test_downloaded_dlc_is_required_and_credited_to_its_app(steam, monkeypatch): assert "DlcDownloads" not in state +def _dlc_plan(gid): + return appinfo.DepotPlan( + {"2138330"}, set(), {"2138330": "2138330"}, {"2138330": gid} + ) + + +def test_a_stub_with_own_app_dlc_finishes_with_the_proven_build(steam, monkeypatch): + """Base game and its own-app DLC both match the public branch: a build-0 + stub is finished, the DLC's gid coming from the DLC's own app info.""" + library, install_dir = steam + (install_dir / ".DepotDownloader" / "2138330_100389.manifest").write_bytes(b"x") + manifest = library.steamapps / "appmanifest_1771300.acf" + manifest.write_text(vdf.dumps("AppState", {"appid": "1771300", "buildid": "0"})) + monkeypatch.setattr( + appinfo, + "get_depot_plan", + lambda appid, language: appinfo.DepotPlan( + {"1771303"}, set(), manifests={"1771303": "1999516201078544527"} + ), + ) + _stub_download(monkeypatch) + monkeypatch.setattr(dlc, "download_owned", lambda *a: _dlc_plan("100389")) + + assert cli.main([*ARGV, "--skip-steamcmd"]) == 0 + assert recognize.read_app_state(manifest)["buildid"] == "23914554" + + def test_a_failed_dlc_download_leaves_the_manifest_alone(steam, monkeypatch): library, _ = steam manifest = library.steamapps / "appmanifest_1771300.acf" - before = manifest.read_text() + before = recognize.read_app_state(manifest) _stub_download(monkeypatch) monkeypatch.setattr(dlc, "download_owned", lambda *a: None) assert cli.main(ARGV) == 1 - assert manifest.read_text() == before + # Only the folder name is fixed up front; nothing claims an install. + after = recognize.read_app_state(manifest) + assert after.pop("installdir") == "KingdomComeDeliverance2" + assert after == before def test_a_dlc_with_a_malformed_depot_section_is_skipped(monkeypatch): _app_info(monkeypatch, dlc_blocks={**DLC_BLOCKS, 2441600: {"depots": "scalar"}}) - assert appinfo.get_dlc_plans(1091500) == {2138330: {"2138330"}} + assert appinfo.get_dlc_plans(1091500) == {2138330: {"2138330": "1"}} diff --git a/_installer_import/tests/test_finish_check.py b/_installer_import/tests/test_finish_check.py index 78870ed..3fae028 100644 --- a/_installer_import/tests/test_finish_check.py +++ b/_installer_import/tests/test_finish_check.py @@ -157,3 +157,52 @@ def test_gate_blocks_before_staging_is_destroyed(tmp_path, monkeypatch): expected_build_id="999", ) assert any("nothing to record as installed" in p for p in problems) + + +def _bg3_dir(tmp_path, gid="8253106406752983615"): + install_dir = tmp_path / "Baldurs Gate 3" + cache_dir = install_dir / ".DepotDownloader" + cache_dir.mkdir(parents=True) + (cache_dir / f"1086941_{gid}.manifest").write_bytes(b"x") + (install_dir / "Gustav.pak").write_bytes(b"x" * 1000) + return install_dir + + +def test_cached_public_manifests_prove_the_build(tmp_path, monkeypatch): + """The enforcer's stub manifest says build 0, and Steam never ran to fill + in TargetBuildID. Every depot holding the public branch's manifest *is* + the current build, so that is no reason to refuse.""" + monkeypatch.setattr("steam_installer.recognize.steam_client_pids", lambda: []) + problems = check_ready_to_finish( + install_dir=_bg3_dir(tmp_path), + app_state={"buildid": "0", "TargetBuildID": "0"}, + required_depots={"1086941"}, + expected_build_id="25605617", + expected_manifests={"1086941": "8253106406752983615"}, + ) + assert problems == [] + + +def test_a_stale_depot_manifest_is_refused(tmp_path, monkeypatch): + monkeypatch.setattr("steam_installer.recognize.steam_client_pids", lambda: []) + problems = check_ready_to_finish( + install_dir=_bg3_dir(tmp_path, gid="111"), + app_state={"buildid": "25605617"}, + required_depots={"1086941"}, + expected_build_id="25605617", + expected_manifests={"1086941": "8253106406752983615"}, + ) + assert any("1086941" in p and "stale" in p for p in problems) + + +def test_a_proven_build_still_needs_a_buildid_to_record(tmp_path, monkeypatch): + """Matching gids prove the content, but the manifest needs a number.""" + monkeypatch.setattr("steam_installer.recognize.steam_client_pids", lambda: []) + problems = check_ready_to_finish( + install_dir=_bg3_dir(tmp_path), + app_state={"buildid": "0"}, + required_depots={"1086941"}, + expected_build_id=None, + expected_manifests={"1086941": "8253106406752983615"}, + ) + assert any("no buildid to record" in p for p in problems)