test / toolsProvider.test.ts
import { describe, expect, it } from "vitest";
import { buildTools, toolsProvider } from "../src/toolsProvider";
import { makeRoot } from "./helpers";
describe("buildTools", () => {
it("exposes exactly read, write and edit", () => {
expect(buildTools("/tmp").map(t => t.name)).toEqual(["read", "write", "edit"]);
});
});
function fakeCtl(setting: string, chatDir: () => string): never {
return {
getGlobalPluginConfig: () => ({ get: () => setting }),
getWorkingDirectory: chatDir,
} as unknown as never;
}
describe("toolsProvider", () => {
it("throws a setting-pointing error when there is no working directory", async () => {
const ctl = fakeCtl("", () => {
throw new Error("This prediction process is not attached to a working directory.");
});
await expect(toolsProvider(ctl)).rejects.toThrow(
'read-write: no working directory. Set "Working directory" in the plugin settings, or attach one to the chat.',
);
});
it("returns three tools when the chat has a working directory", async () => {
const dir = await makeRoot();
const ctl = fakeCtl("", () => dir);
expect((await toolsProvider(ctl)).map(t => t.name)).toEqual(["read", "write", "edit"]);
});
it("returns three tools when the setting is a valid directory", async () => {
const dir = await makeRoot();
const ctl = fakeCtl(dir, () => {
throw new Error("no chat dir");
});
expect((await toolsProvider(ctl)).map(t => t.name)).toEqual(["read", "write", "edit"]);
});
});
test / toolsProvider.test.ts
import { describe, expect, it } from "vitest";
import { buildTools, toolsProvider } from "../src/toolsProvider";
import { makeRoot } from "./helpers";
describe("buildTools", () => {
it("exposes exactly read, write and edit", () => {
expect(buildTools("/tmp").map(t => t.name)).toEqual(["read", "write", "edit"]);
});
});
function fakeCtl(setting: string, chatDir: () => string): never {
return {
getGlobalPluginConfig: () => ({ get: () => setting }),
getWorkingDirectory: chatDir,
} as unknown as never;
}
describe("toolsProvider", () => {
it("throws a setting-pointing error when there is no working directory", async () => {
const ctl = fakeCtl("", () => {
throw new Error("This prediction process is not attached to a working directory.");
});
await expect(toolsProvider(ctl)).rejects.toThrow(
'read-write: no working directory. Set "Working directory" in the plugin settings, or attach one to the chat.',
);
});
it("returns three tools when the chat has a working directory", async () => {
const dir = await makeRoot();
const ctl = fakeCtl("", () => dir);
expect((await toolsProvider(ctl)).map(t => t.name)).toEqual(["read", "write", "edit"]);
});
it("returns three tools when the setting is a valid directory", async () => {
const dir = await makeRoot();
const ctl = fakeCtl(dir, () => {
throw new Error("no chat dir");
});
expect((await toolsProvider(ctl)).map(t => t.name)).toEqual(["read", "write", "edit"]);
});
});