test(agents): isolate shared subagent state

This commit is contained in:
Peter Steinberger
2026-04-14 22:48:56 +01:00
parent e7dfc88bfa
commit 54cf4cd857
9 changed files with 128 additions and 49 deletions

View File

@@ -1,6 +1,7 @@
import { normalizeProviderId } from "../agents/provider-id.js";
import type { ModelProviderConfig } from "../config/types.js";
import type { OpenClawConfig } from "../config/types.openclaw.js";
import { resolveBundledPluginsDir } from "./bundled-dir.js";
import type {
ProviderApplyConfigDefaultsContext,
ProviderNormalizeConfigContext,
@@ -20,6 +21,11 @@ export type BundledProviderPolicySurface = {
const bundledProviderPolicySurfaceCache = new Map<string, BundledProviderPolicySurface | null>();
function buildProviderPolicySurfaceCacheKey(providerId: string): string {
const bundledPluginsDir = resolveBundledPluginsDir();
return `${providerId}::${bundledPluginsDir ?? "<default>"}`;
}
function hasProviderPolicyHook(
mod: Record<string, unknown>,
): mod is Record<string, unknown> & BundledProviderPolicySurface {
@@ -66,16 +72,17 @@ export function resolveBundledProviderPolicySurface(
if (!normalizedProviderId) {
return null;
}
if (bundledProviderPolicySurfaceCache.has(normalizedProviderId)) {
return bundledProviderPolicySurfaceCache.get(normalizedProviderId) ?? null;
const cacheKey = buildProviderPolicySurfaceCacheKey(normalizedProviderId);
if (bundledProviderPolicySurfaceCache.has(cacheKey)) {
return bundledProviderPolicySurfaceCache.get(cacheKey) ?? null;
}
const surface = tryLoadBundledProviderPolicySurface(normalizedProviderId);
if (surface) {
bundledProviderPolicySurfaceCache.set(normalizedProviderId, surface);
bundledProviderPolicySurfaceCache.set(cacheKey, surface);
return surface;
}
bundledProviderPolicySurfaceCache.set(normalizedProviderId, null);
bundledProviderPolicySurfaceCache.set(cacheKey, null);
return null;
}