





















@@ -104,7 +104,13 @@ describe("google gemini cli backend auth bridge", () => {
104104await fs.writeFile(
105105inheritedSettingsPath,
106106`${JSON.stringify({
107- security: { auth: { selectedType: "vertex-ai" } },
107+ security: {
108+ auth: {
109+ selectedType: "vertex-ai",
110+ enforcedType: "oauth-personal",
111+ useExternal: true,
112+ },
113+ },
108114 mcp: { allowed: ["openclaw"] },
109115 mcpServers: { openclaw: { url: "http://127.0.0.1:23119/mcp" } },
110116 })}\n`,
@@ -148,7 +154,13 @@ describe("google gemini cli backend auth bridge", () => {
148154expect(JSON.parse(rootSettingsRaw)).toEqual(JSON.parse(nestedSettingsRaw));
149155const systemSettingsRaw = await fs.readFile(systemSettingsPath ?? "", "utf8");
150156expect(JSON.parse(systemSettingsRaw)).toEqual({
151-security: { auth: { selectedType: "oauth-personal" } },
157+security: {
158+auth: {
159+selectedType: "oauth-personal",
160+enforcedType: "oauth-personal",
161+useExternal: true,
162+},
163+},
152164mcp: { allowed: ["openclaw"] },
153165mcpServers: { openclaw: { url: "http://127.0.0.1:23119/mcp" } },
154166});
@@ -229,6 +241,76 @@ describe("google gemini cli backend auth bridge", () => {
229241}
230242});
231243244+it("rejects inherited Gemini system settings that enforce a different auth type", async () => {
245+const backend = buildGoogleGeminiCliBackend();
246+const workspaceDir = await fs.mkdtemp(path.join(os.tmpdir(), "openclaw-test-workspace-"));
247+248+try {
249+const inheritedSettingsPath = path.join(workspaceDir, "generated-mcp-settings.json");
250+await fs.writeFile(
251+inheritedSettingsPath,
252+`${JSON.stringify({
253+ security: { auth: { enforcedType: "gemini-api-key" } },
254+ })}\n`,
255+"utf8",
256+);
257+const context = buildGeminiOAuthPrepareContext(workspaceDir);
258+context.env = { GEMINI_CLI_SYSTEM_SETTINGS_PATH: inheritedSettingsPath };
259+260+await expect(backend.prepareExecution?.(context)).rejects.toThrow(/enforce gemini-api-key/);
261+} finally {
262+await fs.rm(workspaceDir, { recursive: true, force: true });
263+}
264+});
265+266+it("inherits process Gemini system settings when no generated settings path is present", async () => {
267+const backend = buildGoogleGeminiCliBackend();
268+const workspaceDir = await fs.mkdtemp(path.join(os.tmpdir(), "openclaw-test-workspace-"));
269+const originalSystemSettingsPath = process.env.GEMINI_CLI_SYSTEM_SETTINGS_PATH;
270+let prepared:
271+| Awaited<ReturnType<NonNullable<typeof backend.prepareExecution>>>
272+| null
273+| undefined;
274+275+try {
276+const inheritedSettingsPath = path.join(workspaceDir, "ambient-system-settings.json");
277+await fs.writeFile(
278+inheritedSettingsPath,
279+`${JSON.stringify({
280+ security: {
281+ auth: {
282+ selectedType: "oauth-code-assist",
283+ enforcedType: "oauth-personal",
284+ },
285+ folderTrust: { enabled: true },
286+ },
287+ })}\n`,
288+"utf8",
289+);
290+process.env.GEMINI_CLI_SYSTEM_SETTINGS_PATH = inheritedSettingsPath;
291+292+prepared = await backend.prepareExecution?.(buildGeminiOAuthPrepareContext(workspaceDir));
293+294+const systemSettingsRaw = await fs.readFile(
295+prepared?.env?.GEMINI_CLI_SYSTEM_SETTINGS_PATH ?? "",
296+"utf8",
297+);
298+expect(JSON.parse(systemSettingsRaw)).toEqual({
299+security: {
300+auth: {
301+selectedType: "oauth-personal",
302+enforcedType: "oauth-personal",
303+},
304+folderTrust: { enabled: true },
305+},
306+});
307+} finally {
308+restoreEnv("GEMINI_CLI_SYSTEM_SETTINGS_PATH", originalSystemSettingsPath);
309+await prepared?.cleanup?.();
310+await fs.rm(workspaceDir, { recursive: true, force: true });
311+}
312+});
313+232314it("rejects Vercel AI Gateway profiles for the Gemini CLI backend", async () => {
233315const backend = buildGoogleGeminiCliBackend();
234316const workspaceDir = await fs.mkdtemp(path.join(os.tmpdir(), "openclaw-test-workspace-"));
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。