feat: release 1.5.7 - per-clip workflows, runtime budgets, media-path guards

Three reported issues:

#66: the Video stage workflow picker was keyed by scene id, so choosing a
workflow for one clip overwrote every sibling clip. It is now keyed by clip
id, hydrates each clip's persisted choice, autosaves both
clips.workflow_id and form_workflow_id, and Generate One / Generate All
resolve the workflow per clip (a scene can mix image->video and
video->video extend across its clips).

#64: a 30-second ask could produce a 1:51 script - prompts carried no
per-scene scale and the duration rescale could only grow. Prompts now
state the total seconds and a per-scene budget, and the rescale may shrink
(floor 0.5) so over-written boards pull toward the target; content itself
is never edited.

#67: a hand-written directory path (e.g. ComfyUI's input dir) reached
ComfyUI and died as an opaque Errno 21. prepare_media_inputs now rejects
directory / missing local files before queueing with a node-naming error,
and the agent's run_workflow validates media input_values at call time.
Bare Comfy-side names pass untouched.

534 backend tests pass; svelte-check clean.
This commit is contained in:
Benjiyaya
2026-09-24 02:26:47 +08:00
parent 7551ba9d88
commit d2240b9c5a
12 changed files with 453 additions and 43 deletions
+135 -1
View File
@@ -4,11 +4,34 @@ renumbering."""
from __future__ import annotations
import asyncio
import tempfile
from pathlib import Path
import pytest
import calliope.agent.script_agent as sa
from calliope.agent.script_agent import _generate_scenes_chunked
from calliope.agent.script_agent import _generate_scenes_chunked, generate_script
@pytest.fixture(autouse=True, scope="module")
def _never_touch_real_db():
"""Redirect data_dir before ANY write in this module (repo test rule)."""
import calliope.config as config_module
from calliope.db import migrate_db
prev = {
"data_dir": config_module.settings.data_dir,
"assets_dir": config_module.settings.assets_dir,
"dry_run": config_module.settings.dry_run,
}
with tempfile.TemporaryDirectory() as tmp:
config_module.settings.data_dir = Path(tmp)
config_module.settings.assets_dir = Path(tmp) / "assets"
config_module.settings.dry_run = True
asyncio.run(migrate_db(config_module.settings.db_path))
yield
for k, v in prev.items():
setattr(config_module.settings, k, v)
def _scenes(n: int, start: int = 1):
@@ -166,3 +189,114 @@ def test_continuity_tail_is_passed_to_next_chunk(monkeypatch):
)
# First chunk has no tail; the second continues from the first's scenes.
assert seen_tails == [False, True]
# ─────────────────────────────────────────────────────────────────────────
# Issue #64 — target runtime is a budget, not a floor
# ─────────────────────────────────────────────────────────────────────────
def test_chunk_prompt_carries_per_scene_budget():
from calliope.agent.prompts import build_script_chunk_messages
messages = build_script_chunk_messages(
title="T",
idea="i",
beats=[],
characters=[],
locations=[],
target_duration="30 seconds",
scene_count=5,
chunk_start=1,
chunk_scenes=5,
)
user = messages[1]["content"]
# 30s / 5 scenes = 6s per scene; both the total and the per-scene scale
# must be stated so the model writes content volume to the runtime.
assert "Per-scene budget: ~6 seconds" in user
assert "must play in about 30s" in user
def test_script_prompt_carries_per_scene_budget():
from calliope.agent.prompts import build_script_messages
messages = build_script_messages(
title="T",
idea="i",
beats=[],
characters=[],
locations=[],
target_duration="30 seconds",
scene_count=5,
)
user = messages[1]["content"]
assert "Per-scene budget: ~6 seconds" in user
assert "must play in about 30s" in user
def _mk_project() -> int:
from calliope.db import get_db
from calliope.config import settings
conn = get_db(settings.db_path)
try:
cur = conn.execute(
"INSERT INTO projects (title, idea, target_duration) VALUES ('Budget', 'i', '30 seconds')"
)
conn.commit()
return int(cur.lastrowid)
finally:
conn.close()
def _oversized_scenes(n: int) -> dict:
"""Scenes whose content genuinely runs ~110s total (issue #64 numbers)."""
long_dialog = "\n".join(f"SPEAKER: {'word ' * 40}" for _ in range(4)) # 160w ≈ 64s
long_action = " ".join(["moves carefully forward"] * 40) # 160w ≈ 19s
return {
"scenes": [
{
"order_index": i + 1,
"heading": f"SCENE {i + 1}",
"action": long_action,
"dialog": long_dialog,
"duration_sec": 8,
"character_ids": [],
"location_id": None,
}
for i in range(n)
]
}
def test_oversized_script_durations_shrink_to_target(monkeypatch):
"""Issue #64 regression: a 30s target with ~110s of written content must
rescale scene durations DOWN toward the target (old max(...,1.0) treated
the target as a floor and left the overrun untouched — 1:51 vs 0:30)."""
from calliope.config import settings
from calliope.db import get_db
async def fake_structured(messages, temperature=0.7):
n = 0
for line in messages[1]["content"].splitlines():
if line.startswith("THIS CHUNK:"):
n = int(line.split("exactly", 1)[1].split("scenes")[0].strip())
return _oversized_scenes(n)
monkeypatch.setattr(sa, "generate_structured", fake_structured)
pid = _mk_project()
asyncio.run(generate_script(pid, with_clips=False))
conn = get_db(settings.db_path)
try:
rows = conn.execute(
"SELECT duration_sec FROM scenes WHERE project_id = ? ORDER BY order_index",
(pid,),
).fetchall()
finally:
conn.close()
total = sum(r["duration_sec"] for r in rows)
# 5 scenes × ~83s estimated ≈ 415s → floor 0.5 caps the shrink at ~207s.
# The old code left 415s; the fix must pull meaningfully below it.
assert total <= 220, f"scene durations did not shrink toward the 30s target: {total}s"
assert all(r["duration_sec"] >= 3 for r in rows)