mirror of
https://github.com/aljazceru/opencode.git
synced 2025-12-25 03:34:22 +01:00
fix tests
This commit is contained in:
@@ -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()
|
||||
|
||||
|
||||
Reference in New Issue
Block a user