refactor(auto-reply): share standard set/unset slash parsing

This commit is contained in:
Peter Steinberger
2026-02-18 23:08:18 +00:00
parent 6cbd00a3c6
commit 6eb0964fa6
4 changed files with 53 additions and 10 deletions

View File

@@ -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" });
});
});