Repository navigation
fix(paths): settings and credentials never live in the working directory - #579
Conversation
jrusso1020
left a comment
There was a problem hiding this comment.
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
left a comment
There was a problem hiding this comment.
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
Description
paths.ConfigDir()no longer falls back to.heygenin the working directory when the home directory cannot be resolved. It now returnsErrNoConfigDirwhen there is noHEYGEN_CONFIG_DIRand no absolute home directory, which covers an emptyHOMEand a relative one such as.. Every caller handles that error:config get, the update-check cache and the legacy analytics id.auth loginsaving an API key or an OAuth session, saving user info,config set, and the update-check cache and its lock.auth.CredentialsFileShown(). With no config directory it says "the credentials file".Before, a project folder could hold a
.heygen/credentialsor.heygen/config.tomlthat the CLI read as the person's own, andauth loginwrote the person's credentials into the folder it ran from.To reproduce on main: with
HOMEempty and noHEYGEN_CONFIG_DIR, saving credentials writes./.heygen/credentialsin the working directory. The newinternal/authtest fails that way with main's fallback.Testing
Under Go 1.26 in a container:
go test ./...andgo veton the touched packages pass.gofmt -llists onlyinternal/client/client_test.goandinternal/errors/errors_test.go, which are the same on main.internal/paths/paths_test.go: an empty home,., and a relative home each giveErrNoConfigDir. A real home and the override still resolve.internal/auth/no_config_dir_test.go: with an emptyHOMEandUSERPROFILE, 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.goandcmd/heygen/no_config_dir_test.go: the same forconfig getandconfig set, and for the update-check cache and its lock.ConfigDirreturning.heygenwhen there is no home (main's fallback), all four new tests fail.mustConfigDir()-style test helpers for the new signatures.