crypstie3-node/test/discovery.test.js

32 lines
1.4 KiB
JavaScript

'use strict';
const assert = require('node:assert/strict');
const crypto = require('node:crypto');
const fs = require('node:fs');
const os = require('node:os');
const path = require('node:path');
const { execFileSync } = require('node:child_process');
const test = require('node:test');
test('builds a valid discovery index matching the published skill', () => {
const root = path.resolve(__dirname, '..');
const output = fs.mkdtempSync(path.join(os.tmpdir(), 'crypstie-discovery-'));
try {
execFileSync(process.execPath, [path.join(root, 'scripts', 'build-skill-discovery.js'), output]);
const skill = fs.readFileSync(path.join(output, 'crypstie', 'SKILL.md'));
const index = JSON.parse(fs.readFileSync(path.join(output, 'index.json'), 'utf8'));
const expectedDigest = crypto.createHash('sha256').update(skill).digest('hex');
assert.equal(index.$schema, 'https://schemas.agentskills.io/discovery/0.2.0/schema.json');
assert.equal(index.skills.length, 1);
assert.equal(index.skills[0].name, 'crypstie');
assert.equal(index.skills[0].type, 'skill-md');
assert.equal(index.skills[0].url, '/.well-known/agent-skills/crypstie/SKILL.md');
assert.equal(index.skills[0].digest, `sha256:${expectedDigest}`);
assert.match(fs.readFileSync(path.join(output, 'llms.txt'), 'utf8'), /crypstie on npm/);
} finally {
fs.rmSync(output, { recursive: true, force: true });
}
});