mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-05 08:21:43 +00:00
refactor(extensions): dedupe channel config, onboarding, and monitors
This commit is contained in:
@@ -273,6 +273,36 @@ describe("loginGeminiCliOAuth", () => {
|
||||
});
|
||||
}
|
||||
|
||||
async function runRemoteLoginWithCapturedAuthUrl(
|
||||
loginGeminiCliOAuth: (options: {
|
||||
isRemote: boolean;
|
||||
openUrl: () => Promise<void>;
|
||||
log: (msg: string) => void;
|
||||
note: () => Promise<void>;
|
||||
prompt: () => Promise<string>;
|
||||
progress: { update: () => void; stop: () => void };
|
||||
}) => Promise<{ projectId: string }>,
|
||||
) {
|
||||
let authUrl = "";
|
||||
const result = await loginGeminiCliOAuth({
|
||||
isRemote: true,
|
||||
openUrl: async () => {},
|
||||
log: (msg) => {
|
||||
const found = msg.match(/https:\/\/accounts\.google\.com\/o\/oauth2\/v2\/auth\?[^\s]+/);
|
||||
if (found?.[0]) {
|
||||
authUrl = found[0];
|
||||
}
|
||||
},
|
||||
note: async () => {},
|
||||
prompt: async () => {
|
||||
const state = new URL(authUrl).searchParams.get("state");
|
||||
return `${"http://localhost:8085/oauth2callback"}?code=oauth-code&state=${state}`;
|
||||
},
|
||||
progress: { update: () => {}, stop: () => {} },
|
||||
});
|
||||
return { result, authUrl };
|
||||
}
|
||||
|
||||
let envSnapshot: Partial<Record<(typeof ENV_KEYS)[number], string>>;
|
||||
beforeEach(() => {
|
||||
envSnapshot = Object.fromEntries(ENV_KEYS.map((key) => [key, process.env[key]]));
|
||||
@@ -325,24 +355,8 @@ describe("loginGeminiCliOAuth", () => {
|
||||
});
|
||||
vi.stubGlobal("fetch", fetchMock);
|
||||
|
||||
let authUrl = "";
|
||||
const { loginGeminiCliOAuth } = await import("./oauth.js");
|
||||
const result = await loginGeminiCliOAuth({
|
||||
isRemote: true,
|
||||
openUrl: async () => {},
|
||||
log: (msg) => {
|
||||
const found = msg.match(/https:\/\/accounts\.google\.com\/o\/oauth2\/v2\/auth\?[^\s]+/);
|
||||
if (found?.[0]) {
|
||||
authUrl = found[0];
|
||||
}
|
||||
},
|
||||
note: async () => {},
|
||||
prompt: async () => {
|
||||
const state = new URL(authUrl).searchParams.get("state");
|
||||
return `${"http://localhost:8085/oauth2callback"}?code=oauth-code&state=${state}`;
|
||||
},
|
||||
progress: { update: () => {}, stop: () => {} },
|
||||
});
|
||||
const { result } = await runRemoteLoginWithCapturedAuthUrl(loginGeminiCliOAuth);
|
||||
|
||||
expect(result.projectId).toBe("daily-project");
|
||||
const loadRequests = requests.filter((request) =>
|
||||
@@ -398,24 +412,8 @@ describe("loginGeminiCliOAuth", () => {
|
||||
});
|
||||
vi.stubGlobal("fetch", fetchMock);
|
||||
|
||||
let authUrl = "";
|
||||
const { loginGeminiCliOAuth } = await import("./oauth.js");
|
||||
const result = await loginGeminiCliOAuth({
|
||||
isRemote: true,
|
||||
openUrl: async () => {},
|
||||
log: (msg) => {
|
||||
const found = msg.match(/https:\/\/accounts\.google\.com\/o\/oauth2\/v2\/auth\?[^\s]+/);
|
||||
if (found?.[0]) {
|
||||
authUrl = found[0];
|
||||
}
|
||||
},
|
||||
note: async () => {},
|
||||
prompt: async () => {
|
||||
const state = new URL(authUrl).searchParams.get("state");
|
||||
return `${"http://localhost:8085/oauth2callback"}?code=oauth-code&state=${state}`;
|
||||
},
|
||||
progress: { update: () => {}, stop: () => {} },
|
||||
});
|
||||
const { result } = await runRemoteLoginWithCapturedAuthUrl(loginGeminiCliOAuth);
|
||||
|
||||
expect(result.projectId).toBe("env-project");
|
||||
expect(requests.filter((url) => url.includes("v1internal:loadCodeAssist"))).toHaveLength(3);
|
||||
|
||||
Reference in New Issue
Block a user