Skip to content

Commit 534f795

Browse files
committed
refactor: extract account storage scope wrapper
1 parent 5b7e95d commit 534f795

3 files changed

Lines changed: 91 additions & 1 deletion

File tree

index.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -207,6 +207,7 @@ import {
207207
getRateLimitResetTimeForFamily,
208208
resolveActiveIndex,
209209
} from "./lib/runtime/account-status.js";
210+
import { applyAccountStorageScopeEntry } from "./lib/runtime/account-storage-scope-entry.js";
210211
import { runBrowserOAuthFlow } from "./lib/runtime/browser-oauth-flow.js";
211212
import { handleRuntimeEvent } from "./lib/runtime/event-handler.js";
212213
import { ensureLiveAccountSyncEntry } from "./lib/runtime/live-sync-entry.js";
@@ -544,7 +545,8 @@ export const OpenAIOAuthPlugin: Plugin = async ({ client }: PluginInput) => {
544545
const applyAccountStorageScope = (
545546
pluginConfig: ReturnType<typeof loadPluginConfig>,
546547
): void =>
547-
applyAccountStorageScopeFromConfig(pluginConfig, {
548+
applyAccountStorageScopeEntry({
549+
pluginConfig,
548550
getPerProjectAccounts,
549551
getStorageBackupEnabled,
550552
setStorageBackupEnabled,
@@ -557,6 +559,7 @@ export const OpenAIOAuthPlugin: Plugin = async ({ client }: PluginInput) => {
557559
pluginName: PLUGIN_NAME,
558560
setStoragePath,
559561
cwd: () => process.cwd(),
562+
applyAccountStorageScopeFromConfig,
560563
});
561564

562565
const ensureLiveAccountSync = async (
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
export function applyAccountStorageScopeEntry(params: {
2+
pluginConfig: ReturnType<typeof import("../config.js").loadPluginConfig>;
3+
getPerProjectAccounts: (
4+
config: ReturnType<typeof import("../config.js").loadPluginConfig>,
5+
) => boolean;
6+
getStorageBackupEnabled: (
7+
config: ReturnType<typeof import("../config.js").loadPluginConfig>,
8+
) => boolean;
9+
setStorageBackupEnabled: (enabled: boolean) => void;
10+
isCodexCliSyncEnabled: () => boolean;
11+
getWarningShown: () => boolean;
12+
setWarningShown: (shown: boolean) => void;
13+
logWarn: (message: string) => void;
14+
pluginName: string;
15+
setStoragePath: (path: string | null) => void;
16+
cwd: () => string;
17+
applyAccountStorageScopeFromConfig: (
18+
pluginConfig: ReturnType<typeof import("../config.js").loadPluginConfig>,
19+
deps: {
20+
getPerProjectAccounts: (
21+
config: ReturnType<typeof import("../config.js").loadPluginConfig>,
22+
) => boolean;
23+
getStorageBackupEnabled: (
24+
config: ReturnType<typeof import("../config.js").loadPluginConfig>,
25+
) => boolean;
26+
setStorageBackupEnabled: (enabled: boolean) => void;
27+
isCodexCliSyncEnabled: () => boolean;
28+
getWarningShown: () => boolean;
29+
setWarningShown: (shown: boolean) => void;
30+
logWarn: (message: string) => void;
31+
pluginName: string;
32+
setStoragePath: (path: string | null) => void;
33+
cwd: () => string;
34+
},
35+
) => void;
36+
}): void {
37+
params.applyAccountStorageScopeFromConfig(params.pluginConfig, {
38+
getPerProjectAccounts: params.getPerProjectAccounts,
39+
getStorageBackupEnabled: params.getStorageBackupEnabled,
40+
setStorageBackupEnabled: params.setStorageBackupEnabled,
41+
isCodexCliSyncEnabled: params.isCodexCliSyncEnabled,
42+
getWarningShown: params.getWarningShown,
43+
setWarningShown: params.setWarningShown,
44+
logWarn: params.logWarn,
45+
pluginName: params.pluginName,
46+
setStoragePath: params.setStoragePath,
47+
cwd: params.cwd,
48+
});
49+
}
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
import { describe, expect, it, vi } from "vitest";
2+
import { applyAccountStorageScopeEntry } from "../lib/runtime/account-storage-scope-entry.js";
3+
4+
describe("account storage scope entry", () => {
5+
it("delegates to the config-based storage scope helper with all injected deps", () => {
6+
const applyAccountStorageScopeFromConfig = vi.fn();
7+
applyAccountStorageScopeEntry({
8+
pluginConfig: {} as never,
9+
getPerProjectAccounts: vi.fn(() => true),
10+
getStorageBackupEnabled: vi.fn(() => true),
11+
setStorageBackupEnabled: vi.fn(),
12+
isCodexCliSyncEnabled: vi.fn(() => false),
13+
getWarningShown: vi.fn(() => false),
14+
setWarningShown: vi.fn(),
15+
logWarn: vi.fn(),
16+
pluginName: "plugin",
17+
setStoragePath: vi.fn(),
18+
cwd: vi.fn(() => "/tmp/project"),
19+
applyAccountStorageScopeFromConfig,
20+
});
21+
22+
expect(applyAccountStorageScopeFromConfig).toHaveBeenCalledWith(
23+
expect.anything(),
24+
expect.objectContaining({
25+
getPerProjectAccounts: expect.any(Function),
26+
getStorageBackupEnabled: expect.any(Function),
27+
setStorageBackupEnabled: expect.any(Function),
28+
isCodexCliSyncEnabled: expect.any(Function),
29+
getWarningShown: expect.any(Function),
30+
setWarningShown: expect.any(Function),
31+
logWarn: expect.any(Function),
32+
pluginName: "plugin",
33+
setStoragePath: expect.any(Function),
34+
cwd: expect.any(Function),
35+
}),
36+
);
37+
});
38+
});

0 commit comments

Comments
 (0)