#!/usr/bin/env python3 import hashlib import json import pathlib import sys import tempfile import bpy ACTION_NAME = "WebGapAssignAction" OBJECT_NAME = "WebGapAssignActionObject" def action_state(): obj = bpy.data.objects.get(OBJECT_NAME) if obj is None or obj.animation_data is None or obj.animation_data.action is None: raise RuntimeError("assign_action fixture action is missing") action = obj.animation_data.action channels = [] for layer in action.layers: for strip in layer.strips: for bag in strip.channelbags: for curve in bag.fcurves: channels.append({ "path": curve.data_path, "index": curve.array_index, "frames": [round(float(keyframe.co.x), 6) for keyframe in curve.keyframe_points], }) channels.sort(key=lambda value: (value["path"], value["index"])) return {"name": action.name, "channels": channels} def main(): arguments = sys.argv[sys.argv.index("--") + 1 :] if len(arguments) != 2: raise SystemExit("usage: blender -b --python check-action-assign-action-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) before = action_state() try: poll = bool(bpy.ops.asset.assign_action.poll()) except RuntimeError as error: if "context is incorrect" not in str(error): raise poll = False if poll: raise RuntimeError("asset.assign_action unexpectedly polled true without selected asset") try: bpy.ops.asset.assign_action() except RuntimeError as error: if "No asset selected or active" not in str(error) and "context is incorrect" not in str(error): raise operator_status = "CANCELLED" else: raise RuntimeError("asset.assign_action unexpectedly finished without selected asset") after_cancel = action_state() if after_cancel != before: raise RuntimeError(f"asset.assign_action cancellation changed Main data: {before} != {after_cancel}") with tempfile.NamedTemporaryFile(prefix="m16-assign-action-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 = action_state() if after != before: raise RuntimeError(f"asset.assign_action save/reopen drift: {before} != {after}") report = { "schemaVersion": 1, "task": "M16-GAP-00266", "operation": "ASSET_ASSIGN_ACTION_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-assign-action-desktop-ok poll=false status=CANCELLED mainMutation=none saveReopen=exact") if __name__ == "__main__": try: main() except Exception as error: print(f"asset-assign-action-desktop-failed: {error}") raise SystemExit(1)