mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-10 13:05:01 +00:00
refactor(agents): dedupe plugin hooks and test helpers
This commit is contained in:
@@ -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({
|
||||
|
||||
Reference in New Issue
Block a user