fix(opencode): omit empty apply patch move path (#45329)

This commit is contained in:
Kyle Altendorf 2026-08-31 22:37:19 -04:00 committed by GitHub
parent 5c5c709fee
commit f7da00f35e
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 22 additions and 2 deletions

View file

@ -198,7 +198,7 @@ export const ApplyPatchTool = Tool.define(
patch: change.diff,
additions: change.additions,
deletions: change.deletions,
movePath: change.movePath,
...(change.movePath ? { movePath: change.movePath } : {}),
}))
// Check permissions if needed

View file

@ -1,8 +1,9 @@
import { describe, expect } from "bun:test"
import path from "path"
import * as fs from "fs/promises"
import { PermissionV1 } from "@opencode-ai/core/v1/permission"
import { LayerNode } from "@opencode-ai/core/effect/layer-node"
import { Cause, Effect, Exit, Layer } from "effect"
import { Cause, Effect, Exit, Layer, Schema } from "effect"
import { ApplyPatchTool } from "../../src/tool/apply_patch"
import { LSP } from "@/lsp/lsp"
import { FSUtil } from "@opencode-ai/core/fs-util"
@ -107,6 +108,25 @@ describe("tool.apply_patch freeform", () => {
}),
)
it.instance(
"produces JSON-encodable permission metadata",
() =>
Effect.gen(function* () {
const { ctx, calls } = makeCtx()
yield* execute({ patchText: "*** Begin Patch\n*** Add File: new.txt\n+created\n*** End Patch" }, ctx)
expect(() => {
const request = Schema.encodeUnknownSync(PermissionV1.Request)({
id: PermissionV1.ID.ascending(),
sessionID: baseCtx.sessionID,
...calls[0],
})
Schema.encodeUnknownSync(Schema.Json)(request)
}).not.toThrow()
}),
{ git: true },
)
it.instance(
"applies add/update/delete in one patch",
() =>