Files
skills/checks/skill-build.nix

88 lines
3.1 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;
discovered = discoverSkills ./fixtures/valid;
built = map (skill: mkSkill { inherit pkgs; inherit (skill) name src; }) discovered;
commandSrc = pkgs.runCommandLocal "command-skill-src" { } ''
mkdir -p "$out"
printf '%s\n' '---' 'name: command-skill' 'description: Fixture skill with a command.' '---' \
> "$out/SKILL.md"
cat > "$out/run-command" <<'EOF'
#!/usr/bin/env sh
: "''${TOOL:=tool}" # mkSkill:TOOL
exec "$TOOL" "$@"
EOF
chmod +x "$out/run-command"
'';
commandSkill = mkSkill {
inherit pkgs;
name = "command-skill";
src = commandSrc;
commands = [
{
path = "run-command";
env.TOOL = "${pkgs.coreutils}/bin/printf";
}
];
};
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;
inherit commandSkill;
}
''
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 gamma" ] \
|| fail "discovered names were [$expectedNames], expected [alpha beta 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"
echo "command tier: declared command env defaults are patched"
test -x "$commandSkill/run-command" \
|| fail "declared command is not executable"
grep -qx ': "''${TOOL:=${pkgs.coreutils}/bin/printf}" # mkSkill:TOOL' "$commandSkill/run-command" \
|| fail "declared command env default was not patched"
touch "$out"
''