MCPcopy Create free account
hub / github.com/Gan-Xing/CodexBridge / makeFakeCodexAuthManager

Function makeFakeCodexAuthManager

test/core/bridge_coordinator.test.ts:910–1012  ·  view source on GitHub ↗
({
  accounts = [],
  activeAccountId = null,
  pendingLogin = null,
  refreshResults = [],
  startError = null,
} = {})

Source from the content-addressed store, hash-verified

908}
909
910function makeFakeCodexAuthManager({
911 accounts = [],
912 activeAccountId = null,
913 pendingLogin = null,
914 refreshResults = [],
915 startError = null,
916} = {}) {
917 const state = {
918 accounts: accounts.map((account) => ({ ...account })),
919 activeAccountId,
920 pendingLogin: pendingLogin ? { ...pendingLogin } : null,
921 refreshResults: [...refreshResults],
922 };
923 const startCalls = [];
924 const switchCalls = [];
925 const cancelCalls = [];
926
927 const decorateAccount = (account) => ({
928 ...account,
929 isActive: state.activeAccountId === account.id,
930 });
931
932 return {
933 state,
934 startCalls,
935 switchCalls,
936 cancelCalls,
937 async startDeviceLogin(params: { requestedByScope?: string | null } = {}) {
938 startCalls.push(params);
939 if (startError) {
940 throw startError;
941 }
942 if (!state.pendingLogin) {
943 state.pendingLogin = {
944 flowId: 'flow-1',
945 verificationUriComplete: 'https://auth.openai.com/activate?user_code=ABCD-EFGH',
946 verificationUri: 'https://auth.openai.com/activate',
947 userCode: 'ABCD-EFGH',
948 expiresAt: Date.now() + 15 * 60_000,
949 requestedByScope: params.requestedByScope ?? null,
950 };
951 } else {
952 state.pendingLogin = {
953 ...state.pendingLogin,
954 requestedByScope: params.requestedByScope ?? state.pendingLogin.requestedByScope ?? null,
955 };
956 }
957 return { ...state.pendingLogin };
958 },
959 async refreshPendingLogin() {
960 if (state.refreshResults.length > 0) {
961 const next = state.refreshResults.shift();
962 if (next?.status === 'completed' && next.account) {
963 const existingIndex = state.accounts.findIndex((account) => account.id === next.account.id);
964 if (existingIndex >= 0) {
965 state.accounts[existingIndex] = { ...next.account };
966 } else {
967 state.accounts.push({ ...next.account });

Callers 1

Calls

no outgoing calls

Tested by

no test coverage detected