| 1 | import assert from "node:assert/strict"; |
| 2 | import { test } from "node:test"; |
| 3 | |
| 4 | import type { AgentTemplate } from "@g1t/contracts"; |
| 5 | |
| 6 | import { byDepartment, roleLine, routingWords, startPath, templateListings, templatePath, templatesPath } from "./agent-templates.ts"; |
| 7 | |
| 8 | const template = (id: string, title: string, department = "Engineering"): AgentTemplate => ({ |
| 9 | id, |
| 10 | display_name: title.split(" ")[0]!, |
| 11 | handle: id, |
| 12 | name_ideas: [], |
| 13 | role: title, |
| 14 | title, |
| 15 | department, |
| 16 | responsibilities: ["Do the work"], |
| 17 | subagents: [], |
| 18 | instructions: "", |
| 19 | personality_preset: "crisp", |
| 20 | routing: { floor: null, ceiling: null, providers: [], pinned: null }, |
| 21 | }); |
| 22 | |
| 23 | test("templates live under Agents, and starting one opens the new-agent form with it chosen", () => { |
| 24 | assert.equal(templatesPath("acme"), "/acme/-/agents/templates"); |
| 25 | assert.equal(templatePath("acme", "qa"), "/acme/-/agents/templates/qa"); |
| 26 | assert.equal(startPath("acme", "qa"), "/acme/-/agents/new?template=qa"); |
| 27 | }); |
| 28 | |
| 29 | test("a template counts the agents started from it, not archived ones", () => { |
| 30 | const [eng, qa] = templateListings( |
| 31 | [template("engineering", "Software Engineer"), template("qa", "QA Engineer")], |
| 32 | [ |
| 33 | { id: "a1", handle: "otto", display_name: "Otto", template: "engineering", archived_at: null }, |
| 34 | { id: "a2", handle: "bolt", display_name: "Bolt", template: "engineering", archived_at: "2026-10-01T00:00:00Z" }, |
| 35 | { id: "a3", handle: "g1t", display_name: "g1t", template: null, archived_at: null }, |
| 36 | ], |
| 37 | ); |
| 38 | assert.deepEqual(eng!.agents.map((a) => a.handle), ["otto"]); |
| 39 | assert.equal(qa!.agents.length, 0); |
| 40 | }); |
| 41 | |
| 42 | test("without the agents service, no agent is counted", () => { |
| 43 | const [eng] = templateListings([template("engineering", "Software Engineer")], null); |
| 44 | assert.deepEqual(eng!.agents, []); |
| 45 | }); |
| 46 | |
| 47 | test("templates group by department, in the order they come", () => { |
| 48 | const groups = byDepartment(templateListings([template("a", "A One"), template("b", "B Two", "Sales"), template("c", "C Three"), template("d", "D Four", "")], null)); |
| 49 | assert.deepEqual( |
| 50 | groups.map(([department, list]) => [department, list.map((l) => l.template.id)]), |
| 51 | [ |
| 52 | ["Engineering", ["a", "c"]], |
| 53 | ["Sales", ["b"]], |
| 54 | ["Other", ["d"]], |
| 55 | ], |
| 56 | ); |
| 57 | }); |
| 58 | |
| 59 | test("a role and its model limits read as words", () => { |
| 60 | assert.equal(roleLine({ title: "QA Engineer", department: "Engineering" }), "QA Engineer · Engineering"); |
| 61 | assert.equal(roleLine({ title: "QA Engineer", department: "" }), "QA Engineer"); |
| 62 | assert.equal(routingWords({ floor: null, ceiling: null }), "Any model the work needs"); |
| 63 | assert.equal(routingWords({ floor: "large", ceiling: null }), "Large models or better"); |
| 64 | assert.equal(routingWords({ floor: null, ceiling: "large" }), "Up to large models"); |
| 65 | }); |