feature/pi-refactor
 1/**
 2 * Tests for Agent Tool Integration
 3 * 
 4 * RED phase: Write these tests first, verify they fail
 5 * GREEN phase: Implement tool integration
 6 * REFACTOR phase: Clean up
 7 */
 8
 9import { describe, it, expect, beforeEach } from "vitest";
10import { XmppAgent } from "./agent-wrapper.js";
11import { getModel } from "@mariozechner/pi-ai";
12import { statusTool } from "./tools/status.js";
13
14describe("XmppAgent Tool Integration", () => {
15  let agent: XmppAgent;
16  const testJid = "test@xmpp.sbr.pm";
17  
18  beforeEach(async () => {
19    const model = getModel("google", "gemini-2.0-flash");
20    agent = new XmppAgent(testJid, model, [statusTool]);
21  });
22
23  it("should accept tools in constructor", () => {
24    expect(agent).toBeDefined();
25    const tools = agent.getTools();
26    expect(tools).toHaveLength(1);
27    expect(tools[0].name).toBe("status");
28  });
29
30  it("should allow agent to call status tool", async () => {
31    // Ask a question that should trigger the status tool
32    const response = await agent.processMessage("What is the system status?");
33    
34    expect(response).toBeDefined();
35    expect(typeof response).toBe("string");
36    // Response should contain system information
37    expect(response.toLowerCase()).toMatch(/uptime|memory|load/);
38  }, 15000); // Longer timeout for LLM call with tool
39
40  it("should handle messages that don't need tools", async () => {
41    const response = await agent.processMessage("Hello, how are you?");
42    
43    expect(response).toBeDefined();
44    expect(typeof response).toBe("string");
45    // Should respond without calling tools
46  }, 15000);
47
48  it("should work without any tools", async () => {
49    const model = getModel("google", "gemini-2.0-flash");
50    const agentNoTools = new XmppAgent(testJid, model);
51    
52    const tools = agentNoTools.getTools();
53    expect(tools).toHaveLength(0);
54    
55    const response = await agentNoTools.processMessage("Hello");
56    expect(response).toBeDefined();
57  }, 15000);
58});