dbb7885ffd
CI / check (pull_request) Failing after 1m39s
- Auto-fix: import sorting, formatting (17 files) - Unsafe auto-fix: unused vars, template literals (7 files) - Manual: nursery/noConsole → suspicious/noConsole suppression - Manual: suppress noExcessiveCognitiveComplexity for cmdThreadResume and parseWorkflowPayload - Manual: remove unused destructured vars in current-role tests Closes #48
44 lines
1.7 KiB
TypeScript
44 lines
1.7 KiB
TypeScript
import { readFile, rm } from "node:fs/promises";
|
|
import { tmpdir } from "node:os";
|
|
import { join } from "node:path";
|
|
import { afterAll, describe, expect, it } from "vitest";
|
|
import { writeFileTool } from "../src/tools/write-file.js";
|
|
|
|
const testDir = join(tmpdir(), `write-file-test-${Date.now()}`);
|
|
const ctx = { cwd: testDir, storageRoot: testDir };
|
|
|
|
afterAll(async () => {
|
|
await rm(testDir, { recursive: true, force: true });
|
|
});
|
|
|
|
describe("writeFileTool", () => {
|
|
it("writes file successfully", async () => {
|
|
const result = await writeFileTool.execute({ path: "out.txt", content: "hi" }, ctx);
|
|
expect(result).toMatch(/Wrote 2 bytes/);
|
|
const content = await readFile(join(testDir, "out.txt"), "utf8");
|
|
expect(content).toBe("hi");
|
|
});
|
|
|
|
it("creates parent directories", async () => {
|
|
const result = await writeFileTool.execute({ path: "a/b/c.txt", content: "nested" }, ctx);
|
|
expect(result).toMatch(/Wrote/);
|
|
const content = await readFile(join(testDir, "a/b/c.txt"), "utf8");
|
|
expect(content).toBe("nested");
|
|
});
|
|
|
|
it("returns error when path is not a string", async () => {
|
|
const result = await writeFileTool.execute({ path: 123, content: "x" }, ctx);
|
|
expect(result).toBe("Error: path and content must be strings");
|
|
});
|
|
|
|
it("returns error when content is not a string", async () => {
|
|
const result = await writeFileTool.execute({ path: "x.txt", content: 42 }, ctx);
|
|
expect(result).toBe("Error: path and content must be strings");
|
|
});
|
|
|
|
it("returns error when args is null", async () => {
|
|
const result = await writeFileTool.execute(null, ctx);
|
|
expect(result).toBe("Error: path and content must be strings");
|
|
});
|
|
});
|