-
Notifications
You must be signed in to change notification settings - Fork 152
SD-3352 - fix: refine deletion behavior for anonymous users in overlap-compiler #3655
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
chittolinag
wants to merge
4
commits into
main
Choose a base branch
from
gabriel/sd-3352-bug-same-author-delete-inside-pending-insertion-should
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+320
−15
Open
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
aeacad7
fix: refine deletion behavior for anonymous users in overlap-compiler
chittolina 326e79e
test: add behavior tests for deletion inside own pending insertion (S…
chittolina 254f180
Merge branch 'main' into gabriel/sd-3352-bug-same-author-delete-insid…
chittolinag 91720e5
refactor: enhance overlap-compiler to refine own insertions for anony…
chittolina File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
149 changes: 149 additions & 0 deletions
149
tests/behavior/tests/comments/sd-3352-same-author-delete-inside-insertion.spec.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,149 @@ | ||
| import { test, expect, type SuperDocFixture } from '../../fixtures/superdoc.js'; | ||
|
|
||
| // SD-3352 / TC-SAME-001: deleting text wholly inside your OWN pending tracked | ||
| // insertion must refine the insertion in place — one shrunken suggestion, the | ||
| // way Word handles it (overlap case 11_same_insert_delete_inside_control) — | ||
| // not stack an overlapping deletion on top of your own insertion. | ||
| // | ||
| // The regression trigger was an anonymous session (integrator passes no | ||
| // `user`): typing recognized the anonymous user as itself, but the delete | ||
| // path classified the same user as a different reviewer and minted a nested | ||
| // tracked deletion over their own suggestion. | ||
|
|
||
| test.use({ config: { toolbar: 'full', comments: 'off', trackChanges: true } }); | ||
|
|
||
| // Mirror of SuperDoc's DEFAULT_USER when the integrator passes no `user`. | ||
| const ANONYMOUS_DEFAULT = { id: null, name: 'Default SuperDoc user', email: null }; | ||
| const REVIEWER = { name: 'Guest Reviewer', email: 'track@example.com' }; | ||
|
|
||
| const setUser = (superdoc: SuperDocFixture, user: Record<string, unknown>): Promise<void> => | ||
| superdoc.page.evaluate((u) => { | ||
| (window as any).editor.setOptions({ user: u }); | ||
| }, user); | ||
|
|
||
| /** | ||
| * Snapshot tracked-change state: text grouped by logical change id per mark | ||
| * kind, plus the public document-api read model. | ||
| */ | ||
| const snapshotTrackedState = ( | ||
| superdoc: SuperDocFixture, | ||
| ): Promise<{ | ||
| insertById: Record<string, string>; | ||
| deleteById: Record<string, string>; | ||
| docText: string; | ||
| listItems: Array<{ type: string; text: string }>; | ||
| }> => | ||
| superdoc.page.evaluate(async () => { | ||
| const editor = (window as any).editor; | ||
| const insertById: Record<string, string> = {}; | ||
| const deleteById: Record<string, string> = {}; | ||
| editor.state.doc.descendants((node: any) => { | ||
| if (!node.isText || !node.text) return; | ||
| for (const mark of node.marks ?? []) { | ||
| if (mark.type?.name === 'trackInsert') { | ||
| const id = String(mark.attrs?.id ?? ''); | ||
| insertById[id] = (insertById[id] ?? '') + node.text; | ||
| } else if (mark.type?.name === 'trackDelete') { | ||
| const id = String(mark.attrs?.id ?? ''); | ||
| deleteById[id] = (deleteById[id] ?? '') + node.text; | ||
| } | ||
| } | ||
| }); | ||
| const list = await editor.doc.trackChanges.list(); | ||
| return { | ||
| insertById, | ||
| deleteById, | ||
| docText: editor.state.doc.textContent, | ||
| listItems: (list?.items ?? []).map((item: any) => ({ | ||
| type: String(item.type), | ||
| text: String(item.insertedText ?? item.deletedText ?? ''), | ||
| })), | ||
| }; | ||
| }); | ||
|
|
||
| /** Type a pending insertion in suggesting mode, then delete "HELLO" inside it. */ | ||
| async function typeThenDeleteInsideOwnInsertion(superdoc: SuperDocFixture): Promise<void> { | ||
| await superdoc.setDocumentMode('suggesting'); | ||
| await superdoc.waitForStable(); | ||
| await superdoc.type('ABCHELLOXYZ'); | ||
| await superdoc.waitForStable(); | ||
|
|
||
| const pos = await superdoc.findTextPos('HELLO'); | ||
| await superdoc.setTextSelection(pos, pos + 'HELLO'.length); | ||
| await superdoc.waitForStable(); | ||
| await superdoc.press('Backspace'); | ||
| await superdoc.waitForStable(); | ||
| } | ||
|
|
||
| const expectSingleRefinedInsertion = (state: Awaited<ReturnType<typeof snapshotTrackedState>>) => { | ||
| expect(state.docText).toBe('ABCXYZ'); | ||
| // No overlapping deletion was minted over the user's own suggestion. | ||
| expect(Object.keys(state.deleteById)).toHaveLength(0); | ||
| // One logical insertion remains, refined to the surviving text. | ||
| const insertIds = Object.keys(state.insertById); | ||
| expect(insertIds).toHaveLength(1); | ||
| expect(state.insertById[insertIds[0]]).toBe('ABCXYZ'); | ||
| // Public read model agrees: exactly one reviewable insert item. | ||
| expect(state.listItems).toEqual([{ type: 'insert', text: 'ABCXYZ' }]); | ||
| }; | ||
|
|
||
| test('anonymous session: deleting inside own pending insertion refines it in place (SD-3352)', async ({ superdoc }) => { | ||
| await setUser(superdoc, ANONYMOUS_DEFAULT); | ||
| await typeThenDeleteInsideOwnInsertion(superdoc); | ||
| expectSingleRefinedInsertion(await snapshotTrackedState(superdoc)); | ||
| }); | ||
|
|
||
| test('identified user: deleting inside own pending insertion refines it in place', async ({ superdoc }) => { | ||
| await setUser(superdoc, REVIEWER); | ||
| await typeThenDeleteInsideOwnInsertion(superdoc); | ||
| expectSingleRefinedInsertion(await snapshotTrackedState(superdoc)); | ||
| }); | ||
|
|
||
| test('anonymous session: typing over a selection inside own insertion refines it in place (SD-3352)', async ({ | ||
| superdoc, | ||
| }) => { | ||
| // Replace-path variant: selecting inside your own pending insertion and | ||
| // typing must refine the insertion under its original id — not collapse the | ||
| // deleted half while minting the replacement text as a nested child | ||
| // insertion (overlapParentId) under your own suggestion. | ||
| await setUser(superdoc, ANONYMOUS_DEFAULT); | ||
| await superdoc.setDocumentMode('suggesting'); | ||
| await superdoc.waitForStable(); | ||
| await superdoc.type('ABCHELLOXYZ'); | ||
| await superdoc.waitForStable(); | ||
|
|
||
| const pos = await superdoc.findTextPos('HELLO'); | ||
| await superdoc.setTextSelection(pos, pos + 'HELLO'.length); | ||
| await superdoc.waitForStable(); | ||
| await superdoc.type('Q'); | ||
| await superdoc.waitForStable(); | ||
|
|
||
| const state = await snapshotTrackedState(superdoc); | ||
| expect(state.docText).toBe('ABCQXYZ'); | ||
| expect(Object.keys(state.deleteById)).toHaveLength(0); | ||
| const insertIds = Object.keys(state.insertById); | ||
| expect(insertIds).toHaveLength(1); | ||
| expect(state.insertById[insertIds[0]]).toBe('ABCQXYZ'); | ||
| expect(state.listItems).toEqual([{ type: 'insert', text: 'ABCQXYZ' }]); | ||
| }); | ||
|
|
||
| test('anonymous session: backspacing char-by-char through own insertion stays one refined insertion', async ({ | ||
| superdoc, | ||
| }) => { | ||
| await setUser(superdoc, ANONYMOUS_DEFAULT); | ||
| await superdoc.setDocumentMode('suggesting'); | ||
| await superdoc.waitForStable(); | ||
| await superdoc.type('ABCHELLOXYZ'); | ||
| await superdoc.waitForStable(); | ||
|
|
||
| // Caret after the final "O" of HELLO, then one Backspace per character. | ||
| const pos = await superdoc.findTextPos('HELLO'); | ||
| await superdoc.setTextSelection(pos + 'HELLO'.length); | ||
| await superdoc.waitForStable(); | ||
| for (let i = 0; i < 'HELLO'.length; i += 1) { | ||
| await superdoc.press('Backspace'); | ||
| await superdoc.waitForStable(); | ||
| } | ||
|
|
||
| expectSingleRefinedInsertion(await snapshotTrackedState(superdoc)); | ||
| }); |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.