SyncManagerTests.js 43 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475
  1. import sinon from 'sinon'
  2. import { expect } from 'chai'
  3. import mongodb from 'mongodb-legacy'
  4. import tk from 'timekeeper'
  5. import { Comment, TrackedChange, Range } from 'overleaf-editor-core'
  6. import { strict as esmock } from 'esmock'
  7. const { ObjectId } = mongodb
  8. const MODULE_PATH = '../../../../app/js/SyncManager.js'
  9. const TIMESTAMP = new Date().toISOString()
  10. const USER_ID = 'user-id'
  11. function resyncProjectStructureUpdate(docs, files) {
  12. return {
  13. resyncProjectStructure: { docs, files },
  14. meta: {
  15. ts: TIMESTAMP,
  16. },
  17. }
  18. }
  19. function docContentSyncUpdate(
  20. doc,
  21. content,
  22. ranges = {},
  23. resolvedComments = []
  24. ) {
  25. return {
  26. path: doc.path,
  27. doc: doc.doc,
  28. resyncDocContent: {
  29. content,
  30. ranges,
  31. resolvedComments,
  32. },
  33. meta: {
  34. ts: TIMESTAMP,
  35. },
  36. }
  37. }
  38. function makeComment(commentId, pos, text) {
  39. return {
  40. id: commentId,
  41. op: { p: pos, c: text, t: commentId },
  42. metadata: {
  43. user_id: USER_ID,
  44. ts: TIMESTAMP,
  45. },
  46. }
  47. }
  48. function makeTrackedChange(id, op) {
  49. return {
  50. id,
  51. op,
  52. metadata: { user_id: USER_ID, ts: TIMESTAMP },
  53. }
  54. }
  55. describe('SyncManager', function () {
  56. beforeEach(async function () {
  57. this.now = new Date()
  58. tk.freeze(this.now)
  59. this.projectId = new ObjectId().toString()
  60. this.historyId = 'mock-overleaf-id'
  61. this.syncState = { origin: { kind: 'history-resync' } }
  62. this.db = {
  63. projectHistorySyncState: {
  64. findOne: sinon.stub().resolves(this.syncState),
  65. updateOne: sinon.stub().resolves(),
  66. },
  67. }
  68. this.extendLock = sinon.stub().resolves()
  69. this.LockManager = {
  70. promises: {
  71. runWithLock: sinon.stub().callsFake(async (key, runner) => {
  72. await runner(this.extendLock)
  73. }),
  74. },
  75. }
  76. this.UpdateCompressor = {
  77. diffAsShareJsOps: sinon.stub().returns([]),
  78. }
  79. this.UpdateTranslator = {
  80. isTextUpdate: sinon.stub(),
  81. _convertPathname: sinon.stub(),
  82. }
  83. this.WebApiManager = {
  84. promises: {
  85. getHistoryId: sinon.stub(),
  86. requestResync: sinon.stub().resolves(),
  87. },
  88. }
  89. this.WebApiManager.promises.getHistoryId
  90. .withArgs(this.projectId)
  91. .resolves(this.historyId)
  92. this.ErrorRecorder = {
  93. promises: {
  94. record: sinon.stub().resolves(),
  95. recordSyncStart: sinon.stub().resolves(),
  96. },
  97. }
  98. this.RedisManager = {}
  99. this.SnapshotManager = {
  100. promises: {
  101. getLatestSnapshot: sinon.stub(),
  102. },
  103. }
  104. this.HistoryStoreManager = {
  105. getBlobStore: sinon.stub(),
  106. _getBlobHashFromString: sinon.stub().returns('random-hash'),
  107. }
  108. this.HashManager = {
  109. _getBlobHashFromString: sinon.stub(),
  110. }
  111. this.Metrics = { inc: sinon.stub() }
  112. this.Settings = {
  113. redis: {
  114. lock: {
  115. key_schema: {
  116. projectHistoryLock({ project_id: projectId }) {
  117. return `ProjectHistoryLock:${projectId}`
  118. },
  119. },
  120. },
  121. },
  122. }
  123. this.SyncManager = await esmock(MODULE_PATH, {
  124. '../../../../app/js/LockManager.js': this.LockManager,
  125. '../../../../app/js/UpdateCompressor.js': this.UpdateCompressor,
  126. '../../../../app/js/UpdateTranslator.js': this.UpdateTranslator,
  127. '../../../../app/js/mongodb.js': { ObjectId, db: this.db },
  128. '../../../../app/js/WebApiManager.js': this.WebApiManager,
  129. '../../../../app/js/ErrorRecorder.js': this.ErrorRecorder,
  130. '../../../../app/js/RedisManager.js': this.RedisManager,
  131. '../../../../app/js/SnapshotManager.js': this.SnapshotManager,
  132. '../../../../app/js/HistoryStoreManager.js': this.HistoryStoreManager,
  133. '../../../../app/js/HashManager.js': this.HashManager,
  134. '@overleaf/metrics': this.Metrics,
  135. '@overleaf/settings': this.Settings,
  136. })
  137. })
  138. afterEach(function () {
  139. tk.reset()
  140. })
  141. describe('startResync', function () {
  142. describe('if a sync is not in progress', function () {
  143. beforeEach(async function () {
  144. this.db.projectHistorySyncState.findOne.resolves({})
  145. await this.SyncManager.promises.startResync(this.projectId)
  146. })
  147. it('takes the project lock', function () {
  148. expect(this.LockManager.promises.runWithLock).to.have.been.calledWith(
  149. `ProjectHistoryLock:${this.projectId}`
  150. )
  151. })
  152. it('gets the sync state from mongo', function () {
  153. expect(this.db.projectHistorySyncState.findOne).to.have.been.calledWith(
  154. { project_id: new ObjectId(this.projectId) }
  155. )
  156. })
  157. it('requests a resync from web', function () {
  158. expect(
  159. this.WebApiManager.promises.requestResync
  160. ).to.have.been.calledWith(this.projectId)
  161. })
  162. it('sets the sync state in mongo and prevents it expiring', function () {
  163. expect(
  164. this.db.projectHistorySyncState.updateOne
  165. ).to.have.been.calledWith(
  166. {
  167. project_id: new ObjectId(this.projectId),
  168. },
  169. sinon.match({
  170. $set: {
  171. resyncProjectStructure: true,
  172. resyncDocContents: [],
  173. origin: { kind: 'history-resync' },
  174. },
  175. $currentDate: { lastUpdated: true },
  176. $inc: { resyncCount: 1 },
  177. $unset: { expiresAt: true },
  178. }),
  179. {
  180. upsert: true,
  181. }
  182. )
  183. })
  184. })
  185. describe('if project structure sync is in progress', function () {
  186. beforeEach(function () {
  187. const syncState = { resyncProjectStructure: true }
  188. this.db.projectHistorySyncState.findOne.resolves(syncState)
  189. })
  190. it('returns an error if already syncing', async function () {
  191. await expect(
  192. this.SyncManager.promises.startResync(this.projectId)
  193. ).to.be.rejectedWith('sync ongoing')
  194. })
  195. })
  196. describe('if doc content sync in is progress', function () {
  197. beforeEach(async function () {
  198. const syncState = { resyncDocContents: ['/foo.tex'] }
  199. this.db.projectHistorySyncState.findOne.resolves(syncState)
  200. })
  201. it('returns an error if already syncing', async function () {
  202. await expect(
  203. this.SyncManager.promises.startResync(this.projectId)
  204. ).to.be.rejectedWith('sync ongoing')
  205. })
  206. })
  207. })
  208. describe('setResyncState', function () {
  209. describe('when the sync is starting', function () {
  210. beforeEach(function () {
  211. this.syncState = {
  212. toRaw() {
  213. return {
  214. resyncProjectStructure: true,
  215. resyncDocContents: [],
  216. origin: { kind: 'history-resync' },
  217. }
  218. },
  219. isSyncOngoing: sinon.stub().returns(true),
  220. }
  221. })
  222. it('sets the sync state in mongo and prevents it expiring', async function () {
  223. // SyncState is a private class of SyncManager
  224. // we know the interface however:
  225. await this.SyncManager.promises.setResyncState(
  226. this.projectId,
  227. this.syncState
  228. )
  229. expect(
  230. this.db.projectHistorySyncState.updateOne
  231. ).to.have.been.calledWith(
  232. { project_id: new ObjectId(this.projectId) },
  233. sinon.match({
  234. $set: this.syncState.toRaw(),
  235. $currentDate: { lastUpdated: true },
  236. $inc: { resyncCount: 1 },
  237. $unset: { expiresAt: true },
  238. }),
  239. { upsert: true }
  240. )
  241. })
  242. })
  243. describe('when the sync is ending', function () {
  244. beforeEach(function () {
  245. this.syncState = {
  246. toRaw() {
  247. return {
  248. resyncProjectStructure: false,
  249. resyncDocContents: [],
  250. origin: { kind: 'history-resync' },
  251. }
  252. },
  253. isSyncOngoing: sinon.stub().returns(false),
  254. }
  255. })
  256. it('sets the sync state entry in mongo to expire', async function () {
  257. await this.SyncManager.promises.setResyncState(
  258. this.projectId,
  259. this.syncState
  260. )
  261. expect(
  262. this.db.projectHistorySyncState.updateOne
  263. ).to.have.been.calledWith(
  264. { project_id: new ObjectId(this.projectId) },
  265. sinon.match({
  266. $set: {
  267. resyncProjectStructure: false,
  268. resyncDocContents: [],
  269. origin: { kind: 'history-resync' },
  270. expiresAt: new Date(this.now.getTime() + 90 * 24 * 3600 * 1000),
  271. },
  272. $currentDate: { lastUpdated: true },
  273. }),
  274. { upsert: true }
  275. )
  276. })
  277. })
  278. describe('when the new sync state is null', function () {
  279. it('does not update the sync state in mongo', async function () {
  280. // SyncState is a private class of SyncManager
  281. // we know the interface however:
  282. await this.SyncManager.promises.setResyncState(this.projectId, null)
  283. expect(this.db.projectHistorySyncState.updateOne).to.not.have.been
  284. .called
  285. })
  286. })
  287. })
  288. describe('skipUpdatesDuringSync', function () {
  289. describe('if a sync is not in progress', function () {
  290. beforeEach(async function () {
  291. this.db.projectHistorySyncState.findOne.resolves({})
  292. this.updates = ['some', 'mock', 'updates']
  293. this.result = await this.SyncManager.promises.skipUpdatesDuringSync(
  294. this.projectId,
  295. this.updates
  296. )
  297. })
  298. it('returns all updates', function () {
  299. expect(this.result.updates).to.deep.equal(this.updates)
  300. })
  301. it('should not return any newSyncState', function () {
  302. expect(this.result.syncState).to.be.null
  303. })
  304. })
  305. describe('if a sync in is progress', function () {
  306. beforeEach(function () {
  307. this.renameUpdate = {
  308. pathname: 'old.tex',
  309. newPathname: 'new.tex',
  310. }
  311. this.projectStructureSyncUpdate = {
  312. resyncProjectStructure: {
  313. docs: [{ path: 'new.tex' }],
  314. files: [],
  315. },
  316. }
  317. this.textUpdate = {
  318. doc: new ObjectId(),
  319. op: [{ i: 'a', p: 4 }],
  320. meta: {
  321. pathname: 'new.tex',
  322. doc_length: 4,
  323. },
  324. }
  325. this.docContentSyncUpdate = {
  326. path: 'new.tex',
  327. resyncDocContent: {
  328. content: 'a',
  329. },
  330. }
  331. this.UpdateTranslator.isTextUpdate
  332. .withArgs(this.renameUpdate)
  333. .returns(false)
  334. this.UpdateTranslator.isTextUpdate
  335. .withArgs(this.projectStructureSyncUpdate)
  336. .returns(false)
  337. this.UpdateTranslator.isTextUpdate
  338. .withArgs(this.docContentSyncUpdate)
  339. .returns(false)
  340. this.UpdateTranslator.isTextUpdate
  341. .withArgs(this.textUpdate)
  342. .returns(true)
  343. const syncState = {
  344. resyncProjectStructure: true,
  345. resyncDocContents: [],
  346. origin: { kind: 'history-resync' },
  347. }
  348. this.db.projectHistorySyncState.findOne.resolves(syncState)
  349. })
  350. it('remove updates before a project structure sync update', async function () {
  351. const updates = [
  352. this.renameUpdate,
  353. this.textUpdate,
  354. this.projectStructureSyncUpdate,
  355. ]
  356. const { updates: filteredUpdates, syncState } =
  357. await this.SyncManager.promises.skipUpdatesDuringSync(
  358. this.projectId,
  359. updates
  360. )
  361. expect(filteredUpdates).to.deep.equal([this.projectStructureSyncUpdate])
  362. expect(syncState.toRaw()).to.deep.equal({
  363. resyncProjectStructure: false,
  364. resyncDocContents: ['new.tex'],
  365. origin: { kind: 'history-resync' },
  366. })
  367. })
  368. it('allow project structure updates after project structure sync update', async function () {
  369. const updates = [this.projectStructureSyncUpdate, this.renameUpdate]
  370. const { updates: filteredUpdates, syncState } =
  371. await this.SyncManager.promises.skipUpdatesDuringSync(
  372. this.projectId,
  373. updates
  374. )
  375. expect(filteredUpdates).to.deep.equal([
  376. this.projectStructureSyncUpdate,
  377. this.renameUpdate,
  378. ])
  379. expect(syncState.toRaw()).to.deep.equal({
  380. resyncProjectStructure: false,
  381. resyncDocContents: ['new.tex'],
  382. origin: { kind: 'history-resync' },
  383. })
  384. })
  385. it('remove text updates for a doc before doc sync update', async function () {
  386. const updates = [
  387. this.projectStructureSyncUpdate,
  388. this.textUpdate,
  389. this.docContentSyncUpdate,
  390. ]
  391. const { updates: filteredUpdates, syncState } =
  392. await this.SyncManager.promises.skipUpdatesDuringSync(
  393. this.projectId,
  394. updates
  395. )
  396. expect(filteredUpdates).to.deep.equal([
  397. this.projectStructureSyncUpdate,
  398. this.docContentSyncUpdate,
  399. ])
  400. expect(syncState.toRaw()).to.deep.equal({
  401. resyncProjectStructure: false,
  402. resyncDocContents: [],
  403. origin: { kind: 'history-resync' },
  404. })
  405. })
  406. it('allow text updates for a doc after doc sync update', async function () {
  407. const updates = [
  408. this.projectStructureSyncUpdate,
  409. this.docContentSyncUpdate,
  410. this.textUpdate,
  411. ]
  412. const { updates: filteredUpdates, syncState } =
  413. await this.SyncManager.promises.skipUpdatesDuringSync(
  414. this.projectId,
  415. updates
  416. )
  417. expect(filteredUpdates).to.deep.equal([
  418. this.projectStructureSyncUpdate,
  419. this.docContentSyncUpdate,
  420. this.textUpdate,
  421. ])
  422. expect(syncState.toRaw()).to.deep.equal({
  423. resyncProjectStructure: false,
  424. resyncDocContents: [],
  425. origin: { kind: 'history-resync' },
  426. })
  427. })
  428. })
  429. })
  430. describe('expandSyncUpdates', function () {
  431. beforeEach(function () {
  432. this.persistedDoc = {
  433. doc: 'doc-id',
  434. path: 'main.tex',
  435. }
  436. this.persistedDocContent = 'the quick brown fox jumps over the lazy dog'
  437. this.persistedFile = {
  438. file: 'file-id',
  439. path: '1.png',
  440. _hash: 'abcde',
  441. }
  442. this.loadedSnapshotDoc = {
  443. isEditable: sinon.stub().returns(true),
  444. getContent: sinon.stub().returns(this.persistedDocContent),
  445. getComments: sinon
  446. .stub()
  447. .returns({ toArray: sinon.stub().returns([]) }),
  448. getTrackedChanges: sinon
  449. .stub()
  450. .returns({ asSorted: sinon.stub().returns([]) }),
  451. getHash: sinon.stub().returns(null),
  452. }
  453. this.fileMap = {
  454. 'main.tex': {
  455. isEditable: sinon.stub().returns(true),
  456. getContent: sinon.stub().returns(null),
  457. getHash: sinon.stub().returns(null),
  458. load: sinon.stub().resolves(this.loadedSnapshotDoc),
  459. },
  460. '1.png': {
  461. isEditable: sinon.stub().returns(false),
  462. data: { hash: this.persistedFile._hash },
  463. },
  464. }
  465. this.UpdateTranslator._convertPathname
  466. .withArgs('main.tex')
  467. .returns('main.tex')
  468. this.UpdateTranslator._convertPathname
  469. .withArgs('/main.tex')
  470. .returns('main.tex')
  471. this.UpdateTranslator._convertPathname
  472. .withArgs('another.tex')
  473. .returns('another.tex')
  474. this.UpdateTranslator._convertPathname.withArgs('1.png').returns('1.png')
  475. this.UpdateTranslator._convertPathname.withArgs('2.png').returns('2.png')
  476. this.SnapshotManager.promises.getLatestSnapshot.resolves(this.fileMap)
  477. })
  478. it('returns updates if no sync updates are queued', async function () {
  479. const updates = ['some', 'mock', 'updates']
  480. const expandedUpdates = await this.SyncManager.promises.expandSyncUpdates(
  481. this.projectId,
  482. this.historyId,
  483. updates,
  484. this.extendLock
  485. )
  486. expect(expandedUpdates).to.equal(updates)
  487. expect(this.SnapshotManager.promises.getLatestSnapshot).to.not.have.been
  488. .called
  489. expect(this.extendLock).to.not.have.been.called
  490. })
  491. describe('expanding project structure sync updates', function () {
  492. it('queues nothing for expected docs and files', async function () {
  493. const updates = [
  494. resyncProjectStructureUpdate(
  495. [this.persistedDoc],
  496. [this.persistedFile]
  497. ),
  498. ]
  499. const expandedUpdates =
  500. await this.SyncManager.promises.expandSyncUpdates(
  501. this.projectId,
  502. this.historyId,
  503. updates,
  504. this.extendLock
  505. )
  506. expect(expandedUpdates).to.deep.equal([])
  507. expect(this.extendLock).to.have.been.called
  508. })
  509. it('queues file removes for unexpected files', async function () {
  510. const updates = [resyncProjectStructureUpdate([this.persistedDoc], [])]
  511. const expandedUpdates =
  512. await this.SyncManager.promises.expandSyncUpdates(
  513. this.projectId,
  514. this.historyId,
  515. updates,
  516. this.extendLock
  517. )
  518. expect(expandedUpdates).to.deep.equal([
  519. {
  520. pathname: this.persistedFile.path,
  521. new_pathname: '',
  522. meta: {
  523. resync: true,
  524. ts: TIMESTAMP,
  525. origin: { kind: 'history-resync' },
  526. },
  527. },
  528. ])
  529. expect(this.extendLock).to.have.been.called
  530. })
  531. it('queues doc removes for unexpected docs', async function () {
  532. const updates = [resyncProjectStructureUpdate([], [this.persistedFile])]
  533. const expandedUpdates =
  534. await this.SyncManager.promises.expandSyncUpdates(
  535. this.projectId,
  536. this.historyId,
  537. updates,
  538. this.extendLock
  539. )
  540. expect(expandedUpdates).to.deep.equal([
  541. {
  542. pathname: this.persistedDoc.path,
  543. new_pathname: '',
  544. meta: {
  545. resync: true,
  546. ts: TIMESTAMP,
  547. origin: { kind: 'history-resync' },
  548. },
  549. },
  550. ])
  551. expect(this.extendLock).to.have.been.called
  552. })
  553. it('queues file additions for missing files', async function () {
  554. const newFile = {
  555. path: '2.png',
  556. file: {},
  557. url: 'filestore/2.png',
  558. }
  559. const updates = [
  560. resyncProjectStructureUpdate(
  561. [this.persistedDoc],
  562. [this.persistedFile, newFile]
  563. ),
  564. ]
  565. const expandedUpdates =
  566. await this.SyncManager.promises.expandSyncUpdates(
  567. this.projectId,
  568. this.historyId,
  569. updates,
  570. this.extendLock
  571. )
  572. expect(expandedUpdates).to.deep.equal([
  573. {
  574. pathname: newFile.path,
  575. file: newFile.file,
  576. url: newFile.url,
  577. meta: {
  578. resync: true,
  579. ts: TIMESTAMP,
  580. origin: { kind: 'history-resync' },
  581. },
  582. },
  583. ])
  584. expect(this.extendLock).to.have.been.called
  585. })
  586. it('queues blank doc additions for missing docs', async function () {
  587. const newDoc = {
  588. path: 'another.tex',
  589. doc: new ObjectId().toString(),
  590. }
  591. const updates = [
  592. resyncProjectStructureUpdate(
  593. [this.persistedDoc, newDoc],
  594. [this.persistedFile]
  595. ),
  596. ]
  597. const expandedUpdates =
  598. await this.SyncManager.promises.expandSyncUpdates(
  599. this.projectId,
  600. this.historyId,
  601. updates,
  602. this.extendLock
  603. )
  604. expect(expandedUpdates).to.deep.equal([
  605. {
  606. pathname: newDoc.path,
  607. doc: newDoc.doc,
  608. docLines: '',
  609. meta: {
  610. resync: true,
  611. ts: TIMESTAMP,
  612. origin: { kind: 'history-resync' },
  613. },
  614. },
  615. ])
  616. expect(this.extendLock).to.have.been.called
  617. })
  618. it('removes and re-adds files if whether they are binary differs', async function () {
  619. const fileWichWasADoc = {
  620. path: this.persistedDoc.path,
  621. url: 'filestore/2.png',
  622. _hash: 'other-hash',
  623. }
  624. const updates = [
  625. resyncProjectStructureUpdate(
  626. [],
  627. [fileWichWasADoc, this.persistedFile]
  628. ),
  629. ]
  630. const expandedUpdates =
  631. await this.SyncManager.promises.expandSyncUpdates(
  632. this.projectId,
  633. this.historyId,
  634. updates,
  635. this.extendLock
  636. )
  637. expect(expandedUpdates).to.deep.equal([
  638. {
  639. pathname: fileWichWasADoc.path,
  640. new_pathname: '',
  641. meta: {
  642. resync: true,
  643. ts: TIMESTAMP,
  644. origin: { kind: 'history-resync' },
  645. },
  646. },
  647. {
  648. pathname: fileWichWasADoc.path,
  649. file: fileWichWasADoc.file,
  650. url: fileWichWasADoc.url,
  651. meta: {
  652. resync: true,
  653. ts: TIMESTAMP,
  654. origin: { kind: 'history-resync' },
  655. },
  656. },
  657. ])
  658. expect(this.extendLock).to.have.been.called
  659. })
  660. it("does not remove and re-add files if the expected file doesn't have a hash", async function () {
  661. const fileWichWasADoc = {
  662. path: this.persistedDoc.path,
  663. url: 'filestore/2.png',
  664. }
  665. const updates = [
  666. resyncProjectStructureUpdate(
  667. [],
  668. [fileWichWasADoc, this.persistedFile]
  669. ),
  670. ]
  671. const expandedUpdates =
  672. await this.SyncManager.promises.expandSyncUpdates(
  673. this.projectId,
  674. this.historyId,
  675. updates,
  676. this.extendLock
  677. )
  678. expect(expandedUpdates).to.deep.equal([])
  679. expect(this.extendLock).to.have.been.called
  680. })
  681. it('does not remove and re-add editable files if there is a binary file with same hash', async function () {
  682. const binaryFile = {
  683. file: Object().toString(),
  684. // The paths in the resyncProjectStructureUpdate must have a leading slash ('/')
  685. // The other unit tests in this file are incorrectly missing the leading slash.
  686. // The leading slash is present in web where the paths are created with
  687. // ProjectEntityHandler.getAllEntitiesFromProject in ProjectEntityUpdateHandler.resyncProjectHistory.
  688. path: '/' + this.persistedDoc.path,
  689. url: 'filestore/12345',
  690. _hash: 'abcdef',
  691. }
  692. this.fileMap['main.tex'].data = { hash: 'abcdef' }
  693. const updates = [
  694. resyncProjectStructureUpdate([], [binaryFile, this.persistedFile]),
  695. ]
  696. const expandedUpdates =
  697. await this.SyncManager.promises.expandSyncUpdates(
  698. this.projectId,
  699. this.historyId,
  700. updates,
  701. this.extendLock
  702. )
  703. expect(expandedUpdates).to.deep.equal([])
  704. expect(this.extendLock).to.have.been.called
  705. })
  706. it('removes and re-adds binary files if they do not have same hash', async function () {
  707. const persistedFileWithNewContent = {
  708. _hash: 'anotherhashvalue',
  709. hello: 'world',
  710. path: '1.png',
  711. url: 'filestore-new-url',
  712. }
  713. const updates = [
  714. resyncProjectStructureUpdate(
  715. [this.persistedDoc],
  716. [persistedFileWithNewContent]
  717. ),
  718. ]
  719. const expandedUpdates =
  720. await this.SyncManager.promises.expandSyncUpdates(
  721. this.projectId,
  722. this.historyId,
  723. updates,
  724. this.extendLock
  725. )
  726. expect(expandedUpdates).to.deep.equal([
  727. {
  728. pathname: persistedFileWithNewContent.path,
  729. new_pathname: '',
  730. meta: {
  731. resync: true,
  732. ts: TIMESTAMP,
  733. origin: { kind: 'history-resync' },
  734. },
  735. },
  736. {
  737. pathname: persistedFileWithNewContent.path,
  738. file: persistedFileWithNewContent.file,
  739. url: persistedFileWithNewContent.url,
  740. meta: {
  741. resync: true,
  742. ts: TIMESTAMP,
  743. origin: { kind: 'history-resync' },
  744. },
  745. },
  746. ])
  747. expect(this.extendLock).to.have.been.called
  748. })
  749. it('preserves other updates', async function () {
  750. const update = { mock: 'update' }
  751. const updates = [
  752. update,
  753. resyncProjectStructureUpdate(
  754. [this.persistedDoc],
  755. [this.persistedFile]
  756. ),
  757. ]
  758. const expandedUpdates =
  759. await this.SyncManager.promises.expandSyncUpdates(
  760. this.projectId,
  761. this.historyId,
  762. updates,
  763. this.extendLock
  764. )
  765. expect(expandedUpdates).to.deep.equal([update])
  766. expect(this.extendLock).to.have.been.called
  767. })
  768. })
  769. describe('expanding doc contents sync updates', function () {
  770. it('returns errors from diffAsShareJsOps', async function () {
  771. const diffError = new Error('test')
  772. this.UpdateCompressor.diffAsShareJsOps.throws(diffError)
  773. const updates = [
  774. resyncProjectStructureUpdate(
  775. [this.persistedDoc],
  776. [this.persistedFile]
  777. ),
  778. docContentSyncUpdate(this.persistedDoc, this.persistedDocContent),
  779. ]
  780. await expect(
  781. this.SyncManager.promises.expandSyncUpdates(
  782. this.projectId,
  783. this.historyId,
  784. updates,
  785. this.extendLock
  786. )
  787. ).to.be.rejectedWith(diffError)
  788. expect(this.extendLock).to.have.been.called
  789. })
  790. it('handles an update for a file that is missing from the snapshot', async function () {
  791. const updates = [docContentSyncUpdate('not-in-snapshot.txt', 'test')]
  792. await expect(
  793. this.SyncManager.promises.expandSyncUpdates(
  794. this.projectId,
  795. this.historyId,
  796. updates,
  797. this.extendLock
  798. )
  799. ).to.be.rejectedWith('unrecognised file: not in snapshot')
  800. })
  801. it('queues nothing for in docs whose contents is in sync', async function () {
  802. const updates = [
  803. resyncProjectStructureUpdate(
  804. [this.persistedDoc],
  805. [this.persistedFile]
  806. ),
  807. docContentSyncUpdate(this.persistedDoc, this.persistedDocContent),
  808. ]
  809. this.UpdateCompressor.diffAsShareJsOps.returns([])
  810. const expandedUpdates =
  811. await this.SyncManager.promises.expandSyncUpdates(
  812. this.projectId,
  813. this.historyId,
  814. updates,
  815. this.extendLock
  816. )
  817. expect(expandedUpdates).to.deep.equal([])
  818. expect(this.extendLock).to.have.been.called
  819. })
  820. it('queues text updates for docs whose contents is out of sync', async function () {
  821. const updates = [
  822. resyncProjectStructureUpdate(
  823. [this.persistedDoc],
  824. [this.persistedFile]
  825. ),
  826. docContentSyncUpdate(
  827. this.persistedDoc,
  828. 'the fox jumps over the lazy dog'
  829. ),
  830. ]
  831. this.UpdateCompressor.diffAsShareJsOps.returns([
  832. { d: 'quick brown ', p: 4 },
  833. ])
  834. const expandedUpdates =
  835. await this.SyncManager.promises.expandSyncUpdates(
  836. this.projectId,
  837. this.historyId,
  838. updates,
  839. this.extendLock
  840. )
  841. expect(expandedUpdates).to.deep.equal([
  842. {
  843. doc: this.persistedDoc.doc,
  844. op: [{ d: 'quick brown ', p: 4 }],
  845. meta: {
  846. pathname: this.persistedDoc.path,
  847. doc_length: this.persistedDocContent.length,
  848. resync: true,
  849. ts: TIMESTAMP,
  850. origin: { kind: 'history-resync' },
  851. },
  852. },
  853. ])
  854. expect(this.extendLock).to.have.been.called
  855. })
  856. it('queues text updates for docs created by project structure sync', async function () {
  857. this.UpdateCompressor.diffAsShareJsOps.returns([{ i: 'a', p: 0 }])
  858. const newDoc = {
  859. path: 'another.tex',
  860. doc: new ObjectId().toString(),
  861. }
  862. const newDocContent = 'a'
  863. const updates = [
  864. resyncProjectStructureUpdate(
  865. [this.persistedDoc, newDoc],
  866. [this.persistedFile]
  867. ),
  868. docContentSyncUpdate(newDoc, newDocContent),
  869. ]
  870. const expandedUpdates =
  871. await this.SyncManager.promises.expandSyncUpdates(
  872. this.projectId,
  873. this.historyId,
  874. updates,
  875. this.extendLock
  876. )
  877. expect(expandedUpdates).to.deep.equal([
  878. {
  879. pathname: newDoc.path,
  880. doc: newDoc.doc,
  881. docLines: '',
  882. meta: {
  883. resync: true,
  884. ts: TIMESTAMP,
  885. origin: { kind: 'history-resync' },
  886. },
  887. },
  888. {
  889. doc: newDoc.doc,
  890. op: [{ i: 'a', p: 0 }],
  891. meta: {
  892. pathname: newDoc.path,
  893. doc_length: 0,
  894. resync: true,
  895. ts: TIMESTAMP,
  896. origin: { kind: 'history-resync' },
  897. },
  898. },
  899. ])
  900. expect(this.extendLock).to.have.been.called
  901. })
  902. it('skips text updates for docs when hashes match', async function () {
  903. this.fileMap['main.tex'].getHash.returns('special-hash')
  904. this.HashManager._getBlobHashFromString.returns('special-hash')
  905. const updates = [
  906. resyncProjectStructureUpdate(
  907. [this.persistedDoc],
  908. [this.persistedFile]
  909. ),
  910. docContentSyncUpdate(this.persistedDoc, 'hello'),
  911. ]
  912. const expandedUpdates =
  913. await this.SyncManager.promises.expandSyncUpdates(
  914. this.projectId,
  915. this.historyId,
  916. updates,
  917. this.extendLock
  918. )
  919. expect(expandedUpdates).to.deep.equal([])
  920. expect(this.extendLock).to.have.been.called
  921. })
  922. it('computes text updates for docs when hashes differ', async function () {
  923. this.fileMap['main.tex'].getHash.returns('first-hash')
  924. this.HashManager._getBlobHashFromString.returns('second-hash')
  925. this.UpdateCompressor.diffAsShareJsOps.returns([
  926. { i: 'test diff', p: 0 },
  927. ])
  928. const updates = [
  929. resyncProjectStructureUpdate(
  930. [this.persistedDoc],
  931. [this.persistedFile]
  932. ),
  933. docContentSyncUpdate(this.persistedDoc, 'hello'),
  934. ]
  935. const expandedUpdates =
  936. await this.SyncManager.promises.expandSyncUpdates(
  937. this.projectId,
  938. this.historyId,
  939. updates,
  940. this.extendLock
  941. )
  942. expect(expandedUpdates).to.deep.equal([
  943. {
  944. doc: this.persistedDoc.doc,
  945. op: [{ i: 'test diff', p: 0 }],
  946. meta: {
  947. pathname: this.persistedDoc.path,
  948. doc_length: this.persistedDocContent.length,
  949. resync: true,
  950. ts: TIMESTAMP,
  951. origin: { kind: 'history-resync' },
  952. },
  953. },
  954. ])
  955. expect(this.extendLock).to.have.been.called
  956. })
  957. describe('for docs whose contents is out of sync', function () {
  958. beforeEach(async function () {
  959. const updates = [
  960. resyncProjectStructureUpdate(
  961. [this.persistedDoc],
  962. [this.persistedFile]
  963. ),
  964. docContentSyncUpdate(this.persistedDoc, 'a'),
  965. ]
  966. this.loadedSnapshotDoc.getContent.returns('stored content')
  967. this.UpdateCompressor.diffAsShareJsOps.returns([{ d: 'sdf', p: 1 }])
  968. this.expandedUpdates =
  969. await this.SyncManager.promises.expandSyncUpdates(
  970. this.projectId,
  971. this.historyId,
  972. updates,
  973. this.extendLock
  974. )
  975. })
  976. it('loads content from the history service when needed', function () {
  977. expect(this.expandedUpdates).to.deep.equal([
  978. {
  979. doc: this.persistedDoc.doc,
  980. op: [{ d: 'sdf', p: 1 }],
  981. meta: {
  982. pathname: this.persistedDoc.path,
  983. doc_length: 'stored content'.length,
  984. resync: true,
  985. ts: TIMESTAMP,
  986. origin: { kind: 'history-resync' },
  987. },
  988. },
  989. ])
  990. expect(this.extendLock).to.have.been.called
  991. })
  992. })
  993. })
  994. describe('syncing comments', function () {
  995. beforeEach(function () {
  996. this.loadedSnapshotDoc.getComments.returns({
  997. toArray: sinon
  998. .stub()
  999. .returns([
  1000. new Comment('comment1', [new Range(4, 5)]),
  1001. new Comment('comment2', [new Range(10, 5)], true),
  1002. ]),
  1003. })
  1004. this.comments = [
  1005. makeComment('comment1', 4, 'quick'),
  1006. makeComment('comment2', 10, 'brown'),
  1007. ]
  1008. this.resolvedComments = ['comment2']
  1009. })
  1010. it('does nothing if comments have not changed', async function () {
  1011. const updates = [
  1012. docContentSyncUpdate(
  1013. this.persistedDoc,
  1014. this.persistedDocContent,
  1015. {
  1016. comments: this.comments,
  1017. },
  1018. this.resolvedComments
  1019. ),
  1020. ]
  1021. const expandedUpdates =
  1022. await this.SyncManager.promises.expandSyncUpdates(
  1023. this.projectId,
  1024. this.historyId,
  1025. updates,
  1026. this.extendLock
  1027. )
  1028. expect(expandedUpdates).to.deep.equal([])
  1029. })
  1030. it('adds missing comments', async function () {
  1031. this.comments.push(makeComment('comment3', 20, 'jumps'))
  1032. const updates = [
  1033. docContentSyncUpdate(
  1034. this.persistedDoc,
  1035. this.persistedDocContent,
  1036. {
  1037. comments: this.comments,
  1038. },
  1039. this.resolvedComments
  1040. ),
  1041. ]
  1042. const expandedUpdates =
  1043. await this.SyncManager.promises.expandSyncUpdates(
  1044. this.projectId,
  1045. this.historyId,
  1046. updates,
  1047. this.extendLock
  1048. )
  1049. expect(expandedUpdates).to.deep.equal([
  1050. {
  1051. doc: this.persistedDoc.doc,
  1052. op: [
  1053. {
  1054. c: 'jumps',
  1055. p: 20,
  1056. t: 'comment3',
  1057. },
  1058. ],
  1059. meta: {
  1060. origin: {
  1061. kind: 'history-resync',
  1062. },
  1063. pathname: this.persistedDoc.path,
  1064. resync: true,
  1065. ts: TIMESTAMP,
  1066. doc_length: this.persistedDocContent.length,
  1067. },
  1068. },
  1069. ])
  1070. })
  1071. it('deletes extra comments', async function () {
  1072. this.comments.splice(0, 1)
  1073. const updates = [
  1074. docContentSyncUpdate(
  1075. this.persistedDoc,
  1076. this.persistedDocContent,
  1077. {
  1078. comments: this.comments,
  1079. },
  1080. this.resolvedComments
  1081. ),
  1082. ]
  1083. const expandedUpdates =
  1084. await this.SyncManager.promises.expandSyncUpdates(
  1085. this.projectId,
  1086. this.historyId,
  1087. updates,
  1088. this.extendLock
  1089. )
  1090. expect(expandedUpdates).to.deep.equal([
  1091. {
  1092. pathname: this.persistedDoc.path,
  1093. deleteComment: 'comment1',
  1094. meta: {
  1095. origin: {
  1096. kind: 'history-resync',
  1097. },
  1098. resync: true,
  1099. ts: TIMESTAMP,
  1100. },
  1101. },
  1102. ])
  1103. })
  1104. it('updates comments when ranges differ', async function () {
  1105. this.comments[1] = makeComment('comment2', 16, 'fox')
  1106. const updates = [
  1107. docContentSyncUpdate(
  1108. this.persistedDoc,
  1109. this.persistedDocContent,
  1110. {
  1111. comments: this.comments,
  1112. },
  1113. this.resolvedComments
  1114. ),
  1115. ]
  1116. const expandedUpdates =
  1117. await this.SyncManager.promises.expandSyncUpdates(
  1118. this.projectId,
  1119. this.historyId,
  1120. updates,
  1121. this.extendLock
  1122. )
  1123. expect(expandedUpdates).to.deep.equal([
  1124. {
  1125. doc: 'doc-id',
  1126. op: [
  1127. {
  1128. c: 'fox',
  1129. p: 16,
  1130. t: 'comment2',
  1131. },
  1132. ],
  1133. meta: {
  1134. origin: {
  1135. kind: 'history-resync',
  1136. },
  1137. resync: true,
  1138. ts: TIMESTAMP,
  1139. pathname: this.persistedDoc.path,
  1140. doc_length: this.persistedDocContent.length,
  1141. },
  1142. },
  1143. ])
  1144. })
  1145. it('sets the resolved state when it differs', async function () {
  1146. this.resolvedComments = ['comment1']
  1147. const updates = [
  1148. docContentSyncUpdate(
  1149. this.persistedDoc,
  1150. this.persistedDocContent,
  1151. {
  1152. comments: this.comments,
  1153. },
  1154. this.resolvedComments
  1155. ),
  1156. ]
  1157. const expandedUpdates =
  1158. await this.SyncManager.promises.expandSyncUpdates(
  1159. this.projectId,
  1160. this.historyId,
  1161. updates,
  1162. this.extendLock
  1163. )
  1164. expect(expandedUpdates).to.have.deep.members([
  1165. {
  1166. pathname: this.persistedDoc.path,
  1167. commentId: 'comment1',
  1168. resolved: true,
  1169. },
  1170. {
  1171. pathname: this.persistedDoc.path,
  1172. commentId: 'comment2',
  1173. resolved: false,
  1174. },
  1175. ])
  1176. })
  1177. })
  1178. describe('syncing tracked changes', function () {
  1179. beforeEach(function () {
  1180. this.loadedSnapshotDoc.getTrackedChanges.returns({
  1181. asSorted: sinon.stub().returns([
  1182. new TrackedChange(new Range(4, 6), {
  1183. type: 'delete',
  1184. userId: USER_ID,
  1185. ts: new Date(TIMESTAMP),
  1186. }),
  1187. new TrackedChange(new Range(10, 6), {
  1188. type: 'insert',
  1189. userId: USER_ID,
  1190. ts: new Date(TIMESTAMP),
  1191. }),
  1192. new TrackedChange(new Range(20, 6), {
  1193. type: 'delete',
  1194. userId: USER_ID,
  1195. ts: new Date(TIMESTAMP),
  1196. }),
  1197. new TrackedChange(new Range(40, 3), {
  1198. type: 'insert',
  1199. userId: USER_ID,
  1200. ts: new Date(TIMESTAMP),
  1201. }),
  1202. ]),
  1203. })
  1204. this.changes = [
  1205. makeTrackedChange('td1', { p: 4, d: 'quick ' }),
  1206. makeTrackedChange('ti1', { p: 4, hpos: 10, i: 'brown ' }),
  1207. makeTrackedChange('td2', { p: 14, hpos: 20, d: 'jumps ' }),
  1208. makeTrackedChange('ti2', { p: 28, hpos: 40, i: 'dog' }),
  1209. ]
  1210. })
  1211. it('does nothing if tracked changes have not changed', async function () {
  1212. const updates = [
  1213. docContentSyncUpdate(this.persistedDoc, this.persistedDocContent, {
  1214. changes: this.changes,
  1215. }),
  1216. ]
  1217. const expandedUpdates =
  1218. await this.SyncManager.promises.expandSyncUpdates(
  1219. this.projectId,
  1220. this.historyId,
  1221. updates,
  1222. this.extendLock
  1223. )
  1224. expect(expandedUpdates).to.deep.equal([])
  1225. })
  1226. it('adds new tracked changes', async function () {
  1227. this.changes.splice(
  1228. 3,
  1229. 0,
  1230. makeTrackedChange('td3', { p: 29, hpos: 35, d: 'lazy ' })
  1231. )
  1232. const updates = [
  1233. docContentSyncUpdate(this.persistedDoc, this.persistedDocContent, {
  1234. changes: this.changes,
  1235. }),
  1236. ]
  1237. const expandedUpdates =
  1238. await this.SyncManager.promises.expandSyncUpdates(
  1239. this.projectId,
  1240. this.historyId,
  1241. updates,
  1242. this.extendLock
  1243. )
  1244. expect(expandedUpdates).to.deep.equal([
  1245. {
  1246. doc: this.persistedDoc.doc,
  1247. op: [
  1248. {
  1249. p: 35,
  1250. r: 'lazy ',
  1251. tracking: {
  1252. type: 'delete',
  1253. userId: USER_ID,
  1254. ts: TIMESTAMP,
  1255. },
  1256. },
  1257. ],
  1258. meta: {
  1259. origin: {
  1260. kind: 'history-resync',
  1261. },
  1262. pathname: this.persistedDoc.path,
  1263. resync: true,
  1264. ts: TIMESTAMP,
  1265. doc_length: this.persistedDocContent.length,
  1266. },
  1267. },
  1268. ])
  1269. })
  1270. it('removes extra tracked changes', async function () {
  1271. this.changes.splice(0, 1)
  1272. const updates = [
  1273. docContentSyncUpdate(this.persistedDoc, this.persistedDocContent, {
  1274. changes: this.changes,
  1275. }),
  1276. ]
  1277. const expandedUpdates =
  1278. await this.SyncManager.promises.expandSyncUpdates(
  1279. this.projectId,
  1280. this.historyId,
  1281. updates,
  1282. this.extendLock
  1283. )
  1284. expect(expandedUpdates).to.deep.equal([
  1285. {
  1286. doc: this.persistedDoc.doc,
  1287. op: [
  1288. {
  1289. p: 4,
  1290. r: 'quick ',
  1291. tracking: { type: 'none' },
  1292. },
  1293. ],
  1294. meta: {
  1295. origin: {
  1296. kind: 'history-resync',
  1297. },
  1298. pathname: this.persistedDoc.path,
  1299. resync: true,
  1300. ts: TIMESTAMP,
  1301. doc_length: this.persistedDocContent.length,
  1302. },
  1303. },
  1304. ])
  1305. })
  1306. it('handles overlapping ranges', async function () {
  1307. this.changes = [
  1308. makeTrackedChange('ti1', { p: 0, i: 'the quic' }),
  1309. makeTrackedChange('td1', { p: 8, d: 'k br' }),
  1310. makeTrackedChange('ti2', { p: 14, hpos: 23, i: 'ps over' }),
  1311. ]
  1312. const updates = [
  1313. docContentSyncUpdate(this.persistedDoc, this.persistedDocContent, {
  1314. changes: this.changes,
  1315. }),
  1316. ]
  1317. const expandedUpdates =
  1318. await this.SyncManager.promises.expandSyncUpdates(
  1319. this.projectId,
  1320. this.historyId,
  1321. updates,
  1322. this.extendLock
  1323. )
  1324. // Before: the [quick ][brown ] fox [jumps ]over the lazy dog
  1325. // After: [the quic][k br]own fox jum[ps over] the lazy dog
  1326. expect(expandedUpdates).to.deep.equal([
  1327. {
  1328. doc: this.persistedDoc.doc,
  1329. op: [
  1330. {
  1331. p: 0,
  1332. r: 'the quic',
  1333. tracking: { type: 'insert', userId: USER_ID, ts: TIMESTAMP },
  1334. },
  1335. {
  1336. p: 10,
  1337. r: 'br',
  1338. tracking: { type: 'delete', userId: USER_ID, ts: TIMESTAMP },
  1339. },
  1340. {
  1341. p: 12,
  1342. r: 'own ',
  1343. tracking: { type: 'none' },
  1344. },
  1345. {
  1346. p: 20,
  1347. r: 'jum',
  1348. tracking: { type: 'none' },
  1349. },
  1350. {
  1351. p: 23,
  1352. r: 'ps over',
  1353. tracking: { type: 'insert', userId: USER_ID, ts: TIMESTAMP },
  1354. },
  1355. {
  1356. p: 40,
  1357. r: 'dog',
  1358. tracking: { type: 'none' },
  1359. },
  1360. ],
  1361. meta: {
  1362. origin: { kind: 'history-resync' },
  1363. pathname: this.persistedDoc.path,
  1364. resync: true,
  1365. ts: TIMESTAMP,
  1366. doc_length: this.persistedDocContent.length,
  1367. },
  1368. },
  1369. ])
  1370. })
  1371. })
  1372. })
  1373. })