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 writeFileSync(join(workDir, "file.txt"), "hello");
19 await git.add("file.txt");
20 await git.commit("initial commit");
21});
22
23afterAll(() => {
24 try {
25 rmSync(workDir, { recursive: true, force: true });
26 } catch {}
27});
28
29describe("git_log validation - dead code fix (issue #12)", () => {
30 test("whitespace-only author throws ToolInputError", async () => {
31 const tool = createGitLogTool(workDir);
32 await expect(tool.execute("id", { author: " " })).rejects.toThrow(ToolInputError);
33 });
34
35 test("empty-string author throws ToolInputError", async () => {
36 const tool = createGitLogTool(workDir);
37 await expect(tool.execute("id", { author: "" })).rejects.toThrow(ToolInputError);
38 });
39
40 test("empty-string since throws ToolInputError", async () => {
41 const tool = createGitLogTool(workDir);
42 await expect(tool.execute("id", { since: " " })).rejects.toThrow(ToolInputError);
43 });
44
45 test("empty-string until throws ToolInputError", async () => {
46 const tool = createGitLogTool(workDir);
47 await expect(tool.execute("id", { until: " " })).rejects.toThrow(ToolInputError);
48 });
49
50 test("valid author is accepted", async () => {
51 const tool = createGitLogTool(workDir);
52 // Should not throw
53 const result: any = await tool.execute("id", { author: "Test" });
54 expect(result.details.count).toBeGreaterThanOrEqual(1);
55 });
56});