|
| 1 | +/** |
| 2 | + * Property test: Slash command generation matches discovered agents |
| 3 | + * |
| 4 | + * **Validates: Requirements 3.1** |
| 5 | + * |
| 6 | + * Property statement: For any non-empty set of discovered agents, |
| 7 | + * `buildSlashCommands` SHALL produce exactly one slash command item |
| 8 | + * of kind "agent" for each discovered agent, with the command name |
| 9 | + * matching the agent's name. |
| 10 | + */ |
| 11 | + |
| 12 | +import { test } from "node:test"; |
| 13 | +import assert from "node:assert/strict"; |
| 14 | +import { buildSlashCommands } from "../ui"; |
| 15 | +import type { AgentManifest } from "@vegamo/deepcode-core"; |
| 16 | +import type { SkillInfo } from "@vegamo/deepcode-core"; |
| 17 | + |
| 18 | +// -- Test helpers -- |
| 19 | + |
| 20 | +function makeAgent(overrides: Partial<AgentManifest> = {}): AgentManifest { |
| 21 | + return { |
| 22 | + name: overrides.name ?? "test-agent", |
| 23 | + description: overrides.description ?? "A test agent", |
| 24 | + model: overrides.model ?? "claude", |
| 25 | + skills: overrides.skills ?? [], |
| 26 | + instructions: overrides.instructions ?? "# Test Agent", |
| 27 | + sourcePath: overrides.sourcePath ?? "/fake/path/AGENT.md", |
| 28 | + sourceRoot: overrides.sourceRoot ?? "./.deepcode/agents", |
| 29 | + }; |
| 30 | +} |
| 31 | + |
| 32 | +const emptySkills: SkillInfo[] = []; |
| 33 | + |
| 34 | +// -- Property tests -- |
| 35 | + |
| 36 | +test("Property 4: no agents produces no agent items", () => { |
| 37 | + const items = buildSlashCommands(emptySkills, []); |
| 38 | + const agentItems = items.filter((i) => i.kind === "agent"); |
| 39 | + assert.equal(agentItems.length, 0); |
| 40 | +}); |
| 41 | + |
| 42 | +test("Property 4: single agent produces exactly one agent item with matching name", () => { |
| 43 | + const agents: AgentManifest[] = [makeAgent({ name: "deploy-assistant", description: "Deploys to test environment" })]; |
| 44 | + |
| 45 | + const items = buildSlashCommands(emptySkills, agents); |
| 46 | + const agentItems = items.filter((i) => i.kind === "agent"); |
| 47 | + |
| 48 | + assert.equal(agentItems.length, 1); |
| 49 | + assert.equal(agentItems[0].name, "deploy-assistant"); |
| 50 | + assert.equal(agentItems[0].kind, "agent"); |
| 51 | +}); |
| 52 | + |
| 53 | +test("Property 4: multiple agents produce one item each with correct names", () => { |
| 54 | + const agents: AgentManifest[] = [ |
| 55 | + makeAgent({ name: "deploy-assistant", description: "Deploys to test environment" }), |
| 56 | + makeAgent({ name: "ut-agent", description: "Unit test generation" }), |
| 57 | + makeAgent({ name: "code-review", description: "Reviews code changes" }), |
| 58 | + ]; |
| 59 | + |
| 60 | + const items = buildSlashCommands(emptySkills, agents); |
| 61 | + const agentItems = items.filter((i) => i.kind === "agent"); |
| 62 | + |
| 63 | + assert.equal(agentItems.length, 3); |
| 64 | + assert.deepEqual( |
| 65 | + agentItems.map((i) => i.name), |
| 66 | + ["deploy-assistant", "ut-agent", "code-review"] |
| 67 | + ); |
| 68 | +}); |
| 69 | + |
| 70 | +test("Property 4: agent items appear before skill items and built-in items", () => { |
| 71 | + const skills: SkillInfo[] = [ |
| 72 | + { name: "testing-skill", path: "/skills/testing-skill/SKILL.md", description: "A skill" }, |
| 73 | + ]; |
| 74 | + const agents: AgentManifest[] = [makeAgent({ name: "deploy-assistant", description: "Deploy agent" })]; |
| 75 | + |
| 76 | + const items = buildSlashCommands(skills, agents); |
| 77 | + |
| 78 | + // Find positions |
| 79 | + const agentIndex = items.findIndex((i) => i.kind === "agent"); |
| 80 | + const skillIndex = items.findIndex((i) => i.kind === "skill"); |
| 81 | + const builtinIndex = items.findIndex((i) => i.kind !== "agent" && i.kind !== "skill"); |
| 82 | + |
| 83 | + assert.ok(agentIndex < skillIndex, "Agent items should appear before skill items"); |
| 84 | + assert.ok(agentIndex < builtinIndex, "Agent items should appear before built-in items"); |
| 85 | +}); |
| 86 | + |
| 87 | +test("Property 4: each agent item has kind 'agent' and label matching /<name>", () => { |
| 88 | + const agents: AgentManifest[] = [ |
| 89 | + makeAgent({ name: "deploy-assistant", description: "Deploys to test environment" }), |
| 90 | + makeAgent({ name: "eaa", description: "Accessibility helper" }), |
| 91 | + ]; |
| 92 | + |
| 93 | + const items = buildSlashCommands(emptySkills, agents); |
| 94 | + const agentItems = items.filter((i) => i.kind === "agent"); |
| 95 | + |
| 96 | + for (const agent of agents) { |
| 97 | + const item = agentItems.find((i) => i.name === agent.name); |
| 98 | + assert.ok(item, `Expected to find item for agent "${agent.name}"`); |
| 99 | + assert.equal(item.kind, "agent"); |
| 100 | + assert.equal(item.label, `/${agent.name}`); |
| 101 | + assert.equal(item.description, agent.description); |
| 102 | + } |
| 103 | +}); |
| 104 | + |
| 105 | +test("Property 4: agent count matches exactly — no extra agent items", () => { |
| 106 | + const agents: AgentManifest[] = [ |
| 107 | + makeAgent({ name: "agent-a", description: "First" }), |
| 108 | + makeAgent({ name: "agent-b", description: "Second" }), |
| 109 | + makeAgent({ name: "agent-c", description: "Third" }), |
| 110 | + makeAgent({ name: "agent-d", description: "Fourth" }), |
| 111 | + makeAgent({ name: "agent-e", description: "Fifth" }), |
| 112 | + ]; |
| 113 | + |
| 114 | + const items = buildSlashCommands(emptySkills, agents); |
| 115 | + const agentItems = items.filter((i) => i.kind === "agent"); |
| 116 | + |
| 117 | + assert.equal(agentItems.length, agents.length); |
| 118 | + for (const agent of agents) { |
| 119 | + const matching = agentItems.filter((i) => i.name === agent.name); |
| 120 | + assert.equal(matching.length, 1, `Expected exactly one item for agent "${agent.name}"`); |
| 121 | + } |
| 122 | +}); |
| 123 | + |
| 124 | +test("Property 4: agent with empty description gets '(no description)'", () => { |
| 125 | + const agents: AgentManifest[] = [makeAgent({ name: "no-desc-agent", description: "" })]; |
| 126 | + |
| 127 | + const items = buildSlashCommands(emptySkills, agents); |
| 128 | + const agentItems = items.filter((i) => i.kind === "agent"); |
| 129 | + |
| 130 | + assert.equal(agentItems.length, 1); |
| 131 | + assert.equal(agentItems[0].description, "(no description)"); |
| 132 | +}); |
0 commit comments