Skip to content

Commit dec3c79

Browse files
committed
test(files): make full-rewrite two-writer test actually exercise the concurrent peer edit
1 parent 625efbd commit dec3c79

1 file changed

Lines changed: 14 additions & 6 deletions

File tree

apps/sim/app/workspace/[workspaceId]/files/components/file-viewer/rich-markdown-editor/collaboration/apply-streamed-markdown.concurrent.test.ts

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -183,24 +183,32 @@ describe('two-writer: peer edits while the agent streams', () => {
183183
// peer survival here is CRDT-dependent — reported above, not hard-asserted.
184184
})
185185

186-
it('FULL REWRITE: agent replaces the whole doc while the peer edits the middle — no duplication', () => {
186+
it('FULL REWRITE: peer edits original content that the agent then deletes in a full rewrite', () => {
187187
const { A, B } = seededPair('# Title\n\nAlpha\n\nBeta\n\nGamma')
188188
const session = beginAgentStream(A.editor)!
189189

190+
// Peer edits Beta WHILE it still exists — genuinely concurrent with the impending rewrite.
191+
// (Asserting the insert landed guards against a false-green where the target was already gone.)
192+
expect(peerInsertNear(B.editor, 'Beta', 'PEER ')).toBe(true)
193+
// Agent replaces the WHOLE doc across two frames, deleting Alpha/Beta/Gamma.
190194
applyAgentStreamFrame(A.editor, session, '# Report\n\nOne\n\nTwo')
191-
peerInsertNear(B.editor, 'Beta', 'PEER ')
192195
applyAgentStreamFrame(A.editor, session, '# Report\n\nOne\n\nTwo\n\nThree')
193196
endAgentStream(session)
194197

195198
const textA = A.editor.state.doc.textContent
196199
console.log(`\n[FULL-REWRITE] A: ${JSON.stringify(textA)}`)
197200
console.log(
198-
`[FULL-REWRITE] converged=${fragStr(A.doc) === fragStr(B.doc)} oneCount=${count(textA, 'One')} threeCount=${count(textA, 'Three')} emptyParas=${emptyParas(A.editor)}`
201+
`[FULL-REWRITE] converged=${fragStr(A.doc) === fragStr(B.doc)} peerCount=${count(textA, 'PEER ')} oneCount=${count(textA, 'One')} threeCount=${count(textA, 'Three')} emptyParas=${emptyParas(A.editor)}`
199202
)
200203

201204
expect(fragStr(A.doc)).toBe(fragStr(B.doc)) // convergence
202-
expect(count(textA, 'Three')).toBe(1) // agent content not duplicated by the concurrent merge
203-
expect(count(textA, 'One')).toBe(1)
204-
expect(emptyParas(A.editor)).toBe(0)
205+
expect(count(textA, 'One')).toBe(1) // agent content not duplicated by the concurrent merge
206+
expect(count(textA, 'Three')).toBe(1)
207+
expect(emptyParas(A.editor)).toBe(0) // no stray empties from a delete/insert conflict
208+
// The peer's insert is NOT lost when the rewrite deletes its surrounding paragraph: Yjs preserves
209+
// the inserted text and reattaches it to the nearest surviving anchor (it relocates into the
210+
// rewritten content rather than vanishing). What matters is that it survives exactly once — never
211+
// duplicated, never silently dropped.
212+
expect(count(textA, 'PEER ')).toBe(1)
205213
})
206214
})

0 commit comments

Comments
 (0)