Merge pull request #23212 from overleaf/em-docupdater-send-doc-hash

Send doc hash with history updates from docupdater

GitOrigin-RevId: 119475d4198c6603cecd4fd579a64ff4448261ce
This commit is contained in:
Eric Mc Sween
2025-01-30 09:05:21 +00:00
committed by Copybot
parent d731afed90
commit 76dd6d1e20
5 changed files with 78 additions and 6 deletions
@@ -1,5 +1,4 @@
// @ts-check
const { createHash } = require('node:crypto')
const sinon = require('sinon')
const { expect } = require('chai')
const SandboxedModule = require('sandboxed-module')
@@ -399,7 +398,9 @@ describe('UpdateManager', function () {
this.historyUpdates,
this.pathname,
this.projectHistoryId,
this.lines
this.lines,
this.ranges,
this.updatedDocLines
)
})
@@ -526,6 +527,7 @@ describe('UpdateManager', function () {
describe('_adjustHistoryUpdatesMetadata', function () {
beforeEach(function () {
this.lines = ['some', 'test', 'data']
this.updatedDocLines = ['after', 'updates']
this.historyUpdates = [
{
v: 42,
@@ -570,6 +572,7 @@ describe('UpdateManager', function () {
this.pathname,
this.projectHistoryId,
this.lines,
this.updatedDocLines,
this.ranges,
false
)
@@ -632,6 +635,7 @@ describe('UpdateManager', function () {
this.projectHistoryId,
this.lines,
this.ranges,
this.updatedDocLines,
true
)
this.historyUpdates.should.deep.equal([
@@ -685,6 +689,7 @@ describe('UpdateManager', function () {
meta: {
pathname: this.pathname,
doc_length: 21, // 23 - 'so'
doc_hash: stringHash(this.updatedDocLines.join('\n')),
history_doc_length: 28, // 30 - 'so'
},
},
@@ -699,6 +704,7 @@ describe('UpdateManager', function () {
this.projectHistoryId,
[],
{},
['foobar'],
false
)
this.historyUpdates.should.deep.equal([
@@ -822,3 +828,9 @@ describe('UpdateManager', function () {
})
})
})
function stringHash(s) {
const hash = createHash('sha1')
hash.update(s)
return hash.digest('hex')
}