Skip to content

Commit a4a1abb

Browse files
committed
fix: honor disabled synthetic auth lookup
1 parent 4e34ac4 commit a4a1abb

4 files changed

Lines changed: 51 additions & 4 deletions

File tree

‎src/agents/model-auth.test.ts‎

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,7 @@ vi.mock("../plugins/provider-runtime.js", async () => {
126126

127127
let applyAuthHeaderOverride: typeof import("./model-auth.js").applyAuthHeaderOverride;
128128
let applyLocalNoAuthHeaderOverride: typeof import("./model-auth.js").applyLocalNoAuthHeaderOverride;
129+
let createRuntimeProviderAuthLookup: typeof import("./model-auth.js").createRuntimeProviderAuthLookup;
129130
let formatMissingAuthError: typeof import("./model-auth.js").formatMissingAuthError;
130131
let hasUsableCustomProviderApiKey: typeof import("./model-auth.js").hasUsableCustomProviderApiKey;
131132
let hasSyntheticLocalProviderAuthConfig: typeof import("./model-auth.js").hasSyntheticLocalProviderAuthConfig;
@@ -146,6 +147,7 @@ beforeAll(async () => {
146147
({
147148
applyAuthHeaderOverride,
148149
applyLocalNoAuthHeaderOverride,
150+
createRuntimeProviderAuthLookup,
149151
formatMissingAuthError,
150152
hasSyntheticLocalProviderAuthConfig,
151153
getApiKeyForModel,
@@ -166,6 +168,17 @@ afterEach(() => {
166168
clearRuntimeConfigSnapshot();
167169
});
168170

171+
describe("createRuntimeProviderAuthLookup", () => {
172+
it("omits synthetic auth refs when plugin synthetic auth is disabled", () => {
173+
expect(
174+
createRuntimeProviderAuthLookup({
175+
includePluginSyntheticAuth: false,
176+
env: {},
177+
}).syntheticAuthProviderRefs,
178+
).toBeUndefined();
179+
});
180+
});
181+
169182
async function withoutEnv<T>(key: string, fn: () => Promise<T>): Promise<T> {
170183
const previous = process.env[key];
171184
delete process.env[key];

‎src/agents/model-auth.ts‎

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -106,21 +106,25 @@ export function createRuntimeProviderAuthLookup(params: {
106106
cfg?: OpenClawConfig;
107107
workspaceDir?: string;
108108
env?: NodeJS.ProcessEnv;
109+
includePluginSyntheticAuth?: boolean;
109110
}): RuntimeProviderAuthLookup {
110111
const env = params.env ?? process.env;
111112
const lookupParams = {
112113
config: params.cfg,
113114
workspaceDir: params.workspaceDir,
114115
env,
115116
};
116-
const syntheticAuthProviderRefs = resolveRuntimeSyntheticAuthProviderRefState(lookupParams);
117+
const syntheticAuthProviderRefs =
118+
params.includePluginSyntheticAuth === false
119+
? undefined
120+
: resolveRuntimeSyntheticAuthProviderRefState(lookupParams);
117121
return {
118122
envApiKey: {
119123
aliasMap: resolveProviderAuthAliasMap(lookupParams),
120124
candidateMap: resolveProviderEnvApiKeyCandidates(lookupParams),
121125
authEvidenceMap: resolveProviderEnvAuthEvidence(lookupParams),
122126
},
123-
syntheticAuthProviderRefs: syntheticAuthProviderRefs.complete
127+
syntheticAuthProviderRefs: syntheticAuthProviderRefs?.complete
124128
? syntheticAuthProviderRefs.refs
125129
: undefined,
126130
};

‎src/agents/model-provider-auth.test.ts‎

Lines changed: 31 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,8 +63,12 @@ vi.mock("./agent-scope-config.js", () => ({
6363
resolveDefaultAgentId: () => "default",
6464
}));
6565

66-
const { clearCurrentProviderAuthState, hasAuthForModelProvider, warmCurrentProviderAuthState } =
67-
await import("./model-provider-auth.js");
66+
const {
67+
clearCurrentProviderAuthState,
68+
createProviderAuthChecker,
69+
hasAuthForModelProvider,
70+
warmCurrentProviderAuthState,
71+
} = await import("./model-provider-auth.js");
6872

6973
describe("prepared provider auth state", () => {
7074
afterEach(() => {
@@ -147,6 +151,31 @@ describe("prepared provider auth state", () => {
147151
expect(modelAuthMocks.hasRuntimeAvailableProviderAuth).toHaveBeenCalledTimes(2);
148152
});
149153

154+
it("does not prepare synthetic auth refs when plugin synthetic auth is disabled", async () => {
155+
const cfg = {} as OpenClawConfig;
156+
modelAuthMocks.hasRuntimeAvailableProviderAuth.mockReturnValue(false);
157+
158+
const hasAuth = createProviderAuthChecker({
159+
cfg,
160+
allowPluginSyntheticAuth: false,
161+
discoverExternalCliAuth: false,
162+
});
163+
164+
await expect(hasAuth("openai")).resolves.toBe(false);
165+
166+
expect(modelAuthMocks.createRuntimeProviderAuthLookup).toHaveBeenCalledWith({
167+
cfg,
168+
workspaceDir: undefined,
169+
env: undefined,
170+
includePluginSyntheticAuth: false,
171+
});
172+
const runtimeLookup =
173+
modelAuthMocks.hasRuntimeAvailableProviderAuth.mock.calls[0]?.[0].runtimeLookup;
174+
expect(runtimeLookup).toBe(
175+
modelAuthMocks.createRuntimeProviderAuthLookup.mock.results[0]?.value,
176+
);
177+
});
178+
150179
it("hasAuthForModelProvider uses the prepared answer for equivalent runtime config clones", async () => {
151180
const cfg = { gateway: { port: 18789 } } as OpenClawConfig;
152181
const clonedCfg = structuredClone(cfg);

‎src/agents/model-provider-auth.ts‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -188,6 +188,7 @@ export function createProviderAuthChecker(params: {
188188
cfg: params.cfg,
189189
workspaceDir: params.workspaceDir,
190190
env: params.env,
191+
includePluginSyntheticAuth: params.allowPluginSyntheticAuth !== false,
191192
})),
192193
});
193194
authCache.set(key, value);

0 commit comments

Comments
 (0)