fix(config): add resolved field to ConfigFileSnapshot for pre-defaults config

The initial fix using snapshot.parsed broke configs with $include directives.
This commit adds a new 'resolved' field to ConfigFileSnapshot that contains
the config after $include and ${ENV} substitution but BEFORE runtime defaults
are applied. This is now used by config set/unset to avoid:
1. Breaking configs with $include directives
2. Leaking runtime defaults into the written config file

Also removes applyModelDefaults from writeConfigFile since runtime defaults
should only be applied when loading, not when writing.
This commit is contained in:
Marcus Castro
2026-02-08 10:59:12 -03:00
committed by Peter Steinberger
parent 9e8d9f114d
commit 3189e2f11b
5 changed files with 48 additions and 12 deletions

View File

@@ -306,9 +306,10 @@ export function registerConfigCli(program: Command) {
}
const parsedValue = parseValue(value, opts);
const snapshot = await loadValidConfig();
// Use snapshot.parsed (raw user config) instead of snapshot.config (runtime-merged with defaults)
// Use snapshot.resolved (config after $include and ${ENV} resolution, but BEFORE runtime defaults)
// instead of snapshot.config (runtime-merged with defaults).
// This prevents runtime defaults from leaking into the written config file (issue #6070)
const next = structuredClone(snapshot.parsed) as Record<string, unknown>;
const next = structuredClone(snapshot.resolved) as Record<string, unknown>;
setAtPath(next, parsedPath, parsedValue);
await writeConfigFile(next);
defaultRuntime.log(info(`Updated ${path}. Restart the gateway to apply.`));
@@ -329,9 +330,10 @@ export function registerConfigCli(program: Command) {
throw new Error("Path is empty.");
}
const snapshot = await loadValidConfig();
// Use snapshot.parsed (raw user config) instead of snapshot.config (runtime-merged with defaults)
// Use snapshot.resolved (config after $include and ${ENV} resolution, but BEFORE runtime defaults)
// instead of snapshot.config (runtime-merged with defaults).
// This prevents runtime defaults from leaking into the written config file (issue #6070)
const next = structuredClone(snapshot.parsed) as Record<string, unknown>;
const next = structuredClone(snapshot.resolved) as Record<string, unknown>;
const removed = unsetAtPath(next, parsedPath);
if (!removed) {
defaultRuntime.error(danger(`Config path not found: ${path}`));