Skip to content
This repository was archived by the owner on May 20, 2026. It is now read-only.

Commit 6cf0cb6

Browse files
committed
update test
1 parent d4b0283 commit 6cf0cb6

1 file changed

Lines changed: 13 additions & 7 deletions

File tree

src/extension/xtab/test/node/xtabCustomDiffPatchResponseHandler.spec.ts

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -153,19 +153,24 @@ file.ts:5
153153
expect(returnValue).toBe(cancellationReason);
154154
});
155155

156-
it('does not yield incomplete patch when fetch is cancelled mid-stream', async () => {
157-
// Stream is truncated before the last line "+one more new" is emitted,
158-
// simulating a cancellation that cuts off the response mid-patch.
156+
it('does not yield truncated patch when fetch is cancelled mid-stream', async () => {
157+
// Full response would be:
158+
// file.ts:0 / -old / +new / file.ts:5 / -another old / +another new / +one more new
159+
// But the fetch is cancelled right before "+one more new" is emitted,
160+
// so the stream only delivers lines up to "+another new".
161+
// The second patch is incomplete and must not be yielded.
159162
const truncatedPatchText = `file.ts:0
160163
-old
161164
+new
162165
file.ts:5
163166
-another old
164167
+another new`;
168+
// "+one more new" is missing — fetch was cancelled before it arrived
165169
const linesStream = AsyncIterUtils.fromArray(truncatedPatchText.split('\n'));
166170
const docId = DocumentId.create('file:///file.ts');
167171
const documentBeforeEdits = new StringText('old\n');
168172

173+
let checkCount = 0;
169174
const cancellationReason = new NoNextEditReason.GotCancelled('afterFetchCall');
170175

171176
const { edits, returnValue } = await consumeHandleResponse(
@@ -176,13 +181,14 @@ file.ts:5
176181
undefined,
177182
undefined,
178183
() => {
179-
// Fetch was cancelled — the full patch had "+one more new" but the
180-
// stream was resolved early so it's missing from the second patch.
181-
return cancellationReason;
184+
// Fetch was still running (not yet cancelled) when the first edit was checked,
185+
// but was cancelled before the second (incomplete) edit is about to be yielded.
186+
return checkCount++ > 0 ? cancellationReason : undefined;
182187
},
183188
);
184189

185-
expect(edits).toHaveLength(0);
190+
// The first (complete) edit is yielded; the second (truncated) edit is not
191+
expect(edits).toHaveLength(1);
186192
expect(returnValue).toBe(cancellationReason);
187193
});
188194
});

0 commit comments

Comments
 (0)