fix(config): log config overwrite audits

This commit is contained in:
Peter Steinberger
2026-02-13 20:12:36 +00:00
parent 42eaee8b7e
commit 1655df7ac0
3 changed files with 79 additions and 1 deletions

View File

@@ -725,6 +725,19 @@ export function createConfigIO(overrides: ConfigIoDeps = {}) {
// Do NOT apply runtime defaults when writing — user config should only contain
// explicitly set values. Runtime defaults are applied when loading (issue #6070).
const json = JSON.stringify(stampConfigVersion(outputConfig), null, 2).trimEnd().concat("\n");
const nextHash = hashConfigRaw(json);
const previousHash = resolveConfigSnapshotHash(snapshot);
const changedPathCount = changedPaths?.size;
const logConfigOverwrite = () => {
if (!snapshot.exists) {
return;
}
const changeSummary =
typeof changedPathCount === "number" ? `, changedPaths=${changedPathCount}` : "";
deps.logger.warn(
`Config overwrite: ${configPath} (sha256 ${previousHash ?? "unknown"} -> ${nextHash}, backup=${configPath}.bak${changeSummary})`,
);
};
const tmp = path.join(
dir,
@@ -756,6 +769,7 @@ export function createConfigIO(overrides: ConfigIoDeps = {}) {
await deps.fs.promises.unlink(tmp).catch(() => {
// best-effort
});
logConfigOverwrite();
return;
}
await deps.fs.promises.unlink(tmp).catch(() => {
@@ -763,6 +777,7 @@ export function createConfigIO(overrides: ConfigIoDeps = {}) {
});
throw err;
}
logConfigOverwrite();
}
return {