Skip to content

Commit 74106dd

Browse files
committed
fix(snapshot): address review - gate flag on truncation, trim tests, regen openapi
1 parent 1b45623 commit 74106dd

4 files changed

Lines changed: 10 additions & 64 deletions

File tree

‎packages/core/src/git.ts‎

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -885,10 +885,9 @@ const layer = Layer.effect(
885885
const stat = stats.get(entry.file)
886886
const binary = stat?.binary ?? false
887887
const chunk = binary ? undefined : patches.get(entry.file)
888-
// Budget-withheld patches keep filename/status/counts and expose
889-
// truncated: true so DB rows stay bounded and the UI can collapse.
890-
// (Partial trailing-chunk truncation stays unmarked: known limitation.)
891-
const withheld = !binary && chunk === undefined
888+
// Only a cut-off patch output means the budget withheld this file;
889+
// otherwise a missing chunk is a parse failure, not a truncation.
890+
const withheld = patch.truncated && !binary && chunk === undefined
892891
return {
893892
...entry,
894893
additions: stat?.additions ?? 0,

‎packages/core/src/vcs.ts‎

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import { Location } from "./location.js"
1313
import { Project } from "./project.js"
1414
import { Bus } from "./bus.js"
1515
import { State } from "./state.js"
16-
import { emptyPatch, MAX_PATCH_BYTES, MAX_TOTAL_PATCH_BYTES, PATCH_CONTEXT_LINES } from "./vcs/patch.js"
16+
import { emptyPatch, MAX_TOTAL_PATCH_BYTES, PATCH_CONTEXT_LINES } from "./vcs/patch.js"
1717

1818
export { Base, BranchList, FileStatus, Info, Mode }
1919

@@ -244,10 +244,9 @@ const layer = Layer.effect(
244244
let total = 0
245245
return rows.map((row) => {
246246
const bytes = Buffer.byteLength(row.patch)
247-
// Per-file and total budgets use UTF-8 bytes, not JS string length,
248-
// so multi-byte content cannot slip past the cap. Withheld patches
249-
// keep filename/status/counts and expose truncated: true.
250-
if (bytes > MAX_PATCH_BYTES || total + bytes > MAX_TOTAL_PATCH_BYTES)
247+
// The total check already uses UTF-8 bytes; a withheld patch keeps
248+
// filename/status/counts and exposes truncated: true.
249+
if (total + bytes > MAX_TOTAL_PATCH_BYTES)
251250
return { ...row, patch: emptyPatch(row.file), truncated: true as const }
252251
total += bytes
253252
return row

‎packages/core/test/git.test.ts‎

Lines changed: 0 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -238,61 +238,6 @@ describe("Git trees", () => {
238238
}),
239239
)
240240

241-
it.live("withholds patch text above the total byte budget and marks truncated", () =>
242-
Effect.gen(function* () {
243-
const root = yield* Effect.acquireRelease(
244-
Effect.promise(() => tmpdir()),
245-
(dir) => Effect.promise(() => dir[Symbol.asyncDispose]()),
246-
)
247-
yield* Effect.promise(() => initRepo(root.path))
248-
const git = yield* Git.Service
249-
const repository = yield* git.repo.discover(AbsolutePath.make(root.path))
250-
if (!repository) throw new Error("Repository not found")
251-
const before = yield* git.tree.capture({ repository, scopes: [RelativePath.make(".")] })
252-
// Multi-byte content: byte size (not JS length) drives the budget.
253-
yield* Effect.promise(() => Bun.write(path.join(root.path, "large-unicode.txt"), "🙂".repeat(3_000_000)))
254-
const after = yield* git.tree.capture({ repository, scopes: [RelativePath.make(".")] })
255-
const diffs = yield* git.tree.diff({ repository, from: before, to: after, context: 0 })
256-
expect(diffs).toHaveLength(1)
257-
expect(diffs[0]?.file).toBe("large-unicode.txt")
258-
expect(diffs[0]?.patch).toBe(VcsPatch.emptyPatch("large-unicode.txt"))
259-
expect(diffs[0]?.truncated).toBe(true)
260-
expect(diffs[0]?.additions).toBeGreaterThan(0)
261-
}),
262-
)
263-
264-
it.live("limits total patch text across files, keeping the first under budget", () =>
265-
Effect.gen(function* () {
266-
const root = yield* Effect.acquireRelease(
267-
Effect.promise(() => tmpdir()),
268-
(dir) => Effect.promise(() => dir[Symbol.asyncDispose]()),
269-
)
270-
yield* Effect.promise(() => initRepo(root.path))
271-
const git = yield* Git.Service
272-
const repository = yield* git.repo.discover(AbsolutePath.make(root.path))
273-
if (!repository) throw new Error("Repository not found")
274-
const before = yield* git.tree.capture({ repository, scopes: [RelativePath.make(".")] })
275-
yield* Effect.promise(async () => {
276-
await Bun.write(path.join(root.path, "cap-a.txt"), `${"a".repeat(79)}\n`.repeat(80_000))
277-
await Bun.write(path.join(root.path, "cap-b.txt"), `${"b".repeat(79)}\n`.repeat(80_000))
278-
})
279-
const after = yield* git.tree.capture({ repository, scopes: [RelativePath.make(".")] })
280-
const diffs = yield* git.tree.diff({ repository, from: before, to: after, context: 0 })
281-
const first = diffs.find((item) => item.file === "cap-a.txt")
282-
const second = diffs.find((item) => item.file === "cap-b.txt")
283-
// Either file may win the budget; exactly one must be withheld.
284-
const kept = [first, second].find((item) => item?.truncated !== true)
285-
const dropped = [first, second].find((item) => item?.truncated === true)
286-
expect(kept?.patch).not.toBe("")
287-
expect(kept?.truncated).toBeUndefined()
288-
expect(dropped?.patch).toBe(VcsPatch.emptyPatch(dropped?.file ?? ""))
289-
expect(diffs.filter((item) => item.truncated === true)).toHaveLength(1)
290-
expect(
291-
diffs.reduce((total, item) => total + Buffer.byteLength(item.patch ?? ""), 0),
292-
).toBeLessThanOrEqual(VcsPatch.MAX_TOTAL_PATCH_BYTES)
293-
}),
294-
)
295-
296241
it.live(
297242
"diffs a path selection longer than any platform command line",
298243
() =>

‎packages/protocol/openapi.json‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14765,6 +14765,9 @@
1476514765
"status": {
1476614766
"type": "string",
1476714767
"enum": ["added", "deleted", "modified"]
14768+
},
14769+
"truncated": {
14770+
"type": "boolean"
1476814771
}
1476914772
},
1477014773
"required": ["file", "patch", "additions", "deletions", "status"],

0 commit comments

Comments
 (0)