Skip to content

Commit 65d2ad1

Browse files
committed
fix(shared): token merge treats host names the way secret storage does
Signed-off-by: Yordis Prieto <[email protected]>
1 parent 8b437c4 commit 65d2ad1

3 files changed

Lines changed: 16 additions & 3 deletions

File tree

‎packages/contracts/src/settings.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1696,7 +1696,7 @@ export const ServerSettingsPatch = Schema.Struct({
16961696
otlpLogsUrl: Schema.optionalKey(TrimmedString),
16971697
}),
16981698
),
1699-
/** Merges per host, replacing patched fields whole; redaction markers retain secrets, empty or omitted secrets remove them. */
1699+
/** Merges per host, replacing patched fields whole; redaction markers retain secrets, empty secrets remove them. A non-empty token map keeps the saved tokens of hosts it omits; an empty map clears them all. */
17001700
sourceControlHosts: Schema.optionalKey(Schema.Record(Schema.String, SourceControlHostSettings)),
17011701
// Replace whole maps to avoid half-merged driver configs.
17021702
providerInstances: Schema.optionalKey(Schema.Record(ProviderInstanceId, ProviderInstanceConfig)),

‎packages/shared/src/serverSettings.test.ts‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,10 @@ describe("serverSettings helpers", () => {
139139
"github.com": reference,
140140
"ghe.example": "x",
141141
});
142+
const recased = applyServerSettingsPatch(saved, {
143+
sourceControlHosts: { github: { tokens: { " GitHub.com ": "ghp_new" } } },
144+
});
145+
expect(recased.sourceControlHosts.github?.tokens).toEqual({ "github.com": "ghp_new" });
142146
});
143147

144148
it("inherits actions, preserves existing actions, and supports empty overrides and reset", () => {

‎packages/shared/src/serverSettings.ts‎

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -227,6 +227,15 @@ function mergeSettingsEntries<Value>(
227227
return Object.fromEntries(next);
228228
}
229229

230+
// Secret persistence keys tokens by trimmed, lowercased host, so merge on the same key.
231+
const byHost = (tokens: unknown) =>
232+
Object.fromEntries(
233+
Object.entries(Predicate.isObject(tokens) ? tokens : {}).map(([host, token]) => [
234+
host.trim().toLowerCase(),
235+
token,
236+
]),
237+
);
238+
230239
const knownProjectOverrideKeys = new Set(Object.keys(ProjectSettingsOverrides.fields));
231240

232241
function pickOverrideKeys(entry: ProjectSettingsOverrides | undefined, known: boolean) {
@@ -543,8 +552,8 @@ export function applyServerSettingsPatch(
543552
...(Predicate.isObject(fields.tokens) && Object.keys(fields.tokens).length > 0
544553
? {
545554
tokens: {
546-
...(Predicate.isObject(saved?.tokens) ? saved.tokens : {}),
547-
...fields.tokens,
555+
...byHost(saved?.tokens),
556+
...byHost(fields.tokens),
548557
},
549558
}
550559
: {}),

0 commit comments

Comments
 (0)