Skip to content

fix(paths): settings and credentials never live in the working directory - #579

Merged
miguel-heygen merged 5 commits into
mainfrom
fix/config-dir-never-cwd
Nov 16, 2026
Merged

miguel-heygen merged 5 commits into
mainfrom
fix/config-dir-never-cwd

Conversation

@miguel-heygen

@miguel-heygen miguel-heygen commented Nov 16, 2026 •

Copy link
Copy Markdown
Contributor

Description

paths.ConfigDir() no longer falls back to .heygen in the working directory when the home directory cannot be resolved. It now returns ErrNoConfigDir when there is no HEYGEN_CONFIG_DIR and no absolute home directory, which covers an empty HOME and a relative one such as .. Every caller handles that error:

  • Reads behave as not configured: credential resolution, OAuth tokens, the stored API key, user info, config get, the update-check cache and the legacy analytics id.
  • Writes fail with the error: auth login saving an API key or an OAuth session, saving user info, config set, and the update-check cache and its lock.
  • Clears are a no-op: OAuth tokens, the API key and user info.
  • The telemetry notice still shows, but its "shown" marker is not written.
  • Messages and hints that name the credentials file take the path from one helper, auth.CredentialsFileShown(). With no config directory it says "the credentials file".

Before, a project folder could hold a .heygen/credentials or .heygen/config.toml that the CLI read as the person's own, and auth login wrote the person's credentials into the folder it ran from.

To reproduce on main: with HOME empty and no HEYGEN_CONFIG_DIR, saving credentials writes ./.heygen/credentials in the working directory. The new internal/auth test fails that way with main's fallback.

Testing

Under Go 1.26 in a container:

  • go test ./... and go vet on the touched packages pass. gofmt -l lists only internal/client/client_test.go and internal/errors/errors_test.go, which are the same on main.
  • New tests:
    • internal/paths/paths_test.go: an empty home, ., and a relative home each give ErrNoConfigDir. A real home and the override still resolve.
    • internal/auth/no_config_dir_test.go: with an empty HOME and USERPROFILE, from an empty temporary working directory, every credential save fails, every read is not configured or empty, every clear is a no-op, and the working directory is still empty afterwards.
    • internal/config/no_config_dir_test.go and cmd/heygen/no_config_dir_test.go: the same for config get and config set, and for the update-check cache and its lock.
  • Fails without the fix: with ConfigDir returning .heygen when there is no home (main's fallback), all four new tests fail.
  • The new tests pass three runs in a row.
  • Existing tests now use small mustConfigDir()-style test helpers for the new signatures.
  • golangci-lint v2.11.4 (the version CI pins): 0 issues.

@jrusso1020 jrusso1020 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

APPROVE. Reviewed at ed57ef002df20a1dfcd6b2f02ec56f844eb01bc8 (base is current main).

paths.ConfigDir() now returns ErrNoConfigDir instead of .heygen in the working directory when there is no HEYGEN_CONFIG_DIR and no absolute home. Because the signature changed, every caller has to handle the error, so the compiler enforces coverage. I read each one:

  • Reads are not-configured or empty: the credential resolver, OAuth tokens, the stored API key, user info, config get, the update cache, and the legacy analytics id.
  • Writes return the error: API key and OAuth saves, user info, config set, and the update cache and its lock.
  • Clears are no-ops.
  • The telemetry notice still prints but writes no marker.
  • Messages go through CredentialsFileShown().

Fails without the fix: verified. I put back main's behaviour inside the new signature (return ".heygen", nil on a missing or relative home), and all four new tests fail:

--- FAIL: TestConfigDirIsNeverTheWorkingDirectory               (internal/paths)
--- FAIL: TestNoConfigDirLeavesTheWorkingDirectoryAlone          (internal/auth)
--- FAIL: TestFileProviderWithNoConfigDirLeavesTheWorkingDirectoryAlone (internal/config)
--- FAIL: TestUpdateCacheWithNoConfigDirLeavesTheWorkingDirectoryAlone  (cmd/heygen)

At head: go build ./..., go vet on the touched packages, and go test ./... all pass (Go 1.26).

Nit (non-blocking): the same class remains in internal/analytics sharedConfigPath() (analytics.go:291-297). It joins os.UserHomeDir() with .hyperframes/config.json and checks only err. On Unix, a relative HOME such as . comes back with no error, so the shared config is read from and written to ./.hyperframes/config.json in the working directory. Only the anonymousId field is involved, so the impact is small, but it is the same kind of planted or stray file this PR removes. Fix: if err != nil || !filepath.IsAbs(home) { return "" }. Its callers already treat "" as absent.

Need: yes, settings and credentials could come from or land in the working directory · Size: ok (wide, but each caller change is mechanical and enforced by the new signature) · Reuse: one sentinel error plus one display helper, CredentialsFileShown(), which replaces five copies of filepath.Join(ConfigDir(), "credentials") · Simpler: already minimal · Structure: fine (checked every ConfigDir caller and the analytics home lookup; no split)
Risk: low — the only behaviour change is when home is missing or relative, and that case now fails closed.

— Rames

@jrusso1020 jrusso1020 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

APPROVE (re-pin). Reviewed at e4edf0a7404fbf5e12b7ea66fc9a431be2bed587. The delta since my approval at ed57ef00 is one commit, which removes the unused mustConfigDir() test helper from cmd/heygen/configdir_helper_test.go. No runtime code changed.

At this head, grep -rn mustConfigDir cmd/heygen/ finds nothing, and go vet ./cmd/heygen/ and go test ./cmd/heygen/ both pass. My earlier review stands, including the analytics sharedConfigPath() nit.

— Rames

@miguel-heygen miguel-heygen changed the title fix(paths): settings and credentials never live in the working directory (PRINFRA-6695) fix(paths): settings and credentials never live in the working directory Nov 16, 2026
@miguel-heygen
miguel-heygen merged commit cde86c1 into main Nov 16, 2026
10 checks passed
@miguel-heygen
miguel-heygen deleted the fix/config-dir-never-cwd branch November 16, 2026 02:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants