Skip to content

Commit f7da00f

Browse files
authored
fix(opencode): omit empty apply patch move path (anomalyco#45329)
1 parent 5c5c709 commit f7da00f

2 files changed

Lines changed: 22 additions & 2 deletions

File tree

‎packages/opencode/src/tool/apply_patch.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -198,7 +198,7 @@ export const ApplyPatchTool = Tool.define(
198198
patch: change.diff,
199199
additions: change.additions,
200200
deletions: change.deletions,
201-
movePath: change.movePath,
201+
...(change.movePath ? { movePath: change.movePath } : {}),
202202
}))
203203

204204
// Check permissions if needed

‎packages/opencode/test/tool/apply_patch.test.ts‎

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
import { describe, expect } from "bun:test"
22
import path from "path"
33
import * as fs from "fs/promises"
4+
import { PermissionV1 } from "@opencode-ai/core/v1/permission"
45
import { LayerNode } from "@opencode-ai/core/effect/layer-node"
5-
import { Cause, Effect, Exit, Layer } from "effect"
6+
import { Cause, Effect, Exit, Layer, Schema } from "effect"
67
import { ApplyPatchTool } from "../../src/tool/apply_patch"
78
import { LSP } from "@/lsp/lsp"
89
import { FSUtil } from "@opencode-ai/core/fs-util"
@@ -107,6 +108,25 @@ describe("tool.apply_patch freeform", () => {
107108
}),
108109
)
109110

111+
it.instance(
112+
"produces JSON-encodable permission metadata",
113+
() =>
114+
Effect.gen(function* () {
115+
const { ctx, calls } = makeCtx()
116+
yield* execute({ patchText: "*** Begin Patch\n*** Add File: new.txt\n+created\n*** End Patch" }, ctx)
117+
118+
expect(() => {
119+
const request = Schema.encodeUnknownSync(PermissionV1.Request)({
120+
id: PermissionV1.ID.ascending(),
121+
sessionID: baseCtx.sessionID,
122+
...calls[0],
123+
})
124+
Schema.encodeUnknownSync(Schema.Json)(request)
125+
}).not.toThrow()
126+
}),
127+
{ git: true },
128+
)
129+
110130
it.instance(
111131
"applies add/update/delete in one patch",
112132
() =>

0 commit comments

Comments
 (0)