fix(regression): refresh provider hook cache after config changes

This commit is contained in:
Tak Hoffman
2026-03-27 23:02:25 -05:00
parent 1e2e6fb613
commit 102e313d55
2 changed files with 46 additions and 1 deletions

View File

@@ -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) => {

View File

@@ -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,