mirror of
https://github.com/anomalyco/opencode.git
synced 2026-11-17 05:26:47 +03:00
fix(acp): complete edits whose patch header cannot be parsed
This commit is contained in:
@@ -94,7 +94,7 @@ export const withCompletedDiffs = Effect.fnUntraced(function* (
|
||||
const path = absolutePath(file.file, cwd)
|
||||
const newText = file.status === "deleted" ? "" : yield* Effect.tryPromise(() => Bun.file(path).text())
|
||||
if (file.status === "added") return [diff(path, null, newText)]
|
||||
const recorded = parsePatch(file.patch)[0]
|
||||
const recorded = (yield* Effect.try(() => parsePatch(file.patch)))[0]
|
||||
if (!recorded) return []
|
||||
const oldText = yield* Effect.try(() => applyPatch(newText, reversePatch(recorded)))
|
||||
if (oldText !== false) return [diff(path, oldText, newText)]
|
||||
|
||||
@@ -251,6 +251,35 @@ describe("acp prompt turns over the wire", () => {
|
||||
})
|
||||
})
|
||||
|
||||
// Windows file names cannot contain a newline.
|
||||
const testOutsideWindows = process.platform === "win32" ? test.skip : test
|
||||
testOutsideWindows("completes an edit whose file name breaks the patch header", async () => {
|
||||
await using dir = await tmpdir()
|
||||
const name = "notes.txt\nx"
|
||||
await Bun.write(path.resolve(dir.path, name), "world\n")
|
||||
await using acp = await startWire({
|
||||
onPrompt: ({ sessionID, id }) =>
|
||||
turn(
|
||||
sessionID,
|
||||
id,
|
||||
toolStarted(sessionID, "call_edit", "edit"),
|
||||
toolCalled(sessionID, "call_edit", { path: name, oldString: "hello", newString: "world" }),
|
||||
toolSucceeded(sessionID, "call_edit", { files: [fileDiff(name, "hello\n", "world\n")] }, "edited"),
|
||||
),
|
||||
})
|
||||
await acp.initialize()
|
||||
const session = await acp.newSession(dir.path)
|
||||
|
||||
const result = await acp.prompt(session.sessionId, "edit the file")
|
||||
|
||||
expect(result.stopReason).toBe("end_turn")
|
||||
expect(
|
||||
turnUpdates(acp.updates).find(
|
||||
(item) => item.update.sessionUpdate === "tool_call_update" && item.update.status === "completed",
|
||||
)?.update,
|
||||
).toMatchObject({ content: [{ type: "content", content: { type: "text", text: "edited" } }] })
|
||||
})
|
||||
|
||||
test("routes slash commands and compact through their session endpoints", async () => {
|
||||
await using acp = await startWire()
|
||||
acp.server.catalog.commands = [reviewCommand, { name: "compact", description: "Server compact" }]
|
||||
|
||||
Reference in New Issue
Block a user