Repository navigation
fix(cli): escape audio and media-use output, pin model files - #8013
Conversation
…iles as visible escapes hyperframes audio, audio --read and media-use resolve (including --candidates) printed file names, element ids, transcript words, model descriptions and media manifest fields as they were. They now pass through terminalText, so a control character shows as a visible \xNN escape. The media-use engine runs without the CLI's packages, so it carries a small copy of the helper. --json output is unchanged.
…efixed entries ffmpeg reads an HLS or ffconcat entry with a colon before its first separator as a URL or a drive, and opens it apart from the list's folder. The folder check read entries such as C:Videos\a.mp4 or c:x.mp4 as names inside the folder and approved them. It now refuses any entry, raw or percent-decoded, whose colon comes before its first /, \, ? or #, as it already refuses absolute and parent-folder paths. http and https segments are still kept.
… a sha256 The u2net_human_seg weights and the Kokoro model and voices files were downloaded from release URLs and used whatever bytes arrived, and any cached copy was trusted because it existed. Each file now has a pinned size and sha256. A cached copy is checked before it is loaded and downloaded again when it does not match. A download that does not match is discarded with a message that names the file.
ffmpeg resolves a list's entries against its path cut at the first ? or #. A list at proj/h#z/list.m3u8 naming ../h#z/x.ts was judged against proj/h#z and approved, while ffmpeg opened proj/../h#z/x.ts. Entries are now judged against the same cut folder. A list in a folder such as "Take #2" still passes when its entries resolve inside that folder.
…he download lock ensurePinnedFile removed a cached copy that failed its check before the download lock was taken, so a concurrent run could delete a file another run had just published. downloadFile now takes a keepExisting check and runs it under the lock: a copy that passes is kept, one that fails is removed and downloaded again. The mismatch error now says the file does not match its expected checksum, and that a retry helps only if the download was interrupted or corrupted.
…es recipe and stats output The audio formatters escaped their output line by line, so a newline inside a src, warning or transcript still printed as a real line break. Each output line is now escaped whole with terminalText, which shows a newline inside a field as \x0a. media-use resolve also escapes its recipe lines and its --stats lines, which print recipe names, paths and missed intents.
miguel-heygen
left a comment
There was a problem hiding this comment.
Approving at 4af2604. I found no blockers. I checked the three changes against their siblings:
- Playlist check.
ffmpegListFoldercuts the same absolute path thatlistLeavesresolves, and that is the path the frame extractor hands to-i, so the check and ffmpeg judge the same base. The singleCOLON_BEFORE_SEPARATORtest covers what the old scheme and drive patterns missed (C:Videos\a.mp4, one-letter schemes) and keepsparts/take:2.ts. TheTake #2/cases in the tests match the base cut ffmpeg makes. - Pins. Every
downloadFilecaller that fetches a model is now pinned: background removal, the Kokoro model and voices throughensurePinnedFile, whisper through its existingverify, and the registry embedding model through its own size and sha256 check inlocalModel.ts. WithoutkeepExisting,keepsDestreturnswaited, so other callers behave exactly as before. A copy is removed only after it fails its pin, so a good file another run is reading is never deleted. - Escaping. The remaining unescaped prints in
resolve.mjsshow the person's own arguments (--for,--from,--type), JSON-encoded values, or doctor output from tools on their machine. None of them print project or cache fields.
Non-blocking, take or leave:
utils/download.ts:keepsDestwas inserted betweendownloadFileand its doc comment, so the comment about resuming from the partial file now documentskeepsDest. Moving the helper above that comment puts it back ondownloadFile.keepExistingcould also get a one-line doc likeverifyhas.media-use/lib/terminal-text.mjsis a copy of core'sterminalText. Its logic matches today, but nothing keeps the two in step. A small test in the CLI package that compares both over code points 0x00 to 0xA0 would fail the day one of them changes.- A project inside a parent folder whose name has
#or?now gets its HLS lists refused as leaving their folder. That matches what ffmpeg opens, but the person sees a normal project. If the refusal message named the#or?in the path, the cause would be obvious. - Later, not here:
registry/localModel.tskeeps its own download-then-check-then-unlink path. Moving it ontoensurePinnedFilewould give the pin check a single owner.
jrusso1020
left a comment
There was a problem hiding this comment.
Requesting changes at 4af26042. Both blockers have small fixes.
1. media-use error messages still print raw control characters from project files. This is the same class as #8008. The PR escapes the success line (resolved recipe …) but not the failure path.
- When a recipe isn't found,
useRecipethrowsno recipe named "<slug>" (known: <names>)(lib/recipe-store.mjs:341). The names come from.media/recipes/*/recipe.jsonin the project. - That message reaches
exitError(resolve.mjs:294), which printsconsole.error(\error: ${message}`)at:678` without escaping. - Repro: name a recipe
evil\x1b]0;PWNED\x07\x1b[31mred, then runresolve.mjs --type recipe --entity nope --project …. stderr carriesESC ] 0 ; PWNED BEL ESC [31mas is. - The same raw
error: ${…}sink is at:560,:678,:750and:1408(run().catch). Wrapping those four interminalTextcovers the class. A test with an unknown recipe name, in a project holding a recipe whose name has control characters, would pin it.
2. The required Test check is red because of this PR. Test (support) fails scripts/check-edit-accuracy-filter.test.mjs: "the edit accuracy filter covers every file the bench runs, imports or is built from". The new pinnedFile.ts import chain pulls in packages/cli/src/whisper/modelFile.ts, which the edit_accuracy: paths filter in .github/workflows/ci.yml doesn't list. Adding it next to packages/cli/src/utils/** fixes it. Base a6dd840 is green.
What's verified clean
- audio: the top-level handler escapes thrown errors (
cli.ts:708,terminalLines).formatReportandformatReadescape every line.--jsonoutput is unchanged. - HLS: strace on ffmpeg n8.0.1 confirms ffmpeg uses the parent folder for
a#b/list.m3u8andc?d/list.m3u8, soffmpegListFoldermatches it.- Refused at head:
C:x.ts,c:x, UNC paths,//host, absolute paths,file:,..,%2e%2e, backslash.., and a nested playlist that leaves the folder. - Base allowed
C:x.tsandc:x. - All three call sites use the check.
- Refused at head:
- Pinned models: all three pins match the real files (downloaded and hashed): u2net, kokoro and voices.
- A download is verified before the atomic rename.
- A
.partfile that doesn't match is discarded. - A cached copy is re-checked under the lock.
- Tests: without the PR's source changes, 22 tests fail. All 6 mutants were killed: colon guard,
ffmpegListFolder→dirname,keepExisting, the post-download check, the cached-copy check, and media-useterminalText.
Follow-ups, not blocking (pre-existing)
- An HLS entry that is only a query (
?x) resolves against the playlist file, not its folder. strace showed ffmpeg openlist.m3u8?xand then a segment outside the folder.playlistLeavesItsFoldermisses it, as base does. It's the same resolution class this PR fixes, so worth doing here if you're touching it. cli.ts:76→dotEnv.ts:129prints.envkey names raw on every command, andauth/resolver.ts:120prints the.envfolder path.terminal-text.mjsis a hand-kept copy of core's helper with no drift check. Miguel's note aboutkeepsDestsplittingdownloadFilefrom its JSDoc also stands.- CodeQL's 8 alerts look like false positives (test temp files, and lock/part creation that already existed in
download.ts).
— Rames
The playlist folder check on main (#8014) already refuses colon-prefixed entries and entries read from a folder whose path holds ? or #, so the merge keeps main's notMediaPayload.ts and its tests.
… escapes resolve printed error messages as they were, and some name project or cache data, such as the known recipe names when a recipe is not found. Every error: line now passes through terminalText, as the success lines already do.
The CLI's pinned model download now imports whisper/modelFile.ts, so a change to it must run the edit accuracy bench too.
…e downloadFile The tests wrote fixtures under fixed names in the shared temp folder, and their download stand-in checked for a file before replacing it. Each test now works in its own mkdtemp folder, and the stand-in asks keepExisting directly and renames the part file into place, as downloadFile does.
The media-use engine keeps its own copy of terminalText. A CLI test now compares the two over U+0000 to U+00A0, so a change to either fails until both match. keepsDest moves above downloadFile's doc comment, which belongs to downloadFile.
|
Thanks, both. Every blocker and failing check is fixed in plain follow-up commits on top of Blocker 1: media-use errors print raw control characters (370ac62)
Blocker 2:
CodeQL (ac3c52a)
Merge conflict with main (a580b5b)
Non-blocking notes
Checks run locally
|
jrusso1020
left a comment
There was a problem hiding this comment.
Approving at 019a3628. Both blockers are resolved.
- Escaping: all four
resolve.mjssinks (:560,:678,:750,:1408) and the cache-type line at:1287useterminalText. The newresolve.test.mjscase runs--entity nopein a project with a recipe named with control characters, then asserts stderr showsknown: promo\x1b[2Kwith no raw ESC or BEL. - CI filter:
packages/cli/src/whisper/modelFile.tsis now in theedit_accuracy:filter.check-edit-accuracy-filter.test.mjspasses locally and inTest (support). - Earlier nits: a drift test now compares the media-use copy of
terminalTextwith core's from U+0000 to U+00A0, andkeepsDest's doc comment is fixed. - Merge:
a580b5b1takes main's #8014 for the engine, so the PR no longer touchespackages/engine.
Tests:
resolve.test.mjs: 69 of 69.- Filter test: 2 of 2.
- Parity and pin tests: 11 of 11.
- The
:678mutant was killed by the recipe test.
CI: one run's Studio: edit accuracy gate failed 266 vs the base's 267, on the undo case pathpause-none-px-r0-nested-z100. That case is also listed as unstable in the same report, the PR touches no Studio code, and the rerun scored 267. I read it as a flake, and final CI is green.
Non-blocking: mutants on the :560 and :1408 sinks survive; only the exitError path is tested.
— Rames
miguel-heygen
left a comment
There was a problem hiding this comment.
Re-review: the range from our approval at 4af2604 to 019a362. All of it stays inside this PR's scope.
370ac62:media-use resolvenow runs its fiveerror:lines throughterminalText(resolve.mjs), which covers the "error messages" the body lists.resolve.test.mjsasserts the escaped output.c475d9d: one line inci.yml. The edit-accuracy path filter now includespackages/cli/src/whisper/modelFile.ts, so changes there run the edit-accuracy job. The file sits next to the download code this PR changes. This is CI coverage only, with no behaviour change.ac3c52a: the pinned-model tests (background-removal/manager.pin.test.ts,tts/manager.pin.test.ts,utils/pinnedFile.test.ts) use private temp folders and rename files the waydownloadFiledoes. Tests only.019a362:terminalText.parity.test.tschecks the media-use copy ofterminalTextagainst core's for every code point from U+0000 to U+00A0, andterminal-text.d.mtstypes it.download.tsonly moves an existing doc comment back abovedownloadFile, the function it describes.a580b5bmerges main and has no conflict hunks. As the body says, the PR no longer changespackages/engine: #8014's version on main stands. The net diff against main is the 21 CLI files plus theci.ymlline.
CI is green at this head.
Verdict: APPROVE
…d cube-validate lines #8013 escaped resolve's results, recipes, stats and error lines, and #8087 the adopt skip line. A few resolve lines still printed their values raw: argument errors that repeat --type, --provider, --from, --reuse and the --for path, the measured-grade note and the similar-asset hint that repeats the intent. cube-validate's error can quote a value from the LUT file. They now go through the same terminalText copy, so a control character shows as \xNN. --json output is unchanged.
…d cube-validate lines (heygen-com#8059) heygen-com#8013 escaped resolve's results, recipes, stats and error lines, and heygen-com#8087 the adopt skip line. A few resolve lines still printed their values raw: argument errors that repeat --type, --provider, --from, --reuse and the --for path, the measured-grade note and the similar-asset hint that repeats the intent. cube-validate's error can quote a value from the LUT file. They now go through the same terminalText copy, so a control character shows as \xNN. --json output is unchanged.
What
Two small hardening fixes in the CLI:
hyperframes audio,hyperframes audio --readandhyperframes media-use resolveprint control characters from project and cache files as visible\xNNescapes. Formedia-use resolve, this covers results,--candidates, recipes,--statsand error messages.The playlist folder hardening this PR first carried landed on main in #8014. The merge keeps main's version, so this PR no longer changes
packages/engine.Why
How
terminalText, so a newline inside a field shows as\x0a.lib/terminal-text.mjscarries a small copy ofterminalText. A CLI test compares the copy with core's over U+0000 to U+00A0, so the two cannot drift apart.resolve.mjsandformatCandidatesuse the copy for their result, low-confidence, adopt, recipe, stats anderror:lines.--jsonoutput is unchanged.ensurePinnedFilehelper uses the existingverifiescheck (size and sha256). A cached copy that matches is used as it is.downloadFilegets a newkeepExistingoption. Under the download lock, it keeps a copy that passes. It removes a copy that fails and downloads the file again, so existing caches keep working and concurrent runs never delete each other's files.whisper/modelFile.tsis added to the CIedit_accuracy:paths filter, because the pinned download now imports it.No visible change
\xNN.--jsonoutput is unchanged.Test plan
fails without the fix: the new tests in
audio/analysis/format.test.ts,audio/read/format.test.ts,media-use/lib/candidates.test.mjs,media-use/resolve.test.mjs,media-use/terminalText.parity.test.ts,utils/download.test.ts,background-removal/manager.pin.test.tsandtts/manager.pin.test.tseach fail when the matching source change is reverted.Manual checks:
Ran:
tsc --noEmitforcliandengine.check-comment-citations,check-test-reachabilityandcheck-edit-accuracy-filter.Unit tests added/updated
Manual testing performed
Documentation updated (if applicable)
Comments follow CONTRIBUTING.md "Comments": they say why, not what, and a bug fix says what the code must do and how to reproduce the bug