mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-07 02:01:36 +00:00
refactor(auto-reply): share standard set/unset slash parsing
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
import { describe, expect, it } from "vitest";
|
||||
import { parseStandardSetUnsetSlashCommand } from "./commands-setunset-standard.js";
|
||||
import {
|
||||
parseSetUnsetCommand,
|
||||
parseSetUnsetCommandAction,
|
||||
@@ -114,3 +115,28 @@ describe("parseSlashCommandWithSetUnset", () => {
|
||||
expect(unknownAction).toEqual({ action: "error", message: "Usage: /config show|set|unset" });
|
||||
});
|
||||
});
|
||||
|
||||
describe("parseStandardSetUnsetSlashCommand", () => {
|
||||
it("uses default set/unset/error mappings", () => {
|
||||
const result = parseStandardSetUnsetSlashCommand<ParsedSetUnsetAction>({
|
||||
raw: '/config set a.b={"ok":true}',
|
||||
slash: "/config",
|
||||
invalidMessage: "Invalid /config syntax.",
|
||||
usageMessage: "Usage: /config show|set|unset",
|
||||
onKnownAction: () => undefined,
|
||||
});
|
||||
expect(result).toEqual({ action: "set", path: "a.b", value: { ok: true } });
|
||||
});
|
||||
|
||||
it("supports caller-provided mappings", () => {
|
||||
const result = parseStandardSetUnsetSlashCommand<ParsedSetUnsetAction>({
|
||||
raw: "/config unset a.b",
|
||||
slash: "/config",
|
||||
invalidMessage: "Invalid /config syntax.",
|
||||
usageMessage: "Usage: /config show|set|unset",
|
||||
onKnownAction: () => undefined,
|
||||
onUnset: (path) => ({ action: "unset", path: `wrapped:${path}` }),
|
||||
});
|
||||
expect(result).toEqual({ action: "unset", path: "wrapped:a.b" });
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user