Skip to content

Commit da38aae

Browse files
committed
Merge remote-tracking branch 'upstream/main' into fix/claude-textgen-error-list
2 parents 272e6bd + bff68fb commit da38aae

4 files changed

Lines changed: 50 additions & 6 deletions

File tree

‎apps/web/src/components/settings/SourceControlAppSignInSettings.tsx‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,7 @@ export function SourceControlAppSignInSettings({
171171
/>
172172
</span>
173173
) : tokenOverrides ? (
174-
"Signed in, but the token saved below is used until you remove it."
174+
"Signed in, but the token saved below is used while it can be read."
175175
) : (
176176
"Signed in"
177177
);

‎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: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,24 @@ describe("serverSettings helpers", () => {
127127
});
128128
});
129129

130+
it("keeps a source control host's saved tokens when a patch sets another host's token", () => {
131+
const reference = { provider: "vault", reference: "github/token" };
132+
const saved = applyServerSettingsPatch(DEFAULT_SERVER_SETTINGS, {
133+
sourceControlHosts: { github: { tokens: { "github.com": reference } } },
134+
});
135+
const patched = applyServerSettingsPatch(saved, {
136+
sourceControlHosts: { github: { tokens: { "ghe.example": "x" } } },
137+
});
138+
expect(patched.sourceControlHosts.github?.tokens).toEqual({
139+
"github.com": reference,
140+
"ghe.example": "x",
141+
});
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" });
146+
});
147+
130148
it("inherits actions, preserves existing actions, and supports empty overrides and reset", () => {
131149
const project = { id: ProjectId.make("project-actions"), scripts: [] };
132150
const action = {

‎packages/shared/src/serverSettings.ts‎

Lines changed: 30 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ import {
2323
withIdleCompaction,
2424
} from "@t3tools/contracts";
2525
import * as Option from "effect/Option";
26+
import * as Predicate from "effect/Predicate";
2627
import * as Schema from "effect/Schema";
2728
import { deepMerge } from "./Struct.ts";
2829
import { fromLenientJson } from "./schemaJson.ts";
@@ -226,6 +227,15 @@ function mergeSettingsEntries<Value>(
226227
return Object.fromEntries(next);
227228
}
228229

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+
229239
const knownProjectOverrideKeys = new Set(Object.keys(ProjectSettingsOverrides.fields));
230240

231241
function pickOverrideKeys(entry: ProjectSettingsOverrides | undefined, known: boolean) {
@@ -530,10 +540,26 @@ export function applyServerSettingsPatch(
530540
sourceControlHosts: {
531541
...current.sourceControlHosts,
532542
...Object.fromEntries(
533-
Object.entries(sourceControlHostsPatch).map(([kind, fields]) => [
534-
kind,
535-
{ ...current.sourceControlHosts[kind], ...fields },
536-
]),
543+
Object.entries(sourceControlHostsPatch).map(([kind, fields]) => {
544+
const saved = current.sourceControlHosts[kind];
545+
return [
546+
kind,
547+
{
548+
...saved,
549+
...fields,
550+
// Older clients send the whole token map; a host missing from it keeps its saved
551+
// token. An empty map still clears them all.
552+
...(Predicate.isObject(fields.tokens) && Object.keys(fields.tokens).length > 0
553+
? {
554+
tokens: {
555+
...byHost(saved?.tokens),
556+
...byHost(fields.tokens),
557+
},
558+
}
559+
: {}),
560+
},
561+
];
562+
}),
537563
),
538564
},
539565
}

0 commit comments

Comments
 (0)