fix tests

This commit is contained in:
Dax Raad
2025-11-06 11:42:46 -05:00
parent 065f656fb0
commit 67f3c934fe
2 changed files with 53 additions and 10 deletions

View File

@@ -3,6 +3,7 @@ import path from "path"
import { PatchTool } from "../../src/tool/patch"
import { Instance } from "../../src/project/instance"
import { tmpdir } from "../fixture/fixture"
import { Permission } from "../../src/permission"
import * as fs from "fs/promises"
const ctx = {
@@ -21,9 +22,7 @@ describe("tool.patch", () => {
await Instance.provide({
directory: "/tmp",
fn: async () => {
await expect(patchTool.execute({ patchText: "" }, ctx)).rejects.toThrow(
"patchText is required",
)
expect(patchTool.execute({ patchText: "" }, ctx)).rejects.toThrow("patchText is required")
},
})
})
@@ -32,7 +31,7 @@ describe("tool.patch", () => {
await Instance.provide({
directory: "/tmp",
fn: async () => {
await expect(patchTool.execute({ patchText: "invalid patch" }, ctx)).rejects.toThrow(
expect(patchTool.execute({ patchText: "invalid patch" }, ctx)).rejects.toThrow(
"Failed to parse patch",
)
},
@@ -46,13 +45,29 @@ describe("tool.patch", () => {
const emptyPatch = `*** Begin Patch
*** End Patch`
await expect(patchTool.execute({ patchText: emptyPatch }, ctx)).rejects.toThrow(
expect(patchTool.execute({ patchText: emptyPatch }, ctx)).rejects.toThrow(
"No file changes found in patch",
)
},
})
})
test("should ask permission for files outside working directory", async () => {
await Instance.provide({
directory: "/tmp",
fn: async () => {
const maliciousPatch = `*** Begin Patch
*** Add File: /etc/passwd
+malicious content
*** End Patch`
patchTool.execute({ patchText: maliciousPatch }, ctx)
// TODO: this sucks
await new Promise((resolve) => setTimeout(resolve, 100))
expect(Permission.pending()[ctx.sessionID]).toBeDefined()
},
})
})
test("should handle simple add file operation", async () => {
await using fixture = await tmpdir()