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

providerSkills.test.ts

254 lines7.4 KB

1import { ProviderDriverKind, ProviderInstanceId, type ServerProvider } from "@t3tools/contracts";
2import { describe, expect, it } from "vite-plus/test";
3​
4import {
5 dedupeProviderSkillsByName,
6 formatProviderSkillDisplayName,
7 getProviderSlashCommandsForSlashMenu,
8 getProviderSkillsForSlashMenu,
9 resolveProviderSkillsForCwd,
10 resolveProviderSlashCommandsForCwd,
11 resolveProviderSkillSourceKind,
12} from "./providerSkills.ts";
13​
14const provider = {
15 instanceId: ProviderInstanceId.make("codex"),
16 driver: ProviderDriverKind.make("codex"),
17 enabled: true,
18 installed: true,
19 version: "1.0.0",
20 status: "ready",
21 auth: { status: "authenticated" },
22 checkedAt: "2026-01-01T00:00:00.000Z",
23 models: [],
24 slashCommands: [{ name: "global" }],
25 skills: [{ name: "global", path: "/global/SKILL.md", enabled: true }],
26 workspaceSnapshots: [
27 {
28 cwd: "/workspace/project-a",
29 checkedAt: "2026-01-01T00:01:00.000Z",
30 slashCommands: [{ name: "project" }],
31 skills: [{ name: "project", path: "/workspace/project-a/SKILL.md", enabled: true }],
32 },
33 ],
34} satisfies ServerProvider;
35​
36describe("formatProviderSkillDisplayName", () => {
37 it("prefers the provider display name", () => {
38 expect(
39 formatProviderSkillDisplayName({
40 name: "review-follow-up",
41 displayName: "Review Follow-up",
42 }),
43 ).toBe("Review Follow-up");
44 });
45​
46 it("falls back to a title-cased skill name", () => {
47 expect(
48 formatProviderSkillDisplayName({
49 name: "review-follow-up",
50 }),
51 ).toBe("Review Follow Up");
52 });
53});
54​
55describe("dedupeProviderSkillsByName", () => {
56 it("keeps the first resolved skill and preserves unrelated skill order", () => {
57 const firstSkill = {
58 name: "branch-audit",
59 path: "/Users/matt/.codex/skills/branch-audit/SKILL.md",
60 enabled: true,
61 };
62 const otherSkill = {
63 name: "browser",
64 path: "/Users/matt/.agents/skills/browser/SKILL.md",
65 enabled: true,
66 };
67 const duplicateSkill = {
68 name: "Branch-Audit",
69 path: "/Users/matt/.agents/skills/branch-audit/SKILL.md",
70 enabled: true,
71 };
72​
73 expect(dedupeProviderSkillsByName([firstSkill, otherSkill, duplicateSkill])).toEqual([
74 firstSkill,
75 otherSkill,
76 ]);
77 });
78});
79​
80describe("getProviderSkillsForSlashMenu", () => {
81 it("keeps the skill alias when the provider also exposes it as a slash command", () => {
82 const askMatt = {
83 name: "ask-matt",
84 path: "/Users/matt/.agents/skills/ask-matt/SKILL.md",
85 enabled: true,
86 };
87 expect(getProviderSkillsForSlashMenu([askMatt], true).map((skill) => skill.name)).toEqual([
88 "ask-matt",
89 ]);
90 });
91​
92 it("shows one row when enabled skills share a name", () => {
93 const skills = [
94 {
95 name: "babysit-pr",
96 path: "/Users/matt/.codex/skills/babysit-pr/SKILL.md",
97 enabled: true,
98 },
99 {
100 name: "browser",
101 path: "/Users/matt/.agents/skills/browser/SKILL.md",
102 enabled: true,
103 },
104 {
105 name: "babysit-pr",
106 path: "/Users/matt/.agents/skills/babysit-pr/SKILL.md",
107 enabled: true,
108 },
109 ];
110​
111 expect(getProviderSkillsForSlashMenu(skills, true).map((skill) => skill.name)).toEqual([
112 "babysit-pr",
113 "browser",
114 ]);
115 });
116​
117 it("keeps an enabled skill when a disabled duplicate appears first", () => {
118 const enabledSkill = {
119 name: "babysit-pr",
120 path: "/Users/matt/.agents/skills/babysit-pr/SKILL.md",
121 enabled: true,
122 };
123 const skills = [
124 {
125 name: "babysit-pr",
126 path: "/Users/matt/.codex/skills/babysit-pr/SKILL.md",
127 enabled: false,
128 },
129 enabledSkill,
130 ];
131​
132 expect(getProviderSkillsForSlashMenu(skills, true)).toEqual([enabledSkill]);
133 });
134});
135​
136describe("getProviderSkillsForSlashMenu", () => {
137 it("drops a skill the provider reserves for the agent", () => {
138 const skills = [
139 {
140 name: "legacy-system-context",
141 path: "/Users/matt/.claude/skills/legacy-system-context/SKILL.md",
142 enabled: true,
143 userInvocable: false,
144 },
145 {
146 name: "deploy",
147 path: "/Users/matt/.claude/skills/deploy/SKILL.md",
148 enabled: true,
149 // Reserved for the user, not the agent: still a valid pick.
150 userInvocationOnly: true,
151 },
152 ];
153​
154 expect(getProviderSkillsForSlashMenu(skills, true).map((skill) => skill.name)).toEqual([
155 "deploy",
156 ]);
157 });
158});
159​
160describe("getProviderSlashCommandsForSlashMenu", () => {
161 const commands = [
162 { name: "ask-matt", description: "Ask which skill fits your situation." },
163 { name: "compact", description: "Compact the conversation." },
164 ];
165 const skills = [
166 {
167 name: "ask-matt",
168 path: "/Users/matt/.agents/skills/ask-matt/SKILL.md",
169 enabled: true,
170 },
171 ];
172​
173 it("lets the skill alias win when a provider command has the same name", () => {
174 expect(
175 getProviderSlashCommandsForSlashMenu(commands, skills).map((command) => command.name),
176 ).toEqual(["compact"]);
177 });
178​
179 it("keeps the provider command when the matching skill alias is hidden", () => {
180 const visibleSkills = getProviderSkillsForSlashMenu(skills, false);
181​
182 expect(
183 getProviderSlashCommandsForSlashMenu(commands, visibleSkills).map((command) => command.name),
184 ).toEqual(["ask-matt", "compact"]);
185 });
186});
187​
188describe("resolveProviderSkillSourceKind", () => {
189 it("marks plugin-backed skills as app installs", () => {
190 expect(
191 resolveProviderSkillSourceKind({
192 path: "/Users/julius/.codex/plugins/cache/openai-curated/github/skills/gh-fix-ci/SKILL.md",
193 scope: "user",
194 }),
195 ).toBe("app");
196 });
197​
198 it("maps standard scopes to source kinds", () => {
199 expect(
200 resolveProviderSkillSourceKind({
201 path: "/workspace/.codex/skills/review-follow-up/SKILL.md",
202 scope: "repo",
203 }),
204 ).toBe("repo");
205 expect(
206 resolveProviderSkillSourceKind({
207 path: "/workspace/.codex/skills/review-follow-up/SKILL.md",
208 scope: "project",
209 }),
210 ).toBe("project");
211 expect(
212 resolveProviderSkillSourceKind({
213 path: "/Users/julius/.agents/skills/agent-browser/SKILL.md",
214 scope: "user",
215 }),
216 ).toBe("personal");
217 expect(
218 resolveProviderSkillSourceKind({
219 path: "/usr/local/share/codex/skills/imagegen/SKILL.md",
220 scope: "system",
221 }),
222 ).toBe("system");
223 });
224​
225 it("keeps unknown and missing scopes usable", () => {
226 expect(
227 resolveProviderSkillSourceKind({
228 path: "/opt/skills/team-review/SKILL.md",
229 scope: "team_shared",
230 }),
231 ).toBe("other");
232 expect(
233 resolveProviderSkillSourceKind({
234 path: "/opt/skills/team-review/SKILL.md",
235 }),
236 ).toBe("other");
237 });
238});
239​
240describe("workspace provider snapshots", () => {
241 it("uses the cwd snapshot after a provider session has populated it", () => {
242 expect(resolveProviderSkillsForCwd(provider, "/workspace/project-a")).toEqual([
243 { name: "project", path: "/workspace/project-a/SKILL.md", enabled: true },
244 ]);
245 expect(resolveProviderSlashCommandsForCwd(provider, "/workspace/project-a")).toEqual([
246 { name: "project" },
247 ]);
248 });
249​
250 it("keeps the machine snapshot before this cwd has a provider snapshot", () => {
251 expect(resolveProviderSkillsForCwd(provider, "/workspace/project-b")).toEqual(provider.skills);
252 expect(resolveProviderSlashCommandsForCwd(provider, null)).toEqual(provider.slashCommands);
253 });
254});