Skip to content

preserve unknown config keys in ‘chunk config set’ - #497

Open
jesseworld22 wants to merge 5 commits into
CircleCI-Public:mainfrom
jesseworld22:jesse/preserve-unknown-config-keys
Open

preserve unknown config keys in ‘chunk config set’#497
jesseworld22 wants to merge 5 commits into
CircleCI-Public:mainfrom
jesseworld22:jesse/preserve-unknown-config-keys

Conversation

@jesseworld22

Copy link
Copy Markdown
Contributor

chunk config set rewrote .chunk/config.json through a typed struct and silently dropped every field it didn't model -including keys hand-added to commands[]. config writes now merge onto the existing file, preserving unrecognized keys verbatim while still letting the struct delete the ones it owns.

`chunk config set` rewrote the whole config file through a typed struct, so
every field the struct did not model was dropped with no warning. Keys
hand-added to `commands[]` entries — the reported case was `fileExt`, `limit`,
and `always` on four commands — disappeared after a single unrelated write.

Writes now merge onto the file they are about to replace, via a new
`internal/jsonmerge`. The struct still owns every key it models, so a modeled
key it omits is deleted rather than restored: `chunk auth clear` depends on
that to remove a credential. Unknown keys are copied over verbatim as raw
bytes, after the modeled keys of the same object, so numbers and escapes are
not reformatted on the way through. Array entries are paired between the two
documents by `name`, and only entries the struct has survive — that is what
keeps the deliberately dropped `environment.setup` test step from coming back
while extra keys on the entries that remain are kept.

`config set` now also names the keys it kept but does not recognize, so a typo
is visible instead of silently doing nothing forever.

Fixes the adjacent clobber in the same paths: every writer downgraded any load
error to an empty config, so one stray brace plus one `config set` replaced the
whole file with `{}`. `LoadProjectConfigForUpdate` yields an empty config for a
missing file but refuses one that does not parse, and the write paths use it.
`validate --list` says so rather than reporting that no commands are
configured.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
@jesseworld22 jesseworld22 changed the title preserve unknown config kets in ‘chunk config set’ preserve unknown config keys in ‘chunk config set’ Aug 12, 2026
Comment thread internal/config/config.go Outdated
jesseworld22 and others added 3 commits August 12, 2026 14:31
`marshalPreserving` merged onto the file it was about to replace and dropped the
error if the merge failed, so a file that did not parse was silently flattened to
the keys chunk models — the unknown keys it was supposed to preserve went with it.
The project config was covered by `LoadProjectConfigForUpdate` refusing at load;
the user config leaned on `Load` doing the same, which cannot cover a file that
breaks between the load and the write.

The merge error is now returned. `config.Save` therefore refuses an unparseable
user config and leaves the file alone. `SaveProjectConfig` keeps replacing it,
via a new `marshalOverwriting`, because `chunk init --force` exists to overwrite
a config nobody can fix by hand; its other callers still guard at load.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Comment thread internal/jsonmerge/jsonmerge.go
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