/** * `iapl-skills --dest`: the "not the project root" rule is checked on RESOLVED paths. Before 1.17.1 the check * compared the paths as typed, so `--dest root-link` (a link to `.`), `--dest ..` or `--dest /` passed it, and the * run removed the `iapl-*` folders of the project root, its parent or the filesystem root (IAWL idea 13). */ import { spawnSync } from 'node:child_process' import { existsSync, mkdirSync, mkdtempSync, realpathSync, rmSync, symlinkSync, writeFileSync } from 'node:fs' import { tmpdir } from 'node:os' import path from 'node:path' import { afterAll, describe, expect, test } from 'vitest' const bin = path.resolve(import.meta.dirname, '../bin/iapl-skills.mjs') const made: string[] = [] afterAll(() => { for (const dir of made) {rmSync(dir, { force: true, recursive: true })} }) /** A throw-away project: a parent folder holding `project/` with an `iapl-mine` folder in its root. */ function project() { const parent = realpathSync(mkdtempSync(path.join(tmpdir(), 'iapl-skills-dest-'))) made.push(parent) const dir = path.join(parent, 'project') mkdirSync(path.join(dir, 'iapl-mine'), { recursive: true }) writeFileSync(path.join(dir, 'iapl-mine', 'keep.txt'), 'the project root holds this folder') mkdirSync(path.join(parent, 'iapl-next-door')) return { dir, parent } } const run = (cwd: string, dest: string) => spawnSync(process.execPath, [bin, '--dest', dest, '--no-pointer'], { cwd, encoding: 'utf8' }) describe('iapl-skills --dest is judged after the path is resolved', () => { test('a link to the project root is refused and the root keeps its iapl-* folders', () => { const { dir } = project() symlinkSync('.', path.join(dir, 'root-link')) const result = run(dir, 'root-link') expect(result.status, result.stdout).toBe(1) expect(result.stderr).toMatch(/not the project root/) expect(existsSync(path.join(dir, 'iapl-mine', 'keep.txt'))).toBe(true) }) test('a folder that holds the project (the parent, the filesystem root) is refused', () => { const { dir, parent } = project() for (const dest of ['..', '/', parent]) { const result = run(dir, dest) expect([dest, result.status]).toEqual([dest, 1]) } expect(existsSync(path.join(parent, 'iapl-next-door'))).toBe(true) }) test('a folder inside the project, a new one, or one elsewhere still works', () => { const { dir, parent } = project() expect(run(dir, '.agents/skills').status).toBe(0) expect(existsSync(path.join(dir, '.agents/skills/iapl-setup/SKILL.md'))).toBe(true) const shared = path.join(parent, 'shared-skills') expect(run(dir, shared).status).toBe(0) expect(existsSync(path.join(shared, 'iapl-setup/SKILL.md'))).toBe(true) expect(existsSync(path.join(dir, 'iapl-mine', 'keep.txt'))).toBe(true) }) })