Skip to content

Commit 0ec48a5

Browse files
committed
fix(web): wait for connection before updating providers
1 parent 74541ba commit 0ec48a5

4 files changed

Lines changed: 44 additions & 8 deletions

‎apps/web/src/components/ProviderUpdateLaunchNotification.environments.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ export function useLocalEnvironmentUpdateGroups(): {
6464
})
6565
: environment.label,
6666
isPrimary,
67-
connectionState: isPrimary ? "ready" : normalizeConnectionState(environment.connection.phase),
67+
connectionState: normalizeConnectionState(environment.connection.phase),
6868
providers: providersByEnvironment.get(environment.environmentId) ?? [],
6969
});
7070
}

‎apps/web/src/components/ProviderUpdateLaunchNotification.logic.test.ts‎

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import {
2020
hasOneClickUpdateProviderCandidate,
2121
isProviderUpdateCandidate,
2222
isProviderSettingsUpdateCandidate,
23+
localEnvironmentUpdateNotificationKey,
2324
providerUpdateNotificationKey,
2425
resolveEnvironmentUpdateRowStatus,
2526
type LocalEnvironmentProvidersInput,
@@ -445,6 +446,27 @@ describe("provider update launch notification logic", () => {
445446
?.isSettling,
446447
).toBe(true);
447448
});
449+
450+
it("waits for a connection before offering cached provider updates", () => {
451+
const cachedProvider = provider({ driver: driver("codex") });
452+
const primary = environment({
453+
environmentId: "env-cached",
454+
isPrimary: true,
455+
connectionState: "connecting",
456+
providers: [cachedProvider],
457+
});
458+
const waiting = buildLocalEnvironmentUpdateGroups([primary]);
459+
expect(waiting.groups[0]?.candidates).toEqual([]);
460+
expect(localEnvironmentUpdateNotificationKey(waiting.groups)).toBeNull();
461+
462+
const connected = buildLocalEnvironmentUpdateGroups([
463+
{ ...primary, connectionState: "ready" },
464+
]);
465+
expect(connected.groups[0]?.candidates).toEqual([cachedProvider]);
466+
expect(localEnvironmentUpdateNotificationKey(connected.groups)).toBe(
467+
"env-cached=codex:1.1.0",
468+
);
469+
});
448470
});
449471

450472
describe("resolveEnvironmentUpdateRowStatus", () => {

‎apps/web/src/components/ProviderUpdateLaunchNotification.logic.ts‎

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -749,9 +749,12 @@ export function buildLocalEnvironmentUpdateGroups(
749749
label: environment.label,
750750
isPrimary: environment.isPrimary,
751751
isSettling: environment.connectionState === "connecting",
752-
candidates: collectProviderUpdateCandidates(environment.providers).filter((candidate) =>
753-
canOneClickUpdateProviderCandidate(candidate, environment.providers),
754-
),
752+
candidates:
753+
environment.connectionState === "ready"
754+
? collectProviderUpdateCandidates(environment.providers).filter((candidate) =>
755+
canOneClickUpdateProviderCandidate(candidate, environment.providers),
756+
)
757+
: [],
755758
providers: environment.providers,
756759
}));
757760
const isAnySettling = environments.some(

‎apps/web/src/components/ProviderUpdatePrimaryNotification.tsx‎

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ type ActiveProviderUpdateToast =
3737
readonly key: string;
3838
readonly toastId: ProviderUpdateToastId;
3939
readonly canManageProviders: boolean;
40+
readonly canUpdateProviders: boolean;
4041
}
4142
| {
4243
readonly kind: "update";
@@ -109,6 +110,8 @@ export function ProviderUpdatePrimaryNotification() {
109110
primaryEnvironment?.environmentId ?? null,
110111
AuthProvidersManageScope,
111112
);
113+
const canUpdateProviders =
114+
canManageProviders && primaryEnvironment?.connection.phase === "connected";
112115
const updateProvider = useAtomCommand(serverEnvironment.updateProvider, {
113116
reportFailure: false,
114117
});
@@ -179,7 +182,8 @@ export function ProviderUpdatePrimaryNotification() {
179182
const updateExistingPrompt =
180183
activeToast?.kind === "prompt" &&
181184
activeToast.key === notificationKey &&
182-
activeToast.canManageProviders !== canManageProviders;
185+
(activeToast.canManageProviders !== canManageProviders ||
186+
activeToast.canUpdateProviders !== canUpdateProviders);
183187
if (
184188
!notificationKey ||
185189
dismissedNotificationKeys.has(notificationKey) ||
@@ -204,7 +208,7 @@ export function ProviderUpdatePrimaryNotification() {
204208
if (
205209
updateStarted ||
206210
oneClickProviders.length === 0 ||
207-
!primaryEnvironment ||
211+
primaryEnvironment?.connection.phase !== "connected" ||
208212
!readEnvironmentScope(primaryEnvironment.environmentId, AuthProvidersManageScope)
209213
) {
210214
return;
@@ -291,7 +295,7 @@ export function ProviderUpdatePrimaryNotification() {
291295
oneClickProviders.length > 0
292296
? {
293297
children: "Update",
294-
disabled: !canManageProviders,
298+
disabled: !canUpdateProviders,
295299
onClick: runUpdates,
296300
}
297301
: {
@@ -323,9 +327,16 @@ export function ProviderUpdatePrimaryNotification() {
323327
} else {
324328
toastId = toastManager.add(toastOptions);
325329
}
326-
activeToastRef.current = { kind: "prompt", key: notificationKey, toastId, canManageProviders };
330+
activeToastRef.current = {
331+
kind: "prompt",
332+
key: notificationKey,
333+
toastId,
334+
canManageProviders,
335+
canUpdateProviders,
336+
};
327337
}, [
328338
canManageProviders,
339+
canUpdateProviders,
329340
updateProvider,
330341
dismissNotificationKey,
331342
dismissedNotificationKeys,

0 commit comments

Comments
 (0)