Skip to content

Commit 97fef56

Browse files
committed
test(responses): assert the decoded patch suffix bound
1 parent 9f8cdad commit 97fef56

1 file changed

Lines changed: 13 additions & 2 deletions

File tree

‎tests/responses/responses-custom-tool-stream-consistency.test.ts‎

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
import { describe, expect, test } from "bun:test";
1+
import { describe, expect, spyOn, test } from "bun:test";
2+
import * as patchEnvelope from "../../src/responses/apply-patch-envelope";
23
import {
34
createRoutedCustomToolRestoreBlockRewrite,
45
RoutedCustomToolProgressError,
@@ -191,7 +192,17 @@ describe("routed Responses custom-tool stream consistency", () => {
191192
const body = `+${"x".repeat(65_536)}\n+last line\n`;
192193
const wrapped = JSON.stringify({ input: `${opening}${body}*** End Patch ***\n` });
193194
const normalized = `${opening}${body}*** End Patch\n`;
194-
const result = restoreExecStream(wrapped, wrapped.match(/[\s\S]{1,37}/g)!, "apply_patch");
195+
const original = patchEnvelope.stableCanonicalPatchPrefix;
196+
let longChecks = 0;
197+
const spy = spyOn(patchEnvelope, "stableCanonicalPatchPrefix").mockImplementation((...args) => {
198+
expect(args[1]).toBe(args[0].slice(-64));
199+
if (args[0].length > 64) longChecks++;
200+
return original(...args);
201+
});
202+
let result: ReturnType<typeof restoreExecStream>;
203+
try { result = restoreExecStream(wrapped, wrapped.match(/[\s\S]{1,37}/g)!, "apply_patch"); }
204+
finally { spy.mockRestore(); }
205+
expect(longChecks).toBeGreaterThan(0);
195206
for (const preview of result.previews) expect(normalized.startsWith(preview)).toBe(true);
196207
expect(result.preview).toBe(normalized.slice(0, -1));
197208
expect(result.doneInput).toBe(normalized);

0 commit comments

Comments
 (0)