test: narrow plugin auto-enable manifest coverage

This commit is contained in:
Peter Steinberger
2026-04-11 05:54:36 +01:00
parent 8ab84bceb3
commit c836fd22d0
2 changed files with 20 additions and 44 deletions

View File

@@ -1,7 +1,10 @@
import fs from "node:fs";
import path from "node:path";
import { afterEach, describe, expect, it } from "vitest";
import { applyPluginAutoEnable } from "./plugin-auto-enable.js";
import {
applyPluginAutoEnable,
materializePluginAutoEnableCandidates,
} from "./plugin-auto-enable.js";
import {
makeApnChannelConfig,
makeBluebubblesAndImessageChannels,
@@ -9,7 +12,6 @@ import {
makeRegistry,
makeTempDir,
resetPluginAutoEnableTestState,
writePluginManifestFixture,
} from "./plugin-auto-enable.test-helpers.js";
function applyWithApnChannelConfig(extra?: {
@@ -71,13 +73,25 @@ describe("applyPluginAutoEnable channels", () => {
"utf-8",
);
const result = applyPluginAutoEnable({
const result = materializePluginAutoEnableCandidates({
config: {
channels: {
"env-primary": { token: "primary" },
"env-secondary": { token: "secondary" },
},
},
candidates: [
{
pluginId: "env-primary",
kind: "channel-configured",
channelId: "env-primary",
},
{
pluginId: "env-secondary",
kind: "channel-configured",
channelId: "env-secondary",
},
],
env: {
...makeIsolatedEnv(),
OPENCLAW_STATE_DIR: stateDir,
@@ -212,28 +226,5 @@ describe("applyPluginAutoEnable channels", () => {
expect(result.config.channels?.imessage?.enabled).toBe(true);
expect(result.changes.join("\n")).toContain("iMessage configured, enabled automatically.");
});
it("uses the provided env when loading installed plugin manifests", () => {
const stateDir = makeTempDir();
const pluginDir = path.join(stateDir, "extensions", "apn-channel");
writePluginManifestFixture({
rootDir: pluginDir,
id: "apn-channel",
channels: ["apn"],
});
const result = applyPluginAutoEnable({
config: makeApnChannelConfig(),
env: {
...makeIsolatedEnv(),
OPENCLAW_HOME: undefined,
OPENCLAW_STATE_DIR: stateDir,
OPENCLAW_BUNDLED_PLUGINS_DIR: "/nonexistent/bundled/plugins",
},
});
expect(result.config.plugins?.entries?.["apn-channel"]?.enabled).toBe(true);
expect(result.config.plugins?.entries?.apn).toBeUndefined();
});
});
});

View File

@@ -1,4 +1,3 @@
import path from "node:path";
import { afterEach, describe, expect, it } from "vitest";
import {
applyPluginAutoEnable,
@@ -8,9 +7,7 @@ import {
import {
makeIsolatedEnv,
makeRegistry,
makeTempDir,
resetPluginAutoEnableTestState,
writePluginManifestFixture,
} from "./plugin-auto-enable.test-helpers.js";
import { WhatsAppConfigSchema } from "./zod-schema.providers-whatsapp.js";
@@ -425,25 +422,13 @@ describe("applyPluginAutoEnable core", () => {
expect(result.changes.join("\n")).toContain("IRC configured, enabled automatically.");
});
it("uses the provided env when loading plugin manifests automatically", () => {
const stateDir = makeTempDir();
const pluginDir = path.join(stateDir, "extensions", "apn-channel");
writePluginManifestFixture({
rootDir: pluginDir,
id: "apn-channel",
channels: ["apn"],
});
it("uses the provided manifest registry for plugin channel ids", () => {
const result = applyPluginAutoEnable({
config: {
channels: { apn: { someKey: "value" } },
},
env: {
...makeIsolatedEnv(),
OPENCLAW_HOME: undefined,
OPENCLAW_STATE_DIR: stateDir,
OPENCLAW_BUNDLED_PLUGINS_DIR: "/nonexistent/bundled/plugins",
},
env: makeIsolatedEnv(),
manifestRegistry: makeRegistry([{ id: "apn-channel", channels: ["apn"] }]),
});
expect(result.config.plugins?.entries?.["apn-channel"]?.enabled).toBe(true);