Repository navigation
fix(translate): harden CapCut cloud translation from #169 - #170
Merged
Merged
Conversation
translate --cloud and caption --translate (#169) now: - refuse a reply with more or fewer lines than were sent, instead of pairing translations with the wrong timings; - keep the original text, and its word timings, for a line that comes back without a translation, and count it in kept_original (an empty translation used to blank the text); - send nothing under --dry-run: caption --translate --dry-run reports the lines it would send under `translation`, and --cloud --dry-run says so; - warn on stderr how many lines go to ByteDance's servers, and say in the help and command reference that both flags are experimental and unofficial, as caption --cloud does. The install identity both cloud clients replay (app id, device id, locale, user agent) now lives once in capcut-cloud-headers.ts. Each client keeps the signature captured with its own requests, and the header sets are byte-identical to before, in the same order. The translation tests run offline against a stand-in fetch (request shape, 50-line batches, refused and partial replies, retries, cue word timings, the dry runs). The calls to ByteDance run only with CAPCUT_LIVE=1 and fail loudly there, instead of passing on any error. CI: the Python client's 3.9 job runs on ubuntu-24.04; ubuntu-latest (26.04) has no Python 3.9 build for setup-python. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Follow-up to #169 (CapCut cloud translation, contributed by datnt-97), the way #158 followed #157. Neither flag has been released yet.
What changes
kept_original. Before, an empty translation blanked the line, and a missing one passed silently.--dry-runsends nothing.caption --translate --dry-runcalled ByteDance's servers, because only the draft write is gated by a dry run. It now reports the lines it would send undertranslation(sent: false);caption --cloud --dry-run --translatereports the same.caption --cloud. Every run says on stderr how many lines go to ByteDance's servers, and the help text and command reference call both flags experimental and unofficial.src/capcut-cloud-headers.ts: the identity (app id, device id, locale, user agent) is written once, and each client keeps the signature captured with its own requests. The header objects are byte-identical to before, values and order.test/cloud-translate.test.mjsruns against a stand-in fetch, the pattern ofcloud-asr-flow.test.mjs: request shape, 50-line batches, refused and partial replies, the service's error codes, retries, cue word timings, and both dry runs. The calls to ByteDance run only withCAPCUT_LIVE=1, and fail loudly there instead of passing on any error.ubuntu-24.04:ubuntu-latestis now 26.04, which has no 3.9 build forsetup-python, so that job has failed on master since the image moved. The package still declaresrequires-python >= 3.9.Evidence
npm teston a clean checkout of master with this change: 1,385 passed, 0 failed, 2 skipped (the live suite and one existing skip). The commit went through the repo's pre-commit gate (lint-staged, then build and the full suite).biome check --error-on-warnings src/ test/: clean.DEFAULT_CAPCUT_HEADERSandDEFAULT_CAPCUT_TRANSLATE_HEADERScompared entry by entry against the literals they replace: identical, same key order.docs/command-reference.jsonregenerated fromcapcut describe; only the two flag descriptions change.Door
Two-way. Every change is local to the two unreleased cloud translation flags, the shared header constant and one CI matrix entry; reverting the commit restores #169 as merged.
Blast radius
translate --cloudandcaption --translate(unreleased).caption --cloudgets its headers from the shared builder with unchanged values. No other command, no runtime dependency and no published API changes;translateTextsCapcutCloud(added in #169, never released or exported from the package entry) is removed in favour oftranslateUtterancesCapcutCloud. CI: one Python job moves runner image.