Skip to content

Commit 5bbee73

Browse files
committed
chore(studio): merge the runtime swap-safety branch again
2 parents 50fc025 + b9668c8 commit 5bbee73

45 files changed

Lines changed: 1766 additions & 172 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

‎.github/workflows/regression.yml‎

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ env:
1212
# Graphite can update a branch and its PR base separately for the same head
1313
# SHA. Keep only the newest expensive regression run for each PR/ref.
1414
concurrency:
15-
group: regression-${{ github.event.pull_request.number || github.ref }}
15+
group: regression-${{ github.event.pull_request.number || github.ref }}${{ github.event_name == 'schedule' && '-nightly' || '' }}
1616
# A body or title edit queues behind running checks instead of cancelling them.
1717
cancel-in-progress: ${{ github.event.action != 'edited' || github.event.changes.base != null }}
1818

@@ -31,14 +31,17 @@ on:
3131
push:
3232
branches:
3333
- main
34+
schedule:
35+
# Daily at 06:17 UTC: the full suite, including fixtures too slow for every PR.
36+
- cron: "17 6 * * *"
3437

3538
jobs:
3639
changes:
3740
name: Detect changes
3841
runs-on: ubuntu-latest
3942
timeout-minutes: 2
4043
outputs:
41-
code: ${{ (github.event_name == 'workflow_dispatch' && inputs.catalog_publish) && 'true' || steps.filter.outputs.code }}
44+
code: ${{ (github.event_name == 'schedule' || (github.event_name == 'workflow_dispatch' && inputs.catalog_publish)) && 'true' || steps.filter.outputs.code }}
4245
matrix: ${{ steps.shards.outputs.matrix }}
4346
steps:
4447
# Force git-based change detection instead of the pull_request REST API.
@@ -49,6 +52,7 @@ jobs:
4952
fetch-depth: 0
5053
- uses: dorny/paths-filter@fbd0ab8f3e69293af611ebaee6363fc25e6d187d # v4
5154
id: filter
55+
if: github.event_name != 'schedule'
5256
with:
5357
token: ""
5458
filters: |
@@ -62,9 +66,11 @@ jobs:
6266
# nor explicitly excluded, so a new fixture cannot silently never run.
6367
- name: Plan regression shards
6468
id: shards
69+
env:
70+
NIGHTLY: ${{ github.event_name == 'schedule' && '--nightly' || '' }}
6571
run: |
66-
echo "matrix=$(node packages/producer/scripts/plan-regression-shards.mjs)" >> "$GITHUB_OUTPUT"
67-
node packages/producer/scripts/plan-regression-shards.mjs --pretty
72+
echo "matrix=$(node packages/producer/scripts/plan-regression-shards.mjs $NIGHTLY)" >> "$GITHUB_OUTPUT"
73+
node packages/producer/scripts/plan-regression-shards.mjs $NIGHTLY --pretty
6874
6975
preflight:
7076
name: Preflight (lint + format)
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
import { execFileSync } from "node:child_process";
2+
import { resolve } from "node:path";
3+
4+
// The binaries media-use spawns: HYPERFRAMES_FFMPEG_PATH / HYPERFRAMES_FFPROBE_PATH when set, else PATH.
5+
// A set path that is not a working ffmpeg/ffprobe throws, so a broken override never reads as "no metadata".
6+
const runsByPath = new Map();
7+
8+
export class FfBinarySettingError extends Error {}
9+
10+
function configuredOr(name, envVar) {
11+
const setting = process.env[envVar]?.trim();
12+
if (!setting) return name;
13+
const path = resolve(setting);
14+
if (!runsByPath.has(path)) runsByPath.set(path, isWorking(path, name));
15+
if (!runsByPath.get(path)) {
16+
const why = `${envVar} names "${path}", which is not a working ${name}: fix it or unset it.`;
17+
throw new FfBinarySettingError(why);
18+
}
19+
return path;
20+
}
21+
22+
function isWorking(path, name) {
23+
try {
24+
const out = execFileSync(path, ["-version"], {
25+
encoding: "utf8",
26+
stdio: ["ignore", "pipe", "ignore"],
27+
timeout: 15000,
28+
windowsHide: true,
29+
});
30+
return out.startsWith(`${name} version`);
31+
} catch {
32+
return false;
33+
}
34+
}
35+
36+
export const ffmpegBinary = () => configuredOr("ffmpeg", "HYPERFRAMES_FFMPEG_PATH");
37+
export const ffprobeBinary = () => configuredOr("ffprobe", "HYPERFRAMES_FFPROBE_PATH");

‎packages/cli/src/media-use/lib/probe.mjs‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,19 @@
11
import { execFileSync } from "node:child_process";
22
import { extname } from "node:path";
3+
import { ffprobeBinary } from "./ff-binaries.mjs";
34

45
const IMAGE_EXT = new Set([".jpg", ".jpeg", ".png", ".gif", ".webp", ".svg", ".ico"]);
56

67
export function probe(filePath) {
78
const ext = extname(filePath).toLowerCase();
89
if (ext === ".svg") return { width: null, height: null, duration: null, codec: "svg" };
910

11+
const ffprobe = ffprobeBinary();
1012
try {
1113
// execFileSync (no shell) so a hostile filename like `"; rm -rf ~; ".png`
1214
// can't break out of the quoting — filePath is passed as a literal argv entry.
1315
const raw = execFileSync(
14-
"ffprobe",
16+
ffprobe,
1517
["-v", "quiet", "-print_format", "json", "-show_format", "-show_streams", "--", filePath],
1618
{ encoding: "utf8", timeout: 5000 },
1719
);

‎packages/cli/src/media-use/lib/probe.test.mjs‎

Lines changed: 118 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { test } from "node:test";
22
import assert from "node:assert/strict";
3-
import { mkdtempSync, writeFileSync, existsSync, rmSync } from "node:fs";
3+
import { chmodSync, mkdtempSync, writeFileSync, existsSync, rmSync } from "node:fs";
44
import { join } from "node:path";
55
import { tmpdir } from "node:os";
66
import { probe } from "./probe.mjs";
@@ -29,3 +29,120 @@ test("probe does not execute shell metacharacters in a filename", () => {
2929
rmSync(dir, { recursive: true, force: true });
3030
}
3131
});
32+
33+
test(
34+
"probe runs the ffprobe HYPERFRAMES_FFPROBE_PATH names",
35+
{ skip: process.platform === "win32" },
36+
() => {
37+
const dir = mkdtempSync(join(tmpdir(), "probe-ffprobe-path-"));
38+
const fake = join(dir, "fake-ffprobe");
39+
writeFileSync(
40+
fake,
41+
`#!/bin/sh\n[ "$1" = -version ] && echo 'ffprobe version fake' && exit 0\necho '{"streams":[{"width":7,"height":3,"codec_name":"fake"}]}'\n`,
42+
);
43+
chmodSync(fake, 0o755);
44+
const configured = process.env.HYPERFRAMES_FFPROBE_PATH;
45+
process.env.HYPERFRAMES_FFPROBE_PATH = fake;
46+
try {
47+
assert.deepEqual(probe(join(dir, "clip.png")), {
48+
duration: null,
49+
width: 7,
50+
height: 3,
51+
codec: "fake",
52+
});
53+
} finally {
54+
if (configured === undefined) delete process.env.HYPERFRAMES_FFPROBE_PATH;
55+
else process.env.HYPERFRAMES_FFPROBE_PATH = configured;
56+
rmSync(dir, { recursive: true, force: true });
57+
}
58+
},
59+
);
60+
61+
test("probe refuses an HYPERFRAMES_FFPROBE_PATH that cannot run instead of reporting no metadata", () => {
62+
const configured = process.env.HYPERFRAMES_FFPROBE_PATH;
63+
process.env.HYPERFRAMES_FFPROBE_PATH = join(tmpdir(), "no-ffprobe-here", "ffprobe");
64+
try {
65+
assert.throws(
66+
() => probe("clip.wav"),
67+
/HYPERFRAMES_FFPROBE_PATH names ".*no-ffprobe-here.*fix it or unset it/,
68+
);
69+
} finally {
70+
if (configured === undefined) delete process.env.HYPERFRAMES_FFPROBE_PATH;
71+
else process.env.HYPERFRAMES_FFPROBE_PATH = configured;
72+
}
73+
});
74+
75+
test("probe refuses an HYPERFRAMES_FFPROBE_PATH that names a folder", () => {
76+
const configured = process.env.HYPERFRAMES_FFPROBE_PATH;
77+
process.env.HYPERFRAMES_FFPROBE_PATH = tmpdir();
78+
try {
79+
assert.throws(() => probe("clip.wav"), /HYPERFRAMES_FFPROBE_PATH names .*fix it or unset it/);
80+
} finally {
81+
if (configured === undefined) delete process.env.HYPERFRAMES_FFPROBE_PATH;
82+
else process.env.HYPERFRAMES_FFPROBE_PATH = configured;
83+
}
84+
});
85+
86+
function withFfprobePath(value, run) {
87+
const configured = process.env.HYPERFRAMES_FFPROBE_PATH;
88+
process.env.HYPERFRAMES_FFPROBE_PATH = value;
89+
try {
90+
return run();
91+
} finally {
92+
if (configured === undefined) delete process.env.HYPERFRAMES_FFPROBE_PATH;
93+
else process.env.HYPERFRAMES_FFPROBE_PATH = configured;
94+
}
95+
}
96+
97+
test(
98+
"probe refuses a configured ffprobe that cannot start, exits with an error, or is another tool",
99+
{
100+
skip: process.platform === "win32",
101+
},
102+
() => {
103+
const dir = mkdtempSync(join(tmpdir(), "probe-broken-ffprobe-"));
104+
try {
105+
const noInterpreter = join(dir, "no-interpreter");
106+
writeFileSync(noInterpreter, "#!/nonexistent/interpreter\n");
107+
const failing = join(dir, "failing");
108+
writeFileSync(failing, "#!/bin/sh\nexit 3\n");
109+
const otherTool = join(dir, "other-tool");
110+
writeFileSync(otherTool, "#!/bin/sh\necho 'ffmpeg version 9.9'\n");
111+
for (const broken of [noInterpreter, failing, otherTool]) {
112+
chmodSync(broken, 0o755);
113+
withFfprobePath(broken, () =>
114+
assert.throws(
115+
() => probe("clip.wav"),
116+
/HYPERFRAMES_FFPROBE_PATH names .*fix it or unset it/,
117+
),
118+
);
119+
}
120+
} finally {
121+
rmSync(dir, { recursive: true, force: true });
122+
}
123+
},
124+
);
125+
126+
test(
127+
"probe runs a relative HYPERFRAMES_FFPROBE_PATH from the working folder, not from PATH",
128+
{
129+
skip: process.platform === "win32",
130+
},
131+
() => {
132+
const dir = mkdtempSync(join(tmpdir(), "probe-relative-ffprobe-"));
133+
const prevCwd = process.cwd();
134+
try {
135+
writeFileSync(
136+
join(dir, "local-ffprobe"),
137+
`#!/bin/sh\n[ "$1" = -version ] && echo 'ffprobe version fake' && exit 0\necho '{"streams":[{"width":5,"height":4,"codec_name":"local"}]}'\n`,
138+
);
139+
chmodSync(join(dir, "local-ffprobe"), 0o755);
140+
process.chdir(dir);
141+
const meta = withFfprobePath("local-ffprobe", () => probe("clip.png"));
142+
assert.deepEqual(meta, { duration: null, width: 5, height: 4, codec: "local" });
143+
} finally {
144+
process.chdir(prevCwd);
145+
rmSync(dir, { recursive: true, force: true });
146+
}
147+
},
148+
);

‎packages/cli/src/media-use/lib/tts-local-provider.mjs‎

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import { execFileSync } from "node:child_process";
22
import { existsSync, statSync } from "node:fs";
33
import { tmpdir } from "node:os";
44
import { join } from "node:path";
5+
import { ffprobeBinary } from "./ff-binaries.mjs";
56
import { resolveSpawnCommand } from "../../audio/scripts/lib/tts.mjs";
67

78
// Local voiceover via the packaged Kokoro-82M TTS (the `hyperframes tts` CLI),
@@ -13,10 +14,10 @@ import { resolveSpawnCommand } from "../../audio/scripts/lib/tts.mjs";
1314
// Delegated to the hyperframes CLI (same as transcribe / remove-background), not
1415
// re-implemented here. ffprobe reads the duration back for the ledger.
1516

16-
function probeDurationSeconds(file) {
17+
function probeDurationSeconds(ffprobe, file) {
1718
try {
1819
const out = execFileSync(
19-
"ffprobe",
20+
ffprobe,
2021
["-v", "error", "-show_entries", "format=duration", "-of", "csv=p=0", "--", file],
2122
{ encoding: "utf8", timeout: 15000 },
2223
);
@@ -39,6 +40,7 @@ export async function localTtsGenerate(
3940
env = process.env,
4041
pathExists = existsSync,
4142
) {
43+
const ffprobe = ffprobeBinary();
4244
const outPath = join(tmpdir(), `media-use-kokoro-${process.pid}-${Date.now()}.wav`);
4345
const argv = ["hyperframes", "tts", intent, "--output", outPath];
4446
if (ctx?.voice) argv.push("--voice", ctx.voice);
@@ -85,7 +87,7 @@ export async function localTtsGenerate(
8587
metadata: {
8688
description: intent,
8789
provider: "kokoro.local",
88-
duration: probeDurationSeconds(outPath),
90+
duration: probeDurationSeconds(ffprobe, outPath),
8991
provenance: { engine: "kokoro-82m", prompt: intent },
9092
},
9193
};

‎packages/cli/src/media-use/resolve.mjs‎

Lines changed: 45 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ import { heygenAuthMethod } from "../audio/scripts/lib/heygen.mjs";
3333
import { buildCube, paramsFromIntent } from "./lib/cube-build.mjs";
3434
import { validateCubeFile } from "./lib/cube-validate.mjs";
3535
import { analyzeMediaGrade, formatMeasuredNote } from "./lib/grade-analyzer.mjs";
36+
import { FfBinarySettingError, ffmpegBinary, ffprobeBinary } from "./lib/ff-binaries.mjs";
3637
import {
3738
freezeLibraryLut,
3839
isLibraryLutOfflineMiss,
@@ -144,7 +145,12 @@ const entity = args.entity || null;
144145

145146
if (args.adopt) {
146147
const { adoptExistingAssets } = await import("./lib/adopt.mjs");
147-
const adopted = adoptExistingAssets(projectDir);
148+
let adopted;
149+
try {
150+
adopted = adoptExistingAssets(projectDir);
151+
} catch (err) {
152+
exitError(err.message);
153+
}
148154
if (args.json) {
149155
console.log(JSON.stringify({ ok: true, adopted: adopted.length, assets: adopted }));
150156
} else if (adopted.length === 0) {
@@ -218,7 +224,15 @@ if (args.analyze) {
218224
console.error(`error: --for file not found: ${mediaPath}`);
219225
process.exit(2);
220226
}
221-
const analysis = analyzeMediaGrade(mediaPath);
227+
let analysis;
228+
try {
229+
analysis = analyzeMediaGrade(mediaPath, {
230+
ffmpegPath: ffmpegBinary(),
231+
ffprobePath: ffprobeBinary(),
232+
});
233+
} catch (err) {
234+
exitError(err.message);
235+
}
222236
if (args.json) {
223237
console.log(JSON.stringify({ ok: true, type: "grade-analysis", ...analysis }));
224238
} else {
@@ -503,7 +517,8 @@ async function run() {
503517
// brand stays local: no frame.md/design.md -> upsell the HyperFrames design
504518
// flow rather than reporting a generic miss (B5).
505519
const msg =
506-
providerFailure instanceof BundledSfxAssetsError
520+
providerFailure instanceof BundledSfxAssetsError ||
521+
providerFailure instanceof FfBinarySettingError
507522
? providerFailure.message
508523
: type === "brand"
509524
? "no brand spec found — add a frame.md or design.md (colors/font/logo) to this project. Run the HyperFrames design flow to create one; brand tokens are read locally for deterministic rendering."
@@ -594,7 +609,10 @@ function mergeSmartAdjust(block) {
594609
const mediaPath = resolve(args.for);
595610
// Clear upfront error beats an ffmpeg "No such file" stack on a typo'd path.
596611
if (!existsSync(mediaPath)) throw new Error(`--for file not found: ${mediaPath}`);
597-
const analysis = analyzeMediaGrade(mediaPath);
612+
const analysis = analyzeMediaGrade(mediaPath, {
613+
ffmpegPath: ffmpegBinary(),
614+
ffprobePath: ffprobeBinary(),
615+
});
598616
console.error(formatMeasuredNote(mediaPath, analysis.measured));
599617
return {
600618
...block,
@@ -1060,21 +1078,7 @@ function runDoctor() {
10601078
checks.push(heygenAuthCheck());
10611079
}
10621080

1063-
const ffmpegProbe = runCommand("ffmpeg", ["-version"]);
1064-
checks.push({
1065-
name: "ffmpeg on PATH",
1066-
ok: ffmpegProbe.status === 0,
1067-
detail: ffmpegProbe.status === 0 ? firstLine(ffmpegProbe.stdout) : "ffmpeg not found",
1068-
fix: ffmpegProbe.status === 0 ? "" : "brew install ffmpeg",
1069-
});
1070-
1071-
const ffprobeProbe = runCommand("ffprobe", ["-version"]);
1072-
checks.push({
1073-
name: "ffprobe on PATH",
1074-
ok: ffprobeProbe.status === 0,
1075-
detail: ffprobeProbe.status === 0 ? firstLine(ffprobeProbe.stdout) : "ffprobe not found",
1076-
fix: ffprobeProbe.status === 0 ? "" : "brew install ffmpeg",
1077-
});
1081+
checks.push(ffDoctorCheck("ffmpeg", ffmpegBinary), ffDoctorCheck("ffprobe", ffprobeBinary));
10781082

10791083
const nodeOk = !versionLessThan(process.versions.node, MIN_NODE_VERSION);
10801084
checks.push({
@@ -1140,6 +1144,28 @@ function printMap(label, values) {
11401144
for (const [key, value] of entries) console.log(` ${key}: ${value}`);
11411145
}
11421146

1147+
function ffDoctorCheck(name, binary) {
1148+
let bin;
1149+
try {
1150+
bin = binary();
1151+
} catch (err) {
1152+
return {
1153+
name: `${name} on PATH`,
1154+
ok: false,
1155+
detail: err.message,
1156+
fix: "fix or unset that variable",
1157+
};
1158+
}
1159+
const probe = runCommand(bin, ["-version"]);
1160+
const ok = probe.status === 0;
1161+
return {
1162+
name: `${name} on PATH`,
1163+
ok,
1164+
detail: ok ? firstLine(probe.stdout) : `${name} not found`,
1165+
fix: ok ? "" : "brew install ffmpeg",
1166+
};
1167+
}
1168+
11431169
function runCommand(bin, argv) {
11441170
return spawnSync(bin, argv, {
11451171
encoding: "utf8",

0 commit comments

Comments
 (0)