Files
ipal-kit/test/externalSkills.test.ts
T
Radosław SmolińskiandClaude Opus 5.5 e1f82ce387 ipal-skills --external: vendored third-party agent skills, pinned
- docs/agent/external: Vercel react-best-practices and composition-patterns
  (MIT), Addy Osmani accessibility (MIT), Anthropic frontend-design
  (Apache-2.0), official Payload skill at v3.92.1 (MIT) — text only, each
  with its licence, SOURCE.md (repo, commit) and an override note in front
  of the SKILL.md (ipal-kit first, Payload fetching over swr, DESIGN.md
  tokens, Payload 3 not 4); manifest.json with sha256 per file
- scripts/vendor-external-skills.mjs (maintainer, not shipped): fetches by
  full commit SHA only, rejects non-text or executable files, regenerates
  the manifest; --check verifies it
- ipal-skills --external [names]: copies ext-* after checking every file
  against the manifest, downloads nothing, never touches ext-* folders
  without ipal-kit's SOURCE.md, removes only retired ones it installed;
  an unknown name stops the run before anything is copied
- AGENT.md §14, ipal-setup stage 2 (optional step), README: usage,
  overrides, how to update the pins
- test/externalSkills.test.ts: pins are SHAs, no branch fetch, checksums,
  text only, licences, override note, installer leaves other folders alone

Co-Authored-By: Claude Opus 5.5 <[email protected]>
2026-10-29 11:54:35 +01:00

123 lines
5.6 KiB
TypeScript

/**
* Third-party agent skills vendored into the package (docs/agent/external) and installed by
* `ipal-skills --external`. They are pinned, text-only and carry their licence; the installer
* downloads nothing and leaves the project's own skill folders alone.
*/
import { execFileSync } from 'node:child_process'
import { createHash } from 'node:crypto'
import { cpSync, existsSync, mkdirSync, mkdtempSync, readdirSync, readFileSync, rmSync, statSync, writeFileSync } from 'node:fs'
import { tmpdir } from 'node:os'
import path from 'node:path'
import { afterAll, describe, expect, test } from 'vitest'
type VendoredSkill = {
commit: string
files: Record<string, string>
license: string
name: string
path: string
publisher: string
repo: string
}
const root = path.resolve(import.meta.dirname, '..')
const extDir = path.join(root, 'docs/agent/external')
const manifest = JSON.parse(readFileSync(path.join(extDir, 'manifest.json'), 'utf8')) as { skills: VendoredSkill[] }
const read = (file: string) => readFileSync(file, 'utf8')
function filesOf(dir: string, base = dir): string[] {
return readdirSync(dir).flatMap((name) => {
const full = path.join(dir, name)
return statSync(full).isDirectory() ? filesOf(full, base) : [path.relative(base, full).split(path.sep).join('/')]
})
}
describe('vendored external skills', () => {
test('every skill is pinned to a full commit SHA, never a branch', () => {
expect(manifest.skills.length).toBeGreaterThan(0)
for (const skill of manifest.skills) {
expect(skill.commit, skill.name).toMatch(/^[0-9a-f]{40}$/)
expect(skill.repo, skill.name).toMatch(/^https:\/\/github\.com\/[\w.-]+\/[\w.-]+$/)
}
// The vendoring script holds the same pins, and fetches by commit only.
const script = read(path.join(root, 'scripts/vendor-external-skills.mjs'))
const pins = [...script.matchAll(/commit: '([^']+)'/g)].map((m) => m[1])
expect(pins.sort()).toEqual(manifest.skills.map((s) => s.commit).sort())
expect(script).not.toMatch(/--branch|refs\/heads|\/main\b|\/master\b/)
})
test('the installer downloads nothing', () => {
const bin = read(path.join(root, 'bin/ipal-skills.mjs'))
expect(bin).not.toMatch(/https?:\/\/|\bfetch\(|child_process|execFile|spawn/)
})
test('the files match manifest.json, are text only, and carry a licence and the source', () => {
for (const skill of manifest.skills) {
const dir = path.join(extDir, skill.name)
const files = filesOf(dir).sort()
expect(files, skill.name).toEqual(Object.keys(skill.files).sort())
for (const file of files) {
const full = path.join(dir, file)
expect(createHash('sha256').update(readFileSync(full)).digest('hex'), `${skill.name}/${file}`).toBe(skill.files[file])
expect(file, `${skill.name}: text only`).toMatch(/\.(?:json|md|txt)$|^LICENSE$/)
expect(statSync(full).mode & 0o111, `${skill.name}/${file} is executable`).toBe(0)
}
expect(files.some((f) => /^LICENSE(?:\.md|\.txt)?$/.test(f)), `${skill.name}: licence`).toBe(true)
expect(read(path.join(dir, 'SOURCE.md'))).toContain(skill.commit)
}
})
test('each SKILL.md is renamed to its folder and starts with the project-rules override', () => {
for (const skill of manifest.skills) {
expect(skill.name).toMatch(/^ext-/)
const text = read(path.join(extDir, skill.name, 'SKILL.md'))
expect(text).toMatch(new RegExp(`^---\\nname: ${skill.name}\\n`))
const body = text.slice(text.indexOf('\n---', 3) + 4).trimStart()
expect(body.startsWith('> **Project rules win.**'), skill.name).toBe(true)
// No instruction to pull rules from a live URL at run time.
expect(text).not.toMatch(/raw\.githubusercontent\.com/)
}
})
})
describe('ipal-skills --external', () => {
const work = mkdtempSync(path.join(tmpdir(), 'ipal-ext-test-'))
afterAll(() => rmSync(work, { force: true, recursive: true }))
const skillsDir = path.join(work, '.agents/skills')
const run = (...args: string[]) =>
execFileSync('node', [path.join(root, 'bin/ipal-skills.mjs'), '--no-pointer', ...args], { cwd: work, encoding: 'utf8' })
const names = () => readdirSync(skillsDir).sort()
test('adds ext-* only on request and leaves the project\'s own folders alone', () => {
mkdirSync(path.join(skillsDir, 'my-skill'), { recursive: true })
writeFileSync(path.join(skillsDir, 'my-skill/SKILL.md'), 'own')
mkdirSync(path.join(skillsDir, 'ext-mine'))
writeFileSync(path.join(skillsDir, 'ext-mine/SKILL.md'), 'own ext')
run()
expect(names().filter((n) => n.startsWith('ext-') && n !== 'ext-mine')).toEqual([])
run('--external')
for (const skill of manifest.skills) {expect(existsSync(path.join(skillsDir, skill.name, 'SKILL.md')), skill.name).toBe(true)}
expect(read(path.join(skillsDir, 'my-skill/SKILL.md'))).toBe('own')
expect(read(path.join(skillsDir, 'ext-mine/SKILL.md'))).toBe('own ext')
})
test('removes only retired ext-* folders that ipal-kit installed', () => {
const retired = path.join(skillsDir, 'ext-retired')
mkdirSync(retired)
cpSync(path.join(extDir, manifest.skills[0].name, 'SOURCE.md'), path.join(retired, 'SOURCE.md'))
run('--external', manifest.skills[0].name)
expect(existsSync(retired)).toBe(false)
expect(existsSync(path.join(skillsDir, 'ext-mine'))).toBe(true)
})
test('an unknown name stops the run before anything is copied', () => {
const empty = mkdtempSync(path.join(work, 'empty-'))
expect(() =>
execFileSync('node', [path.join(root, 'bin/ipal-skills.mjs'), '--no-pointer', '--external', 'ext-nope'], { cwd: empty, stdio: 'pipe' }),
).toThrow()
expect(readdirSync(empty)).toEqual([])
})
})