Skip to content

Commit bdeb3b5

Browse files
committed
fix(web): hide deleted providers with prototype keys
1 parent a3a8cbd commit bdeb3b5

2 files changed

Lines changed: 83 additions & 6 deletions

File tree

‎apps/web/src/providerInstances.test.ts‎

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,77 @@ describe("applyProviderInstanceSettings", () => {
119119

120120
expect(entry?.enabled).toBe(false);
121121
});
122+
123+
it.each(["constructor", "toString"])(
124+
"treats a removed custom instance named %s as disabled",
125+
(instanceId) => {
126+
const entries = deriveProviderInstanceEntries([
127+
provider({
128+
provider: ProviderDriverKind.make("claudeAgent"),
129+
instanceId,
130+
}),
131+
]);
132+
const [entry] = applyProviderInstanceSettings(entries, {
133+
providerInstances: {},
134+
providers: {} as never,
135+
});
136+
137+
expect(entry?.enabled).toBe(false);
138+
},
139+
);
140+
141+
it("uses settings for a configured custom instance named constructor", () => {
142+
const instanceId = ProviderInstanceId.make("constructor");
143+
const entries = deriveProviderInstanceEntries([
144+
provider({
145+
provider: ProviderDriverKind.make("claudeAgent"),
146+
instanceId,
147+
}),
148+
]);
149+
const [entry] = applyProviderInstanceSettings(entries, {
150+
providerInstances: {
151+
[instanceId]: {
152+
driver: ProviderDriverKind.make("claudeAgent"),
153+
enabled: false,
154+
},
155+
},
156+
providers: {} as never,
157+
});
158+
159+
expect(entry?.enabled).toBe(false);
160+
});
161+
162+
it("treats a removed default instance for a fork driver as disabled", () => {
163+
const driver = ProviderDriverKind.make("constructor");
164+
const entries = deriveProviderInstanceEntries([
165+
provider({
166+
provider: driver,
167+
instanceId: "constructor",
168+
}),
169+
]);
170+
const [entry] = applyProviderInstanceSettings(entries, {
171+
providerInstances: {},
172+
providers: {} as never,
173+
});
174+
175+
expect(entry?.isDefault).toBe(true);
176+
expect(entry?.enabled).toBe(false);
177+
});
178+
179+
it("uses legacy settings for a built-in default instance", () => {
180+
const entries = deriveProviderInstanceEntries([
181+
provider({
182+
provider: ProviderDriverKind.make("codex"),
183+
instanceId: "codex",
184+
}),
185+
]);
186+
const [entry] = applyProviderInstanceSettings(entries, {
187+
providerInstances: {},
188+
providers: { codex: { enabled: false } } as never,
189+
});
190+
191+
expect(entry?.enabled).toBe(false);
192+
});
122193
});
123194

124195
describe("deriveProviderInstanceEntries", () => {

‎apps/web/src/providerInstances.ts‎

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -233,9 +233,10 @@ export function deriveProviderEntriesByEnvironment(
233233
* settings write, so picker visibility must follow settings rather than waiting
234234
* for probe reconciliation.
235235
*
236-
* Non-default instances only exist through `providerInstances`; if one is
237-
* absent there, its streamed snapshot is stale (for example immediately after
238-
* deletion) and is treated as disabled.
236+
* Only built-in default instances have a legacy `providers` entry. Every
237+
* other instance exists through `providerInstances`; if it is absent there,
238+
* its streamed snapshot is stale (for example immediately after deletion)
239+
* and is treated as disabled.
239240
*/
240241
export function applyProviderInstanceSettings(
241242
entries: ReadonlyArray<ProviderInstanceEntry>,
@@ -246,11 +247,16 @@ export function applyProviderInstanceSettings(
246247
>;
247248

248249
return entries.map((entry) => {
249-
const explicitInstance = settings.providerInstances?.[entry.instanceId];
250+
const explicitInstance = Object.hasOwn(settings.providerInstances, entry.instanceId)
251+
? settings.providerInstances[entry.instanceId]
252+
: undefined;
253+
const legacyProvider = Object.hasOwn(legacyProviders, entry.driverKind)
254+
? legacyProviders[entry.driverKind]
255+
: undefined;
250256
const enabled = explicitInstance
251257
? resolveProviderInstanceEnabled(explicitInstance)
252-
: entry.isDefault
253-
? (legacyProviders[entry.driverKind]?.enabled ?? entry.enabled)
258+
: entry.isDefault && legacyProvider
259+
? (legacyProvider.enabled ?? entry.enabled)
254260
: false;
255261
return enabled === entry.enabled ? entry : { ...entry, enabled };
256262
});

0 commit comments

Comments
 (0)