Repository navigation
fix(cli): a project .env key is used only when nothing is saved - #7848
Conversation
A HEYGEN_API_KEY or HYPERFRAMES_API_KEY that a project .env sets now comes after every credential the person saved or exported. The CLI resolver, the media environment and the media-use skill use it only when there is no saved login, no saved API key and no key in the shell. When one is used, a single stderr line names the .env file. An expired, foreign-client, unreadable or refused login now raises the login error instead of switching to a project .env key, whether or not the folder has a received-files record. A key exported in the shell, or set by the app that launched the CLI, keeps its current place, and the host gateway path is unchanged.
|
Preview deployment for your docs. Learn more about Mintlify Previews.
💡 Tip: Enable Automations to automatically generate PRs for you. |
Edit accuracy: accurate 267 (base branch 267), smooth 101 of thoseThe gate passes. Quarantined, measured but not gated (8)
Unstable (1)
|
jrusso1020
left a comment
There was a problem hiding this comment.
Reviewed at 44935b7422d0ee93b97c8f512621399185ae0ba6.
For HeyGen's API, a project-loaded key now follows the saved login, shell keys and saved API key; a failed/expired/foreign login or unreadable/JSON-syntax-invalid credential file does not select that project key. afterRefreshFailure only considers shell keys. The media wrapper removes the unselected alias before spawning a helper.
Need: yes · Size: ok · Reuse: existing dotenv-origin map and credential store · Simpler: removes the received-files walk · Structure: fine (checked CLI resolver against the existing standalone skill resolver; no new abstraction)
Risk: medium — credential selection controls the account receiving work and paying for it.
The skill duplicates the resolver; it does not call the CLI implementation. Its standalone Node requirement explains that existing split. I checked the two public-API precedence paths, the cloud refresh/401 handoff, and the media child environment. The skill cannot refresh a login itself: it emits a refresh/sign-in instruction. The CLI refreshes where possible; refused refreshes retain the auth error/hint. The media wrapper can still run anonymous/local providers after a nonrefreshable expired login, with all HeyGen credential variables removed; it does not silently send the project key.
Verification: bun run build, CLI bun run typecheck, and gen:skills-manifest --check pass. CLI auth/cloud-auth/dotenv tests plus four reviewer child-process cases: 257 passed. The child loads the actual standalone skill against fresh login, saved API key, expired login and no-store fixtures. Skill credential/TTS/voice suites: 51 passed. Keeping the new tests but reverting resolver, media-environment and skill production code gives 14 CLI failures (48 pass) and 6 skill failures (30 pass); restoration gives 62 CLI / 36 skill passes. Both #7808 and #7837 merge commits are ancestors of this head. These use synthetic credentials and local fixtures/mocked refresh responses, not live paid requests.
Nit — qualify the docs' absolute rule (docs/guides/authentication.mdx:64, docs/packages/cli.mdx:2595): the deliberately retained host-gateway branch still permits a project key ahead of saved credentials when the host set a non-HeyGen API base and supplied no key. The CLI test explicitly pins this exception. In the standalone skill that early gateway path also bypasses the new project-key notice. A project .env cannot itself set the gateway through either allowlisted loader. State that the new last-resort/notice guarantee applies to normal HeyGen resolution, with the host-gateway exception, instead of “never” universally. This exception is existing behavior expressly retained in the PR’s scope, not a new ability for a project to choose the destination host. Existing standalone semantic store-parser leniency and lack of refresh are also not closed by this change.
Current-main trial merge is clean. No new account-switching defect found in the changed normal API paths.
Verdict: APPROVE
Reasoning: The change removes project-key precedence for cloned/unrecorded projects while preserving explicit host/shell behavior, and expired/refused login paths in normal HeyGen resolution do not adopt the project wallet.
— cutroom-review
* chore: release v0.9.54 * chore: release v0.9.54 notes include heygen-com#7827, heygen-com#7825, heygen-com#7845, heygen-com#7848 and heygen-com#7849 * chore: release v0.9.54 notes include heygen-com#7853 * chore: release v0.9.54 notes include heygen-com#7851 and heygen-com#7855
What
A HeyGen key from a project
.envis now the last credential the CLI and the media-use skill consider. It is used only when the person has no saved login, no saved API key and no key exported in the shell. When it is used, the CLI and the skill print one stderr line that names the.envfile.This builds on #7808 and #7837. Those PRs applied the same rule to a
.envthat came in with a received project, which is a folder that a.hyperframes/received-files.jsonrecord lists. This PR applies the rule to every project.env, including folders that have no record, such as a git clone, an unzipped archive or a copied template.Why
Every CLI run loads
HEYGEN_API_KEYandHYPERFRAMES_API_KEYfrom the.envin the working directory. A folder without a received-files record looked like the person's own, so its key behaved like a shell-exported key:auth login --api-key, without any notice.In both cases, uploads, renders and generated media could go to an account that the folder's author chose, not the person running the command.
Related work
Refs #7808 and #7837.
How
The resolution order is now:
HEYGEN_ACCESS_TOKENfrom the host app.HEYGEN_API_KEY, thenHYPERFRAMES_API_KEY, when the shell or the launching app set them.auth login --api-key..env, only when nothing is saved and the shell sets none.Details:
packages/cli/src/auth/resolver.tssplits env keys into shell keys and project keys, using the origin map thatdotEnv.tsalready keeps. The resolver no longer needs the received-files lookup, because the received case is now a subset of the project case.afterRefreshFailurefalls back only to a shell key.withMediaAuthEnvironmentalso dropsHYPERFRAMES_API_KEYfrom the child environment when it passes an API key, so a helper sees only the selected key.heygen.mjsapplies the same order and prints its own notice with the path. Its received-files walk is removed for the same reason.HEYGEN_ACCESS_TOKENand the host gateway path keep their current behaviour. A.envnever overrides a variable that is already set, so a key that HyperFrames Desktop or another host app sets in the environment still counts as a shell key.authhelp text now state the new order.Test plan
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
bunx vitest run src/auth/resolver.test.ts src/auth/media-environment.test.tsinpackages/cli.node --test skills/media-use/audio/scripts/lib/heygen.test.mjs.tsc --noEmitinpackages/cli.New tests cover a folder with no received-files record and a received folder:
Guard tests: a shell key keeps its place, a key the launching app set is not replaced by the
.env, the gateway path is unchanged, and the received-files tests from fix(cli): benchmark keeps received files' rule; a received .env key never replaces a login #7837 still pass.