1import { describe, test, expect, beforeAll, afterAll } from "bun:test";
2import { mkdtempSync, rmSync, writeFileSync } from "node:fs";
3import { tmpdir } from "node:os";
4import { join } from "node:path";
5import simpleGit from "simple-git";
6import { createGitLogTool } from "../src/agent/tools/git/log.js";
7import { ToolInputError } from "../src/util/errors.js";
8
9let workDir: string;
10let git: ReturnType<typeof simpleGit>;
11
12beforeAll(async () => {
13 workDir = mkdtempSync(join(tmpdir(), "rumilo-gitlog-test-"));
14 git = simpleGit(workDir);
15 await git.init();
16 await git.addConfig("user.name", "Test");
17 await git.addConfig("user.email", "test@test.com");
18 await git.addConfig("commit.gpgsign", "false");
19 writeFileSync(join(workDir, "file.txt"), "hello");
20 await git.add("file.txt");
21 await git.commit("initial commit");
22});
23
24afterAll(() => {
25 try {
26 rmSync(workDir, { recursive: true, force: true });
27 } catch {}
28});
29
30describe("git_log validation - dead code fix (issue #12)", () => {
31 test("whitespace-only author throws ToolInputError", async () => {
32 const tool = createGitLogTool(workDir);
33 await expect(tool.execute("id", { author: " " })).rejects.toThrow(ToolInputError);
34 });
35
36 test("empty-string author throws ToolInputError", async () => {
37 const tool = createGitLogTool(workDir);
38 await expect(tool.execute("id", { author: "" })).rejects.toThrow(ToolInputError);
39 });
40
41 test("empty-string since throws ToolInputError", async () => {
42 const tool = createGitLogTool(workDir);
43 await expect(tool.execute("id", { since: " " })).rejects.toThrow(ToolInputError);
44 });
45
46 test("empty-string until throws ToolInputError", async () => {
47 const tool = createGitLogTool(workDir);
48 await expect(tool.execute("id", { until: " " })).rejects.toThrow(ToolInputError);
49 });
50
51 test("valid author is accepted", async () => {
52 const tool = createGitLogTool(workDir);
53 // Should not throw
54 const result: any = await tool.execute("id", { author: "Test" });
55 expect(result.details.count).toBeGreaterThanOrEqual(1);
56 });
57});