refactor: remove unused dead code

This commit is contained in:
Peter Steinberger
2026-05-01 07:33:07 +01:00
parent b0b627e5a9
commit fc1c597dbf
14 changed files with 10 additions and 358 deletions

View File

@@ -1,3 +0,0 @@
// Backwards-compatible entry point.
// Implementation lives in `src/agents/cli-runner.ts` (so we can reuse the same runner for other CLIs).
export { runClaudeCliAgent, runCliAgent } from "./cli-runner.js";

View File

@@ -1,15 +1,9 @@
import fs from "node:fs/promises";
import path from "node:path";
import { afterEach, beforeEach, vi } from "vitest";
import { afterEach, beforeEach } from "vitest";
import { clearConfigCache, clearRuntimeConfigSnapshot } from "../config/config.js";
import type { OpenClawConfig } from "../config/types.openclaw.js";
import { withTempHome as withTempHomeBase } from "../plugin-sdk/test-helpers/temp-home.js";
import { resolveBundledPluginsDir } from "../plugins/bundled-dir.js";
import { resetPluginLoaderTestStateForTest } from "../plugins/loader.test-fixtures.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
@@ -94,47 +88,6 @@ export function unsetEnv(vars: string[]) {
}
}
export const COPILOT_TOKEN_ENV_VARS = ["COPILOT_GITHUB_TOKEN", "GH_TOKEN", "GITHUB_TOKEN"];
const COPILOT_DISCOVERY_ENV_VARS = [
...COPILOT_TOKEN_ENV_VARS,
"OPENCLAW_TEST_ONLY_PROVIDER_PLUGIN_IDS",
];
export async function withUnsetCopilotTokenEnv<T>(fn: () => Promise<T>): Promise<T> {
return withTempEnv(COPILOT_DISCOVERY_ENV_VARS, async () => {
unsetEnv(COPILOT_TOKEN_ENV_VARS);
process.env.OPENCLAW_TEST_ONLY_PROVIDER_PLUGIN_IDS = "github-copilot";
return fn();
});
}
export function mockCopilotTokenExchangeSuccess(): MockFn {
const fetchMock = vi.fn().mockResolvedValue({
ok: true,
status: 200,
json: async () => ({
token: "copilot-token;proxy-ep=proxy.copilot.example",
expires_at: Math.floor(Date.now() / 1000) + 3600,
}),
});
globalThis.fetch = fetchMock as unknown as typeof fetch;
return fetchMock;
}
export async function withCopilotGithubToken<T>(
token: string,
fn: (fetchMock: MockFn) => Promise<T>,
): Promise<T> {
return withTempEnv(COPILOT_DISCOVERY_ENV_VARS, async () => {
process.env.COPILOT_GITHUB_TOKEN = token;
delete process.env.GH_TOKEN;
delete process.env.GITHUB_TOKEN;
process.env.OPENCLAW_TEST_ONLY_PROVIDER_PLUGIN_IDS = "github-copilot";
const fetchMock = mockCopilotTokenExchangeSuccess();
return fn(fetchMock);
});
}
export const MODELS_CONFIG_IMPLICIT_ENV_VARS = [
"OPENCLAW_TEST_ONLY_PROVIDER_PLUGIN_IDS",
"VITEST",
@@ -193,197 +146,6 @@ export const MODELS_CONFIG_IMPLICIT_ENV_VARS = [
"AWS_SHARED_CREDENTIALS_FILE",
];
const TEST_PROVIDER_ENV_TO_PROVIDER_IDS: Record<string, string[]> = {
AI_GATEWAY_API_KEY: ["vercel-ai-gateway"],
ANTHROPIC_VERTEX_PROJECT_ID: ["anthropic-vertex"],
ANTHROPIC_VERTEX_USE_GCP_METADATA: ["anthropic-vertex"],
AWS_ACCESS_KEY_ID: ["amazon-bedrock"],
AWS_BEARER_TOKEN_BEDROCK: ["amazon-bedrock"],
AWS_CONFIG_FILE: ["amazon-bedrock"],
AWS_DEFAULT_REGION: ["amazon-bedrock"],
AWS_PROFILE: ["amazon-bedrock"],
AWS_REGION: ["amazon-bedrock"],
AWS_SECRET_ACCESS_KEY: ["amazon-bedrock"],
AWS_SESSION_TOKEN: ["amazon-bedrock"],
AWS_SHARED_CREDENTIALS_FILE: ["amazon-bedrock"],
BYTEPLUS_API_KEY: ["byteplus"],
CHUTES_API_KEY: ["chutes"],
CHUTES_OAUTH_TOKEN: ["chutes"],
CLOUD_ML_REGION: ["anthropic-vertex"],
CLOUDFLARE_AI_GATEWAY_API_KEY: ["cloudflare-ai-gateway"],
COPILOT_GITHUB_TOKEN: ["github-copilot"],
GEMINI_API_KEY: ["google"],
GITHUB_TOKEN: ["github-copilot"],
GH_TOKEN: ["github-copilot"],
GOOGLE_APPLICATION_CREDENTIALS: ["anthropic-vertex"],
GOOGLE_CLOUD_LOCATION: ["anthropic-vertex"],
GOOGLE_CLOUD_PROJECT: ["anthropic-vertex"],
GOOGLE_CLOUD_PROJECT_ID: ["anthropic-vertex"],
HF_TOKEN: ["huggingface"],
HUGGINGFACE_HUB_TOKEN: ["huggingface"],
KILOCODE_API_KEY: ["kilocode"],
KIMI_API_KEY: ["moonshot", "kimi"],
KIMICODE_API_KEY: ["kimi-coding"],
MINIMAX_API_KEY: ["minimax"],
MINIMAX_OAUTH_TOKEN: ["minimax"],
MODELSTUDIO_API_KEY: ["chutes"],
MOONSHOT_API_KEY: ["moonshot"],
NVIDIA_API_KEY: ["nvidia"],
OLLAMA_API_KEY: ["ollama"],
OPENAI_API_KEY: ["openai"],
OPENROUTER_API_KEY: ["openrouter"],
QIANFAN_API_KEY: ["qianfan"],
STEPFUN_API_KEY: ["stepfun"],
SYNTHETIC_API_KEY: ["custom-proxy"],
TOGETHER_API_KEY: ["together"],
VENICE_API_KEY: ["venice"],
VLLM_API_KEY: ["vllm"],
VOLCANO_ENGINE_API_KEY: ["volcengine"],
XIAOMI_API_KEY: ["xiaomi"],
};
export function snapshotImplicitProviderEnv(env?: NodeJS.ProcessEnv): NodeJS.ProcessEnv {
const source = env ?? process.env;
const snapshot: NodeJS.ProcessEnv = {};
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));
}
export async function resolveImplicitProvidersForTest(
params: Parameters<typeof resolveImplicitProviders>[0],
) {
const env = snapshotImplicitProviderEnv(params.env);
const inferredPluginIds = await inferImplicitProviderTestPluginIds({
agentDir: params.agentDir,
config: params.config,
explicitProviders: params.explicitProviders,
env,
workspaceDir: params.workspaceDir,
});
if (inferredPluginIds.length > 0) {
env.OPENCLAW_TEST_ONLY_PROVIDER_PLUGIN_IDS = inferredPluginIds.join(",");
}
return resolveImplicitProviders({
...params,
env,
});
}
export const CUSTOM_PROXY_MODELS_CONFIG: OpenClawConfig = {
models: {
providers: {

View File

@@ -133,10 +133,6 @@ export function getCallGatewayMock(): Mock {
return hoisted.callGatewayMock;
}
export function getGatewayRequests(): Array<GatewayRequest> {
return getCallGatewayMock().mock.calls.map((call: unknown[]) => call[0] as GatewayRequest);
}
export async function waitForSessionsSpawnEvent(
label: string,
predicate: () => boolean,

View File

@@ -1,7 +1,6 @@
import type { ActivePluginChannelRegistration } from "../plugins/channel-registry-state.types.js";
import { getActivePluginChannelRegistryFromState } from "../plugins/runtime-channel-state.js";
import { normalizeOptionalLowercaseString } from "../shared/string-coerce.js";
import { normalizeChatChannelId, type ChatChannelId } from "./ids.js";
import type { ChannelId } from "./plugins/channel-id.types.js";
function listRegisteredChannelPluginEntries(): ActivePluginChannelRegistration[] {
@@ -12,10 +11,6 @@ function listRegisteredChannelPluginEntries(): ActivePluginChannelRegistration[]
return [];
}
export function normalizeChannelId(raw?: string | null): ChatChannelId | null {
return normalizeChatChannelId(raw);
}
export function normalizeAnyChannelId(raw?: string | null): ChannelId | null {
const key = normalizeOptionalLowercaseString(raw);
if (!key) {

View File

@@ -84,10 +84,6 @@ export function listRegisteredChannelPluginIds(): ChannelId[] {
});
}
export function listRegisteredChannelPluginAliases(): string[] {
return listRegisteredChannelPluginEntries().flatMap((entry) => entry.plugin.meta?.aliases ?? []);
}
export function getRegisteredChannelPluginMeta(
id: string,
): Pick<ChannelMeta, "aliases" | "markdownCapable"> | null {

View File

@@ -1,75 +0,0 @@
import { getChannelSetupWizardAdapter } from "./channel-setup/registry.js";
import type { ChannelSetupWizardAdapter } from "./channel-setup/types.js";
import type { ChannelChoice } from "./onboard-types.js";
type ChannelSetupWizardAdapterPatch = Partial<
Pick<
ChannelSetupWizardAdapter,
| "afterConfigWritten"
| "configure"
| "configureInteractive"
| "configureWhenConfigured"
| "getStatus"
>
>;
type PatchedSetupAdapterFields = {
afterConfigWritten?: ChannelSetupWizardAdapter["afterConfigWritten"];
configure?: ChannelSetupWizardAdapter["configure"];
configureInteractive?: ChannelSetupWizardAdapter["configureInteractive"];
configureWhenConfigured?: ChannelSetupWizardAdapter["configureWhenConfigured"];
getStatus?: ChannelSetupWizardAdapter["getStatus"];
};
export function patchChannelSetupWizardAdapter(
channel: ChannelChoice,
patch: ChannelSetupWizardAdapterPatch,
): () => void {
const adapter = getChannelSetupWizardAdapter(channel);
if (!adapter) {
throw new Error(`missing setup adapter for ${channel}`);
}
const previous: PatchedSetupAdapterFields = {};
if (Object.prototype.hasOwnProperty.call(patch, "getStatus")) {
previous.getStatus = adapter.getStatus;
adapter.getStatus = patch.getStatus ?? adapter.getStatus;
}
if (Object.prototype.hasOwnProperty.call(patch, "afterConfigWritten")) {
previous.afterConfigWritten = adapter.afterConfigWritten;
adapter.afterConfigWritten = patch.afterConfigWritten;
}
if (Object.prototype.hasOwnProperty.call(patch, "configure")) {
previous.configure = adapter.configure;
adapter.configure = patch.configure ?? adapter.configure;
}
if (Object.prototype.hasOwnProperty.call(patch, "configureInteractive")) {
previous.configureInteractive = adapter.configureInteractive;
adapter.configureInteractive = patch.configureInteractive;
}
if (Object.prototype.hasOwnProperty.call(patch, "configureWhenConfigured")) {
previous.configureWhenConfigured = adapter.configureWhenConfigured;
adapter.configureWhenConfigured = patch.configureWhenConfigured;
}
return () => {
if (Object.prototype.hasOwnProperty.call(patch, "getStatus")) {
adapter.getStatus = previous.getStatus!;
}
if (Object.prototype.hasOwnProperty.call(patch, "afterConfigWritten")) {
adapter.afterConfigWritten = previous.afterConfigWritten;
}
if (Object.prototype.hasOwnProperty.call(patch, "configure")) {
adapter.configure = previous.configure!;
}
if (Object.prototype.hasOwnProperty.call(patch, "configureInteractive")) {
adapter.configureInteractive = previous.configureInteractive;
}
if (Object.prototype.hasOwnProperty.call(patch, "configureWhenConfigured")) {
adapter.configureWhenConfigured = previous.configureWhenConfigured;
}
};
}
export const patchChannelOnboardingAdapter = patchChannelSetupWizardAdapter;

View File

@@ -1,2 +1,2 @@
export { readConfigFileSnapshot, readConfigFileSnapshotForWrite } from "../config/io.js";
export { readConfigFileSnapshotForWrite } from "../config/io.js";
export { replaceConfigFile } from "../config/mutate.js";

View File

@@ -30,7 +30,6 @@ const secretRefKeyMock = vi.hoisted(() => vi.fn(() => "env:default:OPENCLAW_GATE
const randomTokenMock = vi.hoisted(() => vi.fn(() => "generated-token"));
vi.mock("./gateway-install-token.persist.runtime.js", () => ({
readConfigFileSnapshot: readConfigFileSnapshotMock,
readConfigFileSnapshotForWrite: readConfigFileSnapshotForWriteMock,
replaceConfigFile: replaceConfigFileMock,
}));

View File

@@ -20,8 +20,6 @@ export type GatewayBind = "loopback" | "lan" | "auto" | "custom" | "tailnet";
export type TailscaleMode = "off" | "serve" | "funnel";
export type NodeManagerChoice = "npm" | "pnpm" | "bun";
export type ChannelChoice = ChannelId;
/** @deprecated Use ChannelChoice. */
export type ProviderChoice = ChannelChoice;
export type { SecretInputMode } from "../plugins/provider-auth-types.js";
type OnboardDynamicProviderOptions = {

View File

@@ -104,4 +104,3 @@ export async function setupWizardCommand(
export const onboardCommand = setupWizardCommand;
export type { OnboardOptions } from "./onboard-types.js";
export type { OnboardOptions as SetupWizardOptions } from "./onboard-types.js";

View File

@@ -1 +1,8 @@
export * from "../../test/helpers/auth-wizard.js";
export {
createAuthTestLifecycle,
createExitThrowingRuntime,
createWizardPrompter,
readAuthProfilesForAgent,
requireOpenClawAgentDir,
setupAuthTestEnv,
} from "../../test/helpers/auth-wizard.js";

View File

@@ -4,7 +4,6 @@ import os from "node:os";
import path from "node:path";
import { fileURLToPath } from "node:url";
import { resolveOpenClawPackageRootSync } from "../infra/openclaw-root.js";
import { FIELD_HELP } from "./schema.help.js";
import type { ConfigSchemaResponse } from "./schema.js";
import { schemaHasChildren } from "./schema.shared.js";
@@ -689,11 +688,3 @@ export async function writeConfigDocBaselineArtifacts(params?: {
export function normalizeConfigDocBaselineHelpPath(pathValue: string): string {
return normalizeBaselinePath(pathValue);
}
export function getNormalizedFieldHelp(): Record<string, string> {
return Object.fromEntries(
Object.entries(FIELD_HELP)
.map(([configPath, help]) => [normalizeBaselinePath(configPath), help] as const)
.toSorted(([left], [right]) => left.localeCompare(right)),
);
}

View File

@@ -1,8 +1,6 @@
export {
applyConfigEnvVars,
collectConfigEnvVars,
collectConfigRuntimeEnvVars,
collectConfigServiceEnvVars,
createConfigRuntimeEnv,
} from "./config-env-vars.js";
export { collectDurableServiceEnvVars, readStateDirDotEnvVars } from "./state-dir-dotenv.js";

View File

@@ -1,11 +0,0 @@
export const WHISPER_BASE_AUDIO_MODEL = {
enabled: true,
models: [
{
command: "whisper",
type: "cli",
args: ["--model", "base"],
timeoutSeconds: 2,
},
],
};