Skip to content

Commit 0adeebd

Browse files
committed
test(runtime): add workspace helpers to routing mocks
1 parent 1ad09d4 commit 0adeebd

1 file changed

Lines changed: 21 additions & 0 deletions

File tree

test/index.test.ts

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -354,6 +354,15 @@ vi.mock("../lib/accounts.js", async () => {
354354
return this.accounts[0] ?? null;
355355
}
356356

357+
getCurrentWorkspace(account: Record<string, unknown>) {
358+
const workspaces = Array.isArray(account.workspaces) ? account.workspaces : [];
359+
const currentWorkspaceIndex =
360+
typeof account.currentWorkspaceIndex === "number"
361+
? account.currentWorkspaceIndex
362+
: 0;
363+
return workspaces[currentWorkspaceIndex] ?? null;
364+
}
365+
357366
recordSuccess() {}
358367
recordRateLimit() {}
359368
recordFailure() {}
@@ -1198,6 +1207,17 @@ describe("OpenAIOAuthPlugin fetch handler", () => {
11981207
getAccountCount: () => accounts.length,
11991208
getCurrentOrNextForFamilyHybrid: () => accounts[selection++] ?? null,
12001209
getCurrentOrNextForFamily: () => accounts[selection++] ?? null,
1210+
getCurrentWorkspace: (account: {
1211+
workspaces?: Array<{ id: string; name?: string; enabled?: boolean }>;
1212+
currentWorkspaceIndex?: number;
1213+
}) => {
1214+
const workspaces = Array.isArray(account.workspaces) ? account.workspaces : [];
1215+
const currentWorkspaceIndex =
1216+
typeof account.currentWorkspaceIndex === "number"
1217+
? account.currentWorkspaceIndex
1218+
: 0;
1219+
return workspaces[currentWorkspaceIndex] ?? null;
1220+
},
12011221
getAccountByIndex: (index: number) => accounts[index] ?? null,
12021222
getAccountsSnapshot: () => accounts,
12031223
isAccountAvailableForFamily: (index: number) => Boolean(accounts[index]),
@@ -2243,6 +2263,7 @@ describe("OpenAIOAuthPlugin fetch handler", () => {
22432263
recordRateLimit: () => {},
22442264
consumeToken: () => true,
22452265
refundToken: () => {},
2266+
getCurrentWorkspace: () => null,
22462267
syncCodexCliActiveSelectionForIndex: async () => {},
22472268
markSwitched: () => {},
22482269
removeAccount: () => {},

0 commit comments

Comments
 (0)