Skip to content

Commit eb86271

Browse files
committed
fix(config): warn instead of reporting OK when config set can't persist (1.1.121)
When the active config is in read-only mode — because it was overridden by an environment variable (e.g. SOCKET_CLI_API_TOKEN / SOCKET_SECURITY_API_TOKEN), SOCKET_CLI_CONFIG, or --config — `updateConfigValue` applies the change in memory only and does not write it to disk. `socket config set` nonetheless led with a reassuring `OK` / "was updated" and tucked the "not persisted" caveat into an easy-to-miss trailing line. A later `socket config get` then showed nothing, making it look like the set had silently failed. outputConfigSet now surfaces the read-only case as a prominent warning (and a GitHub-style > [\!WARNING] block in markdown output) instead of `OK`, and the message spells out why the value was not saved and how to make persistence work. Exit code stays 0 since the in-memory change is still applied for the run. Add a command-level regression test and bump the CLI to 1.1.121.
1 parent 80ccc51 commit eb86271

6 files changed

Lines changed: 47 additions & 12 deletions

File tree

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,11 @@ All notable changes to this project will be documented in this file.
44

55
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/).
66

7+
## [1.1.121](https://github.com/SocketDev/socket-cli/releases/tag/v1.1.121) - 2026-06-17
8+
9+
### Fixed
10+
- `socket config set` no longer reports a misleading `OK` when the value cannot be saved. When the active config is in read-only mode (because it was overridden by an environment variable such as `SOCKET_CLI_API_TOKEN` / `SOCKET_SECURITY_API_TOKEN`, by `SOCKET_CLI_CONFIG`, or by `--config`), the change applies to the current run only. The command now warns clearly that the value was not saved to disk and how to make persistence work, so a subsequent `socket config get` no longer appears to silently lose the value.
11+
712
## [1.1.120](https://github.com/SocketDev/socket-cli/releases/tag/v1.1.120) - 2026-06-12
813

914
### Changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "socket",
3-
"version": "1.1.120",
3+
"version": "1.1.121",
44
"description": "CLI for Socket.dev",
55
"homepage": "https://github.com/SocketDev/socket-cli",
66
"license": "MIT",

src/commands/config/cmd-config-set.test.mts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,4 +114,19 @@ describe('socket config get', async () => {
114114
expect(code, 'dry-run should exit with code 0 if input ok').toBe(0)
115115
},
116116
)
117+
118+
cmdit(
119+
['config', 'set', 'defaultOrg', 'my-test-org', FLAG_CONFIG, '{}'],
120+
'should warn (not report OK) when an override prevents persisting',
121+
async cmd => {
122+
const { code, stderr, stdout } = await spawnSocketCli(binCliPath, cmd)
123+
// The --config override marks the config read-only, so the change is
124+
// applied in-memory only. The user must be clearly told it was not saved
125+
// rather than seeing a reassuring "OK".
126+
const combined = `${stdout}\n${stderr}`
127+
expect(combined).toContain('NOT saved to disk')
128+
expect(stdout).not.toContain('OK')
129+
expect(code, 'an in-memory-only change should still exit 0').toBe(0)
130+
},
131+
)
117132
})

src/commands/config/output-config-set.mts

Lines changed: 19 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -22,20 +22,30 @@ export async function outputConfigSet(
2222
return
2323
}
2424

25+
// A non-empty `data` payload means the change was applied in-memory only and
26+
// was NOT persisted to disk (an env var / --config override puts the config
27+
// in read-only mode). Surface that prominently instead of a reassuring "OK"
28+
// so the user isn't misled into thinking a later `config get` will reflect it.
29+
const notPersistedNote = result.data
30+
2531
if (outputKind === 'markdown') {
2632
logger.log(`# Update config`)
2733
logger.log('')
2834
logger.log(result.message)
29-
if (result.data) {
35+
if (notPersistedNote) {
3036
logger.log('')
31-
logger.log(result.data)
32-
}
33-
} else {
34-
logger.log(`OK`)
35-
logger.log(result.message)
36-
if (result.data) {
37-
logger.log('')
38-
logger.log(result.data)
37+
logger.log('> [!WARNING]')
38+
logger.log(`> ${notPersistedNote}`)
3939
}
40+
return
4041
}
42+
43+
if (notPersistedNote) {
44+
logger.warn(result.message)
45+
logger.warn(notPersistedNote)
46+
return
47+
}
48+
49+
logger.log(`OK`)
50+
logger.log(result.message)
4151
}

src/utils/config.mts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -344,7 +344,12 @@ export function updateConfigValue<Key extends keyof LocalConfig>(
344344
return {
345345
ok: true,
346346
message: `Config key '${key}' was ${wasDeleted ? 'deleted' : `updated`}`,
347-
data: 'Change applied but not persisted; current config is overridden through env var or flag',
347+
data:
348+
'Change applied for this run only — NOT saved to disk. The config is ' +
349+
'overridden by an environment variable or --config flag (e.g. ' +
350+
'SOCKET_CLI_API_TOKEN / SOCKET_SECURITY_API_TOKEN, SOCKET_CLI_CONFIG, ' +
351+
'or --config), which puts it in read-only mode. Remove the override to ' +
352+
'persist changes.',
348353
}
349354
}
350355

src/utils/config.test.mts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ describe('utils/config', () => {
3030
updateConfigValue('defaultOrg', 'fake_test_org'),
3131
).toMatchInlineSnapshot(`
3232
{
33-
"data": "Change applied but not persisted; current config is overridden through env var or flag",
33+
"data": "Change applied for this run only — NOT saved to disk. The config is overridden by an environment variable or --config flag (e.g. SOCKET_CLI_API_TOKEN / SOCKET_SECURITY_API_TOKEN, SOCKET_CLI_CONFIG, or --config), which puts it in read-only mode. Remove the override to persist changes.",
3434
"message": "Config key 'defaultOrg' was updated",
3535
"ok": true,
3636
}

0 commit comments

Comments
 (0)