jenkins-bot has submitted this change and it was merged. ( 
https://gerrit.wikimedia.org/r/355563 )

Change subject: dm.Change: Update store length tracking when adding to history
......................................................................


dm.Change: Update store length tracking when adding to history

ve.dm.Document#storeLengthAtHistoryLength is updated by ve.dm.Document#commit,
but was not updated by ve.dm.Change#addToHistory. This caused
ve.dm.Document#getChangeSince to return an empty store after
a local rebase of a change with a non-empty store.

Change-Id: I432b072ea6364289d79db94c6d1c84b1244406ff
---
M src/dm/ve.dm.Change.js
M tests/dm/ve.dm.RebaseServer.test.js
2 files changed, 95 insertions(+), 0 deletions(-)

Approvals:
  Divec: Looks good to me, approved
  jenkins-bot: Verified



diff --git a/src/dm/ve.dm.Change.js b/src/dm/ve.dm.Change.js
index 5b15d7c..98312d1 100644
--- a/src/dm/ve.dm.Change.js
+++ b/src/dm/ve.dm.Change.js
@@ -674,10 +674,12 @@
                throw new Error( 'this starts at ' + this.start +
                        ' but history ends at ' + 
documentModel.completeHistory.length );
        }
+       // FIXME this code should probably be in dm.Document
        this.stores.forEach( function ( store ) {
                documentModel.store.merge( store );
        } );
        ve.batchPush( documentModel.completeHistory, this.transactions );
+       documentModel.storeLengthAtHistoryLength[ 
documentModel.completeHistory.length ] = documentModel.store.getLength();
 };
 
 /**
diff --git a/tests/dm/ve.dm.RebaseServer.test.js 
b/tests/dm/ve.dm.RebaseServer.test.js
index ded5d52..abffd10 100644
--- a/tests/dm/ve.dm.RebaseServer.test.js
+++ b/tests/dm/ve.dm.RebaseServer.test.js
@@ -181,6 +181,97 @@
                                [ '2', 'receive' ],
                                [ '2', 'assertHist', '-(Bd)-(cA)WP' ]
                        ]
+               },
+               {
+                       name: 'Double client-side rebase with annotation',
+                       initialData: [
+                               { type: 'paragraph' },
+                               { type: '/paragraph' },
+                               { type: 'internalList' },
+                               { type: '/internalList' }
+                       ],
+                       clients: [ '1', '2' ],
+                       ops: [
+                               // Client 1 applies a local change that 
introduces an annotation
+                               [ '1', 'apply', {
+                                       start: 0,
+                                       transactions: [
+                                               {
+                                                       operations: [
+                                                               { type: 
'retain', length: 1 },
+                                                               { type: 
'replace', remove: [], insert: [
+                                                                       [ 'X', 
[ 'h123' ] ],
+                                                                       [ 'Y', 
[ 'h123' ] ],
+                                                                       [ 'Z', 
[ 'h123' ] ]
+                                                               ] },
+                                                               { type: 
'retain', length: 3 }
+                                                       ],
+                                                       author: '1'
+                                               }
+                                       ],
+                                       stores: [
+                                               {
+                                                       hashes: [ 'h123' ],
+                                                       hashStore: {
+                                                               h123: {
+                                                                       type: 
'annotation',
+                                                                       value: {
+                                                                               
type: 'textStyle/bold'
+                                                                       }
+                                                               }
+                                                       }
+                                               }
+                                       ],
+                                       selections: {
+                                               1: {
+                                                       type: 'linear',
+                                                       range: {
+                                                               type: 'range',
+                                                               from: 4,
+                                                               to: 4
+                                                       }
+                                               }
+                                       }
+                               } ],
+                               [ '1', 'assert', function ( assert, client ) {
+                                       var unsubmitted = 
client.getChangeSince( client.sentLength, false );
+                                       assert.deepEqual( unsubmitted.stores[ 0 
].hashes, [ 'h123' ], 'h123 is in the store' );
+                               } ],
+
+                               // Client 2 submits two changes
+                               [ '2', 'apply', [
+                                       [ 'insert', 1, [ 'a' ], 3 ]
+                               ] ],
+                               [ '2', 'submit' ],
+                               [ '2', 'apply', [
+                                       [ 'insert', 2, [ 'b' ], 3 ]
+                               ] ],
+                               [ '2', 'submit' ],
+
+                               // Client 1 rebases its local change twice
+                               [ '2', 'deliver' ],
+                               [ 'server', 'assertHist', 'a' ],
+                               [ '1', 'receive' ],
+                               [ '1', 'assertHist', 'a/XYZ!' ],
+                               [ '1', 'assert', function ( assert, client ) {
+                                       var unsubmitted = 
client.getChangeSince( client.sentLength, false );
+                                       assert.deepEqual( unsubmitted.stores[ 0 
].hashes, [ 'h123' ], 'h123 is still in the store after the first rebase' );
+                               } ],
+
+                               [ '2', 'deliver' ],
+                               [ 'server', 'assertHist', 'ab' ],
+                               [ '1', 'receive' ],
+                               [ '1', 'assertHist', 'ab/XYZ!' ],
+                               [ '1', 'assert', function ( assert, client ) {
+                                       var unsubmitted = 
client.getChangeSince( client.sentLength, false );
+                                       assert.deepEqual( unsubmitted.stores[ 0 
].hashes, [ 'h123' ], 'h123 is still in the store after the second rebase' );
+                               } ],
+
+                               // Client 1 submits its local change
+                               [ '1', 'submit' ],
+                               [ '1', 'deliver' ],
+                               [ 'server', 'assertHist', 'abXYZ' ]
+                       ]
                } ],
                i, j, op, server, client, clients, action, txs;
 
@@ -241,6 +332,8 @@
                                client.deliverOne();
                        } else if ( action === 'receive' ) {
                                client.receiveOne();
+                       } else if ( action === 'assert' ) {
+                               op[ 2 ]( assert, client );
                        }
                }
        }

-- 
To view, visit https://gerrit.wikimedia.org/r/355563
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: merged
Gerrit-Change-Id: I432b072ea6364289d79db94c6d1c84b1244406ff
Gerrit-PatchSet: 1
Gerrit-Project: VisualEditor/VisualEditor
Gerrit-Branch: master
Gerrit-Owner: Catrope <[email protected]>
Gerrit-Reviewer: Divec <[email protected]>
Gerrit-Reviewer: Esanders <[email protected]>
Gerrit-Reviewer: jenkins-bot <>

_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to