fix: identify history images and keep failure reasons visible
Community checks / verify (push) Skipped
Verify Frame Flow / verify (push) Successful in 7m29s

This commit is contained in:
渡口浪人
2026-10-18 22:58:48 +08:00
parent 3a5acaa72a
commit cc3fd02eb7
14 changed files with 157 additions and 32 deletions
+22
View File
@@ -690,6 +690,28 @@
},
"OperationResult": {
"properties": {
"image_name": {
"anyOf": [
{
"type": "string"
},
{
"type": "null"
}
],
"title": "Image Name"
},
"preview_url": {
"anyOf": [
{
"type": "string"
},
{
"type": "null"
}
],
"title": "Preview Url"
},
"cover_id": {
"anyOf": [
{
+62
View File
@@ -0,0 +1,62 @@
from io import BytesIO
from PIL import Image
from pigway_frame_flow.models import DisplayRequest
def test_history_image_survives_cloud_cleanup(client, service):
data = BytesIO()
Image.new("RGB", (40, 60), "blue").save(data, "JPEG")
asset = service.assets.put(data.getvalue(), "example.jpg", "images")
request = DisplayRequest(content={"type": "image", "asset_id": asset["asset_id"]})
op = service.submit(
"display", request.model_dump(mode="json"), "living-room", "admin", "fixture"
)
service.process_one()
service.sync()
result = service.operation(op)["result"]
image_id = result["image_id"]
# Simulate an older receipt without the new name snapshot, then cloud cleanup.
service.db.execute(
"UPDATE operations SET result=? WHERE id=?",
(
'{"image_id":%d,"rendered_asset_id":"%s"}' % (image_id, asset["asset_id"]),
op,
),
)
service.db.execute("DELETE FROM image_sources WHERE device_id=?", ("living-room",))
deletion = service.submit(
"delete",
{"image_id": image_id, "confirm_current": True},
"living-room",
"admin",
"delete-fixture",
)
service.update(deletion, "COMPLETED", {"image_id": image_id})
receipt = client.get("/api/v1/operations/" + deletion).json()["result"]
assert receipt["image_name"] == "example.jpg"
assert client.get(receipt["preview_url"]).status_code == 200
service.assets.path(asset["asset_id"]).unlink()
service.db.execute("DELETE FROM assets WHERE id=?", (asset["asset_id"],))
receipt = client.get("/api/v1/operations/" + deletion).json()["result"]
assert receipt["image_name"] == "example.jpg"
assert receipt["preview_url"] is None
def test_history_missing_local_image_does_not_break_list(client, service):
op = service.submit("delete", {"image_id": 999}, "living-room", "admin", "fixture")
service.update(
op,
"FAILED",
{"image_id": 999},
{
"code": "DEVICE_OFFLINE",
"message": "Device offline",
"request_id": "fixture",
},
)
receipt = client.get("/api/v1/operations/" + op).json()
assert receipt["result"]["image_id"] == 999
assert receipt["result"]["preview_url"] is None
assert receipt["error"]["code"] == "DEVICE_OFFLINE"