refactor(agents): dedupe plugin hooks and test helpers

This commit is contained in:
Peter Steinberger
2026-02-22 07:38:24 +00:00
parent 75c1bfbae8
commit 185fba1d22
16 changed files with 661 additions and 579 deletions

View File

@@ -3,20 +3,23 @@ import type { OpenClawConfig } from "../config/config.js";
import { applyExclusiveSlotSelection } from "./slots.js";
describe("applyExclusiveSlotSelection", () => {
it("selects the slot and disables other entries for the same kind", () => {
const config: OpenClawConfig = {
plugins: {
slots: { memory: "memory-core" },
entries: {
"memory-core": { enabled: true },
memory: { enabled: true },
const createMemoryConfig = (plugins?: OpenClawConfig["plugins"]): OpenClawConfig => ({
plugins: {
...plugins,
entries: {
...plugins?.entries,
memory: {
enabled: true,
...plugins?.entries?.memory,
},
},
};
},
});
const result = applyExclusiveSlotSelection({
const runMemorySelection = (config: OpenClawConfig, selectedId = "memory") =>
applyExclusiveSlotSelection({
config,
selectedId: "memory",
selectedId,
selectedKind: "memory",
registry: {
plugins: [
@@ -26,6 +29,13 @@ describe("applyExclusiveSlotSelection", () => {
},
});
it("selects the slot and disables other entries for the same kind", () => {
const config = createMemoryConfig({
slots: { memory: "memory-core" },
entries: { "memory-core": { enabled: true } },
});
const result = runMemorySelection(config);
expect(result.changed).toBe(true);
expect(result.config.plugins?.slots?.memory).toBe("memory");
expect(result.config.plugins?.entries?.["memory-core"]?.enabled).toBe(false);
@@ -36,15 +46,9 @@ describe("applyExclusiveSlotSelection", () => {
});
it("does nothing when the slot already matches", () => {
const config: OpenClawConfig = {
plugins: {
slots: { memory: "memory" },
entries: {
memory: { enabled: true },
},
},
};
const config = createMemoryConfig({
slots: { memory: "memory" },
});
const result = applyExclusiveSlotSelection({
config,
selectedId: "memory",
@@ -58,14 +62,7 @@ describe("applyExclusiveSlotSelection", () => {
});
it("warns when the slot falls back to a default", () => {
const config: OpenClawConfig = {
plugins: {
entries: {
memory: { enabled: true },
},
},
};
const config = createMemoryConfig();
const result = applyExclusiveSlotSelection({
config,
selectedId: "memory",
@@ -79,6 +76,22 @@ describe("applyExclusiveSlotSelection", () => {
);
});
it("keeps disabled competing plugins disabled without adding disable warnings", () => {
const config = createMemoryConfig({
entries: {
"memory-core": { enabled: false },
},
});
const result = runMemorySelection(config);
expect(result.changed).toBe(true);
expect(result.config.plugins?.entries?.["memory-core"]?.enabled).toBe(false);
expect(result.warnings).toContain(
'Exclusive slot "memory" switched from "memory-core" to "memory".',
);
expect(result.warnings).not.toContain('Disabled other "memory" slot plugins: memory-core.');
});
it("skips changes when no exclusive slot applies", () => {
const config: OpenClawConfig = {};
const result = applyExclusiveSlotSelection({