Skip to content
Source
Sign inSign up
pingdotgg/t3code
Open History to see the last commit

providerSkillSearch.test.ts

59 lines1.8 KB

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;
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("omits disabled skills from results", () => {
52 const skills = [
53 makeSkill({ name: "ui", displayName: "Ui", enabled: false }),
54 makeSkill({ name: "frontend-design", displayName: "Frontend Design" }),
55 ];
56​
57 expect(searchProviderSkills(skills, "ui").map((skill) => skill.name)).toEqual([]);
58 });
59});