gadget/docs/archive/tools/search/list.test.ts

80 lines
2.0 KiB
TypeScript

// src/tools/search/list.test.ts
// Copyright (C) 2025 DTP Technologies, LLC
// All Rights Reserved
import { describe, it, expect, beforeEach } from "vitest";
import ListTool from "./list.js";
describe("ListTool", () => {
let tool: typeof ListTool;
let mockSession: any;
beforeEach(() => {
tool = ListTool;
mockSession = {
_id: "test-session-id",
user: "test-user-id",
};
});
describe("definition", () => {
it("should have correct tool name", () => {
expect(tool.definition.function.name).toBe("list");
});
it("should have correct category", () => {
expect(tool.metadata.category).toBe("search");
});
it("should support all modes", () => {
expect(tool.metadata.modes).toHaveLength(5);
});
});
describe("execute", () => {
it("should list current directory by default", async () => {
const result = await tool.execute({ session: mockSession }, {});
expect(result).toContain("Contents of");
});
it("should list specific directory", async () => {
const result = await tool.execute(
{ session: mockSession },
{ path: "src" },
);
expect(result).toContain("Contents of");
expect(result).toContain("src");
});
it("should return error for non-directory path", async () => {
const result = await tool.execute(
{ session: mockSession },
{ path: "package.json" },
);
expect(result).toContain("INVALID_PARAMETER");
expect(result).toContain("not a directory");
});
it("should support recursive listing", async () => {
const result = await tool.execute(
{ session: mockSession },
{ path: "src", recursive: true, maxDepth: 2 },
);
expect(result).toContain("Contents of");
});
it("should show hidden files when requested", async () => {
const result = await tool.execute(
{ session: mockSession },
{ path: ".", showHidden: true },
);
expect(result).toContain("Contents of");
});
});
});