Continue Blender Web parity task handoff
This commit is contained in:
196
tools/web/check-action-keyframe-delete-desktop.py
Normal file
196
tools/web/check-action-keyframe-delete-desktop.py
Normal file
@@ -0,0 +1,196 @@
|
||||
#!/usr/bin/env python3
|
||||
import hashlib
|
||||
import json
|
||||
import os
|
||||
import pathlib
|
||||
import shutil
|
||||
import sys
|
||||
import tempfile
|
||||
|
||||
import bpy
|
||||
|
||||
|
||||
OBJECT_NAME = "WebGapAnimKeyframeDeleteObject"
|
||||
ACTION_NAME = "WebGapAnimKeyframeDeleteAction"
|
||||
KEYING_SET_NAME = "WebGapAnimKeyframeDeleteSet"
|
||||
DATA_PATH = '["delete_target"]'
|
||||
|
||||
|
||||
def action_report(obj):
|
||||
action = obj.animation_data.action if obj and obj.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
|
||||
obj = bpy.data.objects.get(OBJECT_NAME)
|
||||
if obj is None:
|
||||
raise RuntimeError("keyframe-delete fixture object is missing")
|
||||
active = scene.keying_sets.active
|
||||
return {
|
||||
"selected": bool(obj.select_get()),
|
||||
"active": bpy.context.view_layer.objects.active == obj,
|
||||
"value": round(float(obj["delete_target"]), 6),
|
||||
"activeKeyingSet": active.bl_idname if active else None,
|
||||
"action": action_report(obj),
|
||||
}
|
||||
|
||||
|
||||
def write_report(fixture, output, before, after, *, evidence_status=None):
|
||||
report = {
|
||||
"schemaVersion": 1,
|
||||
"task": "M16-GAP-00181",
|
||||
"operation": "ANIM_KEYFRAME_DELETE_DESKTOP",
|
||||
"fixture": str(fixture),
|
||||
"fixtureSha256": hashlib.sha256(fixture.read_bytes()).hexdigest(),
|
||||
"before": before,
|
||||
"after": after,
|
||||
"poll": True,
|
||||
"operatorStatus": "FINISHED",
|
||||
"mainMutation": "KEYFRAME_DELETED",
|
||||
"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_delete(fixture, output, current):
|
||||
descriptor, temporary = tempfile.mkstemp(prefix="m16-anim-keyframe-delete-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_delete preserved fixture save/reopen drift")
|
||||
if output.exists():
|
||||
previous = json.loads(output.read_text(encoding="utf-8"))
|
||||
if previous.get("task") != "M16-GAP-00181":
|
||||
raise RuntimeError("existing keyframe_delete evidence belongs to another task")
|
||||
else:
|
||||
write_report(fixture, output, current, reopened, evidence_status="PRESERVED")
|
||||
print("anim-keyframe-delete-desktop-ok preserved=exact status=FINISHED mainMutation=keyframe_deleted saveReopen=exact")
|
||||
finally:
|
||||
temporary_path.unlink(missing_ok=True)
|
||||
bpy.ops.wm.quit_blender()
|
||||
|
||||
|
||||
def foreground_delete(fixture, output, before):
|
||||
state = {"started": False}
|
||||
|
||||
def finish_failure(message):
|
||||
print(f"anim-keyframe-delete-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 == "VIEW_3D"), None)
|
||||
if area is None:
|
||||
return finish_failure("no VIEW_3D area available for keyframe_delete")
|
||||
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_delete.poll())
|
||||
result = bpy.ops.anim.keyframe_delete(type=KEYING_SET_NAME) if poll else set()
|
||||
except Exception as error:
|
||||
return finish_failure(f"keyframe_delete failed: {error}")
|
||||
if not poll or result != {"FINISHED"}:
|
||||
return finish_failure(f"unexpected ANIM_OT_keyframe_delete result: poll={poll} result={result}")
|
||||
after = state_report()
|
||||
channels = after["action"]["channels"]
|
||||
if len(channels) != 1 or channels[0]["frames"] != [1.0, 5.0]:
|
||||
return finish_failure(f"keyframe_delete produced unexpected action: {after}")
|
||||
descriptor, temporary = tempfile.mkstemp(prefix="m16-anim-keyframe-delete-", 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_delete save/reopen drift")
|
||||
shutil.copyfile(temporary_path, fixture)
|
||||
write_report(fixture, output, before, reopened)
|
||||
print("anim-keyframe-delete-desktop-ok poll=true status=FINISHED mainMutation=keyframe_deleted 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-delete-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": DATA_PATH,
|
||||
"index": 0,
|
||||
"frames": [1.0, 3.0, 5.0],
|
||||
"values": [1.0, 3.0, 5.0],
|
||||
"selected": [True, True, True],
|
||||
}
|
||||
],
|
||||
}
|
||||
if before["selected"] is not True or before["active"] is not True or before["value"] != 3.0:
|
||||
raise RuntimeError(f"unexpected keyframe_delete source state: {before}")
|
||||
if before["activeKeyingSet"] != KEYING_SET_NAME:
|
||||
raise RuntimeError(f"unexpected keyframe_delete keying set: {before}")
|
||||
if before["action"] != expected:
|
||||
if before["action"]["name"] != ACTION_NAME or before["action"]["channels"] != [
|
||||
{**expected["channels"][0], "frames": [1.0, 5.0], "values": [1.0, 5.0], "selected": [True, True]}
|
||||
]:
|
||||
raise RuntimeError(f"unexpected keyframe_delete source action: {before}")
|
||||
preserved_delete(fixture, output, before)
|
||||
return
|
||||
if bpy.app.background:
|
||||
raise RuntimeError("keyframe_delete requires a foreground VIEW_3D context")
|
||||
foreground_delete(fixture, output, before)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
try:
|
||||
main()
|
||||
except Exception as error:
|
||||
print(f"anim-keyframe-delete-desktop-failed: {error}")
|
||||
raise SystemExit(1)
|
||||
Reference in New Issue
Block a user