fix(core): preserve bounded tool receipts

This commit is contained in:
Kit Langton 2026-07-20 14:58:58 -04:00
commit f7a72fdf32
22 changed files with 278 additions and 17 deletions

View file

@ -2,7 +2,8 @@ import fs from "fs/promises"
import path from "path"
import { fileURLToPath } from "url"
import { describe, expect, test } from "bun:test"
import { Effect, Layer } from "effect"
import { Effect, Layer, Schema } from "effect"
import { parsePatch } from "diff"
import { AppNodeBuilder } from "@opencode-ai/core/effect/app-node-builder"
import { LayerNode } from "@opencode-ai/core/effect/layer-node"
import { FileMutation } from "@opencode-ai/core/file-mutation"
@ -174,6 +175,45 @@ describe("EditTool", () => {
),
)
it.live("retains a bounded patch for large edits", () =>
Effect.acquireUseRelease(
Effect.promise(() => tmpdir()),
(tmp) => {
reset()
const target = path.join(tmp.path, "large.txt")
const before = "x".repeat(9_000)
const after = "y".repeat(9_000)
return Effect.promise(() => fs.writeFile(target, before)).pipe(
Effect.andThen(
withTool(tmp.path, (registry) =>
Effect.gen(function* () {
const settled = yield* settleTool(
registry,
call({ path: "large.txt", oldString: before, newString: after }),
)
const structured = Schema.decodeUnknownSync(EditTool.Output)(settled.output?.structured)
expect(Buffer.byteLength(JSON.stringify(structured))).toBeLessThanOrEqual(
ToolOutputStore.MAX_STRUCTURED_BYTES,
)
expect(() => parsePatch(structured.files[0]?.patch ?? "")).not.toThrow()
expect(structured).toMatchObject({
replacements: 1,
files: [
{
file: "large.txt",
patch: expect.stringContaining("... truncated ..."),
},
],
})
}),
),
),
)
},
(tmp) => Effect.promise(() => tmp[Symbol.asyncDispose]()),
),
)
it.live("accepts an absolute file path inside the active Location", () =>
Effect.acquireUseRelease(
Effect.promise(() => tmpdir()),