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

AntigravitySkills.test.ts

303 lines11.4 KB

1import * as NodeServices from "@effect/platform-node/NodeServices";
2import { assert, it } from "@effect/vitest";
3import * as Effect from "effect/Effect";
4import * as FileSystem from "effect/FileSystem";
5import * as Path from "effect/Path";
6​
7import { discoverAntigravitySkills } from "./AntigravitySkills.ts";
8​
9const writeSkill = Effect.fn("writeSkill")(function* (directory: string, contents: string) {
10 const fileSystem = yield* FileSystem.FileSystem;
11 const path = yield* Path.Path;
12 yield* fileSystem.makeDirectory(directory, { recursive: true });
13 const skillPath = path.join(directory, "SKILL.md");
14 yield* fileSystem.writeFileString(skillPath, contents);
15 return skillPath;
16});
17​
18const makeWorkspace = Effect.fn("makeWorkspace")(function* () {
19 const fileSystem = yield* FileSystem.FileSystem;
20 const path = yield* Path.Path;
21 const temporaryDirectory = yield* fileSystem.makeTempDirectoryScoped({
22 prefix: "t3-antigravity-skills-",
23 });
24 return {
25 cwd: path.join(temporaryDirectory, "workspace"),
26 profileDirectory: path.join(temporaryDirectory, "profile"),
27 };
28});
29​
30it.layer(NodeServices.layer)("discoverAntigravitySkills", (it) => {
31 it.effect("reads skill names, descriptions and paths from the current native roots", () =>
32 Effect.gen(function* () {
33 const path = yield* Path.Path;
34 const input = yield* makeWorkspace();
35 const roots = [
36 { directory: path.join(input.profileDirectory, "config", "skills"), scope: "user" },
37 { directory: path.join(input.cwd, ".gemini", "skills"), scope: "project" },
38 {
39 directory: path.join(input.profileDirectory, "antigravity-cli", "skills"),
40 scope: "user",
41 },
42 { directory: path.join(input.cwd, ".agents", "skills"), scope: "project" },
43 ];
44 const expected = [];
45 for (const [index, root] of roots.entries()) {
46 const name = `review-${index}`;
47 const description = `Review changes in root ${index}.`;
48 const skillPath = yield* writeSkill(
49 path.join(root.directory, name),
50 `---\nname: ${name}\ndescription: ${description}\n---\n# Review\n`,
51 );
52 expected.push({ name, description, path: skillPath, scope: root.scope, enabled: true });
53 }
54​
55 assert.deepEqual(yield* discoverAntigravitySkills(input), expected);
56 }),
57 );
58​
59 it.effect("returns no skills when the native roots are missing", () =>
60 Effect.gen(function* () {
61 const input = yield* makeWorkspace();
62 assert.deepEqual(yield* discoverAntigravitySkills(input), []);
63 }),
64 );
65​
66 it.effect("discovers skills from the legacy workspace root", () =>
67 Effect.gen(function* () {
68 const path = yield* Path.Path;
69 const input = yield* makeWorkspace();
70 const skillPath = yield* writeSkill(
71 path.join(input.cwd, ".agent", "skills", "review"),
72 "---\nname: review\ndescription: Review changes.\n---\n",
73 );
74​
75 assert.deepEqual(yield* discoverAntigravitySkills(input), [
76 {
77 name: "review",
78 description: "Review changes.",
79 path: skillPath,
80 scope: "project",
81 enabled: true,
82 },
83 ]);
84 }),
85 );
86​
87 it.effect("uses native root order for duplicate names", () =>
88 Effect.gen(function* () {
89 const fileSystem = yield* FileSystem.FileSystem;
90 const path = yield* Path.Path;
91 const input = yield* makeWorkspace();
92 const roots = [
93 path.join(input.profileDirectory, "config", "skills"),
94 path.join(input.cwd, ".gemini", "skills"),
95 path.join(input.profileDirectory, "antigravity-cli", "skills"),
96 path.join(input.cwd, ".agents", "skills"),
97 path.join(input.cwd, ".agent", "skills"),
98 ];
99 for (const [index, root] of roots.entries()) {
100 yield* writeSkill(
101 path.join(root, `copy-${index}`),
102 `---\nname: review\ndescription: Copy ${index}.\n---\n`,
103 );
104 }
105​
106 for (const [index, root] of roots.entries()) {
107 const skills = yield* discoverAntigravitySkills(input);
108 assert.equal(skills.length, 1);
109 assert.equal(skills[0]?.path, path.join(root, `copy-${index}`, "SKILL.md"));
110 yield* fileSystem.remove(root, { recursive: true });
111 }
112 }),
113 );
114​
115 it.effect("loads a root skill without scanning its children", () =>
116 Effect.gen(function* () {
117 const fileSystem = yield* FileSystem.FileSystem;
118 const path = yield* Path.Path;
119 const input = yield* makeWorkspace();
120 const root = path.join(input.cwd, ".agents", "skills");
121 const skillPath = yield* writeSkill(root, "---\nname: root-skill\n---\n");
122 yield* writeSkill(path.join(root, "child"), "---\nname: child-skill\n---\n");
123​
124 assert.deepEqual(yield* discoverAntigravitySkills(input), [
125 { name: "root-skill", path: skillPath, scope: "project", enabled: true },
126 ]);
127​
128 yield* fileSystem.writeFileString(skillPath, "---\nname: [invalid\n---\n");
129 assert.deepEqual(yield* discoverAntigravitySkills(input), []);
130 }),
131 );
132​
133 it.effect("uses the filename when valid frontmatter has no name", () =>
134 Effect.gen(function* () {
135 const fileSystem = yield* FileSystem.FileSystem;
136 const path = yield* Path.Path;
137 const input = yield* makeWorkspace();
138 const skillPath = yield* writeSkill(
139 path.join(input.cwd, ".agents", "skills", "not-the-name"),
140 "---\n---\n# Skill body\n",
141 );
142​
143 assert.deepEqual(yield* discoverAntigravitySkills(input), [
144 { name: "SKILL", path: skillPath, scope: "project", enabled: true },
145 ]);
146​
147 const lowerCasePath = path.join(path.dirname(skillPath), "skill.md");
148 yield* fileSystem.rename(skillPath, lowerCasePath);
149 assert.deepEqual(yield* discoverAntigravitySkills(input), [
150 { name: "skill", path: lowerCasePath, scope: "project", enabled: true },
151 ]);
152​
153 yield* fileSystem.rename(lowerCasePath, path.join(path.dirname(skillPath), "SKILL.MD"));
154 assert.deepEqual(yield* discoverAntigravitySkills(input), []);
155 }),
156 );
157​
158 it.effect("accepts native metadata delimiters after leading text", () =>
159 Effect.gen(function* () {
160 const path = yield* Path.Path;
161 const input = yield* makeWorkspace();
162 const skillPath = yield* writeSkill(
163 path.join(input.cwd, ".agents", "skills", "review"),
164 "Leading text.---\nname: review\ndescription: null\n---Skill body.",
165 );
166​
167 assert.deepEqual(yield* discoverAntigravitySkills(input), [
168 { name: "review", path: skillPath, scope: "project", enabled: true },
169 ]);
170 }),
171 );
172​
173 it.effect("ignores invalid files and deeper directories but keeps native hidden skills", () =>
174 Effect.gen(function* () {
175 const fileSystem = yield* FileSystem.FileSystem;
176 const path = yield* Path.Path;
177 const input = yield* makeWorkspace();
178 const root = path.join(input.cwd, ".agents", "skills");
179 const invalidSkills = [
180 ["plain", "# Missing frontmatter\n"],
181 ["broken", "---\nname: [unclosed\n---\n"],
182 ["scalar", "---\n42\n---\n"],
183 ["wrong-type", "---\nname: invalid\ndescription: {}\n---\n"],
184 ["blank-name", '---\nname: " "\n---\n'],
185 ] as const;
186 for (const [name, contents] of invalidSkills) {
187 yield* writeSkill(path.join(root, name), contents);
188 }
189 yield* writeSkill(path.join(root, "nested", "deep"), "---\nname: too-deep\n---\n");
190 yield* writeSkill(
191 path.join(input.cwd, ".claude", "skills", "wrong-provider"),
192 "---\nname: wrong-provider\n---\n",
193 );
194 yield* fileSystem.makeDirectory(path.join(root, ".not-a-skill"));
195 yield* fileSystem.writeFileString(path.join(root, "README.md"), "Not a skill.");
196 const skillPath = yield* writeSkill(
197 path.join(root, ".native-hidden-skill"),
198 "---\nname: native-name\ndescription: >\n Review the code\n and run tests.\n---\n",
199 );
200​
201 assert.deepEqual(yield* discoverAntigravitySkills(input), [
202 {
203 name: "native-name",
204 description: "Review the code and run tests.",
205 path: skillPath,
206 scope: "project",
207 enabled: true,
208 },
209 ]);
210 }),
211 );
212​
213 it.effect("uses native URI order within a root and skips an invalid higher root", () =>
214 Effect.gen(function* () {
215 const fileSystem = yield* FileSystem.FileSystem;
216 const path = yield* Path.Path;
217 const input = yield* makeWorkspace();
218 const root = path.join(input.cwd, ".agents", "skills");
219 yield* writeSkill(
220 path.join(input.profileDirectory, "config", "skills", "review"),
221 "---\nname: [invalid\n---\n",
222 );
223 const nativeOrder = [" space-copy", "!-copy", "ø-copy", "a-copy"];
224 for (const name of nativeOrder) {
225 yield* writeSkill(path.join(root, name), "---\nname: review\n---\n");
226 }
227​
228 for (const name of nativeOrder) {
229 assert.deepEqual(yield* discoverAntigravitySkills(input), [
230 {
231 name: "review",
232 path: path.join(root, name, "SKILL.md"),
233 scope: "project",
234 enabled: true,
235 },
236 ]);
237 yield* fileSystem.remove(path.join(root, name), { recursive: true });
238 }
239 }),
240 );
241​
242 it.effect("follows directory symlinks used to install shared skills", () =>
243 Effect.gen(function* () {
244 const fileSystem = yield* FileSystem.FileSystem;
245 const path = yield* Path.Path;
246 const input = yield* makeWorkspace();
247 const sourceDirectory = path.join(input.profileDirectory, "shared-review");
248 yield* writeSkill(sourceDirectory, "---\nname: review\n---\n");
249 const root = path.join(input.cwd, ".agents", "skills");
250 const linkedDirectory = path.join(root, "review");
251 yield* fileSystem.makeDirectory(root, { recursive: true });
252 yield* fileSystem.symlink(sourceDirectory, linkedDirectory);
253​
254 assert.deepEqual(yield* discoverAntigravitySkills(input), [
255 {
256 name: "review",
257 path: path.join(linkedDirectory, "SKILL.md"),
258 scope: "project",
259 enabled: true,
260 },
261 ]);
262 }),
263 );
264​
265 it.effect("rejects an oversized skill instead of returning an incomplete catalog", () =>
266 Effect.gen(function* () {
267 const path = yield* Path.Path;
268 const input = yield* makeWorkspace();
269 const skillPath = yield* writeSkill(
270 path.join(input.cwd, ".agents", "skills", "oversized"),
271 `---\nname: oversized\ndescription: Read a large skill.\n---\n${"x".repeat(1_000_000)}`,
272 );
273​
274 const result = yield* discoverAntigravitySkills(input).pipe(Effect.result);
275 assert.equal(result._tag, "Failure");
276 if (result._tag === "Failure") {
277 assert.equal(result.failure.reason, "scan-budget-exhausted");
278 assert.equal(result.failure.path, skillPath);
279 }
280 }),
281 );
282​
283 it.effect("bounds the total read size across skills", () =>
284 Effect.gen(function* () {
285 const path = yield* Path.Path;
286 const input = yield* makeWorkspace();
287 const root = path.join(input.cwd, ".agents", "skills");
288 for (let index = 0; index < 9; index += 1) {
289 yield* writeSkill(
290 path.join(root, `large-${index}`),
291 `---\nname: large-${index}\n---\n${"x".repeat(900_000)}`,
292 );
293 }
294​
295 const result = yield* discoverAntigravitySkills(input).pipe(Effect.result);
296 assert.equal(result._tag, "Failure");
297 if (result._tag === "Failure") {
298 assert.equal(result.failure.reason, "scan-budget-exhausted");
299 assert.equal(result.failure.path, path.join(root, "large-8", "SKILL.md"));
300 }
301 }),
302 );
303});