Files
moltbot/src/config/plugin-auto-enable.test-helpers.ts
pashpashpash 563dca82f4 Add Codex happy path prompt snapshots (#75807)
* Add Codex prompt snapshots

* Fix prompt snapshot scenario catalogs

* Harden prompt snapshot drift check

* Fix CLI compat build export

* fix: keep codex snapshots out of core plugin surface

* fix: harden prompt snapshot ci checks

* fix: accept readonly web search onboarding scopes

* fix: repair plugin sdk package boundary types

* fix: clear prompt snapshot ci regressions

* fix: clear latest main ci checks

* fix: resolve latest main discord helper overlap

* fix: refresh codex dynamic tool snapshots

* fix: align prompt snapshot branch with latest ci

* fix: isolate plugin auto enable tests

* test: refresh prompt dynamic tool snapshots

* fix: stabilize bundled channel auto enable

* fix: clean stale prompt snapshots
2026-05-03 00:59:55 +09:00

82 lines
2.7 KiB
TypeScript

import path from "node:path";
import { clearCurrentPluginMetadataSnapshot } from "../plugins/current-plugin-metadata-snapshot.js";
import { type PluginManifestRegistry } from "../plugins/manifest-registry.js";
import { type PluginOrigin } from "../plugins/plugin-origin.types.js";
import { clearPluginSetupRegistryCache } from "../plugins/setup-registry.js";
import { cleanupTrackedTempDirs, makeTrackedTempDir } from "../plugins/test-helpers/fs-fixtures.js";
const tempDirs: string[] = [];
export function resetPluginAutoEnableTestState(): void {
clearCurrentPluginMetadataSnapshot();
clearPluginSetupRegistryCache();
cleanupTrackedTempDirs(tempDirs);
}
export function makeTempDir(): string {
return makeTrackedTempDir("openclaw-plugin-auto-enable", tempDirs);
}
export function makeIsolatedEnv(overrides: NodeJS.ProcessEnv = {}): NodeJS.ProcessEnv {
const rootDir = makeTempDir();
return {
OPENCLAW_STATE_DIR: path.join(rootDir, "state"),
OPENCLAW_BUNDLED_PLUGINS_DIR: path.join(process.cwd(), "extensions"),
OPENCLAW_TEST_TRUST_BUNDLED_PLUGINS_DIR: "1",
VITEST: "true",
...overrides,
};
}
export function makeRegistry(
plugins: Array<{
id: string;
channels: string[];
activation?: { onAgentHarnesses?: string[] };
autoEnableWhenConfiguredProviders?: string[];
modelSupport?: { modelPrefixes?: string[]; modelPatterns?: string[] };
contracts?: { webSearchProviders?: string[]; webFetchProviders?: string[]; tools?: string[] };
providers?: string[];
cliBackends?: string[];
origin?: PluginOrigin;
configSchema?: Record<string, unknown>;
channelConfigs?: Record<
string,
{ schema: Record<string, unknown>; label?: string; preferOver?: string[] }
>;
}>,
): PluginManifestRegistry {
return {
plugins: plugins.map((plugin) => ({
id: plugin.id,
channels: plugin.channels,
activation: plugin.activation,
autoEnableWhenConfiguredProviders: plugin.autoEnableWhenConfiguredProviders,
modelSupport: plugin.modelSupport,
contracts: plugin.contracts,
configSchema: plugin.configSchema,
channelConfigs: plugin.channelConfigs,
providers: plugin.providers ?? [],
cliBackends: plugin.cliBackends ?? [],
skills: [],
hooks: [],
origin: plugin.origin ?? "config",
rootDir: `/fake/${plugin.id}`,
source: `/fake/${plugin.id}/index.js`,
manifestPath: `/fake/${plugin.id}/openclaw.plugin.json`,
})),
diagnostics: [],
};
}
export function makeApnChannelConfig() {
return { channels: { apn: { someKey: "value" } } };
}
export function makeBluebubblesAndImessageChannels() {
return {
bluebubbles: { serverUrl: "http://localhost:1234", password: "x" },
imessage: { cliPath: "/usr/local/bin/imsg" },
};
}