refactor: delete unused test support modules

This commit is contained in:
Peter Steinberger
2026-05-01 12:24:12 +01:00
parent 8fd9264ae7
commit 5fbf406beb
3 changed files with 0 additions and 159 deletions

View File

@@ -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<void>) {
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);
}
}

View File

@@ -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<SecurityAuditOptions, "config"> & { preserveExecApprovals?: boolean },
): Promise<SecurityAuditReport> {
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),
);
}

View File

@@ -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<typeof createEmptyPluginRegistry> | 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<typeof import("../plugins/bundled-compat.js")>();
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 };
}