|
1 | 1 | import { describe, it, expect } from "bun:test"; |
2 | | -import { TOOL_DEFINITIONS } from "@/utils/tools/toolDefinitions"; |
| 2 | +import { createStatusSetTool } from "./status_set"; |
| 3 | +import type { ToolConfiguration } from "@/utils/tools/tools"; |
| 4 | +import { createRuntime } from "@/runtime/runtimeFactory"; |
| 5 | +import type { ToolCallOptions } from "ai"; |
3 | 6 |
|
4 | | -describe("status_set schema validation", () => { |
5 | | - const schema = TOOL_DEFINITIONS.status_set.schema; |
| 7 | +describe("status_set tool validation", () => { |
| 8 | + const mockConfig: ToolConfiguration = { |
| 9 | + cwd: "/test", |
| 10 | + runtime: createRuntime({ type: "local", srcBaseDir: "/tmp" }), |
| 11 | + runtimeTempDir: "/tmp", |
| 12 | + }; |
| 13 | + |
| 14 | + const mockToolCallOptions: ToolCallOptions = { |
| 15 | + toolCallId: "test-call-id", |
| 16 | + messages: [], |
| 17 | + }; |
6 | 18 |
|
7 | 19 | describe("emoji validation", () => { |
8 | | - it("should accept single emoji characters", () => { |
9 | | - expect(() => schema.parse({ emoji: "🔍", message: "Test" })).not.toThrow(); |
10 | | - expect(() => schema.parse({ emoji: "📝", message: "Test" })).not.toThrow(); |
11 | | - expect(() => schema.parse({ emoji: "✅", message: "Test" })).not.toThrow(); |
12 | | - expect(() => schema.parse({ emoji: "🚀", message: "Test" })).not.toThrow(); |
13 | | - expect(() => schema.parse({ emoji: "⏳", message: "Test" })).not.toThrow(); |
| 20 | + it("should accept single emoji characters", async () => { |
| 21 | + const tool = createStatusSetTool(mockConfig); |
| 22 | + |
| 23 | + const emojis = ["🔍", "📝", "✅", "🚀", "⏳"]; |
| 24 | + for (const emoji of emojis) { |
| 25 | + const result = await tool.execute!({ emoji, message: "Test" }, mockToolCallOptions); |
| 26 | + expect(result).toEqual({ success: true, emoji, message: "Test" }); |
| 27 | + } |
14 | 28 | }); |
15 | 29 |
|
16 | | - it("should reject multiple emojis", () => { |
17 | | - expect(() => schema.parse({ emoji: "🔍📝", message: "Test" })).toThrow(); |
18 | | - expect(() => schema.parse({ emoji: "✅✅", message: "Test" })).toThrow(); |
| 30 | + it("should reject multiple emojis", async () => { |
| 31 | + const tool = createStatusSetTool(mockConfig); |
| 32 | + |
| 33 | + const result1 = await tool.execute!({ emoji: "🔍📝", message: "Test" }, mockToolCallOptions); |
| 34 | + expect(result1).toEqual({ success: false, error: "emoji must be a single emoji character" }); |
| 35 | + |
| 36 | + const result2 = await tool.execute!({ emoji: "✅✅", message: "Test" }, mockToolCallOptions); |
| 37 | + expect(result2).toEqual({ success: false, error: "emoji must be a single emoji character" }); |
19 | 38 | }); |
20 | 39 |
|
21 | | - it("should reject text (non-emoji)", () => { |
22 | | - expect(() => schema.parse({ emoji: "a", message: "Test" })).toThrow(); |
23 | | - expect(() => schema.parse({ emoji: "abc", message: "Test" })).toThrow(); |
24 | | - expect(() => schema.parse({ emoji: "!", message: "Test" })).toThrow(); |
| 40 | + it("should reject text (non-emoji)", async () => { |
| 41 | + const tool = createStatusSetTool(mockConfig); |
| 42 | + |
| 43 | + const result1 = await tool.execute!({ emoji: "a", message: "Test" }, mockToolCallOptions); |
| 44 | + expect(result1).toEqual({ success: false, error: "emoji must be a single emoji character" }); |
| 45 | + |
| 46 | + const result2 = await tool.execute!({ emoji: "abc", message: "Test" }, mockToolCallOptions); |
| 47 | + expect(result2).toEqual({ success: false, error: "emoji must be a single emoji character" }); |
| 48 | + |
| 49 | + const result3 = await tool.execute!({ emoji: "!", message: "Test" }, mockToolCallOptions); |
| 50 | + expect(result3).toEqual({ success: false, error: "emoji must be a single emoji character" }); |
25 | 51 | }); |
26 | 52 |
|
27 | | - it("should reject empty emoji", () => { |
28 | | - expect(() => schema.parse({ emoji: "", message: "Test" })).toThrow(); |
| 53 | + it("should reject empty emoji", async () => { |
| 54 | + const tool = createStatusSetTool(mockConfig); |
| 55 | + |
| 56 | + const result = await tool.execute!({ emoji: "", message: "Test" }, mockToolCallOptions); |
| 57 | + expect(result).toEqual({ success: false, error: "emoji must be a single emoji character" }); |
29 | 58 | }); |
30 | 59 |
|
31 | | - it("should reject emoji with text", () => { |
32 | | - expect(() => schema.parse({ emoji: "🔍a", message: "Test" })).toThrow(); |
33 | | - expect(() => schema.parse({ emoji: "x🔍", message: "Test" })).toThrow(); |
| 60 | + it("should reject emoji with text", async () => { |
| 61 | + const tool = createStatusSetTool(mockConfig); |
| 62 | + |
| 63 | + const result1 = await tool.execute!({ emoji: "🔍a", message: "Test" }, mockToolCallOptions); |
| 64 | + expect(result1).toEqual({ success: false, error: "emoji must be a single emoji character" }); |
| 65 | + |
| 66 | + const result2 = await tool.execute!({ emoji: "x🔍", message: "Test" }, mockToolCallOptions); |
| 67 | + expect(result2).toEqual({ success: false, error: "emoji must be a single emoji character" }); |
34 | 68 | }); |
35 | 69 | }); |
36 | 70 |
|
37 | 71 | describe("message validation", () => { |
38 | | - it("should accept messages up to 40 characters", () => { |
39 | | - expect(() => schema.parse({ emoji: "✅", message: "a".repeat(40) })).not.toThrow(); |
40 | | - expect(() => schema.parse({ emoji: "✅", message: "Analyzing code structure" })).not.toThrow(); |
41 | | - expect(() => schema.parse({ emoji: "✅", message: "Done" })).not.toThrow(); |
42 | | - }); |
| 72 | + it("should accept messages up to 40 characters", async () => { |
| 73 | + const tool = createStatusSetTool(mockConfig); |
| 74 | + |
| 75 | + const result1 = await tool.execute!( |
| 76 | + { emoji: "✅", message: "a".repeat(40) }, |
| 77 | + mockToolCallOptions |
| 78 | + ); |
| 79 | + expect(result1.success).toBe(true); |
43 | 80 |
|
44 | | - it("should reject messages over 40 characters", () => { |
45 | | - expect(() => schema.parse({ emoji: "✅", message: "a".repeat(41) })).toThrow(); |
46 | | - expect(() => schema.parse({ emoji: "✅", message: "a".repeat(50) })).toThrow(); |
| 81 | + const result2 = await tool.execute!( |
| 82 | + { emoji: "✅", message: "Analyzing code structure" }, |
| 83 | + mockToolCallOptions |
| 84 | + ); |
| 85 | + expect(result2.success).toBe(true); |
47 | 86 | }); |
48 | 87 |
|
49 | | - it("should accept empty message", () => { |
50 | | - expect(() => schema.parse({ emoji: "✅", message: "" })).not.toThrow(); |
| 88 | + it("should accept empty message", async () => { |
| 89 | + const tool = createStatusSetTool(mockConfig); |
| 90 | + |
| 91 | + const result = await tool.execute!({ emoji: "✅", message: "" }, mockToolCallOptions); |
| 92 | + expect(result.success).toBe(true); |
51 | 93 | }); |
52 | 94 | }); |
53 | 95 | }); |
|
0 commit comments