Skip to content

Local-first AI coding agent desktop: Electron + Rust host core + pi Agent Harness + user-installable plugins

1.7 KB
Raw Blame
import { describe, expect, it } from "vitest";
import { pluginSkillsDigest, type PluginSkillDef } from "./plugin-skills.js";

function skill(overrides: Partial<PluginSkillDef> = {}): PluginSkillDef {
  return {
    id: "demo.notes/summarise",
    name: "Summarise notes",
    description: "Group notes by tag.",
    ...overrides,
  };
}

describe("pluginSkillsDigest", () => {
  it("is empty without skills", () => {
    expect(pluginSkillsDigest()).toBe("");
    expect(pluginSkillsDigest([])).toBe("");
  });

  it("is stable for the same catalog", () => {
    expect(pluginSkillsDigest([skill()])).toBe(pluginSkillsDigest([skill()]));
  });

  it("changes when catalog text the model reads changes", () => {
    const base = pluginSkillsDigest([skill()]);
    expect(pluginSkillsDigest([skill({ id: "demo.notes/other" })])).not.toBe(base);
    expect(pluginSkillsDigest([skill({ name: "Renamed" })])).not.toBe(base);
    expect(pluginSkillsDigest([skill({ description: "Group by date." })])).not.toBe(
      base,
    );
  });

  it("distinguishes order, because the prompt lists skills in order", () => {
    expect(pluginSkillsDigest([skill({ id: "a" }), skill({ id: "b" })])).not.toBe(
      pluginSkillsDigest([skill({ id: "b" }), skill({ id: "a" })]),
    );
  });

  it("ignores a missing description consistently", () => {
    const without = pluginSkillsDigest([{ id: "a", name: "A" }]);
    expect(pluginSkillsDigest([{ id: "a", name: "A", description: "" }])).toBe(without);
  });
});

it("does not confuse delimiter-containing catalog fields", () => {
  expect(pluginSkillsDigest([{ id: "a", name: "b:c", description: "d" }])).not.toBe(
    pluginSkillsDigest([{ id: "a", name: "b", description: "c:d" }]),
  );
});