#!/usr/bin/env python3 import hashlib import json import pathlib import sys import tempfile import bpy IMAGE_NAME = "WebGapAssetDownloadImage" def image_state(): image = bpy.data.images.get(IMAGE_NAME) if image is None: raise RuntimeError("asset download fixture image is missing") return { "name": image.name, "filepath": image.filepath, "source": image.source, "packed": image.packed_file is not None, "size": [int(image.generated_width), int(image.generated_height)], } def main(): arguments = sys.argv[sys.argv.index("--") + 1 :] if len(arguments) != 2: raise SystemExit("usage: blender -b --python check-action-asset-download-desktop.py -- FIXTURE REPORT") fixture, output = (pathlib.Path(value).resolve() for value in arguments) output.unlink(missing_ok=True) bpy.ops.wm.open_mainfile(filepath=str(fixture), load_ui=False) bpy.context.preferences.system.use_online_access = True before = image_state() poll = bool(bpy.ops.asset.asset_download.poll()) try: bpy.ops.asset.asset_download(relative_asset_identifier="WebGapAssetDownload") except RuntimeError as error: if "Asset could not be found" not in str(error): raise operator_status = "CANCELLED" else: raise RuntimeError("asset.asset_download unexpectedly finished without a remote asset") after_cancel = image_state() if after_cancel != before: raise RuntimeError(f"asset.asset_download cancellation changed Main data: {before} != {after_cancel}") with tempfile.NamedTemporaryFile(prefix="m16-asset-download-reopen-", suffix=".blend", dir=fixture.parent) as temporary: bpy.ops.wm.save_as_mainfile(filepath=temporary.name, check_existing=False, compress=True) bpy.ops.wm.open_mainfile(filepath=temporary.name, load_ui=False) after = image_state() if after != before: raise RuntimeError(f"asset.asset_download save/reopen drift: {before} != {after}") report = { "schemaVersion": 1, "task": "M16-GAP-00264", "operation": "ASSET_ASSET_DOWNLOAD_DESKTOP", "fixture": str(fixture), "fixtureSha256": hashlib.sha256(fixture.read_bytes()).hexdigest(), "before": before, "after": after, "poll": poll, "operatorStatus": operator_status, "mainMutation": "NONE", "saveReopen": "EXACT", "blenderVersion": bpy.app.version_string, } output.parent.mkdir(parents=True, exist_ok=True) output.write_text(json.dumps(report, indent=2, sort_keys=True) + "\n", encoding="utf-8") print("asset-asset-download-desktop-ok status=CANCELLED mainMutation=none saveReopen=exact") if __name__ == "__main__": try: main() except Exception as error: print(f"asset-asset-download-desktop-failed: {error}") raise SystemExit(1)