|
1 | 1 | import assert from "node:assert/strict"; |
| 2 | +import { execFileSync } from "node:child_process"; |
2 | 3 | import { mkdirSync, mkdtempSync, readdirSync, readFileSync, rmSync, writeFileSync } from "node:fs"; |
3 | 4 | import { tmpdir } from "node:os"; |
4 | 5 | import { join } from "node:path"; |
@@ -217,3 +218,43 @@ test("every build-frame.mjs copy stages the style axis it promises", () => { |
217 | 218 | ); |
218 | 219 | } |
219 | 220 | }); |
| 221 | + |
| 222 | +for (const workflow of ["pr-to-video", "faceless-explainer", "product-launch-video"]) { |
| 223 | + for (const skin of [null, skins[0]]) { |
| 224 | + test(`${workflow} ${skin ? "skin" : "default"} keeps transcript markup inside script data`, () => { |
| 225 | + const project = mkdtempSync(join(tmpdir(), "caption-script-data-")); |
| 226 | + const text = '</ScRiPt><img src=x onerror="alert(1)"><!-- <script> & end'; |
| 227 | + try { |
| 228 | + writeFileSync( |
| 229 | + join(project, "STORYBOARD.md"), |
| 230 | + "---\nformat: 1920x1080\nmessage: T\n---\n\n## Frame 1 — A\n- duration: 3s\n- src: compositions/frames/01-a.html\n", |
| 231 | + ); |
| 232 | + writeFileSync( |
| 233 | + join(project, "audio_meta.json"), |
| 234 | + JSON.stringify({ |
| 235 | + voices: [{ frame: 1, words: [{ text, start: 0, end: 1 }] }], |
| 236 | + }), |
| 237 | + ); |
| 238 | + if (skin) writeFileSync(join(project, "caption-skin.html"), skin.source); |
| 239 | + const script = fileURLToPath( |
| 240 | + new URL(`../../${workflow}/scripts/captions.mjs`, import.meta.url), |
| 241 | + ); |
| 242 | + execFileSync(process.execPath, [script, "build", "--hyperframes", project]); |
| 243 | + const html = readFileSync(join(project, "compositions/captions.html"), "utf8"); |
| 244 | + const start = html.indexOf("var GROUPS ="); |
| 245 | + assert.ok(start >= 0, "generated caption data exists"); |
| 246 | + const end = html.toLowerCase().indexOf("</script", start); |
| 247 | + assert.ok(end > start, "generated script has a closing tag"); |
| 248 | + const inline = html.slice(start, end); |
| 249 | + assert.ok(!html.includes("<img"), "transcript cannot create an HTML element"); |
| 250 | + const data = inline.match(/var GROUPS = (.*);/); |
| 251 | + assert.ok(data, "entire data assignment remains inside the script element"); |
| 252 | + const groups = JSON.parse(data[1]); |
| 253 | + assert.equal(groups[0].text, text); |
| 254 | + assert.equal(groups[0].words[0].text, text); |
| 255 | + } finally { |
| 256 | + rmSync(project, { recursive: true, force: true }); |
| 257 | + } |
| 258 | + }); |
| 259 | + } |
| 260 | +} |
0 commit comments