|
1 | | -import { lstat, readlink, realpath, symlink } from 'node:fs/promises'; |
| 1 | +import { lstat, readlink, realpath, symlink as fsSymlink } from 'node:fs/promises'; |
2 | 2 | import { fileURLToPath } from 'node:url'; |
3 | | -import { describe, it, expect } from 'vitest'; |
| 3 | +import { describe, it, expect, vi } from 'vitest'; |
4 | 4 | import { createFixture, createMocks } from '../test-utils/index.ts'; |
5 | | -import { copySkills, findParentPackage, resolveSkillsSource, updateAgentsMd } from './sync.ts'; |
| 5 | +import { |
| 6 | + copySkills, |
| 7 | + findParentPackage, |
| 8 | + resolveSkillsSource, |
| 9 | + sync, |
| 10 | + updateAgentsMd, |
| 11 | +} from './sync.ts'; |
6 | 12 |
|
7 | 13 | describe('copySkills', () => { |
8 | 14 | it('symlinks each skill into the destination', async () => { |
@@ -96,7 +102,7 @@ describe('copySkills', () => { |
96 | 102 | }, |
97 | 103 | }); |
98 | 104 | // Left behind by an older sync that linked through the real path. |
99 | | - await symlink( |
| 105 | + await fsSymlink( |
100 | 106 | `${await realpath(fileURLToPath(new URL('store/skills/', fixture.root)))}/removed`, |
101 | 107 | fileURLToPath(new URL('project/skills/removed', fixture.root)), |
102 | 108 | ); |
@@ -127,7 +133,7 @@ describe('updateAgentsMd', () => { |
127 | 133 | }); |
128 | 134 |
|
129 | 135 | expect(await fixture.text('AGENTS.md')).toContain( |
130 | | - '- **test** — [skills/test/SKILL.md](skills/test/SKILL.md) - Vitest test runner with colocated .test.ts files\n', |
| 136 | + '- **test** — [.agents/skills/test/SKILL.md](.agents/skills/test/SKILL.md) - Vitest test runner with colocated .test.ts files\n', |
131 | 137 | ); |
132 | 138 | }); |
133 | 139 | }); |
@@ -180,3 +186,62 @@ describe('findParentPackage', () => { |
180 | 186 | expect(await findParentPackage()).toBe(null); |
181 | 187 | }); |
182 | 188 | }); |
| 189 | + |
| 190 | +describe('sync', () => { |
| 191 | + it('links skills into .agents/skills and replaces links from older syncs', async () => { |
| 192 | + const fixture = await createFixture({ |
| 193 | + project: { |
| 194 | + 'package.json': '{ "name": "my-app" }', |
| 195 | + 'AGENTS.md': '# Project\n', |
| 196 | + '.gitignore': 'node_modules\n\n# bsh:skills\nskills/lifecycle/\n# /bsh:skills\n', |
| 197 | + // Left behind by an older version, now dangling. |
| 198 | + skills: { |
| 199 | + lifecycle: ({ symlink }) => |
| 200 | + symlink('../node_modules/.pnpm/old-hash/node_modules/@bomb.sh/tools/skills/lifecycle'), |
| 201 | + 'mine.md': 'user-owned', |
| 202 | + }, |
| 203 | + }, |
| 204 | + }); |
| 205 | + // Resolve the real path so relative links survive a symlinked tmpdir (macOS). |
| 206 | + const project = await realpath(fileURLToPath(new URL('project/', fixture.root))); |
| 207 | + createMocks({ env: { INIT_CWD: project } }); |
| 208 | + vi.spyOn(console, 'info').mockImplementation(() => {}); |
| 209 | + |
| 210 | + await sync({ args: [] }); |
| 211 | + |
| 212 | + const link = fileURLToPath(new URL('project/.agents/skills/lifecycle', fixture.root)); |
| 213 | + expect((await lstat(link)).isSymbolicLink()).toBe(true); |
| 214 | + expect(await fixture.text('project/.agents/skills/lifecycle/SKILL.md')).toContain( |
| 215 | + 'name: lifecycle', |
| 216 | + ); |
| 217 | + |
| 218 | + await expect( |
| 219 | + lstat(fileURLToPath(new URL('project/skills/lifecycle', fixture.root))), |
| 220 | + ).rejects.toThrow(); |
| 221 | + expect(await fixture.text('project/skills/mine.md')).toBe('user-owned'); |
| 222 | + |
| 223 | + const gitignore = await fixture.text('project/.gitignore'); |
| 224 | + expect(gitignore).toContain('.agents/skills/lifecycle/'); |
| 225 | + expect(gitignore).not.toMatch(/^skills\//m); |
| 226 | + |
| 227 | + expect(await fixture.text('project/AGENTS.md')).toContain( |
| 228 | + '[.agents/skills/lifecycle/SKILL.md](.agents/skills/lifecycle/SKILL.md)', |
| 229 | + ); |
| 230 | + }); |
| 231 | + |
| 232 | + it('removes the legacy skills directory once it is empty', async () => { |
| 233 | + const fixture = await createFixture({ |
| 234 | + project: { |
| 235 | + 'package.json': '{ "name": "my-app" }', |
| 236 | + skills: { lifecycle: ({ symlink }) => symlink('../gone/lifecycle') }, |
| 237 | + }, |
| 238 | + }); |
| 239 | + const project = await realpath(fileURLToPath(new URL('project/', fixture.root))); |
| 240 | + createMocks({ env: { INIT_CWD: project } }); |
| 241 | + vi.spyOn(console, 'info').mockImplementation(() => {}); |
| 242 | + |
| 243 | + await sync({ args: [] }); |
| 244 | + |
| 245 | + expect(await fixture.isDirectory('project/skills')).toBe(false); |
| 246 | + }); |
| 247 | +}); |
0 commit comments