From 5fbf406bebe9f20a277dcd2266de88d3bb7e0ba5 Mon Sep 17 00:00:00 2001 From: Peter Steinberger Date: Fri, 1 May 2026 12:24:12 +0100 Subject: [PATCH] refactor: delete unused test support modules --- .../audit-channel-security.test-helpers.ts | 19 ---- src/security/audit.test-helpers.ts | 49 ---------- ...rovider-registry-allowlist.test-helpers.ts | 91 ------------------- 3 files changed, 159 deletions(-) delete mode 100644 src/security/audit-channel-security.test-helpers.ts delete mode 100644 src/security/audit.test-helpers.ts delete mode 100644 src/test-utils/provider-registry-allowlist.test-helpers.ts diff --git a/src/security/audit-channel-security.test-helpers.ts b/src/security/audit-channel-security.test-helpers.ts deleted file mode 100644 index c750e0e88ea..00000000000 --- a/src/security/audit-channel-security.test-helpers.ts +++ /dev/null @@ -1,19 +0,0 @@ -import fs from "node:fs/promises"; -import os from "node:os"; -import path from "node:path"; -import { withEnvAsync } from "../test-utils/env.js"; - -export async function withChannelSecurityStateDir(fn: (tmp: string) => Promise) { - const fixtureRoot = await fs.mkdtemp(path.join(os.tmpdir(), "openclaw-security-audit-channel-")); - const stateDir = path.join(fixtureRoot, "state"); - const credentialsDir = path.join(stateDir, "credentials"); - await fs.mkdir(credentialsDir, { - recursive: true, - mode: 0o700, - }); - try { - await withEnvAsync({ OPENCLAW_STATE_DIR: stateDir }, () => fn(stateDir)); - } finally { - await fs.rm(fixtureRoot, { recursive: true, force: true }).catch(() => undefined); - } -} diff --git a/src/security/audit.test-helpers.ts b/src/security/audit.test-helpers.ts deleted file mode 100644 index ec85d6c6a89..00000000000 --- a/src/security/audit.test-helpers.ts +++ /dev/null @@ -1,49 +0,0 @@ -import { saveExecApprovals } from "../infra/exec-approvals.js"; -import type { SecurityAuditOptions, SecurityAuditReport } from "./audit.js"; -import { runSecurityAudit } from "./audit.js"; - -export const execDockerRawUnavailable: NonNullable< - SecurityAuditOptions["execDockerRawFn"] -> = async () => { - return { - stdout: Buffer.alloc(0), - stderr: Buffer.from("docker unavailable"), - code: 1, - }; -}; - -export function successfulProbeResult(url: string) { - return { - ok: true, - url, - connectLatencyMs: 1, - error: null, - close: null, - health: null, - status: null, - presence: null, - configSnapshot: null, - }; -} - -export async function audit( - config: SecurityAuditOptions["config"], - extra?: Omit & { preserveExecApprovals?: boolean }, -): Promise { - if (!extra?.preserveExecApprovals) { - saveExecApprovals({ version: 1, agents: {} }); - } - const { preserveExecApprovals: _preserveExecApprovals, ...options } = extra ?? {}; - return runSecurityAudit({ - config, - includeFilesystem: false, - includeChannelSecurity: false, - ...options, - }); -} - -export function hasFinding(res: SecurityAuditReport, checkId: string, severity?: string): boolean { - return res.findings.some( - (finding) => finding.checkId === checkId && (severity == null || finding.severity === severity), - ); -} diff --git a/src/test-utils/provider-registry-allowlist.test-helpers.ts b/src/test-utils/provider-registry-allowlist.test-helpers.ts deleted file mode 100644 index 071d91d81ee..00000000000 --- a/src/test-utils/provider-registry-allowlist.test-helpers.ts +++ /dev/null @@ -1,91 +0,0 @@ -import { beforeEach, vi } from "vitest"; -import { createEmptyPluginRegistry } from "../plugins/registry-empty.js"; - -const providerRegistryAllowlistMocks = vi.hoisted(() => ({ - resolveRuntimePluginRegistry: vi.fn< - (params?: unknown) => ReturnType | undefined - >(() => undefined), - loadPluginManifestRegistry: vi.fn(() => ({ plugins: [], diagnostics: [] })), - withBundledPluginEnablementCompat: vi.fn(({ config }) => config), - withBundledPluginVitestCompat: vi.fn(({ config }) => config), -})); - -vi.mock("../plugins/loader.js", () => ({ - resolveRuntimePluginRegistry: providerRegistryAllowlistMocks.resolveRuntimePluginRegistry, -})); - -vi.mock("../plugins/manifest-registry.js", () => ({ - loadPluginManifestRegistry: providerRegistryAllowlistMocks.loadPluginManifestRegistry, -})); - -vi.mock("../plugins/bundled-compat.js", async (importOriginal) => { - const actual = await importOriginal(); - return { - ...actual, - withBundledPluginEnablementCompat: - providerRegistryAllowlistMocks.withBundledPluginEnablementCompat, - withBundledPluginVitestCompat: providerRegistryAllowlistMocks.withBundledPluginVitestCompat, - }; -}); - -export function getProviderRegistryAllowlistMocks(): typeof providerRegistryAllowlistMocks { - return providerRegistryAllowlistMocks; -} - -export function createEmptyProviderRegistryAllowlistFallbackRegistry(): ReturnType< - typeof createEmptyPluginRegistry -> { - return createEmptyPluginRegistry(); -} - -export function installProviderRegistryAllowlistMockDefaults(): void { - beforeEach(() => { - providerRegistryAllowlistMocks.resolveRuntimePluginRegistry.mockReset(); - providerRegistryAllowlistMocks.resolveRuntimePluginRegistry.mockReturnValue(undefined); - providerRegistryAllowlistMocks.loadPluginManifestRegistry.mockReset(); - providerRegistryAllowlistMocks.loadPluginManifestRegistry.mockReturnValue({ - plugins: [], - diagnostics: [], - }); - providerRegistryAllowlistMocks.withBundledPluginEnablementCompat.mockReset(); - providerRegistryAllowlistMocks.withBundledPluginEnablementCompat.mockImplementation( - ({ config }) => config, - ); - providerRegistryAllowlistMocks.withBundledPluginVitestCompat.mockReset(); - providerRegistryAllowlistMocks.withBundledPluginVitestCompat.mockImplementation( - ({ config }) => config, - ); - }); -} - -export function primeBundledProviderAllowlistFallback(params: { - contractKey: "imageGenerationProviders" | "mediaUnderstandingProviders"; - providerId?: string; -}) { - const providerId = params.providerId ?? "openai"; - const cfg = { plugins: { allow: ["custom-plugin"] } }; - const compatConfig = { - plugins: { - allow: ["custom-plugin", providerId], - entries: { [providerId]: { enabled: true } }, - }, - }; - - providerRegistryAllowlistMocks.loadPluginManifestRegistry.mockReturnValue({ - plugins: [ - { - id: providerId, - origin: "bundled", - contracts: { [params.contractKey]: [providerId] }, - }, - ] as never, - diagnostics: [], - }); - providerRegistryAllowlistMocks.withBundledPluginEnablementCompat.mockReturnValue(compatConfig); - providerRegistryAllowlistMocks.withBundledPluginVitestCompat.mockReturnValue(compatConfig); - providerRegistryAllowlistMocks.resolveRuntimePluginRegistry.mockImplementation(() => - createEmptyProviderRegistryAllowlistFallbackRegistry(), - ); - - return { cfg, compatConfig, providerId }; -}