Skip to content

Commit 8d65a37

Browse files
committed
fix: scope synthetic auth registry lookup
1 parent 73f448c commit 8d65a37

3 files changed

Lines changed: 44 additions & 32 deletions

File tree

src/agents/model-auth.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ export function createRuntimeProviderAuthLookup(params: {
113113
workspaceDir: params.workspaceDir,
114114
env,
115115
};
116-
const syntheticAuthProviderRefs = resolveRuntimeSyntheticAuthProviderRefState();
116+
const syntheticAuthProviderRefs = resolveRuntimeSyntheticAuthProviderRefState(lookupParams);
117117
return {
118118
envApiKey: {
119119
aliasMap: resolveProviderAuthAliasMap(lookupParams),

src/plugins/synthetic-auth.runtime.test.ts

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,34 @@ describe("synthetic auth runtime refs", () => {
8585
expect(pluginRegistryMocks.loadPluginRegistrySnapshotWithMetadata).toHaveBeenCalledWith({});
8686
});
8787

88+
it("loads manifest synthetic auth refs with the current runtime scope", () => {
89+
const config = { plugins: { allow: ["external-local"] } };
90+
const env = { OPENCLAW_HOME: "/tmp/openclaw-home" };
91+
pluginRegistryMocks.loadPluginRegistrySnapshotWithMetadata.mockReturnValue({
92+
source: "persisted",
93+
snapshot: {
94+
plugins: [{ syntheticAuthRefs: ["external-local"] }],
95+
},
96+
diagnostics: [],
97+
});
98+
99+
expect(
100+
resolveRuntimeSyntheticAuthProviderRefState({
101+
config: config as never,
102+
workspaceDir: "/tmp/workspace",
103+
env,
104+
}),
105+
).toEqual({
106+
refs: ["external-local"],
107+
complete: true,
108+
});
109+
expect(pluginRegistryMocks.loadPluginRegistrySnapshotWithMetadata).toHaveBeenCalledWith({
110+
config,
111+
workspaceDir: "/tmp/workspace",
112+
env,
113+
});
114+
});
115+
88116
it("uses persisted registry external auth provider refs before the runtime registry exists", () => {
89117
const snapshot = {
90118
plugins: [{ syntheticAuthRefs: [] }],

src/plugins/synthetic-auth.runtime.ts

Lines changed: 15 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { normalizeProviderId } from "../agents/provider-id.js";
22
import { loadPluginManifestRegistryForInstalledIndex } from "./manifest-registry-installed.js";
33
import { loadPluginRegistrySnapshotWithMetadata } from "./plugin-registry.js";
4-
import type { PluginRegistrySnapshot } from "./plugin-registry.js";
4+
import type { LoadPluginRegistryParams, PluginRegistrySnapshot } from "./plugin-registry.js";
55
import { getPluginRegistryState } from "./runtime-state.js";
66

77
function uniqueProviderRefs(values: readonly string[]): string[] {
@@ -20,15 +20,12 @@ function uniqueProviderRefs(values: readonly string[]): string[] {
2020
}
2121

2222
function resolveManifestSyntheticAuthProviderRefState(
23-
params: {
24-
index?: PluginRegistrySnapshot;
25-
registryDiagnostics?: readonly unknown[];
26-
} = {},
23+
params: SyntheticAuthProviderRefParams = {},
2724
): { refs: string[]; complete: boolean } {
2825
if (params.index && (params.registryDiagnostics?.length ?? 0) > 0) {
2926
return { refs: [], complete: false };
3027
}
31-
const result = loadPluginRegistrySnapshotWithMetadata({ index: params.index });
28+
const result = loadPluginRegistrySnapshotWithMetadata(params);
3229
if (result.source !== "persisted" && result.source !== "provided") {
3330
return { refs: [], complete: false };
3431
}
@@ -40,16 +37,18 @@ function resolveManifestSyntheticAuthProviderRefState(
4037
};
4138
}
4239

40+
type SyntheticAuthProviderRefParams = LoadPluginRegistryParams & {
41+
index?: PluginRegistrySnapshot;
42+
registryDiagnostics?: readonly unknown[];
43+
};
44+
4345
function resolveManifestExternalAuthProviderRefs(
44-
params: {
45-
index?: PluginRegistrySnapshot;
46-
registryDiagnostics?: readonly unknown[];
47-
} = {},
46+
params: SyntheticAuthProviderRefParams = {},
4847
): string[] {
4948
if (params.index && (params.registryDiagnostics?.length ?? 0) > 0) {
5049
return [];
5150
}
52-
const result = loadPluginRegistrySnapshotWithMetadata({ index: params.index });
51+
const result = loadPluginRegistrySnapshotWithMetadata(params);
5352
if (result.source !== "persisted" && result.source !== "provided") {
5453
return [];
5554
}
@@ -62,19 +61,13 @@ function resolveManifestExternalAuthProviderRefs(
6261
}
6362

6463
export function resolveRuntimeSyntheticAuthProviderRefs(
65-
params: {
66-
index?: PluginRegistrySnapshot;
67-
registryDiagnostics?: readonly unknown[];
68-
} = {},
64+
params: SyntheticAuthProviderRefParams = {},
6965
): string[] {
7066
return resolveRuntimeSyntheticAuthProviderRefState(params).refs;
7167
}
7268

7369
export function resolveRuntimeSyntheticAuthProviderRefState(
74-
params: {
75-
index?: PluginRegistrySnapshot;
76-
registryDiagnostics?: readonly unknown[];
77-
} = {},
70+
params: SyntheticAuthProviderRefParams = {},
7871
): { refs: string[]; complete: boolean } {
7972
const registry = getPluginRegistryState()?.activeRegistry;
8073
if (registry) {
@@ -99,17 +92,11 @@ export function resolveRuntimeSyntheticAuthProviderRefState(
9992
complete: true,
10093
};
10194
}
102-
return resolveManifestSyntheticAuthProviderRefState({
103-
index: params.index,
104-
registryDiagnostics: params.registryDiagnostics,
105-
});
95+
return resolveManifestSyntheticAuthProviderRefState(params);
10696
}
10797

10898
export function resolveRuntimeExternalAuthProviderRefs(
109-
params: {
110-
index?: PluginRegistrySnapshot;
111-
registryDiagnostics?: readonly unknown[];
112-
} = {},
99+
params: SyntheticAuthProviderRefParams = {},
113100
): string[] {
114101
const registry = getPluginRegistryState()?.activeRegistry;
115102
if (registry) {
@@ -135,8 +122,5 @@ export function resolveRuntimeExternalAuthProviderRefs(
135122
.map((entry) => entry.backend.id),
136123
]);
137124
}
138-
return resolveManifestExternalAuthProviderRefs({
139-
index: params.index,
140-
registryDiagnostics: params.registryDiagnostics,
141-
});
125+
return resolveManifestExternalAuthProviderRefs(params);
142126
}

0 commit comments

Comments
 (0)