Skip to content

Local video editor for coding agents: 42 FFmpeg tools with a machine-readable contract and an MCP server, for Claude Code, Cursor and Codex. Cut, captions, reframe, loudness, platform exports. No cloud, no API keys.

render.py: exit non-zero when the check stage fails (#32)

Shogo Kajiyama6ba24a2870f5
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 4a4d3d8..1d42031 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -4,6 +4,7 @@
## Unreleased — FFmpeg 8+ / Windows compatibility for caption and color
+- **`render.py`'s check stage now sets the exit code.** A `project.json` with a `"check"` stage always returned 0, even when the delivery-spec check failed or `check.py` itself couldn't run — `render.py` was the one tool in the skill that could report a broken deliverable as a success. It now exits 1 in both cases, matching `check.py`'s own exit code exactly; `--json`'s `check` field still carries the full row-by-row result either way, and the output file is still written (this changes the exit code, not what gets rendered).
- **Test: docstring examples can't drift from the parser.** `scenes.py`'s docstring once claimed a ranking option (motion) that was never implemented; that was prose, not an example, so nothing caught it. A new `test_contract.py` test at least closes the more common version of this gap: every `--flag` used in a script's own `Examples:` lines must exist in that script's real argparse parser, checked via the contract's `input_schema`. Verified to catch a deliberately introduced typo before writing this entry. Does not (and cannot) catch a false claim made only in prose.
- **SKILL.md: explicit language-matching instruction.** The agent has always been graded on replying in the user's language (see the 24-prompt eval), but SKILL.md never actually said to — it worked by the model's own default, not by instruction. The Report format section now says explicitly: reply in whatever language the request was written in (Japanese, English, Chinese, or any other), keep only the field labels (`Done:`, `Steps:`, ...) in English, and follow a language switch mid-conversation. No code change; this only affects the model-facing instructions.
- **`multicam.py` low-confidence warning.** `sync.py` warns on stderr when its cross-correlation confidence is below 0.1 ("check that both files contain the same audio event"); `multicam.py` used the same measurement per camera but never warned, even though it applies the offset to a rendered cut rather than just reporting it. It now warns per camera below the same threshold. SKILL.md's existing "check `confidence` before trusting a sync" guidance now names `multicam.py`'s per-camera confidence explicitly.
diff --git a/scripts/render.py b/scripts/render.py
index dc5c172..07fc5ce 100755
--- a/scripts/render.py
+++ b/scripts/render.py
@@ -36,6 +36,12 @@ graphics → overlays → audio → loudness → export → check. Missing stage
skipped. "brand" points caption/graphics/overlay at a brand.json (fonts,
colours, logo, safe margin); {"logo": true} in overlays places the brand logo.
+"check" mirrors check.py's own exit code: a delivery-spec FAIL (or check.py
+itself failing to run) exits 1, same as running check.py directly would --
+the render is not silently reported as successful just because every stage
+up to it completed. The output file is still written and `--json`'s
+`check` field still carries the full row-by-row result either way.
+
Examples:
python3 render.py --init project.json # write a commented starter project
python3 render.py project.json # render
@@ -338,14 +344,19 @@ def main() -> int:
# ---- check
ck = proj.get("check")
check_result = None
+ exit_code = 0
if ck and ck.get("platform") and not STATE["dry_run"]:
proc = subprocess.run([sys.executable, str(HERE / "check.py"), output, "--platform", ck["platform"], "--json"], stdout=subprocess.PIPE, stderr=subprocess.PIPE, text=True)
try:
check_result = json.loads(proc.stdout)
except ValueError:
check_result = {"error": proc.stderr.strip()[-300:]}
- if check_result.get("failed"):
+ if check_result.get("error"):
+ info(f"check: could not run check.py — {check_result['error']}")
+ exit_code = 1
+ elif check_result.get("failed"):
info(f"check: {check_result['failed']} FAIL — " + "; ".join(f"{r['check']}={r['value']} ({r['fix']})" for r in check_result["checks"] if r["status"] == "FAIL"))
+ exit_code = 1
else:
info(f"check: OK for {ck['platform']}")
stages_done.append("check")
@@ -355,7 +366,7 @@ def main() -> int:
shutil.rmtree(work, ignore_errors=True)
info(f"rendered {output} via {' → '.join(stages_done)}")
emit(output, stages=stages_done, check=check_result)
- return 0
+ return exit_code
if __name__ == "__main__":
diff --git a/tests/test_all.py b/tests/test_all.py
index 0caf6d8..f9f496c 100644
--- a/tests/test_all.py
+++ b/tests/test_all.py
@@ -768,6 +768,20 @@ class FFmpegSkillTests(unittest.TestCase):
self.assertEqual(out["stages"], ["clips", "join"])
self.assertTrue(Path(out["output"]).exists())
+ def test_render_exits_nonzero_when_the_check_stage_fails(self):
+ """A render whose deliverable fails its own check stage must not report success."""
+ proj = OUT / "project_bad_check.json"
+ proj.write_text(json.dumps({
+ "output": "render_bad.mp4",
+ "clips": [{"src": "source.mp4", "in": "0:01", "out": "0:04"}],
+ "export": {"preset": "reels"}, # portrait 9:16 output
+ "check": {"platform": "broadcast"}, # broadcast requires 16:9 -- guaranteed aspect FAIL
+ }), encoding="utf-8")
+ proc = script("render.py", proj, "--fast", "--json", expect_fail=True)
+ data = json.loads(proc.stdout)
+ self.assertGreater(data["check"]["failed"], 0, data["check"])
+ self.assertTrue(Path(data["output"]).exists(), "the deliverable is still written even though it fails delivery spec")
+
def test_join_width_keeps_aspect(self):
out = OUT / "join_w.mp4"
script("join.py", self.src, self.src, "--transition", "none", "--width", "640", "--fast", "-o", out)
diff --git a/tests/test_contract.py b/tests/test_contract.py
index f94b6a2..ee7893a 100644
--- a/tests/test_contract.py
+++ b/tests/test_contract.py
@@ -574,9 +574,11 @@ class ContractTests(unittest.TestCase):
self.assertTrue(Path(look["output"]).exists())
project = self.out("project.json")
project.write_text(json.dumps({"output": str(self.out("render.mp4")), "frame": {"aspect": "9:16", "width": 360, "fps": 30},
- "clips": [{"src": str(self.src), "in": 0, "out": 3}], "export": {"preset": "reels"}, "check": {"platform": "reels"}}), encoding="utf-8")
+ "clips": [{"src": str(self.src), "in": 0, "out": 3}], "loudness": {"lufs": -14, "tp": -1},
+ "export": {"preset": "reels"}, "check": {"platform": "reels"}}), encoding="utf-8")
doc = self._run_structured("render", {"project": str(project), "fast": True})
self.assertEqual(doc["status"], "completed")
+ self.assertEqual(doc["check"]["failed"], 0, doc["check"])
self._verify("render", doc["output"])
def test_mcp_tool_call_round_trip(self):