惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

H
Help Net Security
爱范儿
爱范儿
V
Visual Studio Blog
Last Week in AI
Last Week in AI
阮一峰的网络日志
阮一峰的网络日志
雷峰网
雷峰网
Hugging Face - Blog
Hugging Face - Blog
博客园 - 【当耐特】
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
博客园 - 三生石上(FineUI控件)
博客园 - Franky
博客园 - 叶小钗
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
The Cloudflare Blog
大猫的无限游戏
大猫的无限游戏
人人都是产品经理
人人都是产品经理
M
MIT News - Artificial intelligence
罗磊的独立博客
L
LangChain Blog
Jina AI
Jina AI
IT之家
IT之家
J
Java Code Geeks
Microsoft Azure Blog
Microsoft Azure Blog
博客园_首页

Recent Commits to openclaw:main

test: merge chat side-result checks · openclaw/openclaw@ddd2c2a test: merge cron history checks · openclaw/openclaw@f7eb746 test: merge responsive navigation shell checks · openclaw/openclaw@c2e4b47 docs(changelog): add codex oauth fixes · openclaw/openclaw@628e6cd test: merge navigation routing cases · openclaw/openclaw@5d8cecb Tests: mock channel registry bundled fallback · openclaw/openclaw@2b08233 Secrets: avoid broad web search discovery for single plugin config · openclaw/openclaw@a464f59 test: merge config view browser checks · openclaw/openclaw@20cf511 fix(status): align oauth health with runtime · openclaw/openclaw@eed7116 feat: add macOS screen snapshots for monitor preview (#67954) thanks … · openclaw/openclaw@f377db1 fix: report shared auth scopes in hello-ok (#67810) thanks @BunsDev · openclaw/openclaw@0b6c39b Auto-reply: avoid eager bundled route fallback · openclaw/openclaw@3ea1bf4 Tests: narrow session binding contract setup · openclaw/openclaw@54e4e16 fix(macOS): enable undo/redo in webchat composer text input (#34962) · openclaw/openclaw@00951dc Tests: speed up channel setup promotion · openclaw/openclaw@82b529a Docs: refresh agent instructions · openclaw/openclaw@5775fe2 fix(auth): serialize OAuth refresh across agents to fix #26322 (#67876) · openclaw/openclaw@8e79080 test: allow ollama public surface boundary test · openclaw/openclaw@7d4f1a6 Docs: add test performance guardrails · openclaw/openclaw@89706d3 Tests: restore context-engine usage proof · openclaw/openclaw@e4c4f95 Tests: slim context engine runtime coverage · openclaw/openclaw@74c198f ci: retry failed custom checkouts · openclaw/openclaw@0ee5baf test: trim duplicate provider auth onboarding cases · openclaw/openclaw@1ffc02e matrix: fix sessions_spawn --thread subagent session spawning (#67643) · openclaw/openclaw@1ce2596 test: reduce auth choice fixture churn · openclaw/openclaw@857b9cd test: mock health status config boundaries · openclaw/openclaw@9d5ab4a test: mock onboard config io boundary · openclaw/openclaw@299694d test: mock legacy state plugin boundaries · openclaw/openclaw@2713089 test: mock channel install boundaries · openclaw/openclaw@b945248 test: mock doctor preview channel boundaries · openclaw/openclaw@b1a3ad4
fix(google-vertex): support production ADC modes (#83971)...
damianFelixP · 2026-05-25 · via Recent Commits to openclaw:main

@@ -4,21 +4,40 @@ import path from "node:path";

44

import type { Model } from "@earendil-works/pi-ai";

55

import { afterAll, afterEach, beforeAll, beforeEach, describe, expect, it, vi } from "vitest";

667-

const { buildGuardedModelFetchMock, guardedFetchMock } = vi.hoisted(() => ({

8-

buildGuardedModelFetchMock: vi.fn(),

9-

guardedFetchMock: vi.fn(),

10-

}));

7+

const {

8+

buildGuardedModelFetchMock,

9+

guardedFetchMock,

10+

googleAuthGetAccessTokenMock,

11+

googleAuthMock,

12+

} = vi.hoisted(() => {

13+

const googleAuthGetAccessTokenMock = vi.fn();

14+

return {

15+

buildGuardedModelFetchMock: vi.fn(),

16+

guardedFetchMock: vi.fn(),

17+

googleAuthGetAccessTokenMock,

18+

googleAuthMock: vi.fn(function GoogleAuthMock() {

19+

return {

20+

getAccessToken: googleAuthGetAccessTokenMock,

21+

};

22+

}),

23+

};

24+

});

11251226

vi.mock("openclaw/plugin-sdk/provider-transport-runtime", async (importOriginal) => ({

1327

...(await importOriginal()),

1428

buildGuardedModelFetch: buildGuardedModelFetchMock,

1529

}));

163031+

vi.mock("google-auth-library", () => ({

32+

GoogleAuth: googleAuthMock,

33+

}));

34+1735

let buildGoogleGenerativeAiParams: typeof import("./transport-stream.js").buildGoogleGenerativeAiParams;

1836

let buildGoogleGemini3FirstResponseRetryParams: typeof import("./transport-stream.js").buildGoogleGemini3FirstResponseRetryParams;

1937

let createGoogleGenerativeAiTransportStreamFn: typeof import("./transport-stream.js").createGoogleGenerativeAiTransportStreamFn;

2038

let createGoogleVertexTransportStreamFn: typeof import("./transport-stream.js").createGoogleVertexTransportStreamFn;

2139

let hasGoogleVertexAuthorizedUserAdcSync: typeof import("./vertex-adc.js").hasGoogleVertexAuthorizedUserAdcSync;

40+

let resolveGoogleVertexAuthorizedUserHeaders: typeof import("./vertex-adc.js").resolveGoogleVertexAuthorizedUserHeaders;

2241

let resetGoogleVertexAuthorizedUserTokenCacheForTest: typeof import("./vertex-adc.js").resetGoogleVertexAuthorizedUserTokenCacheForTest;

23422443

const MODEL_PROVIDER_REQUEST_TRANSPORT_SYMBOL = Symbol.for(

@@ -254,13 +273,18 @@ describe("google transport stream", () => {

254273

createGoogleGenerativeAiTransportStreamFn,

255274

createGoogleVertexTransportStreamFn,

256275

} = await import("./transport-stream.js"));

257-

({ hasGoogleVertexAuthorizedUserAdcSync, resetGoogleVertexAuthorizedUserTokenCacheForTest } =

258-

await import("./vertex-adc.js"));

276+

({

277+

hasGoogleVertexAuthorizedUserAdcSync,

278+

resolveGoogleVertexAuthorizedUserHeaders,

279+

resetGoogleVertexAuthorizedUserTokenCacheForTest,

280+

} = await import("./vertex-adc.js"));

259281

});

260282261283

beforeEach(() => {

262284

buildGuardedModelFetchMock.mockReset();

263285

guardedFetchMock.mockReset();

286+

googleAuthGetAccessTokenMock.mockReset();

287+

googleAuthMock.mockClear();

264288

buildGuardedModelFetchMock.mockReturnValue(guardedFetchMock);

265289

resetGoogleVertexAuthorizedUserTokenCacheForTest();

266290

});

@@ -271,6 +295,7 @@ describe("google transport stream", () => {

271295272296

afterAll(() => {

273297

vi.doUnmock("openclaw/plugin-sdk/provider-transport-runtime");

298+

vi.doUnmock("google-auth-library");

274299

vi.resetModules();

275300

});

276301

@@ -695,6 +720,89 @@ describe("google transport stream", () => {

695720

});

696721

});

697722723+

it("detects supported Vertex ADC sources synchronously", async () => {

724+

const tempDir = await mkdtemp(path.join(os.tmpdir(), "openclaw-google-vertex-adc-detect-"));

725+

for (const type of ["authorized_user", "external_account", "service_account"]) {

726+

const credentialsPath = path.join(tempDir, `${type}.json`);

727+

await writeFile(credentialsPath, JSON.stringify({ type }), "utf8");

728+729+

expect(

730+

hasGoogleVertexAuthorizedUserAdcSync({

731+

GOOGLE_APPLICATION_CREDENTIALS: credentialsPath,

732+

}),

733+

).toBe(true);

734+

}

735+736+

expect(

737+

hasGoogleVertexAuthorizedUserAdcSync({

738+

HOME: path.join(tempDir, "empty-home"),

739+

KUBERNETES_SERVICE_HOST: "10.0.0.1",

740+

}),

741+

).toBe(false);

742+

});

743+744+

it("resolves non-file Vertex ADC through google-auth-library without OAuth refresh fetch", async () => {

745+

const tempDir = await mkdtemp(path.join(os.tmpdir(), "openclaw-google-vertex-authlib-"));

746+

vi.stubEnv("GOOGLE_APPLICATION_CREDENTIALS", "");

747+

vi.stubEnv("HOME", path.join(tempDir, "home"));

748+

vi.stubEnv("APPDATA", "");

749+

googleAuthGetAccessTokenMock.mockResolvedValueOnce("ya29.google-auth-token");

750+

const tokenFetchMock = vi.fn();

751+752+

await expect(resolveGoogleVertexAuthorizedUserHeaders(tokenFetchMock)).resolves.toEqual({

753+

Authorization: "Bearer ya29.google-auth-token",

754+

});

755+756+

expect(googleAuthMock).toHaveBeenCalledWith({

757+

scopes: ["https://www.googleapis.com/auth/cloud-platform"],

758+

});

759+

expect(googleAuthGetAccessTokenMock).toHaveBeenCalledTimes(1);

760+

expect(tokenFetchMock).not.toHaveBeenCalled();

761+

});

762+763+

it("uses google-auth-library bearer auth for Google Vertex credential marker requests", async () => {

764+

const tempDir = await mkdtemp(path.join(os.tmpdir(), "openclaw-google-vertex-authlib-stream-"));

765+

vi.stubEnv("GOOGLE_APPLICATION_CREDENTIALS", "");

766+

vi.stubEnv("HOME", path.join(tempDir, "home"));

767+

vi.stubEnv("APPDATA", "");

768+

vi.stubEnv("GOOGLE_CLOUD_PROJECT", "vertex-project");

769+

vi.stubEnv("GOOGLE_CLOUD_LOCATION", "us-central1");

770+

googleAuthGetAccessTokenMock.mockResolvedValueOnce("ya29.transport-token");

771+

const tokenFetchMock = vi.fn();

772+

guardedFetchMock.mockResolvedValueOnce(

773+

buildSseResponse([

774+

{

775+

candidates: [{ content: { parts: [{ text: "ok" }] }, finishReason: "STOP" }],

776+

},

777+

]),

778+

);

779+780+

const streamFn = createGoogleVertexTransportStreamFn();

781+

const stream = await Promise.resolve(

782+

streamFn(

783+

buildGoogleVertexModel(),

784+

{

785+

messages: [{ role: "user", content: "hello", timestamp: 0 }],

786+

} as Parameters<typeof streamFn>[1],

787+

{

788+

apiKey: "gcp-vertex-credentials",

789+

fetch: tokenFetchMock,

790+

} as Parameters<typeof streamFn>[2],

791+

),

792+

);

793+

await stream.result();

794+795+

expect(tokenFetchMock).not.toHaveBeenCalled();

796+

const guardedCall = requireMockCall(guardedFetchMock, 0, "guarded fetch");

797+

const guardedInit = requireRequestInit(guardedCall, "guarded fetch");

798+

expectHeaders(guardedInit, {

799+

Authorization: "Bearer ya29.transport-token",

800+

"Content-Type": "application/json",

801+

accept: "text/event-stream",

802+

});

803+

expect(new Headers(guardedInit.headers).has("x-goog-api-key")).toBe(false);

804+

});

805+698806

it("refreshes authorized_user ADC before Google Vertex requests", async () => {

699807

const tempDir = await mkdtemp(path.join(os.tmpdir(), "openclaw-google-vertex-adc-"));

700808

const credentialsPath = path.join(tempDir, "application_default_credentials.json");