test: dedupe plugin core utility suites

This commit is contained in:
Peter Steinberger
2026-03-28 01:37:20 +00:00
parent 2accc0391a
commit fad42b19ee
8 changed files with 320 additions and 322 deletions

View File

@@ -6,50 +6,16 @@ import {
} from "./config-state.js";
describe("normalizePluginsConfig", () => {
it("uses default memory slot when not specified", () => {
const result = normalizePluginsConfig({});
expect(result.slots.memory).toBe("memory-core");
});
it("respects explicit memory slot value", () => {
const result = normalizePluginsConfig({
slots: { memory: "custom-memory" },
});
expect(result.slots.memory).toBe("custom-memory");
});
it("disables memory slot when set to 'none' (case insensitive)", () => {
expect(
normalizePluginsConfig({
slots: { memory: "none" },
}).slots.memory,
).toBeNull();
expect(
normalizePluginsConfig({
slots: { memory: "None" },
}).slots.memory,
).toBeNull();
});
it("trims whitespace from memory slot value", () => {
const result = normalizePluginsConfig({
slots: { memory: " custom-memory " },
});
expect(result.slots.memory).toBe("custom-memory");
});
it("uses default when memory slot is empty string", () => {
const result = normalizePluginsConfig({
slots: { memory: "" },
});
expect(result.slots.memory).toBe("memory-core");
});
it("uses default when memory slot is whitespace only", () => {
const result = normalizePluginsConfig({
slots: { memory: " " },
});
expect(result.slots.memory).toBe("memory-core");
it.each([
[{}, "memory-core"],
[{ slots: { memory: "custom-memory" } }, "custom-memory"],
[{ slots: { memory: "none" } }, null],
[{ slots: { memory: "None" } }, null],
[{ slots: { memory: " custom-memory " } }, "custom-memory"],
[{ slots: { memory: "" } }, "memory-core"],
[{ slots: { memory: " " } }, "memory-core"],
] as const)("normalizes memory slot for %o", (config, expected) => {
expect(normalizePluginsConfig(config).slots.memory).toBe(expected);
});
it("normalizes plugin hook policy flags", () => {
@@ -172,36 +138,42 @@ describe("resolveEffectiveEnableState", () => {
});
}
it("enables bundled channels when channels.<id>.enabled=true", () => {
const state = resolveBundledTelegramState({
enabled: true,
});
expect(state).toEqual({ enabled: true });
});
it("keeps explicit plugin-level disable authoritative", () => {
const state = resolveBundledTelegramState({
enabled: true,
entries: {
telegram: {
enabled: false,
it.each([
[{ enabled: true }, { enabled: true }],
[
{
enabled: true,
entries: {
telegram: {
enabled: false,
},
},
},
});
expect(state).toEqual({ enabled: false, reason: "disabled in config" });
{ enabled: false, reason: "disabled in config" },
],
] as const)("resolves bundled telegram state for %o", (config, expected) => {
expect(resolveBundledTelegramState(config)).toEqual(expected);
});
});
describe("resolveEnableState", () => {
it("enables bundled plugins only when manifest metadata marks them enabled by default", () => {
expect(resolveEnableState("openai", "bundled", normalizePluginsConfig({}))).toEqual({
enabled: false,
reason: "bundled (disabled by default)",
});
expect(resolveEnableState("openai", "bundled", normalizePluginsConfig({}), true)).toEqual({
enabled: true,
});
});
it.each([
[
"openai",
"bundled",
normalizePluginsConfig({}),
undefined,
{ enabled: false, reason: "bundled (disabled by default)" },
],
["openai", "bundled", normalizePluginsConfig({}), true, { enabled: true }],
["google", "bundled", normalizePluginsConfig({}), true, { enabled: true }],
["profile-aware", "bundled", normalizePluginsConfig({}), true, { enabled: true }],
] as const)(
"resolves %s enable state for origin=%s manifestEnabledByDefault=%s",
(id, origin, config, manifestEnabledByDefault, expected) => {
expect(resolveEnableState(id, origin, config, manifestEnabledByDefault)).toEqual(expected);
},
);
it("keeps the selected memory slot plugin enabled even when omitted from plugins.allow", () => {
const state = resolveEnableState(
@@ -232,29 +204,21 @@ describe("resolveEnableState", () => {
expect(state).toEqual({ enabled: false, reason: "disabled in config" });
});
it("disables workspace plugins by default when they are only auto-discovered from the workspace", () => {
const state = resolveEnableState("workspace-helper", "workspace", normalizePluginsConfig({}));
expect(state).toEqual({
enabled: false,
reason: "workspace plugin (disabled by default)",
});
});
it("allows workspace plugins when explicitly listed in plugins.allow", () => {
const state = resolveEnableState(
"workspace-helper",
"workspace",
it.each([
[
normalizePluginsConfig({}),
{
enabled: false,
reason: "workspace plugin (disabled by default)",
},
],
[
normalizePluginsConfig({
allow: ["workspace-helper"],
}),
);
expect(state).toEqual({ enabled: true });
});
it("allows workspace plugins when explicitly enabled in plugin entries", () => {
const state = resolveEnableState(
"workspace-helper",
"workspace",
{ enabled: true },
],
[
normalizePluginsConfig({
entries: {
"workspace-helper": {
@@ -262,8 +226,10 @@ describe("resolveEnableState", () => {
},
},
}),
);
expect(state).toEqual({ enabled: true });
{ enabled: true },
],
] as const)("resolves workspace-helper enable state for %o", (config, expected) => {
expect(resolveEnableState("workspace-helper", "workspace", config)).toEqual(expected);
});
it("does not let the default memory slot auto-enable an untrusted workspace plugin", () => {
@@ -279,14 +245,4 @@ describe("resolveEnableState", () => {
reason: "workspace plugin (disabled by default)",
});
});
it("keeps bundled plugins enabled when manifest metadata marks them enabled by default", () => {
const state = resolveEnableState("google", "bundled", normalizePluginsConfig({}), true);
expect(state).toEqual({ enabled: true });
});
it("allows bundled plugins to opt into default enablement from manifest metadata", () => {
const state = resolveEnableState("profile-aware", "bundled", normalizePluginsConfig({}), true);
expect(state).toEqual({ enabled: true });
});
});