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

View File

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