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

providerSkills.test.ts

184 lines6.3 KB

1import { ProviderDriverKind, ProviderInstanceId, type ServerProvider } from "@t3tools/contracts";
2import { describe, expect, it } from "vite-plus/test";
3​
4import {
5 getProviderSkillsForSlashMenu,
6 hasCompleteProviderWorkspaceSnapshot,
7 resolveProviderForCwd,
8 resolveProviderSkillsForCwd,
9 resolveProviderSlashCommandsForCwd,
10} from "./providerSkills.ts";
11​
12const provider = {
13 instanceId: ProviderInstanceId.make("codex"),
14 driver: ProviderDriverKind.make("codex"),
15 enabled: true,
16 installed: true,
17 version: "1.0.0",
18 status: "ready",
19 auth: { status: "authenticated" },
20 checkedAt: "2026-01-01T00:00:00.000Z",
21 models: [],
22 slashCommands: [{ name: "global" }],
23 skills: [{ name: "global", path: "/global/SKILL.md", enabled: true }],
24 workspaceSnapshots: [
25 {
26 cwd: "/workspace/project-a",
27 checkedAt: "2026-01-01T00:01:00.000Z",
28 slashCommands: [{ name: "project" }],
29 skills: [{ name: "project", path: "/workspace/project-a/SKILL.md", enabled: true }],
30 },
31 ],
32} satisfies ServerProvider;
33​
34describe("getProviderSkillsForSlashMenu", () => {
35 it("keeps the skill alias when the provider also exposes it as a slash command", () => {
36 const askMatt = {
37 name: "ask-matt",
38 path: "/Users/matt/.agents/skills/ask-matt/SKILL.md",
39 enabled: true,
40 };
41 expect(getProviderSkillsForSlashMenu([askMatt], true).map((skill) => skill.name)).toEqual([
42 "ask-matt",
43 ]);
44 });
45​
46 it("shows one row when enabled skills share a name", () => {
47 const skills = [
48 {
49 name: "babysit-pr",
50 path: "/Users/matt/.codex/skills/babysit-pr/SKILL.md",
51 enabled: true,
52 },
53 {
54 name: "browser",
55 path: "/Users/matt/.agents/skills/browser/SKILL.md",
56 enabled: true,
57 },
58 {
59 name: "babysit-pr",
60 path: "/Users/matt/.agents/skills/babysit-pr/SKILL.md",
61 enabled: true,
62 },
63 ];
64​
65 expect(getProviderSkillsForSlashMenu(skills, true).map((skill) => skill.name)).toEqual([
66 "babysit-pr",
67 "browser",
68 ]);
69 });
70​
71 it("keeps an enabled skill when a disabled duplicate appears first", () => {
72 const enabledSkill = {
73 name: "babysit-pr",
74 path: "/Users/matt/.agents/skills/babysit-pr/SKILL.md",
75 enabled: true,
76 };
77 const skills = [
78 {
79 name: "babysit-pr",
80 path: "/Users/matt/.codex/skills/babysit-pr/SKILL.md",
81 enabled: false,
82 },
83 enabledSkill,
84 ];
85​
86 expect(getProviderSkillsForSlashMenu(skills, true)).toEqual([enabledSkill]);
87 });
88});
89​
90describe("workspace provider snapshots", () => {
91 it("uses the cwd snapshot after a provider session has populated it", () => {
92 expect(resolveProviderSkillsForCwd(provider, "/workspace/project-a")).toEqual([
93 { name: "project", path: "/workspace/project-a/SKILL.md", enabled: true },
94 ]);
95 expect(resolveProviderSlashCommandsForCwd(provider, "/workspace/project-a")).toEqual([
96 { name: "project" },
97 ]);
98 });
99​
100 it("keeps the machine snapshot before this cwd has a provider snapshot", () => {
101 expect(resolveProviderSkillsForCwd(provider, "/workspace/project-b")).toEqual(provider.skills);
102 expect(resolveProviderSlashCommandsForCwd(provider, null)).toEqual(provider.slashCommands);
103 });
104​
105 it("uses partial workspace skills and commands while keeping discovery retryable", () => {
106 const partial = {
107 ...provider,
108 workspaceSnapshots: provider.workspaceSnapshots.map((snapshot) => ({
109 ...snapshot,
110 slashCommands: [{ name: "compact" }],
111 slashCommandsPending: true,
112 })),
113 } satisfies ServerProvider;
114 expect(resolveProviderSkillsForCwd(partial, "/workspace/project-a")).toEqual(
115 provider.workspaceSnapshots[0]?.skills,
116 );
117 expect(resolveProviderSlashCommandsForCwd(partial, "/workspace/project-a")).toEqual([
118 { name: "compact" },
119 ]);
120 expect(hasCompleteProviderWorkspaceSnapshot(partial, "/workspace/project-a")).toBe(false);
121 expect(hasCompleteProviderWorkspaceSnapshot(provider, "/workspace/project-a")).toBe(true);
122 expect(hasCompleteProviderWorkspaceSnapshot(provider, "/workspace/project-b")).toBe(false);
123 expect(hasCompleteProviderWorkspaceSnapshot(undefined, "/workspace/project-a")).toBe(false);
124 expect(hasCompleteProviderWorkspaceSnapshot(provider, null)).toBe(false);
125 });
126});
127​
128describe("resolveProviderForCwd", () => {
129 it("switches workspace options for every model without changing the machine catalog", () => {
130 const reasoning = {
131 id: "reasoning",
132 label: "Reasoning",
133 type: "select" as const,
134 options: [{ id: "high", label: "High" }],
135 };
136 const globalAgent = {
137 id: "agent",
138 label: "Agent",
139 type: "select" as const,
140 options: [{ id: "build", label: "Build" }],
141 };
142 const workspaceAgent = {
143 ...globalAgent,
144 options: [{ id: "readonly", label: "Readonly" }],
145 };
146 const emptyAgent = { ...globalAgent, options: [] };
147 const catalog: ServerProvider = {
148 ...provider,
149 models: [
150 {
151 slug: "model",
152 name: "Model",
153 isCustom: false,
154 capabilities: { optionDescriptors: [globalAgent, reasoning] },
155 },
156 { slug: "custom", name: "Custom", isCustom: true, capabilities: null },
157 { slug: "legacy", name: "Legacy", isCustom: false, capabilities: {} },
158 ],
159 workspaceSnapshots: [
160 ...provider.workspaceSnapshots,
161 ...[workspaceAgent, emptyAgent].map((agent, index) => ({
162 ...provider.workspaceSnapshots[0]!,
163 cwd: `/workspace/options-${index}`,
164 optionDescriptors: [agent],
165 })),
166 ],
167 };
168 const original = structuredClone(catalog);
169​
170 for (const [index, agent] of [workspaceAgent, emptyAgent, workspaceAgent].entries()) {
171 const scoped = resolveProviderForCwd(catalog, `/workspace/options-${index % 2}`);
172 expect(scoped.models.map((model) => model.capabilities?.optionDescriptors)).toEqual([
173 expect.arrayContaining([reasoning, agent]),
174 [agent],
175 [agent],
176 ]);
177 expect(scoped.models[0]?.capabilities?.optionDescriptors).toHaveLength(2);
178 }
179 expect(catalog).toEqual(original);
180 expect(resolveProviderForCwd(catalog, "/workspace/unknown")).toBe(catalog);
181 expect(resolveProviderForCwd(catalog, "/workspace/project-a")).toBe(catalog);
182 expect(resolveProviderForCwd(catalog, null)).toBe(catalog);
183 });
184});