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