fix(#321): replace JSON config default clone with structuredClone (#324)

This commit is contained in:
Tom Boucher
2026-05-26 12:22:02 -04:00
committed by GitHub
parent e4f29feabc
commit e5a5a75938
3 changed files with 29 additions and 1 deletions

View File

@@ -0,0 +1,5 @@
---
type: Fixed
pr: 321
---
**`loadConfig` now clones config defaults with `structuredClone`** — avoids JSON round-trip fragility in defaults merging used by config loads and related tooling.

View File

@@ -158,7 +158,7 @@ function normalizeLegacyKeys(parsed) {
function mergeDefaults(parsed) {
// Start with a deep clone of defaults, then overlay parsed
const defaults = JSON.parse(JSON.stringify(CONFIG_DEFAULTS));
const defaults = structuredClone(CONFIG_DEFAULTS);
return deepMergeConfig(defaults, parsed);
}

View File

@@ -0,0 +1,23 @@
'use strict';
const { test } = require('node:test');
const assert = require('node:assert/strict');
const configuration = require('../get-shit-done/bin/lib/configuration.cjs');
test('mergeDefaults clones defaults without JSON serialization fragility (#321)', () => {
const sentinelKey = '__bug321_bigint_sentinel__';
const sentinelValue = BigInt('9007199254740993001');
configuration.CONFIG_DEFAULTS[sentinelKey] = sentinelValue;
try {
const merged = configuration.mergeDefaults({});
assert.equal(
merged[sentinelKey],
sentinelValue,
'mergeDefaults must preserve non-JSON scalar defaults when cloning'
);
}
finally {
delete configuration.CONFIG_DEFAULTS[sentinelKey];
}
});