mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-01 00:30:21 +00:00
fix(regression): refresh provider hook cache after config changes
This commit is contained in:
@@ -214,6 +214,49 @@ describe("provider-runtime", () => {
|
||||
});
|
||||
});
|
||||
|
||||
it("invalidates cached runtime providers when config mutates in place", () => {
|
||||
const config = {
|
||||
plugins: {
|
||||
entries: {
|
||||
demo: { enabled: false },
|
||||
},
|
||||
},
|
||||
} as { plugins: { entries: { demo: { enabled: boolean } } } };
|
||||
resolveOwningPluginIdsForProviderMock.mockReturnValue(["demo"]);
|
||||
resolvePluginProvidersMock.mockImplementation((params) => {
|
||||
const runtimeConfig = params?.config as typeof config | undefined;
|
||||
const enabled = runtimeConfig?.plugins?.entries?.demo?.enabled === true;
|
||||
return enabled
|
||||
? [
|
||||
{
|
||||
id: DEMO_PROVIDER_ID,
|
||||
label: "Demo",
|
||||
auth: [],
|
||||
},
|
||||
]
|
||||
: [];
|
||||
});
|
||||
|
||||
expect(
|
||||
resolveProviderRuntimePlugin({
|
||||
provider: DEMO_PROVIDER_ID,
|
||||
config: config as never,
|
||||
}),
|
||||
).toBeUndefined();
|
||||
|
||||
config.plugins.entries.demo.enabled = true;
|
||||
|
||||
expect(
|
||||
resolveProviderRuntimePlugin({
|
||||
provider: DEMO_PROVIDER_ID,
|
||||
config: config as never,
|
||||
}),
|
||||
).toMatchObject({
|
||||
id: DEMO_PROVIDER_ID,
|
||||
});
|
||||
expect(resolvePluginProvidersMock).toHaveBeenCalledTimes(2);
|
||||
});
|
||||
|
||||
it("dispatches runtime hooks for the matched provider", async () => {
|
||||
resolveCatalogHookProviderPluginIdsMock.mockReturnValue(["openai"]);
|
||||
resolveOwningPluginIdsForProviderMock.mockImplementation((params) => {
|
||||
|
||||
@@ -78,6 +78,7 @@ function resolveHookProviderCacheBucket(params: {
|
||||
}
|
||||
|
||||
function buildHookProviderCacheKey(params: {
|
||||
config?: OpenClawConfig;
|
||||
workspaceDir?: string;
|
||||
onlyPluginIds?: string[];
|
||||
env?: NodeJS.ProcessEnv;
|
||||
@@ -86,7 +87,7 @@ function buildHookProviderCacheKey(params: {
|
||||
workspaceDir: params.workspaceDir,
|
||||
env: params.env,
|
||||
});
|
||||
return `${roots.workspace ?? ""}::${roots.global}::${roots.stock ?? ""}::${JSON.stringify(params.onlyPluginIds ?? [])}`;
|
||||
return `${roots.workspace ?? ""}::${roots.global}::${roots.stock ?? ""}::${JSON.stringify(params.config ?? null)}::${JSON.stringify(params.onlyPluginIds ?? [])}`;
|
||||
}
|
||||
|
||||
export function clearProviderRuntimeHookCache(): void {
|
||||
@@ -116,6 +117,7 @@ function resolveProviderPluginsForHooks(params: {
|
||||
env,
|
||||
});
|
||||
const cacheKey = buildHookProviderCacheKey({
|
||||
config: params.config,
|
||||
workspaceDir: params.workspaceDir,
|
||||
onlyPluginIds: params.onlyPluginIds,
|
||||
env,
|
||||
|
||||
Reference in New Issue
Block a user