File size: 2,382 Bytes
4fa5831
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
/* Node smoke test for skillforge.js parity. Run: node test_skillforge.mjs
 * Uses a minimal yaml shim covering only the shapes the tests exercise. */
import { readFileSync } from "node:fs";
import assert from "node:assert";
import vm from "node:vm";

const shim = {
  load(src) {
    const o = {};
    for (const raw of src.split("\n")) {
      const line = raw.replace(/\r$/, "");
      if (!line.trim() || line.trim().startsWith("#")) continue;
      const m = line.match(/^([A-Za-z0-9_-]+):\s*(.*)$/);
      if (!m) { const e = new Error("bad yaml line: " + line); throw e; }
      let v = m[2].trim();
      if (v.startsWith("[") && !v.endsWith("]")) throw new Error("unterminated flow seq");
      o[m[1]] = v.replace(/^["']|["']$/g, "");
    }
    return o;
  },
};

const ctx = { window: { jsyaml: shim }, globalThis: {} };
vm.createContext(ctx);
vm.runInContext(readFileSync(new URL("./skillforge.js", import.meta.url), "utf8"), ctx);
const SF = ctx.window.SkillForge;

const GOOD = `---
name: pdf-form-filler
description: Fills interactive PDF forms from a data mapping. Use when the user asks to complete or auto-fill a PDF form, e.g. "fill out this application PDF".
---

# PDF Form Filler

## When to use
- Fillable PDF + field values.

## Instructions
1. Inspect fields.
2. Map and flatten.
`;

assert.ok(SF.validateSkill(GOOD).ok, "good skill should pass");
assert.ok(!SF.validateSkill("# no frontmatter").ok, "missing frontmatter fails");

const bad = SF.validateSkill('---\nname: Not_Kebab!!\ndescription: short\n---\n\nbody\n');
assert.ok(!bad.ok && bad.errors.some(e => e.includes("kebab-case")), "kebab error");

assert.ok(!SF.validateSkill('---\nname: [unclosed\n---\nbody\n').ok, "invalid yaml fails");

const weak = SF.lintDescription("Does stuff.");
const strong = SF.lintDescription(
  'Converts Markdown notes into a styled slide deck. Use when the user asks to ' +
  '"turn this into slides" or "make a deck", e.g. a report rendered as shareable slides.');
assert.ok(weak.score < 55 && strong.score >= 55, `scores ${weak.score}/${strong.score}`);

const md = SF.scaffoldSkill("My Cool Skill", "Reviews Terraform plans for drift.",
  "the user runs terraform plan and wants a risk summary");
assert.ok(md.includes("name: my-cool-skill"), "scaffold name");
assert.ok(SF.validateSkill(md).ok, "scaffold output validates");

console.log("all checks passed");