test cleanup

This commit is contained in:
Dax Raad
2025-10-24 09:29:38 -04:00
parent 7003efd2da
commit 4cab66da6c
2 changed files with 54 additions and 59 deletions

View File

@@ -1,7 +1,6 @@
import { describe, expect, test } from "bun:test" import { describe, expect, test } from "bun:test"
import path from "path" import path from "path"
import { BashTool } from "../../src/tool/bash" import { BashTool } from "../../src/tool/bash"
import { Log } from "../../src/util/log"
import { Instance } from "../../src/project/instance" import { Instance } from "../../src/project/instance"
const ctx = { const ctx = {
@@ -15,7 +14,6 @@ const ctx = {
const bash = await BashTool.init() const bash = await BashTool.init()
const projectRoot = path.join(__dirname, "../..") const projectRoot = path.join(__dirname, "../..")
Log.init({ print: false })
describe("tool.bash", () => { describe("tool.bash", () => {
test("basic", async () => { test("basic", async () => {

View File

@@ -1,7 +1,6 @@
import { describe, expect, test } from "bun:test" import { describe, expect, test } from "bun:test"
import path from "path" import path from "path"
import { PatchTool } from "../../src/tool/patch" import { PatchTool } from "../../src/tool/patch"
import { Log } from "../../src/util/log"
import { Instance } from "../../src/project/instance" import { Instance } from "../../src/project/instance"
import { tmpdir } from "../fixture/fixture" import { tmpdir } from "../fixture/fixture"
import * as fs from "fs/promises" import * as fs from "fs/promises"
@@ -16,16 +15,13 @@ const ctx = {
} }
const patchTool = await PatchTool.init() const patchTool = await PatchTool.init()
Log.init({ print: false })
describe("tool.patch", () => { describe("tool.patch", () => {
test("should validate required parameters", async () => { test("should validate required parameters", async () => {
await Instance.provide({ await Instance.provide({
directory: "/tmp", directory: "/tmp",
fn: async () => { fn: async () => {
await expect( await expect(patchTool.execute({ patchText: "" }, ctx)).rejects.toThrow("patchText is required")
patchTool.execute({ patchText: "" }, ctx)
).rejects.toThrow("patchText is required")
}, },
}) })
}) })
@@ -34,9 +30,7 @@ describe("tool.patch", () => {
await Instance.provide({ await Instance.provide({
directory: "/tmp", directory: "/tmp",
fn: async () => { fn: async () => {
await expect( await expect(patchTool.execute({ patchText: "invalid patch" }, ctx)).rejects.toThrow("Failed to parse patch")
patchTool.execute({ patchText: "invalid patch" }, ctx)
).rejects.toThrow("Failed to parse patch")
}, },
}) })
}) })
@@ -48,9 +42,9 @@ describe("tool.patch", () => {
const emptyPatch = `*** Begin Patch const emptyPatch = `*** Begin Patch
*** End Patch` *** End Patch`
await expect( await expect(patchTool.execute({ patchText: emptyPatch }, ctx)).rejects.toThrow(
patchTool.execute({ patchText: emptyPatch }, ctx) "No file changes found in patch",
).rejects.toThrow("No file changes found in patch") )
}, },
}) })
}) })
@@ -64,9 +58,9 @@ describe("tool.patch", () => {
+malicious content +malicious content
*** End Patch` *** End Patch`
await expect( await expect(patchTool.execute({ patchText: maliciousPatch }, ctx)).rejects.toThrow(
patchTool.execute({ patchText: maliciousPatch }, ctx) "is not in the current working directory",
).rejects.toThrow("is not in the current working directory") )
}, },
}) })
}) })
@@ -119,7 +113,7 @@ describe("tool.patch", () => {
// Verify file was created with correct content // Verify file was created with correct content
const filePath = path.join(fixture.path, "config.js") const filePath = path.join(fixture.path, "config.js")
const content = await fs.readFile(filePath, "utf-8") const content = await fs.readFile(filePath, "utf-8")
expect(content).toBe("const API_KEY = \"test-key\"\nconst DEBUG = false\nconst VERSION = \"1.0\"") expect(content).toBe('const API_KEY = "test-key"\nconst DEBUG = false\nconst VERSION = "1.0"')
}, },
}) })
}) })
@@ -173,7 +167,10 @@ describe("tool.patch", () => {
// Verify nested file was created // Verify nested file was created
const nestedPath = path.join(fixture.path, "deep", "nested", "file.txt") const nestedPath = path.join(fixture.path, "deep", "nested", "file.txt")
const exists = await fs.access(nestedPath).then(() => true).catch(() => false) const exists = await fs
.access(nestedPath)
.then(() => true)
.catch(() => false)
expect(exists).toBe(true) expect(exists).toBe(true)
const content = await fs.readFile(nestedPath, "utf-8") const content = await fs.readFile(nestedPath, "utf-8")