Files
aigc-home/calliope-backend/tests/test_item_generate_attach.py
T
Benjiyaya 71bed77095 Add tabbed video ref picker, stricter agent HITL, and item attach.
Playground creates a new misc. item instead of overwriting one; item generate jobs persist the image path. Notes in docs/changelogs/2026-08-23.md.
2026-08-24 04:29:49 +08:00

52 lines
1.7 KiB
Python

"""Misc. Item generate jobs must attach the downloaded file to the item row."""
from __future__ import annotations
from calliope.config import settings
from calliope.db import get_db
from calliope.queue.worker import queue_worker
def test_item_generate_attaches_reference_image(client):
pid = client.post("/api/projects", json={"title": "Item Attach"}).json()["id"]
item = client.post(
f"/api/projects/{pid}/items",
json={"name": "Mecha Suits", "description": "exoskeletons"},
).json()
assert item.get("reference_image_path") in (None, "")
dest = settings.assets_dir / str(pid) / "image"
dest.mkdir(parents=True, exist_ok=True)
path = dest / "mecha.png"
path.write_bytes(b"\x89PNG\r\n")
queue_worker._apply_outputs_to_entities(
{"kind": "image", "scene_id": None},
{"item_id": item["id"]},
[str(path)],
)
assets = client.get(f"/api/projects/{pid}/assets").json()
row = next(i for i in assets["items"] if i["id"] == item["id"])
assert row["reference_image_path"] == str(path)
conn = get_db(settings.db_path)
try:
db_row = conn.execute(
"SELECT reference_image_path FROM items WHERE id = ?", (item["id"],)
).fetchone()
finally:
conn.close()
assert db_row["reference_image_path"] == str(path)
def test_item_job_label_uses_name(client):
pid = client.post("/api/projects", json={"title": "Item Label"}).json()["id"]
item = client.post(
f"/api/projects/{pid}/items",
json={"name": "Energy Shield", "description": "bubble"},
).json()
label = queue_worker._job_label(
{"kind": "image", "id": 301, "payload_json": f'{{"item_id": {item["id"]}}}'},
)
assert label == "Energy Shield · item"