Add the content tier: a standalone flake that auto-discovers each skill (a directory containing a SKILL.md, at any depth) and exposes it as an individually addressable derivation built by lib.mkSkill. Directories without a SKILL.md are descended through as cosmetic containers; once a SKILL.md is found, that directory's subfolders are its assets, not further skills. Skill names must be globally unique across the tree — a collision is a hard eval-time error, not a warning. A fixture-driven skill-build check under `nix flake check` exercises the recursive walk, the builder, the SKILL.md-at-$out-root contract, the eval-time name passthru, and the collision error. The repo ships no real skill content yet, so packages.<system> is empty today.
65 lines
2.7 KiB
Nix
65 lines
2.7 KiB
Nix
# The skill-build check: drives fixture skills through the content tier so
|
|
# `nix flake check` covers every discovery shape and the collision hard-error.
|
|
{
|
|
pkgs,
|
|
mkSkill,
|
|
discoverSkills,
|
|
}:
|
|
let
|
|
inherit (pkgs) lib;
|
|
|
|
# A valid tree covering every discovery shape at once: two top-level skills
|
|
# (alpha, delta), a skill nested under a cosmetic container (beta, which also
|
|
# owns an asset subfolder whose own SKILL.md must NOT become a skill), and a
|
|
# skill several containers deep (gamma).
|
|
discovered = discoverSkills ./fixtures/valid;
|
|
built = map (skill: mkSkill { inherit pkgs; inherit (skill) name src; }) discovered;
|
|
|
|
# Discovery of a tree with two skills resolving to the same name must throw at
|
|
# eval.
|
|
# tryEval catches the throw, so the check can assert discovery failed rather
|
|
# than silently clobbering.
|
|
collision = builtins.tryEval (discoverSkills ./fixtures/collision);
|
|
|
|
discoveredNames = lib.sort (a: b: a < b) (map (skill: skill.name) discovered);
|
|
in
|
|
pkgs.runCommandLocal "skill-build-check"
|
|
{
|
|
# Referencing every built skill forces each one to build before this
|
|
# derivation — that is the "build every auto-discovered skill" coverage.
|
|
# Each entry is "name=storepath" so the assertions can read each $out root
|
|
# without re-deriving anything, and confirm the name passthru round-trips.
|
|
pairs = lib.concatStringsSep " " (map (skill: "${skill.skillName}=${skill}") built);
|
|
collisionSucceeded = if collision.success then "yes" else "no";
|
|
expectedNames = lib.concatStringsSep " " discoveredNames;
|
|
}
|
|
''
|
|
fail() { echo "FAIL: $1" >&2; exit 1; }
|
|
|
|
echo "content tier: the name-collision fixture must fail discovery at eval"
|
|
[ "$collisionSucceeded" = no ] \
|
|
|| fail "a two-skills-one-name tree was discovered without error"
|
|
|
|
echo "content tier: discovery finds every skill regardless of nesting depth,"
|
|
echo " and stops at a skill rather than descending into its assets"
|
|
[ "$expectedNames" = "alpha beta delta gamma" ] \
|
|
|| fail "discovered names were [$expectedNames], expected [alpha beta delta gamma]"
|
|
|
|
echo "content tier: each built skill has SKILL.md at its \$out root"
|
|
beta_path=
|
|
for pair in $pairs; do
|
|
name="''${pair%%=*}"
|
|
path="''${pair#*=}"
|
|
test -f "$path/SKILL.md" || fail "$name has no SKILL.md at its \$out root"
|
|
[ "$name" = beta ] && beta_path="$path"
|
|
done
|
|
|
|
echo "content tier: a skill's asset subfolder rides along in \$out and is"
|
|
echo " not split off into its own skill"
|
|
[ -n "$beta_path" ] || fail "beta was not discovered"
|
|
test -f "$beta_path/tools/SKILL.md" \
|
|
|| fail "beta's asset subfolder did not ride along into \$out"
|
|
|
|
touch "$out"
|
|
''
|