From fc1c597dbfe6106aaaeca57a0f82a7e1adaa77ec Mon Sep 17 00:00:00 2001 From: Peter Steinberger Date: Fri, 1 May 2026 07:33:07 +0100 Subject: [PATCH] refactor: remove unused dead code --- src/agents/claude-cli-runner.ts | 3 - src/agents/models-config.e2e-harness.ts | 240 +----------------- ...s.subagents.sessions-spawn.test-harness.ts | 4 - src/channels/registry-normalize.ts | 5 - src/channels/registry.ts | 4 - src/commands/channel-test-helpers.ts | 75 ------ .../gateway-install-token.persist.runtime.ts | 2 +- src/commands/gateway-install-token.test.ts | 1 - src/commands/onboard-types.ts | 2 - src/commands/onboard.ts | 1 - src/commands/test-wizard-helpers.ts | 9 +- src/config/doc-baseline.ts | 9 - src/config/env-vars.ts | 2 - src/config/legacy-migrate.test-helpers.ts | 11 - 14 files changed, 10 insertions(+), 358 deletions(-) delete mode 100644 src/agents/claude-cli-runner.ts delete mode 100644 src/commands/channel-test-helpers.ts delete mode 100644 src/config/legacy-migrate.test-helpers.ts diff --git a/src/agents/claude-cli-runner.ts b/src/agents/claude-cli-runner.ts deleted file mode 100644 index f2dd81aa7ac..00000000000 --- a/src/agents/claude-cli-runner.ts +++ /dev/null @@ -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"; diff --git a/src/agents/models-config.e2e-harness.ts b/src/agents/models-config.e2e-harness.ts index 7ef19844b02..52acd298cc2 100644 --- a/src/agents/models-config.e2e-harness.ts +++ b/src/agents/models-config.e2e-harness.ts @@ -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(fn: (home: string) => Promise): Promise { // 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(fn: () => Promise): Promise { - 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( - token: string, - fn: (fetchMock: MockFn) => Promise, -): Promise { - 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 = { - 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 { - if (!agentDir) { - return []; - } - try { - const raw = await fs.readFile(path.join(agentDir, "auth-profiles.json"), "utf8"); - const parsed = JSON.parse(raw) as { - profiles?: Record; - order?: Record; - }; - const providers = new Set(); - 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 | null; - env: NodeJS.ProcessEnv; - workspaceDir?: string; -}): Promise { - const providerIds = new Set(); - 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(); - 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[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: { diff --git a/src/agents/openclaw-tools.subagents.sessions-spawn.test-harness.ts b/src/agents/openclaw-tools.subagents.sessions-spawn.test-harness.ts index c73388d8521..d505b48d430 100644 --- a/src/agents/openclaw-tools.subagents.sessions-spawn.test-harness.ts +++ b/src/agents/openclaw-tools.subagents.sessions-spawn.test-harness.ts @@ -133,10 +133,6 @@ export function getCallGatewayMock(): Mock { return hoisted.callGatewayMock; } -export function getGatewayRequests(): Array { - return getCallGatewayMock().mock.calls.map((call: unknown[]) => call[0] as GatewayRequest); -} - export async function waitForSessionsSpawnEvent( label: string, predicate: () => boolean, diff --git a/src/channels/registry-normalize.ts b/src/channels/registry-normalize.ts index 0693361e615..c1a9a6cd3de 100644 --- a/src/channels/registry-normalize.ts +++ b/src/channels/registry-normalize.ts @@ -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) { diff --git a/src/channels/registry.ts b/src/channels/registry.ts index def4b7debf0..838cd289d7c 100644 --- a/src/channels/registry.ts +++ b/src/channels/registry.ts @@ -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 | null { diff --git a/src/commands/channel-test-helpers.ts b/src/commands/channel-test-helpers.ts deleted file mode 100644 index 99e3e23d5c0..00000000000 --- a/src/commands/channel-test-helpers.ts +++ /dev/null @@ -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; diff --git a/src/commands/gateway-install-token.persist.runtime.ts b/src/commands/gateway-install-token.persist.runtime.ts index 4f8a93ffa53..0dcaa938c6e 100644 --- a/src/commands/gateway-install-token.persist.runtime.ts +++ b/src/commands/gateway-install-token.persist.runtime.ts @@ -1,2 +1,2 @@ -export { readConfigFileSnapshot, readConfigFileSnapshotForWrite } from "../config/io.js"; +export { readConfigFileSnapshotForWrite } from "../config/io.js"; export { replaceConfigFile } from "../config/mutate.js"; diff --git a/src/commands/gateway-install-token.test.ts b/src/commands/gateway-install-token.test.ts index 4de873d93cc..1822673b486 100644 --- a/src/commands/gateway-install-token.test.ts +++ b/src/commands/gateway-install-token.test.ts @@ -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, })); diff --git a/src/commands/onboard-types.ts b/src/commands/onboard-types.ts index 6d69d58e3e1..afb2613ddc0 100644 --- a/src/commands/onboard-types.ts +++ b/src/commands/onboard-types.ts @@ -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 = { diff --git a/src/commands/onboard.ts b/src/commands/onboard.ts index 6507d650e19..e8184b6f94c 100644 --- a/src/commands/onboard.ts +++ b/src/commands/onboard.ts @@ -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"; diff --git a/src/commands/test-wizard-helpers.ts b/src/commands/test-wizard-helpers.ts index 77d6eaa0754..6cb3700b4fd 100644 --- a/src/commands/test-wizard-helpers.ts +++ b/src/commands/test-wizard-helpers.ts @@ -1 +1,8 @@ -export * from "../../test/helpers/auth-wizard.js"; +export { + createAuthTestLifecycle, + createExitThrowingRuntime, + createWizardPrompter, + readAuthProfilesForAgent, + requireOpenClawAgentDir, + setupAuthTestEnv, +} from "../../test/helpers/auth-wizard.js"; diff --git a/src/config/doc-baseline.ts b/src/config/doc-baseline.ts index c4f2b7d75a9..ab56ce281f0 100644 --- a/src/config/doc-baseline.ts +++ b/src/config/doc-baseline.ts @@ -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 { - return Object.fromEntries( - Object.entries(FIELD_HELP) - .map(([configPath, help]) => [normalizeBaselinePath(configPath), help] as const) - .toSorted(([left], [right]) => left.localeCompare(right)), - ); -} diff --git a/src/config/env-vars.ts b/src/config/env-vars.ts index 94a1c7e6b4c..5708b95acf4 100644 --- a/src/config/env-vars.ts +++ b/src/config/env-vars.ts @@ -1,8 +1,6 @@ export { applyConfigEnvVars, - collectConfigEnvVars, collectConfigRuntimeEnvVars, - collectConfigServiceEnvVars, createConfigRuntimeEnv, } from "./config-env-vars.js"; export { collectDurableServiceEnvVars, readStateDirDotEnvVars } from "./state-dir-dotenv.js"; diff --git a/src/config/legacy-migrate.test-helpers.ts b/src/config/legacy-migrate.test-helpers.ts deleted file mode 100644 index c59b64ec309..00000000000 --- a/src/config/legacy-migrate.test-helpers.ts +++ /dev/null @@ -1,11 +0,0 @@ -export const WHISPER_BASE_AUDIO_MODEL = { - enabled: true, - models: [ - { - command: "whisper", - type: "cli", - args: ["--model", "base"], - timeoutSeconds: 2, - }, - ], -};