Files
agent-radar 2ed3415fb7
Publish Claude Code Binaries / Stage and publish binaries (push) Canceled after 0s
Publish Tutti App Runtime / Build darwin-arm64 (push) Canceled after 0s
Publish Tutti App Runtime / Build darwin-amd64 (push) Canceled after 0s
Publish Tutti App Runtime / Build linux-amd64 (push) Canceled after 0s
Publish Tutti App Runtime / Build windows-amd64 (push) Canceled after 0s
Sync Tutti Agent Skills / sync (push) Canceled after 0s
Windows Agent Adapters / Test Windows agent adapters (push) Canceled after 0s
Windows Daemon Adapters / Test Windows daemon adapters (push) Canceled after 0s
Publish Tutti App Runtime / Publish runtime catalog (push) Canceled after 0s
源码快照 @ 2026-09-01 (source-only, 剔除非源码素材)
2026-09-01 20:17:27 +08:00

78 lines
2.4 KiB
TypeScript

import { describe, expect, it } from "vitest";
import {
draftForSlashCommand,
filterSlashCommands,
labelForSlashCommand,
mergeSlashCommands,
moveSlashCommandHighlight,
parseSlashCommandInvocation,
promptForSlashCommand
} from "./agentSlashCommands";
describe("agentSlashCommands", () => {
it("filters by command name prefix and description substring", () => {
const commands = [
{ name: "web", description: "Search online" },
{ name: "read", description: "Open files" },
{ name: "review", description: "Inspect changes" }
];
expect(
filterSlashCommands(commands, "re").map((command) => command.name)
).toEqual(["read", "review"]);
expect(
filterSlashCommands(commands, "online").map((command) => command.name)
).toEqual(["web"]);
});
it("wraps keyboard highlight movement and creates draft text", () => {
expect(moveSlashCommandHighlight(0, 3, -1)).toBe(2);
expect(moveSlashCommandHighlight(2, 3, 1)).toBe(0);
expect(draftForSlashCommand({ name: " web " })).toBe("/web ");
expect(draftForSlashCommand({ name: " web " }, " /w")).toBe(" /web ");
});
it("merges provider commands before fallback commands and deduplicates by name", () => {
expect(
mergeSlashCommands(
[
{ name: " compact ", description: "provider compact" },
{ name: "read" }
],
[
{ name: "compact", description: "fallback compact" },
{ name: "status" }
]
)
).toEqual([
{ name: "compact", description: "provider compact" },
{ name: "read" },
{ name: "status" }
]);
});
it("parses prompt-start slash command invocations with arguments", () => {
expect(parseSlashCommandInvocation(" /plan refactor auth")).toEqual({
args: "refactor auth",
commandName: "plan",
leadingWhitespace: " ",
normalizedPrompt: "/plan refactor auth"
});
expect(parseSlashCommandInvocation("/compact")).toEqual({
args: "",
commandName: "compact",
leadingWhitespace: "",
normalizedPrompt: "/compact"
});
expect(parseSlashCommandInvocation("please /compact")).toBeNull();
});
it("creates prompt text for a slash command", () => {
expect(promptForSlashCommand({ name: " init " })).toBe("/init");
});
it("creates display text for a slash command", () => {
expect(labelForSlashCommand({ name: " compact " })).toBe("compact");
});
});