Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion packages/opencode/src/tool/apply_patch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
22 changes: 21 additions & 1 deletion packages/opencode/test/tool/apply_patch.test.ts
Original file line number Diff line number Diff line change
@@ -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"
Expand Down Expand Up @@ -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",
() =>
Expand Down
Loading