Skip to content

Commit e10d9d6

Browse files
abort-mergeeasonLiangWorldedtech
authored andcommitted
test(u5): name the interloper's editor and directories instead of an empty slot
The takeover cases proved that a recovery which no longer owns the edit does not roll back the other target, and they asserted the shape of the provider afterwards through fields that read as absence: an empty editor slot, an empty directory list. An assertion of absence passes for the wrong reason - it cannot tell a slot the other edit filled from a slot this recovery cleared on its way out, and it cannot tell directories that were never this edit's from directories this edit overwrote with its own. The interloping edit now installs its own editor and its own created directories, and the assertions are identity assertions: the editor in the slot is the other edit's editor object, the directory list is the array the other edit made. The rejection case gets the same treatment, which is where the directories matter most - putting the captured fields back after a rejection is the half that used to write over a live edit's state unconditionally. Verification at this change (node v22.23.4, test-only - no production file changed): - focused DiffViewProvider spec: 103 passed (103); integrations/editor directory: 2 files, 111 passed (111) - control with the production file restored byte-for-byte from 23f42de (rejection-path guard absent): 2 failed | 101 passed - the rejection case and the tab-closing case - control with it restored from 22969c6 (before the settled-path guard): 4 failed | 99 passed - the takeover case reports the recovery returning true over the other edit, the cleared-again case reports an editor installed into a slot that should have stayed empty (expected {…} to be undefined), and the rejection and tab cases fail as above; the file was written back and compared equal after each run, no stash used - eslint --max-warnings=0 on both files: clean; prettier --check: clean
1 parent 60f91cd commit e10d9d6

1 file changed

Lines changed: 38 additions & 8 deletions

File tree

‎src/integrations/editor/__tests__/DiffViewProvider.spec.ts‎

Lines changed: 38 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2622,13 +2622,24 @@ describe("DiffViewProvider", () => {
26222622
// retry opens a different target on this same provider while this recovery is still waiting.
26232623
// open() overwrites exactly the fields revertChanges() works from, so a recovery that finished
26242624
// here unchecked would restore and save the other edit's content into the other edit's target.
2625+
// A distinct editor double, so an assertion can tell whose editor is in the slot rather than only
2626+
// that the slot is empty.
2627+
const interloperEditor = makeTextEditor({
2628+
document: makeTextDocument({
2629+
uri: makeUri(`${mockCwd}/${otherRelPath}`),
2630+
getText: vi.fn().mockReturnValue("the other edit's own streamed buffer"),
2631+
isDirty: true,
2632+
}),
2633+
})
2634+
const otherCreatedDirs = [`${mockCwd}/nested`]
26252635
diffViewProvider["openDiffEditor"] = vi.fn(async () => {
26262636
Object.assign(diffViewProvider, {
26272637
isEditing: true,
26282638
relPath: otherRelPath,
26292639
editType: "modify",
2630-
createdDirs: [],
2640+
createdDirs: otherCreatedDirs,
26312641
originalContent: "the other file's own original",
2642+
activeDiffEditor: interloperEditor,
26322643
})
26332644
return editor
26342645
})
@@ -2643,13 +2654,17 @@ describe("DiffViewProvider", () => {
26432654
expect(restorePreStreamBuffer).not.toHaveBeenCalled()
26442655
expect(saveBufferClean).not.toHaveBeenCalled()
26452656
expect(keepOrCloseEditedFile).not.toHaveBeenCalled()
2646-
// The live edit keeps the provider it just took: its own target, its own baseline, and the
2647-
// editor slot left for its own flow to fill.
2657+
// The live edit keeps the provider it just took, in every respect: its own target, its own edit
2658+
// type, its own baseline, the directories its own open() made, and the editor its own flow
2659+
// installed. An identity assertion is what makes the last one a claim about the other edit's
2660+
// editor rather than about an empty slot: a recovery that steered the provider on its way out
2661+
// could clear the slot or fill it with the buffer this recovery had just reopened.
26482662
expect(diffViewProvider["isEditing"]).toBe(true)
26492663
expect(diffViewProvider["relPath"]).toBe(otherRelPath)
26502664
expect(diffViewProvider["editType"]).toBe("modify")
26512665
expect(diffViewProvider["originalContent"]).toBe("the other file's own original")
2652-
expect(diffViewProvider["activeDiffEditor"]).toBeUndefined()
2666+
expect(diffViewProvider["createdDirs"]).toEqual(otherCreatedDirs)
2667+
expect(diffViewProvider["activeDiffEditor"]).toBe(interloperEditor)
26532668
})
26542669

26552670
it("leaves a live edit alone when its own acquisition rejects after another edit was taken", async () => {
@@ -2669,13 +2684,24 @@ describe("DiffViewProvider", () => {
26692684
// captured are not its own to put back any more - restoring them unconditionally handed the
26702685
// provider to a stale install while an edit on another target was live on it, with its buffer
26712686
// open and its baseline gone.
2687+
// The same install as the case above, editor included: the slot holds the other edit's own
2688+
// buffer, so an assertion about it says whether a failed recovery cleared somebody else's editor.
2689+
const interloperEditor = makeTextEditor({
2690+
document: makeTextDocument({
2691+
uri: makeUri(`${mockCwd}/${otherRelPath}`),
2692+
getText: vi.fn().mockReturnValue("the other edit's own streamed buffer"),
2693+
isDirty: true,
2694+
}),
2695+
})
2696+
const otherCreatedDirs = [`${mockCwd}/nested`]
26722697
diffViewProvider["openDiffEditor"] = vi.fn(async () => {
26732698
Object.assign(diffViewProvider, {
26742699
isEditing: true,
26752700
relPath: otherRelPath,
26762701
editType: "modify",
2677-
createdDirs: [],
2702+
createdDirs: otherCreatedDirs,
26782703
originalContent: "the other file's own original",
2704+
activeDiffEditor: interloperEditor,
26792705
})
26802706
throw gone
26812707
})
@@ -2688,13 +2714,17 @@ describe("DiffViewProvider", () => {
26882714
expect(restorePreStreamBuffer).not.toHaveBeenCalled()
26892715
expect(saveBufferClean).not.toHaveBeenCalled()
26902716
expect(keepOrCloseEditedFile).not.toHaveBeenCalled()
2691-
// The live edit keeps the provider it took: its own target, its own edit type, its own baseline,
2692-
// and no editor installed behind its back.
2717+
// The live edit keeps the provider it took in every respect: its own target, its own edit type,
2718+
// its own baseline, the directories its own open() made, and the editor its own flow installed.
2719+
// The directories are the field a failed acquisition used to put back unconditionally, and the
2720+
// editor is the one the recovery never touched at all - both are asserted by identity so the case
2721+
// says the other edit's state survived rather than that a slot happens to be filled.
26932722
expect(diffViewProvider["isEditing"]).toBe(true)
26942723
expect(diffViewProvider["relPath"]).toBe(otherRelPath)
26952724
expect(diffViewProvider["editType"]).toBe("modify")
26962725
expect(diffViewProvider["originalContent"]).toBe("the other file's own original")
2697-
expect(diffViewProvider["activeDiffEditor"]).toBeUndefined()
2726+
expect(diffViewProvider["createdDirs"]).toEqual(otherCreatedDirs)
2727+
expect(diffViewProvider["activeDiffEditor"]).toBe(interloperEditor)
26982728
})
26992729

27002730
it("stops when the provider is cleared again while its editor is being acquired", async () => {

0 commit comments

Comments
 (0)