import fs from "node:fs/promises"; import path from "node:path"; import { afterEach, beforeEach, vi } from "vitest"; import { withTempHome as withTempHomeBase } from "../../test/helpers/temp-home.js"; import { clearConfigCache, clearRuntimeConfigSnapshot } from "../config/config.js"; import type { OpenClawConfig } from "../config/types.openclaw.js"; import { resolveBundledPluginsDir } from "../plugins/bundled-dir.js"; import { resetPluginLoaderTestStateForTest } from "../plugins/loader.test-fixtures.js"; import { resetProviderRuntimeHookCacheForTest } from "../plugins/provider-runtime.js"; import { resolveOwningPluginIdsForProvider } from "../plugins/providers.js"; import type { MockFn } from "../test-utils/vitest-mock-fn.js"; import { resetModelsJsonReadyCacheForTest } from "./models-config-state.js"; import { resolveImplicitProviders } from "./models-config.providers.implicit.js";
export function withModelsTempHome<T>(fn: (home: string) => Promise<T>): Promise<T> { // Models-config tests do not exercise session persistence; skip draining // unrelated session lock state during temp-home teardown. return withTempHomeBase(fn, {
prefix: "openclaw-models-",
skipSessionCleanup: true,
});
}
for (const envVar of MODELS_CONFIG_IMPLICIT_ENV_VARS) { const value = source[envVar]; if (value !== undefined) {
snapshot[envVar] = value;
}
}
// Provider discovery tests can temporarily scrub VITEST/NODE_ENV to exercise // live HTTP paths. Keep the bundled plugin root pinned to the source checkout // so those tests do not fall back to potentially stale dist-runtime wrappers.
snapshot.VITEST ??= process.env.VITEST;
snapshot.NODE_ENV ??= process.env.NODE_ENV;
snapshot.OPENCLAW_BUNDLED_PLUGINS_DIR ??=
resolveBundledPluginsDir({ VITEST: "true" } as NodeJS.ProcessEnv) ?? undefined;
return snapshot;
}
async function inferAuthProfileProviderIds(agentDir?: string): Promise<string[]> { if (!agentDir) { return [];
} try { const raw = await fs.readFile(path.join(agentDir, "auth-profiles.json"), "utf8"); const parsed = JSON.parse(raw) as {
profiles?: Record<string, { provider?: string }>;
order?: Record<string, unknown>;
}; const providers = new Set<string>(); for (const providerId of Object.keys(parsed.order ?? {})) { if (providerId.trim()) {
providers.add(providerId.trim());
}
} for (const profile of Object.values(parsed.profiles ?? {})) { const providerId = profile?.provider?.trim(); if (providerId) {
providers.add(providerId);
}
} return [...providers];
} catch { return [];
}
}
async function inferImplicitProviderTestPluginIds(params: {
agentDir?: string;
config?: OpenClawConfig;
explicitProviders?: Record<string, unknown> | null;
env: NodeJS.ProcessEnv;
workspaceDir?: string;
}): Promise<string[]> { const providerIds = new Set<string>(); for (const providerId of Object.keys(params.config?.models?.providers ?? {})) { if (providerId.trim()) {
providerIds.add(providerId.trim());
}
} for (const providerId of Object.keys(params.explicitProviders ?? {})) { if (providerId.trim()) {
providerIds.add(providerId.trim());
}
} const legacyGrokApiKey =
params.config?.tools?.web?.search && typeof params.config.tools.web.search === "object" && "grok" in params.config.tools.web.search
? (params.config.tools.web.search.grok as { apiKey?: unknown } | undefined)?.apiKey
: undefined; if (legacyGrokApiKey !== undefined && params.config?.plugins?.entries?.xai?.enabled !== false) {
providerIds.add("xai");
} for (const [envVar, mappedProviderIds] of Object.entries(TEST_PROVIDER_ENV_TO_PROVIDER_IDS)) { if (!params.env[envVar]?.trim()) { continue;
} for (const providerId of mappedProviderIds) {
providerIds.add(providerId);
}
} for (const providerId of await inferAuthProfileProviderIds(params.agentDir)) {
providerIds.add(providerId);
} for (const [pluginId, entry] of Object.entries(params.config?.plugins?.entries ?? {})) { if (!pluginId.trim() || entry?.enabled === false) { continue;
} const pluginConfig =
entry.config && typeof entry.config === "object"
? (entry.config as { webSearch?: { apiKey?: unknown } })
: undefined; if (pluginConfig?.webSearch?.apiKey !== undefined) {
providerIds.add(pluginId);
}
} if (providerIds.size === 0) { // No config/env/auth hints: keep ambient local auto-discovery focused on the // one provider that is expected to probe localhost in tests. return ["ollama"];
}
const pluginIds = new Set<string>(); for (const providerId of providerIds) { const owningPluginIds =
resolveOwningPluginIdsForProvider({
provider: providerId,
config: params.config,
workspaceDir: params.workspaceDir,
env: params.env,
}) ?? []; for (const pluginId of owningPluginIds) {
pluginIds.add(pluginId);
}
} return [...pluginIds].toSorted((left, right) => left.localeCompare(right));
}
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.