Open History to see the last commit
1import { describe, expect, it } from "vite-plus/test";
2
3import type { ServerProviderSkill } from "@t3tools/contracts";
4
5import { searchProviderSkills } from "./providerSkillSearch";
6
7function makeSkill(input: Partial<ServerProviderSkill> & Pick<ServerProviderSkill, "name">) {
8 return {
9 path: `/tmp/${input.name}/SKILL.md`,
10 enabled: true,
11 ...input,
12 } satisfies ServerProviderSkill;
13}
14
15describe("searchProviderSkills", () => {
16 it("moves exact ui matches ahead of broader ui matches", () => {
17 const skills = [
18 makeSkill({
19 name: "agent-browser",
20 displayName: "Agent Browser",
21 shortDescription: "Browser automation CLI for AI agents",
22 }),
23 makeSkill({
24 name: "building-native-ui",
25 displayName: "Building Native Ui",
26 shortDescription: "Complete guide for building beautiful apps with Expo Router",
27 }),
28 makeSkill({
29 name: "ui",
30 displayName: "Ui",
31 shortDescription: "Explore, build, and refine UI.",
32 }),
33 ];
34
35 expect(searchProviderSkills(skills, "ui").map((skill) => skill.name)).toEqual([
36 "ui",
37 "building-native-ui",
38 ]);
39 });
40
41 it("uses fuzzy ranking for abbreviated queries", () => {
42 const skills = [
43 makeSkill({ name: "gh-fix-ci", displayName: "Gh Fix Ci" }),
44 makeSkill({ name: "github", displayName: "Github" }),
45 makeSkill({ name: "agent-browser", displayName: "Agent Browser" }),
46 ];
47
48 expect(searchProviderSkills(skills, "gfc").map((skill) => skill.name)).toEqual(["gh-fix-ci"]);
49 });
50
51 it("keeps user-only skills and omits agent-only ones", () => {
52 const skills = [
53 makeSkill({ name: "re-release-version", userInvocationOnly: true }),
54 makeSkill({ name: "release-context", userInvocable: false }),
55 makeSkill({ name: "release-version" }),
56 ];
57
58 expect(searchProviderSkills(skills, "release").map((skill) => skill.name)).toEqual([
59 "release-version",
60 "re-release-version",
61 ]);
62 });
63
64 it("omits disabled skills from results", () => {
65 const skills = [
66 makeSkill({ name: "ui", displayName: "Ui", enabled: false }),
67 makeSkill({ name: "frontend-design", displayName: "Frontend Design" }),
68 ];
69
70 expect(searchProviderSkills(skills, "ui").map((skill) => skill.name)).toEqual([]);
71 });
72
73 it("returns every enabled skill for an empty query", () => {
74 const skills = [
75 makeSkill({ name: "unslop" }),
76 makeSkill({ name: "browser" }),
77 makeSkill({ name: "disabled", enabled: false }),
78 ];
79
80 expect(searchProviderSkills(skills, "").map((skill) => skill.name)).toEqual([
81 "unslop",
82 "browser",
83 ]);
84 });
85
86 it("returns the first enabled definition for each skill name", () => {
87 const skills = [
88 makeSkill({ name: "branch-audit", path: "/Users/matt/.codex/skills/branch-audit/SKILL.md" }),
89 makeSkill({ name: "browser" }),
90 makeSkill({ name: "branch-audit", path: "/Users/matt/.agents/skills/branch-audit/SKILL.md" }),
91 ];
92
93 expect(searchProviderSkills(skills, "").map((skill) => skill.path)).toEqual([
94 "/Users/matt/.codex/skills/branch-audit/SKILL.md",
95 "/tmp/browser/SKILL.md",
96 ]);
97 });
98});