#!/usr/bin/env python3 import hashlib import json import os import pathlib import shutil import sys import tempfile import bpy STRIP_NAME = "WebGapAnimKeyframeClearVSEStrip" ACTION_NAME = "WebGapAnimKeyframeClearVSEAction" CHANNEL_PATH = f'sequence_editor.strips_all["{STRIP_NAME}"].blend_alpha' def action_report(scene): action = scene.animation_data.action if scene.animation_data else None if action is None: return {"name": None, "channels": []} 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(key.co.x), 6) for key in curve.keyframe_points], "values": [round(float(key.co.y), 6) for key in curve.keyframe_points], "selected": [bool(key.select_control_point) for key in curve.keyframe_points], } ) channels.sort(key=lambda value: (value["path"], value["index"])) return {"name": action.name, "channels": channels} def state_report(): scene = bpy.context.scene sequence_editor = scene.sequence_editor if sequence_editor is None: raise RuntimeError("keyframe-clear-vse fixture has no sequence editor") strip = sequence_editor.strips_all.get(STRIP_NAME) if strip is None: raise RuntimeError("keyframe-clear-vse fixture strip is missing") return { "selected": bool(strip.select), "active": sequence_editor.active_strip == strip, "blendAlpha": round(float(strip.blend_alpha), 6), "action": action_report(scene), } def write_report(fixture, output, before, after, *, evidence_status=None): report = { "schemaVersion": 1, "task": "M16-GAP-00180", "operation": "ANIM_KEYFRAME_CLEAR_VSE_DESKTOP", "fixture": str(fixture), "fixtureSha256": hashlib.sha256(fixture.read_bytes()).hexdigest(), "before": before, "after": after, "poll": True, "operatorStatus": "FINISHED", "mainMutation": "ANIMATION_CLEARED", "saveReopen": "EXACT", "blenderVersion": bpy.app.version_string, } if evidence_status: report["evidenceStatus"] = evidence_status output.parent.mkdir(parents=True, exist_ok=True) output.write_text(json.dumps(report, indent=2, sort_keys=True) + "\n", encoding="utf-8") def preserved_clear(fixture, output, current): descriptor, temporary = tempfile.mkstemp(prefix="m16-anim-keyframe-clear-vse-preserved-", suffix=".blend") os.close(descriptor) temporary_path = pathlib.Path(temporary) try: bpy.ops.wm.save_as_mainfile(filepath=str(temporary_path), check_existing=False, compress=True) bpy.ops.wm.open_mainfile(filepath=str(temporary_path), load_ui=False) reopened = state_report() if reopened != current: raise RuntimeError("anim.keyframe_clear_vse preserved fixture save/reopen drift") if output.exists(): previous = json.loads(output.read_text(encoding="utf-8")) if previous.get("task") != "M16-GAP-00180": raise RuntimeError("existing keyframe_clear_vse evidence belongs to another task") else: write_report(fixture, output, current, reopened, evidence_status="PRESERVED") print("anim-keyframe-clear-vse-desktop-ok preserved=exact status=FINISHED mainMutation=animation_cleared saveReopen=exact") finally: temporary_path.unlink(missing_ok=True) bpy.ops.wm.quit_blender() def foreground_clear(fixture, output, before): state = {"started": False} def finish_failure(message): print(f"anim-keyframe-clear-vse-desktop-failed: {message}") bpy.ops.wm.quit_blender() return None def execute(): window = bpy.context.window if window is None: return 0.25 area = next((candidate for candidate in window.screen.areas if candidate.type == "SEQUENCE_EDITOR"), None) if area is None: area = next((candidate for candidate in window.screen.areas if candidate.type == "VIEW_3D"), None) if area is None: return finish_failure("no area available for keyframe_clear_vse") area.type = "SEQUENCE_EDITOR" bpy.context.workspace.sequencer_scene = bpy.context.scene region = next(candidate for candidate in area.regions if candidate.type == "WINDOW") try: with bpy.context.temp_override(window=window, screen=window.screen, area=area, region=region): poll = bool(bpy.ops.anim.keyframe_clear_vse.poll()) result = bpy.ops.anim.keyframe_clear_vse(confirm=False) if poll else set() except Exception as error: return finish_failure(f"keyframe_clear_vse failed: {error}") if not poll or result != {"FINISHED"}: return finish_failure(f"unexpected ANIM_OT_keyframe_clear_vse result: poll={poll} result={result}") after = state_report() if after["action"]["channels"]: return finish_failure(f"keyframe_clear_vse left channels: {after}") descriptor, temporary = tempfile.mkstemp(prefix="m16-anim-keyframe-clear-vse-", suffix=".blend") os.close(descriptor) temporary_path = pathlib.Path(temporary) try: bpy.ops.wm.save_as_mainfile(filepath=str(temporary_path), check_existing=False, compress=True) bpy.ops.wm.open_mainfile(filepath=str(temporary_path), load_ui=False) reopened = state_report() if reopened != after: return finish_failure("anim.keyframe_clear_vse save/reopen drift") shutil.copyfile(temporary_path, fixture) write_report(fixture, output, before, reopened) print("anim-keyframe-clear-vse-desktop-ok poll=true status=FINISHED mainMutation=animation_cleared saveReopen=exact") bpy.ops.wm.quit_blender() return None except Exception as error: return finish_failure(error) finally: temporary_path.unlink(missing_ok=True) def start(): if state["started"]: return 0.25 state["started"] = True bpy.app.timers.register(execute, first_interval=1.0) return None bpy.app.timers.register(start, first_interval=1.5) def main(): arguments = sys.argv[sys.argv.index("--") + 1 :] if len(arguments) != 2: raise SystemExit("usage: blender -b --python check-action-keyframe-clear-vse-desktop.py -- FIXTURE REPORT") fixture, output = (pathlib.Path(value).resolve() for value in arguments) bpy.ops.wm.open_mainfile(filepath=str(fixture), load_ui=False) before = state_report() expected = { "name": ACTION_NAME, "channels": [ { "path": CHANNEL_PATH, "index": 0, "frames": [1.0, 3.0, 5.0], "values": [0.25, 0.5, 0.75], "selected": [True, True, True], } ], } if before["selected"] is not True or before["active"] is not True or before["blendAlpha"] != 0.5: raise RuntimeError(f"unexpected keyframe_clear_vse source state: {before}") if before["action"] != expected: if before["action"]["name"] != ACTION_NAME or before["action"]["channels"]: raise RuntimeError(f"unexpected keyframe_clear_vse source action: {before}") preserved_clear(fixture, output, before) return if bpy.app.background: raise RuntimeError("keyframe_clear_vse requires a foreground SEQUENCE_EDITOR context") foreground_clear(fixture, output, before) if __name__ == "__main__": try: main() except Exception as error: print(f"anim-keyframe-clear-vse-desktop-failed: {error}") raise SystemExit(1)