- 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
This commit is contained in:
@@ -1,8 +1,8 @@
|
||||
import { mkdtemp, rm } from "node:fs/promises";
|
||||
import { tmpdir } from "node:os";
|
||||
import { join } from "node:path";
|
||||
import { afterEach, beforeEach, describe, expect, test } from "vitest";
|
||||
import { createMemoryStore } from "@ocas/core";
|
||||
import { afterEach, beforeEach, describe, expect, test } from "vitest";
|
||||
import { storeBuiltinDetail } from "../src/detail.js";
|
||||
import { appendSessionTurn, initSessionDir } from "../src/session.js";
|
||||
import type { BuiltinTurnPayload } from "../src/types.js";
|
||||
|
||||
@@ -1,51 +1,51 @@
|
||||
import { describe, it, expect, beforeAll, afterAll } from "vitest";
|
||||
import { readFileTool } from "../src/tools/read-file.js";
|
||||
import { writeFile, mkdir, rm } from "node:fs/promises";
|
||||
import { join } from "node:path";
|
||||
import { mkdir, rm, writeFile } from "node:fs/promises";
|
||||
import { tmpdir } from "node:os";
|
||||
import { join } from "node:path";
|
||||
import { afterAll, beforeAll, describe, expect, it } from "vitest";
|
||||
import { readFileTool } from "../src/tools/read-file.js";
|
||||
|
||||
const testDir = join(tmpdir(), `read-file-test-${Date.now()}`);
|
||||
const ctx = { cwd: testDir, storageRoot: testDir };
|
||||
|
||||
beforeAll(async () => {
|
||||
await mkdir(testDir, { recursive: true });
|
||||
await writeFile(join(testDir, "hello.txt"), "hello world", "utf8");
|
||||
await mkdir(testDir, { recursive: true });
|
||||
await writeFile(join(testDir, "hello.txt"), "hello world", "utf8");
|
||||
});
|
||||
|
||||
afterAll(async () => {
|
||||
await rm(testDir, { recursive: true, force: true });
|
||||
await rm(testDir, { recursive: true, force: true });
|
||||
});
|
||||
|
||||
describe("readFileTool", () => {
|
||||
it("reads a file successfully", async () => {
|
||||
const result = await readFileTool.execute({ path: "hello.txt" }, ctx);
|
||||
expect(result).toBe("hello world");
|
||||
});
|
||||
it("reads a file successfully", async () => {
|
||||
const result = await readFileTool.execute({ path: "hello.txt" }, ctx);
|
||||
expect(result).toBe("hello world");
|
||||
});
|
||||
|
||||
it("returns error for non-existent file", async () => {
|
||||
const result = await readFileTool.execute({ path: "nope.txt" }, ctx);
|
||||
expect(result).toMatch(/^Error:/);
|
||||
});
|
||||
it("returns error for non-existent file", async () => {
|
||||
const result = await readFileTool.execute({ path: "nope.txt" }, ctx);
|
||||
expect(result).toMatch(/^Error:/);
|
||||
});
|
||||
|
||||
it("returns error for directory", async () => {
|
||||
const result = await readFileTool.execute({ path: "." }, ctx);
|
||||
expect(result).toBe("Error: not a file");
|
||||
});
|
||||
it("returns error for directory", async () => {
|
||||
const result = await readFileTool.execute({ path: "." }, ctx);
|
||||
expect(result).toBe("Error: not a file");
|
||||
});
|
||||
|
||||
it("returns error when path is not a string", async () => {
|
||||
const result = await readFileTool.execute({ path: 123 }, ctx);
|
||||
expect(result).toBe("Error: path must be a string");
|
||||
});
|
||||
it("returns error when path is not a string", async () => {
|
||||
const result = await readFileTool.execute({ path: 123 }, ctx);
|
||||
expect(result).toBe("Error: path must be a string");
|
||||
});
|
||||
|
||||
it("returns error when args is null", async () => {
|
||||
const result = await readFileTool.execute(null, ctx);
|
||||
expect(result).toBe("Error: path must be a string");
|
||||
});
|
||||
it("returns error when args is null", async () => {
|
||||
const result = await readFileTool.execute(null, ctx);
|
||||
expect(result).toBe("Error: path must be a string");
|
||||
});
|
||||
|
||||
it("returns error for file exceeding 512KB limit", async () => {
|
||||
const bigFile = join(testDir, "big.txt");
|
||||
await writeFile(bigFile, Buffer.alloc(512 * 1024 + 1, 65));
|
||||
const result = await readFileTool.execute({ path: "big.txt" }, ctx);
|
||||
expect(result).toMatch(/Error:.*limit/);
|
||||
});
|
||||
it("returns error for file exceeding 512KB limit", async () => {
|
||||
const bigFile = join(testDir, "big.txt");
|
||||
await writeFile(bigFile, Buffer.alloc(512 * 1024 + 1, 65));
|
||||
const result = await readFileTool.execute({ path: "big.txt" }, ctx);
|
||||
expect(result).toMatch(/Error:.*limit/);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -1,38 +1,38 @@
|
||||
import { describe, it, expect } from "vitest";
|
||||
import { runCommandTool } from "../src/tools/run-command.js";
|
||||
import { tmpdir } from "node:os";
|
||||
import { describe, expect, it } from "vitest";
|
||||
import { runCommandTool } from "../src/tools/run-command.js";
|
||||
|
||||
const ctx = { cwd: tmpdir(), storageRoot: tmpdir() };
|
||||
|
||||
describe("runCommandTool", () => {
|
||||
it("runs echo command and checks stdout", async () => {
|
||||
const result = await runCommandTool.execute({ command: "echo hello" }, ctx);
|
||||
expect(result).toContain("hello");
|
||||
expect(result).toContain("stdout");
|
||||
});
|
||||
it("runs echo command and checks stdout", async () => {
|
||||
const result = await runCommandTool.execute({ command: "echo hello" }, ctx);
|
||||
expect(result).toContain("hello");
|
||||
expect(result).toContain("stdout");
|
||||
});
|
||||
|
||||
it("returns exit code", async () => {
|
||||
const result = await runCommandTool.execute({ command: "exit 0" }, ctx);
|
||||
expect(result).toContain("exit_code: 0");
|
||||
});
|
||||
it("returns exit code", async () => {
|
||||
const result = await runCommandTool.execute({ command: "exit 0" }, ctx);
|
||||
expect(result).toContain("exit_code: 0");
|
||||
});
|
||||
|
||||
it("returns non-zero exit code", async () => {
|
||||
const result = await runCommandTool.execute({ command: "exit 42" }, ctx);
|
||||
expect(result).toContain("exit_code: 42");
|
||||
});
|
||||
it("returns non-zero exit code", async () => {
|
||||
const result = await runCommandTool.execute({ command: "exit 42" }, ctx);
|
||||
expect(result).toContain("exit_code: 42");
|
||||
});
|
||||
|
||||
it("returns error when command is not a string", async () => {
|
||||
const result = await runCommandTool.execute({ command: 123 }, ctx);
|
||||
expect(result).toBe("Error: command must be a string");
|
||||
});
|
||||
it("returns error when command is not a string", async () => {
|
||||
const result = await runCommandTool.execute({ command: 123 }, ctx);
|
||||
expect(result).toBe("Error: command must be a string");
|
||||
});
|
||||
|
||||
it("returns error when args is null", async () => {
|
||||
const result = await runCommandTool.execute(null, ctx);
|
||||
expect(result).toBe("Error: command must be a string");
|
||||
});
|
||||
it("returns error when args is null", async () => {
|
||||
const result = await runCommandTool.execute(null, ctx);
|
||||
expect(result).toBe("Error: command must be a string");
|
||||
});
|
||||
|
||||
it("custom cwd works", async () => {
|
||||
const result = await runCommandTool.execute({ command: "pwd", cwd: "/tmp" }, ctx);
|
||||
expect(result).toContain("/tmp");
|
||||
});
|
||||
it("custom cwd works", async () => {
|
||||
const result = await runCommandTool.execute({ command: "pwd", cwd: "/tmp" }, ctx);
|
||||
expect(result).toContain("/tmp");
|
||||
});
|
||||
});
|
||||
|
||||
@@ -3,13 +3,13 @@ import { mkdtemp, rm } from "node:fs/promises";
|
||||
import { tmpdir } from "node:os";
|
||||
import { join } from "node:path";
|
||||
import { afterEach, beforeEach, describe, expect, test } from "vitest";
|
||||
import type { BuiltinTurnPayload } from "../src/types.js";
|
||||
import {
|
||||
appendSessionTurn,
|
||||
initSessionDir,
|
||||
readSessionTurns,
|
||||
removeSession,
|
||||
} from "../src/session.js";
|
||||
import type { BuiltinTurnPayload } from "../src/types.js";
|
||||
|
||||
describe("session", () => {
|
||||
let storageRoot: string;
|
||||
|
||||
@@ -1,43 +1,43 @@
|
||||
import { describe, it, expect, afterAll } from "vitest";
|
||||
import { writeFileTool } from "../src/tools/write-file.js";
|
||||
import { readFile, rm } from "node:fs/promises";
|
||||
import { join } from "node:path";
|
||||
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 });
|
||||
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("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("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 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 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");
|
||||
});
|
||||
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");
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user