Skip to content

AI video skill for Claude Code & Codex — cinematic, editable product promos with Remotion: 124 shot recipe cards, 150 motion previews, beat sync, sound design, Motion Workbench & JianYing (CapCut CN) export.

fix: complete contact-sheet and Windows follow-ups (#120)

Yihaoc81ec7418635
diff --git a/.github/workflows/contact-sheet-tests.yml b/.github/workflows/contact-sheet-tests.yml
new file mode 100644
index 0000000..dcdf533
--- /dev/null
+++ b/.github/workflows/contact-sheet-tests.yml
@@ -0,0 +1,35 @@
+name: Contact sheet tests
+
+on:
+ pull_request:
+ branches: [main]
+ paths:
+ - 'shot-polish/**'
+ - '.github/workflows/contact-sheet-tests.yml'
+ push:
+ branches: [main]
+ paths:
+ - 'shot-polish/**'
+ - '.github/workflows/contact-sheet-tests.yml'
+
+permissions:
+ contents: read
+
+jobs:
+ contact-sheet:
+ strategy:
+ fail-fast: false
+ matrix:
+ os: [ubuntu-22.04, ubuntu-24.04]
+ runs-on: ${{ matrix.os }}
+ timeout-minutes: 10
+ steps:
+ - uses: actions/checkout@v4
+ - name: Install FFmpeg
+ run: sudo apt-get update && sudo apt-get install -y --no-install-recommends ffmpeg
+ - name: Verify sampled frames and contact sheet pixels
+ run: |
+ # Test distro FFmpeg, including Ubuntu 22.04's FFmpeg 4.4.
+ export PATH="/usr/bin:$PATH"
+ ffmpeg -version
+ python3 -m unittest discover -s shot-polish -p test_sheet.py -v
diff --git a/.github/workflows/pr-checks.yml b/.github/workflows/pr-checks.yml
index f77fbc0..245547b 100644
--- a/.github/workflows/pr-checks.yml
+++ b/.github/workflows/pr-checks.yml
@@ -154,6 +154,8 @@ jobs:
cd template && ../workbench/node_modules/.bin/tsc --noEmit -p tsconfig.json
- name: Theme and palette regressions
run: npm --prefix workbench run test:themes
+ - name: Export errors and Python interpreter regressions
+ run: npm --prefix workbench run test:platform
- name: Retired demos remain compatible with saved projects
run: npm --prefix workbench run test:legacy
diff --git a/shot-polish/sheet.py b/shot-polish/sheet.py
index 50cce5d..ca727f9 100644
--- a/shot-polish/sheet.py
+++ b/shot-polish/sheet.py
@@ -8,6 +8,7 @@ tot = int(subprocess.check_output(['ffprobe', '-v', 'error', '-count_frames', '-
n = min(n, tot)
picks = [(2 * k + 1) * tot // (2 * n) for k in range(n)]
sel = '+'.join(f'eq(n\\,{p})' for p in picks)
+# A single output image needs no video sync mode (the flags vary by FFmpeg version).
subprocess.check_call(['ffmpeg', '-v', 'error', '-y', '-i', src, '-vf',
- f"select='{sel}',scale=480:-1,tile=4x{(n + 3) // 4}", '-frames:v', '1', '-vsync', '0', dst])
+ f"select='{sel}',scale=480:-1,tile=4x{(n + 3) // 4}", '-frames:v', '1', dst])
print(f'{tot} frames; sheet frames {",".join(map(str, picks))}')
diff --git a/workbench/package.json b/workbench/package.json
index 04c4359..a9a22ff 100644
--- a/workbench/package.json
+++ b/workbench/package.json
@@ -4,6 +4,7 @@
"version": "0.1.0",
"type": "module",
"scripts": {
+ "test:platform": "node --test scripts/test-platform.mjs",
"test:themes": "node scripts/test-themes.mjs",
"test:legacy": "node scripts/gen-index.mjs && node scripts/test-legacy.mjs",
"gen": "node scripts/gen-index.mjs",
diff --git a/workbench/scripts/parity.mjs b/workbench/scripts/parity.mjs
index 9e9d61f..3d605e4 100644
--- a/workbench/scripts/parity.mjs
+++ b/workbench/scripts/parity.mjs
@@ -5,7 +5,7 @@
//
// 渲染 ProjImported(清单刚导入、未改动的工作台工程)与 ProjOriginal(成片工程自己的 Main)
// 同一帧的 PNG 到 .parity/,用 PIL 逐像素比对(每通道差 > tolerance 的像素占比)。
-// 前置:已 `node scripts/open.mjs <工程>` 链接成片,清单提供了 `original`,本机有 python3 + Pillow。
+// 前置:已 `node scripts/open.mjs <工程>` 链接成片,清单提供了 `original`,本机有 python/python3 + Pillow。
// 打包一次、渲多帧(remotion still 每次都重新打包,8 帧要跑八次 bundle)。
// 退出码:0 全部一致;1 有帧存在差异;2 无法得出结论(前置缺失 / 比对未执行)——绝不假绿。
import { bundle } from "@remotion/bundler";
@@ -26,13 +26,11 @@ if (!existsSync(join(wb, "proj", "workbench.ts"))) {
process.exit(2);
}
// 比对依赖先检查,别渲完一堆帧才发现比不了(Windows 上通常是 python 而非 python3)
-{
- const py = process.platform === "win32" ? ["python", "python3"] : ["python3", "python"];
- const ok = py.some((c) => spawnSync(c, ["-c", "import PIL"], { encoding: "utf8" }).status === 0);
- if (!ok) {
- console.error("parity 需要 python + Pillow 做像素比对:pip install pillow");
- process.exit(2);
- }
+const pythonCommands = process.platform === "win32" ? ["python", "python3"] : ["python3", "python"];
+const python = pythonCommands.find((c) => spawnSync(c, ["-c", "import PIL"], { encoding: "utf8" }).status === 0);
+if (!python) {
+ console.error("parity 需要 python + Pillow 做像素比对:pip install pillow");
+ process.exit(2);
}
// Remotion 静态服务器拒绝符号链接:同导出流程,先解引用同步到 .render-public
@@ -89,7 +87,7 @@ print(bad, a.size[0] * a.size[1], max(max(p) for p in px))
const results = []; // { f, verdict: "same" | "diff" | "inconclusive", detail }
for (const f of FRAMES) {
const [a, b] = await Promise.all([render("ProjImported", f), render("ProjOriginal", f)]);
- const py = spawnSync("python3", ["-c", PY_DIFF, a, b, String(TOL)], { encoding: "utf8" });
+ const py = spawnSync(python, ["-c", PY_DIFF, a, b, String(TOL)], { encoding: "utf8" });
if (py.status !== 0) {
const detail = (py.stdout + py.stderr).trim().split("\n").pop() ?? "";
results.push({ f, verdict: "inconclusive", detail });
diff --git a/workbench/scripts/test-platform.mjs b/workbench/scripts/test-platform.mjs
new file mode 100644
index 0000000..83299d7
--- /dev/null
+++ b/workbench/scripts/test-platform.mjs
@@ -0,0 +1,135 @@
+import assert from "node:assert/strict";
+import { EventEmitter } from "node:events";
+import fs from "node:fs";
+import { createRequire } from "node:module";
+import os from "node:os";
+import path from "node:path";
+import test from "node:test";
+import { fileURLToPath, pathToFileURL } from "node:url";
+import ts from "typescript";
+
+const wb = path.resolve(path.dirname(fileURLToPath(import.meta.url)), "..");
+const require = createRequire(import.meta.url);
+const AsyncFunction = Object.getPrototypeOf(async function () {}).constructor;
+
+// Execute the actual CLI/plugin with the project's compiler. Only expensive
+// rendering/process launches and Vite registration are stubbed; file operations
+// use isolated real directories so cleanup and failed asset copies are exercised.
+function compile(file, fixture) {
+ const source = fs.readFileSync(path.join(wb, file), "utf8")
+ .replace(/^#![^\n]*\n/, "")
+ .replaceAll("import.meta.url", JSON.stringify(pathToFileURL(path.join(fixture, file)).href));
+ return ts.transpileModule(source, {
+ compilerOptions: { module: ts.ModuleKind.CommonJS, target: ts.ScriptTarget.ES2022, esModuleInterop: true },
+ }).outputText;
+}
+
+function fixture(t) {
+ const dir = fs.mkdtempSync(path.join(os.tmpdir(), "shotcraft-platform-"));
+ t.after(() => fs.rmSync(dir, { recursive: true, force: true }));
+ fs.mkdirSync(path.join(dir, "public"));
+ fs.mkdirSync(path.join(dir, "proj"));
+ fs.writeFileSync(path.join(dir, "proj/workbench.ts"), "export const WORKBENCH = {};");
+ return dir;
+}
+
+test("failed asset copy ends the export response, cleans props and permits a retry", t => {
+ const dir = fixture(t);
+ const broken = path.join(dir, "public/broken.png");
+ fs.symlinkSync(path.join(dir, "missing.png"), broken);
+ let launches = 0;
+ const mocks = {
+ vite: { defineConfig: config => config },
+ "@vitejs/plugin-react": () => ({}),
+ "node:child_process": { spawn: () => {
+ launches++;
+ const child = new EventEmitter();
+ child.stdout = new EventEmitter();
+ child.stderr = new EventEmitter();
+ return child;
+ } },
+ };
+ const mod = { exports: {} };
+ new Function("require", "module", "exports", compile("vite.config.ts", dir))(
+ id => Object.hasOwn(mocks, id) ? mocks[id] : require(id), mod, mod.exports,
+ );
+ let middleware;
+ const plugin = mod.exports.default.plugins.find(p => p.name === "wb-render-export");
+ plugin.configureServer({ middlewares: { use: (route, handler) => {
+ assert.equal(route, "/api/export");
+ middleware = handler;
+ } } });
+ const request = () => {
+ const req = Object.assign(new EventEmitter(), { method: "POST", url: "/" });
+ const res = { ends: 0, headers: {}, setHeader(k, v) { this.headers[k] = v; },
+ end(body) { this.ends++; this.body = JSON.parse(body); } };
+ middleware(req, res);
+ req.emit("data", JSON.stringify({ project: { name: "Retry export" } }));
+ req.emit("end");
+ return res;
+ };
+ const failed = request();
+ assert.equal(failed.ends, 1, "the failed POST must finish instead of hanging");
+ assert.equal(failed.statusCode, 500);
+ assert.equal(failed.headers["Content-Type"], "application/json");
+ assert.match(failed.body.error, /素材同步失败/);
+ assert.equal(launches, 0);
+ assert.deepEqual(fs.readdirSync(path.join(dir, "exports")), []);
+
+ fs.unlinkSync(broken);
+ fs.writeFileSync(path.join(dir, "public/asset.txt"), "valid asset");
+ const retry = request();
+ assert.equal(retry.ends, 1);
+ assert.equal(retry.statusCode, 200);
+ assert.match(retry.body.id, /^[a-z0-9]+$/);
+ assert.equal(launches, 1);
+});
+
+for (const [platform, available] of [["win32", "python"], ["win32", "python3"], ["linux", "python"]]) {
+ test(`parity reuses ${available} for every comparison on ${platform}`, async t => {
+ const result = await runParity(t, platform, available);
+ assert.equal(result.exitCode, 0);
+ assert.equal(result.renders, 4);
+ assert.equal(result.comparisons.length, 2);
+ assert.ok(result.comparisons.every(call => call.command === available));
+ });
+}
+
+test("parity exits before rendering if neither interpreter has Pillow", async t => {
+ const result = await runParity(t, "win32", null);
+ assert.equal(result.exitCode, 2);
+ assert.equal(result.bundles, 0);
+ assert.equal(result.renders, 0);
+ assert.equal(result.comparisons.length, 0);
+});
+
+async function runParity(t, platform, available) {
+ const dir = fixture(t);
+ const result = { exitCode: 0, bundles: 0, renders: 0, comparisons: [] };
+ class Exit extends Error { constructor(code) { super(); this.code = code; } }
+ const mocks = {
+ "@remotion/bundler": { bundle: async () => { result.bundles++; return "fixture"; } },
+ "@remotion/renderer": {
+ selectComposition: async ({ id }) => ({ id }),
+ renderStill: async () => { result.renders++; },
+ },
+ "node:child_process": { spawnSync: (command, args) => {
+ const probe = args[1] === "import PIL";
+ if (!probe) result.comparisons.push({ command, args });
+ if (command !== available) return { status: 1, stdout: "", stderr: "unavailable" };
+ return { status: 0, stdout: probe ? "" : "0 100 0\n", stderr: "" };
+ } },
+ };
+ const mod = { exports: {} };
+ try {
+ await new AsyncFunction("require", "module", "exports", "process", "console", compile("scripts/parity.mjs", dir))(
+ id => Object.hasOwn(mocks, id) ? mocks[id] : require(id), mod, mod.exports,
+ { platform, argv: ["node", "parity.mjs", "--frames", "1,2"], exit: code => { throw new Exit(code); } },
+ { log() {}, error() {} },
+ );
+ } catch (error) {
+ if (!(error instanceof Exit)) throw error;
+ result.exitCode = error.code;
+ }
+ return result;
+}
diff --git a/workbench/vite.config.ts b/workbench/vite.config.ts
index 61c655a..181033c 100644
--- a/workbench/vite.config.ts
+++ b/workbench/vite.config.ts
@@ -117,6 +117,7 @@ const renderExportPlugin = (): Plugin => {
dropProps();
job.status = "error";
job.lastLine = `素材同步失败(无法解引用 public/):${syncErr}`;
+ send(500, { error: job.lastLine });
return;
}
{