Skip to content

Commit ede4db3

Browse files
committed
Keep footer config synced across runtime refreshes
1 parent 0577c35 commit ede4db3

2 files changed

Lines changed: 44 additions & 6 deletions

File tree

index.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2075,9 +2075,6 @@ export const OpenAIOAuthPlugin: Plugin = async ({ client }: PluginInput) => {
20752075
const unsupportedCodexFallbackChain =
20762076
getUnsupportedCodexFallbackChain(pluginConfig);
20772077
const toastDurationMs = getToastDurationMs(pluginConfig);
2078-
const persistAccountFooter = getPersistAccountFooter(pluginConfig);
2079-
const persistAccountFooterStyle =
2080-
getPersistAccountFooterStyle(pluginConfig);
20812078
const fetchTimeoutMs = getFetchTimeoutMs(pluginConfig);
20822079
const streamStallTimeoutMs = getStreamStallTimeoutMs(pluginConfig);
20832080

@@ -2176,6 +2173,9 @@ export const OpenAIOAuthPlugin: Plugin = async ({ client }: PluginInput) => {
21762173
init?: RequestInit,
21772174
): Promise<Response> {
21782175
try {
2176+
// Keep request-time toast behavior and later account.switch refreshes
2177+
// aligned with the latest config/env snapshot.
2178+
syncRuntimePluginConfig(loadPluginConfig());
21792179
if (cachedAccountManager && cachedAccountManager !== accountManager) {
21802180
accountManager = cachedAccountManager;
21812181
}
@@ -2506,7 +2506,7 @@ while (attempted.size < Math.max(1, accountCount)) {
25062506
extractAccountEmail(accountAuth.access) ?? account.email;
25072507

25082508
if (
2509-
!persistAccountFooter &&
2509+
!runtimePersistAccountFooter &&
25102510
accountCount > 1 &&
25112511
accountManager.shouldShowAccountToast(
25122512
account.index,
@@ -2886,7 +2886,7 @@ while (attempted.size < Math.max(1, accountCount)) {
28862886
}
28872887

28882888
accountManager.recordSuccess(account, modelFamily, model);
2889-
if (persistAccountFooter) {
2889+
if (runtimePersistAccountFooter) {
28902890
const liveAccountCount = accountManager.getAccountCount();
28912891
const persistedAccountCount =
28922892
liveAccountCount > 0
@@ -2899,7 +2899,7 @@ while (attempted.size < Math.max(1, accountCount)) {
28992899
account,
29002900
account.index,
29012901
persistedAccountCount,
2902-
persistAccountFooterStyle,
2902+
runtimePersistAccountFooterStyle,
29032903
indicatorRevision,
29042904
);
29052905
}

test/index.test.ts

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2405,6 +2405,44 @@ describe("OpenAIOAuthPlugin fetch handler", () => {
24052405
);
24062406
});
24072407

2408+
it("syncs account-switch footer behavior after a runtime config refresh enables it", async () => {
2409+
await disablePersistedFooter();
2410+
mockStorage.accounts = [
2411+
{ accountId: "acc-1", email: "user@example.com", refreshToken: "refresh-token" },
2412+
{ accountId: "acc-2", email: "user2@example.com", refreshToken: "refresh-2" },
2413+
];
2414+
2415+
const { plugin, sdk, mockClient } = await setupPlugin();
2416+
2417+
await enablePersistedFooter("full-email");
2418+
await plugin.auth.loader(
2419+
async () => ({
2420+
type: "oauth" as const,
2421+
access: "access-token",
2422+
refresh: "refresh-token",
2423+
expires: Date.now() + 60_000,
2424+
multiAccount: true,
2425+
}),
2426+
{ options: {}, models: {} },
2427+
);
2428+
await sendPersistedAccountRequest(sdk, "session-switch-sync");
2429+
mockClient.tui.showToast.mockClear();
2430+
2431+
await plugin.event({
2432+
event: { type: "account.select", properties: { index: 1 } },
2433+
});
2434+
2435+
expect(mockClient.tui.showToast).not.toHaveBeenCalledWith({
2436+
body: {
2437+
message: "Switched to account 2",
2438+
variant: "info",
2439+
},
2440+
});
2441+
expect(
2442+
(await readPersistedAccountIndicator(plugin, "session-switch-sync")).variant,
2443+
).toBe("user2@example.com [2/2]");
2444+
});
2445+
24082446
it("shows the account-switch info toast when the footer is disabled", async () => {
24092447
await disablePersistedFooter();
24102448
mockStorage.accounts = [

0 commit comments

Comments
 (0)