/** * Extension entry point: the default export must wire up all seven tools, * four slash commands, and both event handlers exactly once. */ import { test } from "node:test"; import assert from "node:assert/strict"; import defaultExport from "../src/index.ts"; import { mockPi } from "./helpers.ts"; test("default export registers all seven AI tools", () => { const { pi, tools } = mockPi(); defaultExport(pi); assert.deepEqual( tools.map((t) => t.name).sort(), [ "docgraph_init", "docgraph_read", "docgraph_sync", "docgraph_ticket_create", "docgraph_ticket_list", "docgraph_ticket_update", "docgraph_update", ].sort(), ); for (const t of tools) { assert.ok(t.label, `${t.name} needs a label`); assert.ok(t.description.length > 10, `${t.name} needs a real description`); assert.equal(typeof t.execute, "function", `${t.name} needs an execute handler`); } }); test("default export registers all four slash commands", () => { const { pi, commands } = mockPi(); defaultExport(pi); assert.deepEqual( commands.map((c) => c.name).sort(), ["docgraph:graph", "docgraph:init", "docgraph:sync", "docgraph:tickets"].sort(), ); for (const c of commands) assert.equal(typeof c.handler, "function"); }); test("default export registers both event handlers", () => { const { pi, events } = mockPi(); defaultExport(pi); assert.deepEqual( events.map((e) => e.event).sort(), ["before_agent_start", "session_start"], ); for (const e of events) assert.equal(typeof e.handler, "function"); }); test("default export can be invoked more than once without error", () => { const { pi, tools, commands, events } = mockPi(); defaultExport(pi); defaultExport(pi); // A process may load/refresh an extension more than once // Registrations are appended exactly once per invocation. assert.equal(tools.length, 14); assert.equal(commands.length, 8); assert.equal(events.length, 4); });