Skip to content

Open-source Grok Bot alternative for named AI teammates. Local-first desktop, web, and mobile clients with per-bot tools, instructions, and memory. Independent fork of T3 Code.

5.1 KB
Raw Blame
import { describe, expect, it } from "vite-plus/test";

import {
  formatProviderSkillDisplayName,
  getProviderSlashCommandsForSlashMenu,
  getProviderSkillsForSlashMenu,
  resolveProviderSkillSourceKind,
  resolveProviderSkillTextIcon,
} from "./providerSkills.ts";

describe("formatProviderSkillDisplayName", () => {
  it("prefers the provider display name", () => {
    expect(
      formatProviderSkillDisplayName({
        name: "review-follow-up",
        displayName: "Review Follow-up",
      }),
    ).toBe("Review Follow-up");
  });

  it("falls back to a title-cased skill name", () => {
    expect(
      formatProviderSkillDisplayName({
        name: "review-follow-up",
      }),
    ).toBe("Review Follow Up");
  });
});

describe("getProviderSkillsForSlashMenu", () => {
  it("keeps the skill alias when the provider also exposes it as a slash command", () => {
    const askMatt = {
      name: "ask-matt",
      path: "/Users/matt/.agents/skills/ask-matt/SKILL.md",
      enabled: true,
    };

    expect(getProviderSkillsForSlashMenu([askMatt], true).map((skill) => skill.name)).toEqual([
      "ask-matt",
    ]);
  });
});

describe("getProviderSlashCommandsForSlashMenu", () => {
  const commands = [
    { name: "ask-matt", description: "Ask which skill fits your situation." },
    { name: "compact", description: "Compact the conversation." },
  ];

  const skills = [
    {
      name: "ask-matt",
      path: "/Users/matt/.agents/skills/ask-matt/SKILL.md",
      enabled: true,
    },
  ];

  it("lets the skill alias win when a provider command has the same name", () => {
    expect(
      getProviderSlashCommandsForSlashMenu(commands, skills).map((command) => command.name),
    ).toEqual(["compact"]);
  });

  it("keeps the provider command when the matching skill alias is hidden", () => {
    const visibleSkills = getProviderSkillsForSlashMenu(skills, false);

    expect(
      getProviderSlashCommandsForSlashMenu(commands, visibleSkills).map((command) => command.name),
    ).toEqual(["ask-matt", "compact"]);
  });
});

describe("resolveProviderSkillSourceKind", () => {
  it("marks plugin-backed skills as app installs", () => {
    expect(
      resolveProviderSkillSourceKind({
        path: "/Users/julius/.codex/plugins/cache/openai-curated/github/skills/gh-fix-ci/SKILL.md",
        scope: "user",
      }),
    ).toBe("app");
  });

  it("maps standard scopes to source kinds", () => {
    expect(
      resolveProviderSkillSourceKind({
        path: "/workspace/.codex/skills/review-follow-up/SKILL.md",
        scope: "repo",
      }),
    ).toBe("repo");
    expect(
      resolveProviderSkillSourceKind({
        path: "/workspace/.codex/skills/review-follow-up/SKILL.md",
        scope: "project",
      }),
    ).toBe("project");
    expect(
      resolveProviderSkillSourceKind({
        path: "/Users/julius/.agents/skills/agent-browser/SKILL.md",
        scope: "user",
      }),
    ).toBe("personal");
    expect(
      resolveProviderSkillSourceKind({
        path: "/usr/local/share/codex/skills/imagegen/SKILL.md",
        scope: "system",
      }),
    ).toBe("system");
  });

  it("keeps unknown and missing scopes usable", () => {
    expect(
      resolveProviderSkillSourceKind({
        path: "/opt/skills/team-review/SKILL.md",
        scope: "team_shared",
      }),
    ).toBe("other");
    expect(
      resolveProviderSkillSourceKind({
        path: "/opt/skills/team-review/SKILL.md",
      }),
    ).toBe("other");
  });
});

describe("resolveProviderSkillTextIcon", () => {
  it.each([
    ["a single emoji", "๐Ÿ”ง"],
    ["a pictographic symbol", "โ˜…"],
    ["an emoji with a variation selector", "โค๏ธ"],
    ["a skin-tone modifier", "๐Ÿ‘๐Ÿฝ"],
    ["a ZWJ sequence", "๐Ÿง‘โ€๐Ÿ’ป"],
    ["a ZWJ sequence with selector and modifier", "๐Ÿณ๏ธโ€๐ŸŒˆ"],
    ["a regional-indicator flag", "๐Ÿ‡ฏ๐Ÿ‡ต"],
    ["a subdivision tag flag", "๐Ÿด๓ ง๓ ข๓ ฅ๓ ฎ๓ ง๓ ฟ"],
    ["a digit keycap", "1๏ธโƒฃ"],
    ["a hash keycap", "#๏ธโƒฃ"],
    ["an asterisk keycap", "*๏ธโƒฃ"],
  ])("accepts %s", (_label, icon) => {
    expect(resolveProviderSkillTextIcon({ icon })).toBe(icon);
  });

  it("strips surrounding spaces", () => {
    expect(resolveProviderSkillTextIcon({ icon: " ๐Ÿง‘โ€๐Ÿ’ป " })).toBe("๐Ÿง‘โ€๐Ÿ’ป");
  });

  it.each([
    ["a missing icon", undefined],
    ["a named glyph", "wrench"],
    ["an absolute asset path", "/icons/small.png"],
    ["a relative asset path", "./assets/icon.svg"],
    ["a bare digit", "1"],
    ["multi-glyph text", "ใ‚ใ„ใ†"],
    ["several emoji", "๐Ÿ”ง๐Ÿ”จ"],
    ["a bidi embedding", "โ€ช๐Ÿ”ง"],
    ["a bidi override", "โ€ฎโ€ฎ"],
    ["a bidi isolate", "๐Ÿ”งโฆ"],
    ["a left-to-right mark", "โ€Ž๐Ÿ”ง"],
    ["a right-to-left mark", "๐Ÿ”งโ€"],
    ["a C0 control", "๐Ÿ”ง\u0007"],
    ["a C1 control", "\u0085"],
    ["a line separator", "๐Ÿ”งโ€จ"],
    ["a paragraph separator", "โ€ฉ"],
    ["a zero-width space", "๐Ÿ”งโ€‹"],
    ["a word joiner", "โ ๐Ÿ”ง"],
    ["a trailing ZWJ", "๐Ÿ”งโ€"],
    ["a ZWJ joining non-emoji", "aโ€b"],
  ])("rejects %s", (_label, icon) => {
    expect(resolveProviderSkillTextIcon(icon === undefined ? {} : { icon })).toBeNull();
  });
});