This commit is contained in:
5
.changeset/eager-elks-romp.md
Normal file
5
.changeset/eager-elks-romp.md
Normal 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.
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
|
||||
23
tests/bug-321-config-defaults-clone-strategy.test.cjs
Normal file
23
tests/bug-321-config-defaults-clone-strategy.test.cjs
Normal 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];
|
||||
}
|
||||
});
|
||||
Reference in New Issue
Block a user