fix(config): persist config set under an env token; fail on ephemeral overrides#1366
Merged
Merged
Conversation
d34ca06 to
db94217
Compare
Benjamin Barslev Nielsen (barslev)
approved these changes
Jun 17, 2026
db94217 to
1576fb5
Compare
config set can't persistconfig set under an env token; fail on ephemeral overrides
1576fb5 to
f3d6fb3
Compare
…al overrides (1.1.121) A Socket API token supplied via env (SOCKET_CLI_API_TOKEN / SOCKET_SECURITY_API_TOKEN and legacy aliases) used to put the entire config into read-only mode, so `socket config set <key> <value>` silently failed to save while still printing `OK`, and a later `socket config get` then showed nothing. A token from the environment now overrides authentication only: unrelated keys such as defaultOrg are written to disk as expected, while the env token itself is still never persisted (getDefaultApiToken resolves it straight from the environment, so it is no longer mirrored into the cached config). When the config is genuinely ephemeral, because it was fully overridden via --config, SOCKET_CLI_CONFIG, or SOCKET_CLI_NO_API_TOKEN, `socket config set` now fails with a clear error instead of pretending it succeeded; the in-memory-only change is a no-op for a one-shot command. `config get apiToken` still reports the env-supplied token, which takes precedence over persisted / --config values. Adds unit and command-level regression tests and bumps the CLI to 1.1.121.
f3d6fb3 to
1fd205d
Compare
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.
Problem
When a Socket API token was supplied via an environment variable
(
SOCKET_CLI_API_TOKEN/SOCKET_SECURITY_API_TOKEN, or the legacy aliases),the entire config was put into read-only mode. As a result,
socket config set <key> <value>silently failed to persist — yet still printeda reassuring
OK— and a latersocket config getshowed nothing, so it lookedlike the value had been silently lost.
This is a common setup (keeping the token in an env var), and there's no good
reason that having a token in the environment should prevent saving an unrelated
key such as
defaultOrg.Fix
A token from the environment now overrides authentication only:
getDefaultApiToken()already resolves the env token directly from theenvironment, so it is no longer mirrored into the persisted config cache and no
longer flips the config to read-only. Unrelated keys (e.g.
defaultOrg) arewritten to disk as expected via
socket config set.socket config get apiTokenstill reports the env token, which continues totake precedence over persisted /
--configvalues.meow-with-subcommands.mtsthatstill claimed the env token was injected into the cache and marked read-only.
When the config is genuinely ephemeral — fully overridden via
--config,SOCKET_CLI_CONFIG, orSOCKET_CLI_NO_API_TOKEN—socket config setnowfails with a clear error instead of pretending it succeeded. For a one-shot
command, an in-memory-only change is a no-op (nothing reads it before the process
exits), so failing is the honest outcome. (Note: under a full override,
config set --jsonnow emitsok:falseand exits 1, where it previouslyreported
ok:true.)Testing
pnpm check:tsc— clean. oxlint — clean on the changed config files (theconstants.ENVimport-style warnings inmeow-with-subcommands.mtsarepre-existing and unchanged by this PR).
src/utils/config.test.mts— updated read-only message snapshot; addedcoverage asserting a token-env override is not read-only while
--configand
SOCKET_CLI_NO_API_TOKENare.src/commands/config/cmd-config-set.test.mts— added: (1) a full--configoverride makes
config setfail; (2) with only a token env var,config set defaultOrgpersists to disk (verified by reading the written config file) andthe env token is not written.
config+login+logoutsuites pass (36 tests).Bumps the CLI to
1.1.121with a CHANGELOG entry.