@webex/plugin-meetings 3.12.0-next.12 → 3.12.0-next.121

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (227) hide show
  1. package/AGENTS.md +9 -0
  2. package/dist/aiEnableRequest/index.js +15 -2
  3. package/dist/aiEnableRequest/index.js.map +1 -1
  4. package/dist/breakouts/breakout.js +8 -3
  5. package/dist/breakouts/breakout.js.map +1 -1
  6. package/dist/breakouts/events.js +29 -14
  7. package/dist/breakouts/events.js.map +1 -1
  8. package/dist/breakouts/index.js +90 -3
  9. package/dist/breakouts/index.js.map +1 -1
  10. package/dist/common/errors/webex-errors.js +49 -5
  11. package/dist/common/errors/webex-errors.js.map +1 -1
  12. package/dist/config.js +2 -2
  13. package/dist/config.js.map +1 -1
  14. package/dist/constants.js +37 -10
  15. package/dist/constants.js.map +1 -1
  16. package/dist/controls-options-manager/index.js +46 -10
  17. package/dist/controls-options-manager/index.js.map +1 -1
  18. package/dist/hashTree/constants.js +4 -1
  19. package/dist/hashTree/constants.js.map +1 -1
  20. package/dist/hashTree/hashTreeParser.js +1045 -393
  21. package/dist/hashTree/hashTreeParser.js.map +1 -1
  22. package/dist/hashTree/utils.js +20 -0
  23. package/dist/hashTree/utils.js.map +1 -1
  24. package/dist/index.js +7 -0
  25. package/dist/index.js.map +1 -1
  26. package/dist/interceptors/dataChannelAuthToken.js +75 -15
  27. package/dist/interceptors/dataChannelAuthToken.js.map +1 -1
  28. package/dist/interceptors/locusRetry.js +23 -8
  29. package/dist/interceptors/locusRetry.js.map +1 -1
  30. package/dist/interpretation/index.js +10 -1
  31. package/dist/interpretation/index.js.map +1 -1
  32. package/dist/interpretation/interpretation.types.js +7 -0
  33. package/dist/interpretation/interpretation.types.js.map +1 -0
  34. package/dist/interpretation/siLanguage.js +1 -1
  35. package/dist/locus-info/controlsUtils.js +4 -1
  36. package/dist/locus-info/controlsUtils.js.map +1 -1
  37. package/dist/locus-info/index.js +406 -121
  38. package/dist/locus-info/index.js.map +1 -1
  39. package/dist/locus-info/infoUtils.js +36 -5
  40. package/dist/locus-info/infoUtils.js.map +1 -1
  41. package/dist/locus-info/types.js +19 -0
  42. package/dist/locus-info/types.js.map +1 -1
  43. package/dist/media/MediaConnectionAwaiter.js +15 -2
  44. package/dist/media/MediaConnectionAwaiter.js.map +1 -1
  45. package/dist/media/index.js +8 -2
  46. package/dist/media/index.js.map +1 -1
  47. package/dist/media/properties.js +4 -5
  48. package/dist/media/properties.js.map +1 -1
  49. package/dist/meeting/in-meeting-actions.js +5 -1
  50. package/dist/meeting/in-meeting-actions.js.map +1 -1
  51. package/dist/meeting/index.js +1667 -834
  52. package/dist/meeting/index.js.map +1 -1
  53. package/dist/meeting/locusMediaRequest.js +229 -82
  54. package/dist/meeting/locusMediaRequest.js.map +1 -1
  55. package/dist/meeting/muteState.js +10 -1
  56. package/dist/meeting/muteState.js.map +1 -1
  57. package/dist/meeting/request.js +5 -2
  58. package/dist/meeting/request.js.map +1 -1
  59. package/dist/meeting/util.js +34 -2
  60. package/dist/meeting/util.js.map +1 -1
  61. package/dist/meeting-info/meeting-info-v2.js +2 -2
  62. package/dist/meeting-info/meeting-info-v2.js.map +1 -1
  63. package/dist/meetings/index.js +256 -118
  64. package/dist/meetings/index.js.map +1 -1
  65. package/dist/meetings/meetings.types.js +6 -1
  66. package/dist/meetings/meetings.types.js.map +1 -1
  67. package/dist/meetings/request.js +39 -0
  68. package/dist/meetings/request.js.map +1 -1
  69. package/dist/meetings/util.js +116 -18
  70. package/dist/meetings/util.js.map +1 -1
  71. package/dist/member/index.js +10 -0
  72. package/dist/member/index.js.map +1 -1
  73. package/dist/member/types.js.map +1 -1
  74. package/dist/member/util.js +30 -0
  75. package/dist/member/util.js.map +1 -1
  76. package/dist/members/index.js +101 -43
  77. package/dist/members/index.js.map +1 -1
  78. package/dist/members/util.js +8 -1
  79. package/dist/members/util.js.map +1 -1
  80. package/dist/metrics/constants.js +7 -1
  81. package/dist/metrics/constants.js.map +1 -1
  82. package/dist/multistream/codec/constants.js +63 -0
  83. package/dist/multistream/codec/constants.js.map +1 -0
  84. package/dist/multistream/mediaRequestManager.js +62 -15
  85. package/dist/multistream/mediaRequestManager.js.map +1 -1
  86. package/dist/multistream/receiveSlot.js +9 -0
  87. package/dist/multistream/receiveSlot.js.map +1 -1
  88. package/dist/reachability/clusterReachability.js.map +1 -1
  89. package/dist/reachability/index.js +121 -83
  90. package/dist/reachability/index.js.map +1 -1
  91. package/dist/reachability/reachability.types.js +2 -0
  92. package/dist/reachability/reachability.types.js.map +1 -1
  93. package/dist/reachability/util.js +45 -0
  94. package/dist/reachability/util.js.map +1 -1
  95. package/dist/reactions/reactions.type.js.map +1 -1
  96. package/dist/recording-controller/index.js +1 -3
  97. package/dist/recording-controller/index.js.map +1 -1
  98. package/dist/roap/turnDiscovery.js +8 -1
  99. package/dist/roap/turnDiscovery.js.map +1 -1
  100. package/dist/types/common/errors/webex-errors.d.ts +32 -2
  101. package/dist/types/config.d.ts +2 -2
  102. package/dist/types/constants.d.ts +13 -1
  103. package/dist/types/controls-options-manager/index.d.ts +16 -0
  104. package/dist/types/hashTree/constants.d.ts +1 -0
  105. package/dist/types/hashTree/hashTreeParser.d.ts +189 -22
  106. package/dist/types/hashTree/utils.d.ts +7 -0
  107. package/dist/types/index.d.ts +3 -0
  108. package/dist/types/interceptors/locusRetry.d.ts +4 -4
  109. package/dist/types/interpretation/interpretation.types.d.ts +10 -0
  110. package/dist/types/locus-info/index.d.ts +61 -7
  111. package/dist/types/locus-info/infoUtils.d.ts +8 -0
  112. package/dist/types/locus-info/types.d.ts +21 -1
  113. package/dist/types/media/MediaConnectionAwaiter.d.ts +10 -1
  114. package/dist/types/media/properties.d.ts +6 -2
  115. package/dist/types/meeting/in-meeting-actions.d.ts +4 -0
  116. package/dist/types/meeting/index.d.ts +175 -11
  117. package/dist/types/meeting/locusMediaRequest.d.ts +12 -0
  118. package/dist/types/meeting/request.d.ts +1 -0
  119. package/dist/types/meeting/util.d.ts +9 -0
  120. package/dist/types/meetings/index.d.ts +38 -18
  121. package/dist/types/meetings/meetings.types.d.ts +15 -0
  122. package/dist/types/meetings/request.d.ts +14 -0
  123. package/dist/types/member/index.d.ts +1 -0
  124. package/dist/types/member/types.d.ts +1 -0
  125. package/dist/types/member/util.d.ts +9 -0
  126. package/dist/types/members/index.d.ts +15 -2
  127. package/dist/types/members/util.d.ts +1 -5
  128. package/dist/types/metrics/constants.d.ts +6 -0
  129. package/dist/types/multistream/codec/constants.d.ts +7 -0
  130. package/dist/types/multistream/mediaRequestManager.d.ts +22 -5
  131. package/dist/types/reachability/clusterReachability.d.ts +3 -3
  132. package/dist/types/reachability/index.d.ts +10 -3
  133. package/dist/types/reachability/reachability.types.d.ts +7 -0
  134. package/dist/types/reachability/util.d.ts +17 -0
  135. package/dist/types/reactions/reactions.type.d.ts +3 -0
  136. package/dist/webinar/index.js +307 -161
  137. package/dist/webinar/index.js.map +1 -1
  138. package/package.json +23 -23
  139. package/src/aiEnableRequest/index.ts +16 -0
  140. package/src/breakouts/breakout.ts +3 -1
  141. package/src/breakouts/events.ts +33 -11
  142. package/src/breakouts/index.ts +110 -1
  143. package/src/common/errors/webex-errors.ts +50 -3
  144. package/src/config.ts +2 -2
  145. package/src/constants.ts +21 -3
  146. package/src/controls-options-manager/index.ts +62 -10
  147. package/src/hashTree/constants.ts +7 -0
  148. package/src/hashTree/hashTreeParser.ts +796 -192
  149. package/src/hashTree/utils.ts +19 -0
  150. package/src/index.ts +6 -0
  151. package/src/interceptors/dataChannelAuthToken.ts +88 -12
  152. package/src/interceptors/locusRetry.ts +25 -4
  153. package/src/interpretation/index.ts +27 -9
  154. package/src/interpretation/interpretation.types.ts +11 -0
  155. package/src/locus-info/controlsUtils.ts +3 -1
  156. package/src/locus-info/index.ts +412 -130
  157. package/src/locus-info/infoUtils.ts +41 -6
  158. package/src/locus-info/types.ts +25 -1
  159. package/src/media/MediaConnectionAwaiter.ts +21 -4
  160. package/src/media/index.ts +10 -1
  161. package/src/media/properties.ts +8 -3
  162. package/src/meeting/in-meeting-actions.ts +8 -0
  163. package/src/meeting/index.ts +922 -116
  164. package/src/meeting/locusMediaRequest.ts +106 -6
  165. package/src/meeting/muteState.ts +10 -1
  166. package/src/meeting/request.ts +11 -0
  167. package/src/meeting/util.ts +46 -5
  168. package/src/meeting-info/meeting-info-v2.ts +4 -2
  169. package/src/meetings/index.ts +168 -79
  170. package/src/meetings/meetings.types.ts +19 -0
  171. package/src/meetings/request.ts +43 -0
  172. package/src/meetings/util.ts +117 -4
  173. package/src/member/index.ts +10 -0
  174. package/src/member/types.ts +1 -0
  175. package/src/member/util.ts +29 -0
  176. package/src/members/index.ts +70 -7
  177. package/src/members/util.ts +12 -4
  178. package/src/metrics/constants.ts +6 -0
  179. package/src/multistream/codec/constants.ts +58 -0
  180. package/src/multistream/mediaRequestManager.ts +119 -28
  181. package/src/multistream/receiveSlot.ts +18 -0
  182. package/src/reachability/clusterReachability.ts +3 -2
  183. package/src/reachability/index.ts +47 -16
  184. package/src/reachability/reachability.types.ts +11 -0
  185. package/src/reachability/util.ts +36 -0
  186. package/src/reactions/reactions.type.ts +3 -0
  187. package/src/recording-controller/index.ts +1 -2
  188. package/src/roap/turnDiscovery.ts +9 -1
  189. package/src/webinar/index.ts +216 -38
  190. package/test/unit/spec/aiEnableRequest/index.ts +86 -0
  191. package/test/unit/spec/breakouts/breakout.ts +9 -3
  192. package/test/unit/spec/breakouts/events.ts +120 -2
  193. package/test/unit/spec/breakouts/index.ts +191 -2
  194. package/test/unit/spec/common/errors/webex-errors.ts +78 -0
  195. package/test/unit/spec/controls-options-manager/index.js +139 -32
  196. package/test/unit/spec/hashTree/hashTreeParser.ts +2299 -243
  197. package/test/unit/spec/hashTree/utils.ts +37 -0
  198. package/test/unit/spec/interceptors/dataChannelAuthToken.ts +196 -0
  199. package/test/unit/spec/interceptors/locusRetry.ts +205 -4
  200. package/test/unit/spec/interpretation/index.ts +26 -4
  201. package/test/unit/spec/locus-info/controlsUtils.js +172 -57
  202. package/test/unit/spec/locus-info/index.js +643 -63
  203. package/test/unit/spec/locus-info/infoUtils.js +184 -1
  204. package/test/unit/spec/media/MediaConnectionAwaiter.ts +55 -0
  205. package/test/unit/spec/media/index.ts +92 -0
  206. package/test/unit/spec/media/properties.ts +23 -23
  207. package/test/unit/spec/meeting/in-meeting-actions.ts +4 -0
  208. package/test/unit/spec/meeting/index.js +2704 -135
  209. package/test/unit/spec/meeting/locusMediaRequest.ts +406 -4
  210. package/test/unit/spec/meeting/muteState.js +81 -0
  211. package/test/unit/spec/meeting/request.js +12 -0
  212. package/test/unit/spec/meeting/utils.js +153 -1
  213. package/test/unit/spec/meeting-info/meetinginfov2.js +19 -10
  214. package/test/unit/spec/meetings/index.js +479 -48
  215. package/test/unit/spec/meetings/request.js +141 -0
  216. package/test/unit/spec/meetings/utils.js +402 -51
  217. package/test/unit/spec/member/index.js +7 -0
  218. package/test/unit/spec/member/util.js +89 -0
  219. package/test/unit/spec/members/index.js +216 -0
  220. package/test/unit/spec/members/request.js +37 -1
  221. package/test/unit/spec/members/utils.js +63 -0
  222. package/test/unit/spec/multistream/mediaRequestManager.ts +501 -37
  223. package/test/unit/spec/reachability/index.ts +128 -46
  224. package/test/unit/spec/reachability/util.ts +31 -0
  225. package/test/unit/spec/recording-controller/index.js +9 -8
  226. package/test/unit/spec/roap/turnDiscovery.ts +20 -0
  227. package/test/unit/spec/webinar/index.ts +332 -31
@@ -1,12 +1,19 @@
1
1
  import HashTreeParser, {
2
2
  LocusInfoUpdateType,
3
3
  MeetingEndedError,
4
+ LocusNotFoundError,
5
+ SyncAllBackoffType,
4
6
  } from '@webex/plugin-meetings/src/hashTree/hashTreeParser';
5
7
  import HashTree from '@webex/plugin-meetings/src/hashTree/hashTree';
6
8
  import {expect} from '@webex/test-helper-chai';
7
9
  import sinon from 'sinon';
8
10
  import {assert} from '@webex/test-helper-chai';
9
11
  import {EMPTY_HASH} from '@webex/plugin-meetings/src/hashTree/constants';
12
+ import testUtils from '@webex/plugin-meetings/test/utils/testUtils';
13
+ import { some } from 'lodash';
14
+ import Metrics from '@webex/plugin-meetings/src/metrics';
15
+ import BEHAVIORAL_METRICS from '@webex/plugin-meetings/src/metrics/constants';
16
+ import LoggerProxy from '@webex/plugin-meetings/src/common/logs/logger-proxy';
10
17
 
11
18
  const visibleDataSetsUrl = 'https://locus-a.wbx2.com/locus/api/v1/loci/97d64a5f/visibleDataSets';
12
19
 
@@ -111,6 +118,7 @@ function createDataSet(name: string, leafCount: number, version = 1) {
111
118
  name,
112
119
  idleMs: 1000,
113
120
  backoff: {maxMs: 1000, exponent: 2},
121
+ heartbeatIntervalMs: 5000,
114
122
  };
115
123
  }
116
124
 
@@ -151,31 +159,45 @@ describe('HashTreeParser', () => {
151
159
  let webexRequest: sinon.SinonStub;
152
160
  let callback: sinon.SinonStub;
153
161
  let mathRandomStub: sinon.SinonStub;
162
+ let metricsStub: sinon.SinonStub;
163
+ let loggerInfoStub: sinon.SinonStub;
154
164
 
155
165
  beforeEach(() => {
156
166
  clock = sinon.useFakeTimers();
157
167
  webexRequest = sinon.stub();
158
168
  callback = sinon.stub();
159
169
  mathRandomStub = sinon.stub(Math, 'random').returns(0);
170
+ metricsStub = sinon.stub(Metrics, 'sendBehavioralMetric');
171
+ loggerInfoStub = sinon.stub(LoggerProxy.logger, 'info');
160
172
  });
161
173
  afterEach(() => {
162
174
  clock.restore();
163
175
  mathRandomStub.restore();
176
+ metricsStub.restore();
177
+ loggerInfoStub.restore();
164
178
  });
165
179
 
166
180
  // Helper to create a HashTreeParser instance with common defaults
167
181
  function createHashTreeParser(
168
182
  initialLocus: any = exampleInitialLocus,
169
183
  metadata: any = exampleMetadata,
170
- excludedDataSets?: string[]
184
+ excludedDataSets?: string[],
185
+ syncLatencyTracker?: any,
186
+ syncLatencyMeetingId = 'meeting-1',
187
+ generateTrackingId?: any
171
188
  ) {
172
189
  return new HashTreeParser({
173
190
  initialLocus,
174
191
  metadata,
175
192
  webexRequest,
176
- locusInfoUpdateCallback: callback,
193
+ callbacks: {
194
+ locusInfoUpdateCallback: callback,
195
+ syncLatencyTracker,
196
+ generateTrackingId,
197
+ },
177
198
  debugId: 'test',
178
199
  excludedDataSets,
200
+ syncLatencyMeetingId,
179
201
  });
180
202
  }
181
203
 
@@ -216,7 +238,7 @@ describe('HashTreeParser', () => {
216
238
  }
217
239
 
218
240
  // Helper to mock sendSyncRequestToLocus response
219
- function mockSendSyncRequestResponse(dataSetUrl: string, response: any) {
241
+ function mockSendSyncRequestResponse(dataSetUrl: string, response: any, headers?: any) {
220
242
  webexRequest
221
243
  .withArgs(
222
244
  sinon.match({
@@ -226,6 +248,7 @@ describe('HashTreeParser', () => {
226
248
  )
227
249
  .resolves({
228
250
  body: response,
251
+ headers,
229
252
  });
230
253
  }
231
254
 
@@ -566,6 +589,11 @@ describe('HashTreeParser', () => {
566
589
  },
567
590
  data: {info: {id: 'some-fake-locus-info'}},
568
591
  },
592
+ ],
593
+ });
594
+
595
+ assert.calledWith(callback, {updateType: LocusInfoUpdateType.OBJECTS_UPDATED,
596
+ updatedObjects: [
569
597
  {
570
598
  htMeta: {
571
599
  elementId: {
@@ -631,6 +659,32 @@ describe('HashTreeParser', () => {
631
659
  expect(syncCalls[2].args[0].uri).to.equal(`${atdActiveDataSet.url}/sync`);
632
660
  });
633
661
 
662
+ it('sends leafCount=1 with a single empty leaf for initialization sync, regardless of actual dataset leafCount', async () => {
663
+ const parser = createHashTreeParser({dataSets: [], locus: null}, null);
664
+
665
+ // Use a dataset with leafCount=16 to verify the initialization sync always uses leafCount=1
666
+ const mainDataSet = createDataSet('main', 16, 1100);
667
+
668
+ mockGetAllDataSetsMetadata(webexRequest, visibleDataSetsUrl, [mainDataSet]);
669
+ mockSyncRequest(webexRequest, mainDataSet.url);
670
+
671
+ await parser.initializeFromMessage({
672
+ dataSets: [],
673
+ visibleDataSetsUrl,
674
+ locusUrl,
675
+ });
676
+
677
+ assert.calledWith(webexRequest, {
678
+ method: 'POST',
679
+ uri: `${mainDataSet.url}/sync`,
680
+ qs: {rootHash: sinon.match.string},
681
+ body: {
682
+ leafCount: 1,
683
+ leafDataEntries: [{leafIndex: 0, elementIds: []}],
684
+ },
685
+ });
686
+ });
687
+
634
688
  it('handles sync response that has locusStateElements undefined', async () => {
635
689
  const minimalInitialLocus = {
636
690
  dataSets: [],
@@ -671,8 +725,11 @@ describe('HashTreeParser', () => {
671
725
  assert.notCalled(callback);
672
726
  });
673
727
 
674
- [404, 409].forEach((errorCode) => {
675
- it(`emits MeetingEndedError if getting visible datasets returns ${errorCode}`, async () => {
728
+ [
729
+ {errorCode: 404, expectedError: LocusNotFoundError},
730
+ {errorCode: 409, expectedError: MeetingEndedError},
731
+ ].forEach(({errorCode, expectedError}) => {
732
+ it(`throws ${expectedError.name} if getting visible datasets returns ${errorCode}`, async () => {
676
733
  const minimalInitialLocus = {
677
734
  dataSets: [],
678
735
  locus: null,
@@ -695,7 +752,6 @@ describe('HashTreeParser', () => {
695
752
  )
696
753
  .rejects(error);
697
754
 
698
- // initializeFromMessage should throw MeetingEndedError
699
755
  let thrownError;
700
756
  try {
701
757
  await parser.initializeFromMessage({
@@ -707,7 +763,7 @@ describe('HashTreeParser', () => {
707
763
  thrownError = e;
708
764
  }
709
765
 
710
- expect(thrownError).to.be.instanceOf(MeetingEndedError);
766
+ expect(thrownError).to.be.instanceOf(expectedError);
711
767
  });
712
768
  });
713
769
  });
@@ -1729,12 +1785,122 @@ describe('HashTreeParser', () => {
1729
1785
  });
1730
1786
  });
1731
1787
 
1732
- describe('emits MEETING_ENDED', () => {
1733
- [404, 409].forEach((statusCode) => {
1734
- it(`when /hashtree returns ${statusCode}`, async () => {
1788
+ it('filters a "main" sync response down to the requested dataset, ignoring shared datasets like "unjoined"', async () => {
1789
+ // Set up a parser where both "main" and "unjoined" are visible and share the core locus
1790
+ // element (they always advance to the same version on the server).
1791
+ const sharedInitialLocus = {
1792
+ dataSets: [createDataSet('main', 16, 1000), createDataSet('unjoined', 16, 1000)],
1793
+ locus: {
1794
+ url: locusUrl,
1795
+ htMeta: {
1796
+ elementId: {type: 'locus', id: 0, version: 200},
1797
+ dataSetNames: ['main', 'unjoined'],
1798
+ },
1799
+ links: {resources: {visibleDataSets: {url: visibleDataSetsUrl}}},
1800
+ participants: [],
1801
+ },
1802
+ };
1803
+ const sharedMetadata = {
1804
+ htMeta: {elementId: {type: 'metadata', id: 5, version: 50}, dataSetNames: ['self']},
1805
+ visibleDataSets: [
1806
+ {name: 'main', url: `${locusUrl}/datasets/main`},
1807
+ {name: 'unjoined', url: `${locusUrl}/datasets/unjoined`},
1808
+ ],
1809
+ };
1810
+
1811
+ const parser = createHashTreeParser(sharedInitialLocus, sharedMetadata);
1812
+
1813
+ // both datasets have their own hash tree, sharing the locus element
1814
+ assert.exists(parser.dataSets.main.hashTree);
1815
+ assert.exists(parser.dataSets.unjoined.hashTree);
1816
+
1817
+ // start the sync timer with a normal "main" message (mismatched root hash)
1818
+ const message = {
1819
+ dataSets: [{...createDataSet('main', 16, 1100), root: 'a'.repeat(32)}],
1820
+ visibleDataSetsUrl,
1821
+ locusUrl,
1822
+ locusStateElements: [
1823
+ {
1824
+ htMeta: {
1825
+ elementId: {type: 'locus' as const, id: 0, version: 201},
1826
+ dataSetNames: ['main'],
1827
+ },
1828
+ data: {info: {id: 'initial-update'}},
1829
+ },
1830
+ ],
1831
+ };
1832
+ parser.handleMessage(message, 'initial message');
1833
+ assert.calledOnce(callback);
1834
+ callback.resetHistory();
1835
+
1836
+ const mainDataSetUrl = parser.dataSets.main.url;
1837
+
1838
+ mockGetHashesFromLocusResponse(
1839
+ mainDataSetUrl,
1840
+ new Array(16).fill('0'.repeat(32)),
1841
+ createDataSet('main', 16, 1101)
1842
+ );
1843
+
1844
+ // The sync response for "main" also carries the "unjoined" dataset, the shared locus
1845
+ // element tagged with both datasets, and an "unjoined"-only element - all of which must
1846
+ // be filtered out so that only the requested "main" data is processed.
1847
+ const mainSyncDataSet = createDataSet('main', 16, 1101);
1848
+ mainSyncDataSet.root = parser.dataSets.main.hashTree.getRootHash();
1849
+ mockSendSyncRequestResponse(mainDataSetUrl, {
1850
+ dataSets: [mainSyncDataSet, createDataSet('unjoined', 16, 1101)],
1851
+ visibleDataSetsUrl,
1852
+ locusUrl,
1853
+ locusStateElements: [
1854
+ {
1855
+ htMeta: {
1856
+ elementId: {type: 'locus' as const, id: 0, version: 202},
1857
+ dataSetNames: ['main', 'unjoined'],
1858
+ },
1859
+ data: {info: {id: 'synced-shared-locus'}},
1860
+ },
1861
+ {
1862
+ htMeta: {
1863
+ elementId: {type: 'participant' as const, id: 99, version: 500},
1864
+ dataSetNames: ['unjoined'],
1865
+ },
1866
+ data: {person: {name: 'unjoined-only'}},
1867
+ },
1868
+ ],
1869
+ });
1870
+
1871
+ await clock.tickAsync(1000);
1872
+
1873
+ // the "unjoined" dataset info must NOT be updated from a "main" sync response
1874
+ expect(parser.dataSets.unjoined.version).to.equal(1000);
1875
+
1876
+ // the shared locus element is reported exactly once (not once per dataset), and the
1877
+ // "unjoined"-only element is not reported at all
1878
+ assert.calledOnceWithExactly(callback, {
1879
+ updateType: LocusInfoUpdateType.OBJECTS_UPDATED,
1880
+ updatedObjects: [
1881
+ {
1882
+ htMeta: {
1883
+ elementId: {type: 'locus', id: 0, version: 202},
1884
+ dataSetNames: ['main', 'unjoined'],
1885
+ },
1886
+ data: {info: {id: 'synced-shared-locus'}},
1887
+ },
1888
+ ],
1889
+ });
1890
+
1891
+ // the filtered-out dataset and element are logged
1892
+ assert.calledWith(
1893
+ loggerInfoStub,
1894
+ sinon.match(
1895
+ 'keeping only dataset "main", filtering out datasets: [unjoined:1101], elements: [participant:99:500]'
1896
+ )
1897
+ );
1898
+ });
1899
+
1900
+ describe('emits MEETING_ENDED when 409/2403004 is returned', () => {
1901
+ it('when /hashtree returns 409', async () => {
1735
1902
  const parser = createHashTreeParser();
1736
1903
 
1737
- // Send a message to trigger sync algorithm
1738
1904
  const message = {
1739
1905
  dataSets: [createDataSet('main', 16, 1100)],
1740
1906
  visibleDataSetsUrl,
@@ -1759,12 +1925,9 @@ describe('HashTreeParser', () => {
1759
1925
 
1760
1926
  const mainDataSetUrl = parser.dataSets.main.url;
1761
1927
 
1762
- // Mock getHashesFromLocus to reject with the sentinel error
1763
- const error: any = new Error(`Request failed with status ${statusCode}`);
1764
- error.statusCode = statusCode;
1765
- if (statusCode === 409) {
1766
- error.body = {errorCode: 2403004};
1767
- }
1928
+ const error: any = new Error('Request failed with status 409');
1929
+ error.statusCode = 409;
1930
+ error.body = {errorCode: 2403004};
1768
1931
  webexRequest
1769
1932
  .withArgs(
1770
1933
  sinon.match({
@@ -1774,23 +1937,22 @@ describe('HashTreeParser', () => {
1774
1937
  )
1775
1938
  .rejects(error);
1776
1939
 
1777
- // Trigger sync by advancing time
1778
1940
  await clock.tickAsync(1000);
1779
1941
 
1780
- // Verify callback was called with MEETING_ENDED
1781
1942
  assert.calledOnceWithExactly(callback, {updateType: LocusInfoUpdateType.MEETING_ENDED});
1782
1943
 
1783
- // Verify all timers are stopped
1784
1944
  Object.values(parser.dataSets).forEach((ds: any) => {
1785
1945
  assert.isUndefined(ds.timer);
1786
1946
  assert.isUndefined(ds.heartbeatWatchdogTimer);
1787
1947
  });
1948
+
1949
+ // Verify no sync failure metric was sent for end-meeting sentinel
1950
+ assert.notCalled(metricsStub);
1788
1951
  });
1789
1952
 
1790
- it(`when /sync returns ${statusCode}`, async () => {
1953
+ it('when /sync returns 409', async () => {
1791
1954
  const parser = createHashTreeParser();
1792
1955
 
1793
- // Send a message to trigger sync algorithm
1794
1956
  const message = {
1795
1957
  dataSets: [createDataSet('main', 16, 1100)],
1796
1958
  visibleDataSetsUrl,
@@ -1815,19 +1977,15 @@ describe('HashTreeParser', () => {
1815
1977
 
1816
1978
  const mainDataSetUrl = parser.dataSets.main.url;
1817
1979
 
1818
- // Mock getHashesFromLocus to succeed
1819
1980
  mockGetHashesFromLocusResponse(
1820
1981
  mainDataSetUrl,
1821
1982
  new Array(16).fill('00000000000000000000000000000000'),
1822
1983
  createDataSet('main', 16, 1101)
1823
1984
  );
1824
1985
 
1825
- // Mock sendSyncRequestToLocus to reject with the sentinel error
1826
- const error: any = new Error(`Request failed with status ${statusCode}`);
1827
- error.statusCode = statusCode;
1828
- if (statusCode === 409) {
1829
- error.body = {errorCode: 2403004};
1830
- }
1986
+ const error: any = new Error('Request failed with status 409');
1987
+ error.statusCode = 409;
1988
+ error.body = {errorCode: 2403004};
1831
1989
  webexRequest
1832
1990
  .withArgs(
1833
1991
  sinon.match({
@@ -1837,19 +1995,130 @@ describe('HashTreeParser', () => {
1837
1995
  )
1838
1996
  .rejects(error);
1839
1997
 
1840
- // Trigger sync by advancing time
1841
1998
  await clock.tickAsync(1000);
1842
1999
 
1843
- // Verify callback was called with MEETING_ENDED
1844
2000
  assert.calledOnceWithExactly(callback, {updateType: LocusInfoUpdateType.MEETING_ENDED});
1845
2001
 
2002
+ Object.values(parser.dataSets).forEach((ds: any) => {
2003
+ assert.isUndefined(ds.timer);
2004
+ assert.isUndefined(ds.heartbeatWatchdogTimer);
2005
+ });
2006
+ });
2007
+ });
2008
+
2009
+ describe('emits LOCUS_NOT_FOUND and stops parser when 404 is returned', () => {
2010
+ it('when /hashtree returns 404', async () => {
2011
+ const parser = createHashTreeParser();
2012
+
2013
+ const message = {
2014
+ dataSets: [createDataSet('main', 16, 1100)],
2015
+ visibleDataSetsUrl,
2016
+ locusUrl,
2017
+ locusStateElements: [
2018
+ {
2019
+ htMeta: {
2020
+ elementId: {
2021
+ type: 'locus' as const,
2022
+ id: 0,
2023
+ version: 201,
2024
+ },
2025
+ dataSetNames: ['main'],
2026
+ },
2027
+ data: {info: {id: 'initial-update'}},
2028
+ },
2029
+ ],
2030
+ };
2031
+
2032
+ parser.handleMessage(message, 'initial message');
2033
+ callback.resetHistory();
2034
+
2035
+ const mainDataSetUrl = parser.dataSets.main.url;
2036
+
2037
+ const error: any = new Error('Request failed with status 404');
2038
+ error.statusCode = 404;
2039
+ webexRequest
2040
+ .withArgs(
2041
+ sinon.match({
2042
+ method: 'GET',
2043
+ uri: `${mainDataSetUrl}/hashtree`,
2044
+ })
2045
+ )
2046
+ .rejects(error);
2047
+
2048
+ await clock.tickAsync(1000);
2049
+
2050
+ assert.calledOnceWithExactly(callback, {updateType: LocusInfoUpdateType.LOCUS_NOT_FOUND});
2051
+
2052
+ // Verify parser is stopped
2053
+ expect(parser.state).to.equal('stopped');
2054
+
1846
2055
  // Verify all timers are stopped
1847
2056
  Object.values(parser.dataSets).forEach((ds: any) => {
1848
2057
  assert.isUndefined(ds.timer);
1849
2058
  assert.isUndefined(ds.heartbeatWatchdogTimer);
1850
2059
  });
1851
2060
  });
1852
- });
2061
+
2062
+ it('when /sync returns 404', async () => {
2063
+ const parser = createHashTreeParser();
2064
+
2065
+ const message = {
2066
+ dataSets: [createDataSet('main', 16, 1100)],
2067
+ visibleDataSetsUrl,
2068
+ locusUrl,
2069
+ locusStateElements: [
2070
+ {
2071
+ htMeta: {
2072
+ elementId: {
2073
+ type: 'locus' as const,
2074
+ id: 0,
2075
+ version: 201,
2076
+ },
2077
+ dataSetNames: ['main'],
2078
+ },
2079
+ data: {info: {id: 'initial-update'}},
2080
+ },
2081
+ ],
2082
+ };
2083
+
2084
+ parser.handleMessage(message, 'initial message');
2085
+ callback.resetHistory();
2086
+
2087
+ const mainDataSetUrl = parser.dataSets.main.url;
2088
+
2089
+ mockGetHashesFromLocusResponse(
2090
+ mainDataSetUrl,
2091
+ new Array(16).fill('00000000000000000000000000000000'),
2092
+ createDataSet('main', 16, 1101)
2093
+ );
2094
+
2095
+ const error: any = new Error('Request failed with status 404');
2096
+ error.statusCode = 404;
2097
+ webexRequest
2098
+ .withArgs(
2099
+ sinon.match({
2100
+ method: 'POST',
2101
+ uri: `${mainDataSetUrl}/sync`,
2102
+ })
2103
+ )
2104
+ .rejects(error);
2105
+
2106
+ await clock.tickAsync(1000);
2107
+
2108
+ assert.calledOnceWithExactly(callback, {updateType: LocusInfoUpdateType.LOCUS_NOT_FOUND});
2109
+
2110
+ // Verify parser is stopped
2111
+ expect(parser.state).to.equal('stopped');
2112
+
2113
+ // Verify all timers are stopped
2114
+ Object.values(parser.dataSets).forEach((ds: any) => {
2115
+ assert.isUndefined(ds.timer);
2116
+ assert.isUndefined(ds.heartbeatWatchdogTimer);
2117
+ });
2118
+
2119
+ // Verify no sync failure metric was sent for end-meeting sentinel
2120
+ assert.notCalled(metricsStub);
2121
+ });
1853
2122
  });
1854
2123
 
1855
2124
  it('requests only mismatched hashes during sync', async () => {
@@ -2020,63 +2289,284 @@ describe('HashTreeParser', () => {
2020
2289
  },
2021
2290
  });
2022
2291
  });
2023
- });
2024
2292
 
2025
- describe('handles visible data sets changes correctly', () => {
2026
- it('handles addition of visible data set (one that does not require async initialization)', async () => {
2027
- // Create a parser with visible datasets
2293
+ it('restarts the sync timer when sync response is empty so that a future sync can be triggered', async () => {
2028
2294
  const parser = createHashTreeParser();
2029
2295
 
2030
- // Stub updateItems on self hash tree to return true
2031
- sinon.stub(parser.dataSets.self.hashTree, 'updateItems').returns([true]);
2032
-
2033
- // Send a message with Metadata object that has a new visibleDataSets list
2034
- const message = {
2035
- dataSets: [createDataSet('self', 1, 2100), createDataSet('attendees', 8, 4000)],
2036
- visibleDataSetsUrl,
2037
- locusUrl,
2038
- locusStateElements: [
2296
+ // Send a heartbeat with a mismatched root hash to trigger runSyncAlgorithm
2297
+ const heartbeatMessage = {
2298
+ dataSets: [
2039
2299
  {
2040
- htMeta: {
2041
- elementId: {
2042
- type: 'metadata' as const,
2043
- id: 5,
2044
- version: 51,
2045
- },
2046
- dataSetNames: ['self'],
2047
- },
2048
- data: {
2049
- visibleDataSets: [
2050
- {
2051
- name: 'main',
2052
- url: 'https://locus-a.wbx2.com/locus/api/v1/loci/97d64a5f/datasets/main',
2053
- },
2054
- {
2055
- name: 'self',
2056
- url: 'https://locus-a.wbx2.com/locus/api/v1/loci/97d64a5f/participant/713e9f99/datasets/self',
2057
- },
2058
- {
2059
- name: 'atd-unmuted',
2060
- url: 'https://locus-a.wbx2.com/locus/api/v1/loci/97d64a5f/datasets/atd-unmuted',
2061
- },
2062
- {
2063
- name: 'attendees',
2064
- url: 'https://locus-a.wbx2.com/locus/api/v1/loci/97d64a5f/datasets/attendees',
2065
- },
2066
- ], // added 'attendees'
2067
- },
2300
+ ...createDataSet('main', 16, 1100),
2301
+ root: 'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa1', // different from ours
2068
2302
  },
2069
2303
  ],
2304
+ visibleDataSetsUrl,
2305
+ locusUrl,
2070
2306
  };
2071
2307
 
2072
- parser.handleMessage(message, 'add visible dataset');
2308
+ parser.handleMessage(heartbeatMessage, 'heartbeat with mismatch');
2073
2309
 
2074
- // Verify that 'attendees' was added to visibleDataSets
2075
- expect(parser.visibleDataSets.some((vds) => vds.name === 'attendees')).to.be.true;
2310
+ // The sync timer should be set
2311
+ expect(parser.dataSets.main.timer).to.not.be.undefined;
2076
2312
 
2077
- // Verify that a hash tree was created for 'attendees'
2078
- assert.exists(parser.dataSets.attendees.hashTree);
2079
- assert.equal(parser.dataSets.attendees.hashTree.numLeaves, 8);
2313
+ // Mock responses for the first sync - return null (204/empty body)
2314
+ const mainDataSetUrl = parser.dataSets.main.url;
2315
+ mockGetHashesFromLocusResponse(
2316
+ mainDataSetUrl,
2317
+ new Array(16).fill('00000000000000000000000000000000'),
2318
+ {
2319
+ ...createDataSet('main', 16, 1101),
2320
+ root: 'bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb', // still mismatched
2321
+ }
2322
+ );
2323
+ mockSendSyncRequestResponse(mainDataSetUrl, null);
2324
+
2325
+ // Advance time to fire the sync timer (idleMs=1000 + backoff=0)
2326
+ await clock.tickAsync(1000);
2327
+
2328
+ // Verify sync was triggered
2329
+ assert.calledWith(
2330
+ webexRequest,
2331
+ sinon.match({
2332
+ method: 'POST',
2333
+ uri: `${mainDataSetUrl}/sync`,
2334
+ })
2335
+ );
2336
+
2337
+ // After empty response, runSyncAlgorithm should have been called,
2338
+ // setting a new sync timer as a safety net
2339
+ expect(parser.dataSets.main.timer).to.not.be.undefined;
2340
+
2341
+ // Reset and set up mocks for the second sync
2342
+ webexRequest.resetHistory();
2343
+ mockGetHashesFromLocusResponse(
2344
+ mainDataSetUrl,
2345
+ new Array(16).fill('00000000000000000000000000000000'),
2346
+ {
2347
+ ...createDataSet('main', 16, 1102),
2348
+ root: 'cccccccccccccccccccccccccccccccc', // still mismatched
2349
+ }
2350
+ );
2351
+ mockSendSyncRequestResponse(mainDataSetUrl, null);
2352
+
2353
+ // Advance time again to fire the second sync timer
2354
+ await clock.tickAsync(1000);
2355
+
2356
+ // Verify a second sync was triggered
2357
+ assert.calledWith(
2358
+ webexRequest,
2359
+ sinon.match({
2360
+ method: 'POST',
2361
+ uri: `${mainDataSetUrl}/sync`,
2362
+ })
2363
+ );
2364
+ });
2365
+
2366
+ it('updates dataSet.leafCount when hash tree is resized during sync so that the sync request has the correct leafCount', async () => {
2367
+ const parser = createHashTreeParser();
2368
+
2369
+ // Send a heartbeat with a mismatched root hash to trigger runSyncAlgorithm
2370
+ const heartbeatMessage = {
2371
+ dataSets: [
2372
+ {
2373
+ ...createDataSet('main', 16, 1100),
2374
+ root: 'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa1', // different from ours
2375
+ },
2376
+ ],
2377
+ visibleDataSetsUrl,
2378
+ locusUrl,
2379
+ };
2380
+
2381
+ parser.handleMessage(heartbeatMessage, 'heartbeat with mismatch');
2382
+
2383
+ // The sync timer should be set
2384
+ expect(parser.dataSets.main.timer).to.not.be.undefined;
2385
+
2386
+ const mainDataSetUrl = parser.dataSets.main.url;
2387
+ const newLeafCount = 32;
2388
+
2389
+ // Mock getHashesFromLocus response with a DIFFERENT leafCount (32 instead of 16)
2390
+ mockGetHashesFromLocusResponse(
2391
+ mainDataSetUrl,
2392
+ new Array(newLeafCount).fill('00000000000000000000000000000000'),
2393
+ createDataSet('main', newLeafCount, 1101)
2394
+ );
2395
+
2396
+ // Mock the sync request - use matching root hash
2397
+ const syncResponseDataSet = createDataSet('main', newLeafCount, 1102);
2398
+ syncResponseDataSet.root = parser.dataSets.main.hashTree.getRootHash();
2399
+ mockSendSyncRequestResponse(mainDataSetUrl, {
2400
+ dataSets: [syncResponseDataSet],
2401
+ visibleDataSetsUrl,
2402
+ locusUrl,
2403
+ locusStateElements: [],
2404
+ });
2405
+
2406
+ // Advance time to fire the sync timer (idleMs=1000 + backoff=0)
2407
+ await clock.tickAsync(1000);
2408
+
2409
+ // Verify the sync request was sent with the NEW leafCount (32), not the old one (16)
2410
+ assert.calledWith(
2411
+ webexRequest,
2412
+ sinon.match({
2413
+ method: 'POST',
2414
+ uri: `${mainDataSetUrl}/sync`,
2415
+ body: sinon.match({
2416
+ leafCount: newLeafCount,
2417
+ }),
2418
+ })
2419
+ );
2420
+ });
2421
+
2422
+ it('sends HASH_TREE_SYNC_FAILURE metric when GET /hashtree request fails', async () => {
2423
+ const parser = createHashTreeParser();
2424
+
2425
+ // Send a heartbeat with a mismatched root hash to trigger runSyncAlgorithm
2426
+ const heartbeatMessage = {
2427
+ dataSets: [
2428
+ {
2429
+ ...createDataSet('main', 16, 1100),
2430
+ root: 'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa1',
2431
+ },
2432
+ ],
2433
+ visibleDataSetsUrl,
2434
+ locusUrl,
2435
+ };
2436
+
2437
+ parser.handleMessage(heartbeatMessage, 'heartbeat with mismatch');
2438
+
2439
+ const mainDataSetUrl = parser.dataSets.main.url;
2440
+ const hashTreeError = new Error('server error') as any;
2441
+ hashTreeError.statusCode = 500;
2442
+
2443
+ webexRequest
2444
+ .withArgs(
2445
+ sinon.match({
2446
+ method: 'GET',
2447
+ uri: `${mainDataSetUrl}/hashtree`,
2448
+ })
2449
+ )
2450
+ .rejects(hashTreeError);
2451
+
2452
+ await clock.tickAsync(1000);
2453
+
2454
+ assert.calledOnceWithExactly(metricsStub, BEHAVIORAL_METRICS.HASH_TREE_SYNC_FAILURE, {
2455
+ debugId: 'test',
2456
+ dataSetName: 'main',
2457
+ request: 'GET /hashtree',
2458
+ statusCode: 500,
2459
+ reason: 'server error',
2460
+ });
2461
+ });
2462
+
2463
+ it('sends HASH_TREE_SYNC_FAILURE metric when POST /sync request fails', async () => {
2464
+ const parser = createHashTreeParser();
2465
+
2466
+ // Send a heartbeat with a mismatched root hash to trigger runSyncAlgorithm
2467
+ const heartbeatMessage = {
2468
+ dataSets: [
2469
+ {
2470
+ ...createDataSet('main', 16, 1100),
2471
+ root: 'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa1',
2472
+ },
2473
+ ],
2474
+ visibleDataSetsUrl,
2475
+ locusUrl,
2476
+ };
2477
+
2478
+ parser.handleMessage(heartbeatMessage, 'heartbeat with mismatch');
2479
+
2480
+ const mainDataSetUrl = parser.dataSets.main.url;
2481
+
2482
+ // Mock getHashesFromLocus to succeed
2483
+ mockGetHashesFromLocusResponse(
2484
+ mainDataSetUrl,
2485
+ new Array(16).fill('00000000000000000000000000000000'),
2486
+ createDataSet('main', 16, 1101)
2487
+ );
2488
+
2489
+ // Mock sendSyncRequestToLocus to fail
2490
+ const syncError = new Error('sync failed') as any;
2491
+ syncError.statusCode = 500;
2492
+
2493
+ webexRequest
2494
+ .withArgs(
2495
+ sinon.match({
2496
+ method: 'POST',
2497
+ uri: `${mainDataSetUrl}/sync`,
2498
+ })
2499
+ )
2500
+ .rejects(syncError);
2501
+
2502
+ await clock.tickAsync(1000);
2503
+
2504
+ assert.calledOnceWithExactly(metricsStub, BEHAVIORAL_METRICS.HASH_TREE_SYNC_FAILURE, {
2505
+ debugId: 'test',
2506
+ dataSetName: 'main',
2507
+ request: 'POST /sync',
2508
+ statusCode: 500,
2509
+ reason: 'sync failed',
2510
+ });
2511
+ });
2512
+
2513
+ });
2514
+
2515
+ describe('handles visible data sets changes correctly', () => {
2516
+ it('handles addition of visible data set (one that does not require async initialization)', async () => {
2517
+ // Create a parser with visible datasets
2518
+ const parser = createHashTreeParser();
2519
+
2520
+ // Stub updateItems on self hash tree to return true
2521
+ sinon.stub(parser.dataSets.self.hashTree, 'updateItems').returns([true]);
2522
+
2523
+ // Send a message with Metadata object that has a new visibleDataSets list
2524
+ const message = {
2525
+ dataSets: [createDataSet('self', 1, 2100), createDataSet('attendees', 8, 4000)],
2526
+ visibleDataSetsUrl,
2527
+ locusUrl,
2528
+ locusStateElements: [
2529
+ {
2530
+ htMeta: {
2531
+ elementId: {
2532
+ type: 'metadata' as const,
2533
+ id: 5,
2534
+ version: 51,
2535
+ },
2536
+ dataSetNames: ['self'],
2537
+ },
2538
+ data: {
2539
+ visibleDataSets: [
2540
+ {
2541
+ name: 'main',
2542
+ url: 'https://locus-a.wbx2.com/locus/api/v1/loci/97d64a5f/datasets/main',
2543
+ },
2544
+ {
2545
+ name: 'self',
2546
+ url: 'https://locus-a.wbx2.com/locus/api/v1/loci/97d64a5f/participant/713e9f99/datasets/self',
2547
+ },
2548
+ {
2549
+ name: 'atd-unmuted',
2550
+ url: 'https://locus-a.wbx2.com/locus/api/v1/loci/97d64a5f/datasets/atd-unmuted',
2551
+ },
2552
+ {
2553
+ name: 'attendees',
2554
+ url: 'https://locus-a.wbx2.com/locus/api/v1/loci/97d64a5f/datasets/attendees',
2555
+ },
2556
+ ], // added 'attendees'
2557
+ },
2558
+ },
2559
+ ],
2560
+ };
2561
+
2562
+ parser.handleMessage(message, 'add visible dataset');
2563
+
2564
+ // Verify that 'attendees' was added to visibleDataSets
2565
+ expect(parser.visibleDataSets.some((vds) => vds.name === 'attendees')).to.be.true;
2566
+
2567
+ // Verify that a hash tree was created for 'attendees'
2568
+ assert.exists(parser.dataSets.attendees.hashTree);
2569
+ assert.equal(parser.dataSets.attendees.hashTree.numLeaves, 8);
2080
2570
 
2081
2571
  // Verify callback was called with the metadata update (appears twice - processed once for visible dataset changes, once in main loop)
2082
2572
  assert.calledOnceWithExactly(callback, {updateType: LocusInfoUpdateType.OBJECTS_UPDATED,
@@ -2291,7 +2781,7 @@ describe('HashTreeParser', () => {
2291
2781
  expect(syncCalls[1].args[0].uri).to.equal(`${newAtdActiveDataSet.url}/sync`);
2292
2782
  });
2293
2783
 
2294
- it('emits MEETING_ENDED if async init of a new visible dataset fails with 404', async () => {
2784
+ it('emits LOCUS_NOT_FOUND if async init of a new visible dataset fails with 404', async () => {
2295
2785
  const parser = createHashTreeParser();
2296
2786
 
2297
2787
  // Stub updateItems on self hash tree to return true
@@ -2356,8 +2846,8 @@ describe('HashTreeParser', () => {
2356
2846
  // Wait for the async initialization (queueMicrotask) to complete
2357
2847
  await clock.tickAsync(0);
2358
2848
 
2359
- // Verify callback was called with MEETING_ENDED
2360
- assert.calledOnceWithExactly(callback, {updateType: LocusInfoUpdateType.MEETING_ENDED});
2849
+ // Verify callback was called with LOCUS_NOT_FOUND (404 means locus URL is stale, not necessarily meeting ended)
2850
+ assert.calledOnceWithExactly(callback, {updateType: LocusInfoUpdateType.LOCUS_NOT_FOUND});
2361
2851
  });
2362
2852
 
2363
2853
  it('handles removal of visible data set', async () => {
@@ -2517,58 +3007,208 @@ describe('HashTreeParser', () => {
2517
3007
  // Verify callback was NOT called (no updates for non-visible datasets)
2518
3008
  assert.notCalled(callback);
2519
3009
  });
2520
- });
2521
3010
 
2522
- describe('heartbeat watchdog', () => {
2523
- it('initiates sync immediately only for the specific data set whose heartbeat watchdog fires', async () => {
2524
- const parser = createHashTreeParser();
2525
- const heartbeatIntervalMs = 5000;
3011
+ it('reports update for object that moves from removed visible dataset to new visible dataset even if version is unchanged', async () => {
3012
+ // The purpose of this test is to verify that when an object
3013
+ // moves from one visible dataset to another without version change,
3014
+ // the parser still reports it as an update.
3015
+ // Locus has some additional signalling for this - the "view" property in htMeta.elementId.
3016
+ // When a view changes, the contents of the object may change even if version doesn't.
3017
+ // HashTreeParser doesn't use the "view" property, because it doesn't need to -
3018
+ // the same functionality is achieved thanks to the fact that a new visible data set means
3019
+ // a new hash tree is created, so HashTreeParser still detects the change as new
3020
+ // object is added to the new hash tree.
3021
+
3022
+ // Setup: parser with visible datasets "self" and "unjoined"
3023
+ const unjoinedDataSet = createDataSet('unjoined', 4, 3000);
3024
+ const selfDataSet = createDataSet('self', 1, 2000);
3025
+
3026
+ // start with Locus that has "info" in both "unjoined" and "main" datasets,
3027
+ // but only "unjoined" is visible.
3028
+ const initialLocus = {
3029
+ dataSets: [selfDataSet, unjoinedDataSet],
3030
+ locus: {
3031
+ url: 'https://locus-a.wbx2.com/locus/api/v1/loci/97d64a5f',
3032
+ links: {resources: {visibleDataSets: {url: visibleDataSetsUrl}}},
3033
+ // info object in "unjoined" dataset with version 500
3034
+ info: {
3035
+ htMeta: {
3036
+ elementId: {
3037
+ type: 'info',
3038
+ id: 42,
3039
+ version: 500,
3040
+ view: ['unjoined'], // not used by our code, but here for completeness - that's what real Locus would send
3041
+ },
3042
+ dataSetNames: ['main', 'unjoined'],
3043
+ },
3044
+ someField: 'some-initial-value',
3045
+ },
3046
+ self: {
3047
+ htMeta: {
3048
+ elementId: {
3049
+ type: 'self',
3050
+ id: 4,
3051
+ version: 100,
3052
+ },
3053
+ dataSetNames: ['self'],
3054
+ },
3055
+ },
3056
+ },
3057
+ };
2526
3058
 
2527
- // Send initial heartbeat message for 'main' only
2528
- const heartbeatMessage = {
2529
- dataSets: [
2530
- {
2531
- ...createDataSet('main', 16, 1100),
2532
- root: parser.dataSets.main.hashTree.getRootHash(),
3059
+ const metadata = {
3060
+ htMeta: {
3061
+ elementId: {
3062
+ type: 'metadata',
3063
+ id: 5,
3064
+ version: 50,
2533
3065
  },
3066
+ dataSetNames: ['self'],
3067
+ },
3068
+ visibleDataSets: [
3069
+ {name: 'self', url: selfDataSet.url},
3070
+ {name: 'unjoined', url: unjoinedDataSet.url},
2534
3071
  ],
2535
- visibleDataSetsUrl,
2536
- locusUrl,
2537
- heartbeatIntervalMs,
2538
3072
  };
2539
3073
 
2540
- parser.handleMessage(heartbeatMessage, 'initial heartbeat');
2541
-
2542
- // Verify only 'main' watchdog timer is set
2543
- expect(parser.dataSets.main.heartbeatWatchdogTimer).to.not.be.undefined;
2544
- expect(parser.dataSets.self.heartbeatWatchdogTimer).to.be.undefined;
2545
- expect(parser.dataSets['atd-unmuted'].heartbeatWatchdogTimer).to.be.undefined;
3074
+ const parser = createHashTreeParser(initialLocus, metadata);
2546
3075
 
2547
- // Mock responses for performSync (GET hashtree then POST sync for leafCount > 1)
2548
- const mainDataSetUrl = parser.dataSets.main.url;
2549
- mockGetHashesFromLocusResponse(
2550
- mainDataSetUrl,
2551
- new Array(16).fill('00000000000000000000000000000000'),
2552
- createDataSet('main', 16, 1101)
2553
- );
2554
- mockSendSyncRequestResponse(mainDataSetUrl, null);
3076
+ // Verify initial state: unjoined is visible and has the info object
3077
+ expect(parser.visibleDataSets.some((vds) => vds.name === 'unjoined')).to.be.true;
3078
+ assert.exists(parser.dataSets.unjoined.hashTree);
3079
+ assert.equal(parser.dataSets.unjoined.hashTree?.getItemVersion(42, 'info'), 500);
2555
3080
 
2556
- // Advance time past heartbeatIntervalMs + backoff (Math.random returns 0, so backoff = 0)
2557
- // performSync is called immediately when the watchdog fires - no additional delay
2558
- await clock.tickAsync(heartbeatIntervalMs);
3081
+ // Stub updateItems on self hash tree to return true for metadata update
3082
+ sinon.stub(parser.dataSets.self.hashTree, 'updateItems').returns([true]);
2559
3083
 
2560
- // Verify sync request was sent immediately for 'main' (GET hashtree + POST sync)
2561
- assert.calledWith(
2562
- webexRequest,
2563
- sinon.match({
2564
- method: 'GET',
2565
- uri: `${mainDataSetUrl}/hashtree`,
2566
- })
2567
- );
3084
+ // Now send a message that:
3085
+ // 1. Changes visible datasets: removes "unjoined", adds "main"
3086
+ // 2. Contains the same info object (same id=42, same version=500) but we see the view from "main" dataset
3087
+ const mainDataSet = createDataSet('main', 16, 1000);
2568
3088
 
2569
- // Verify no sync requests were sent for other datasets
2570
- assert.neverCalledWith(
2571
- webexRequest,
3089
+ const message = {
3090
+ dataSets: [selfDataSet, mainDataSet],
3091
+ visibleDataSetsUrl,
3092
+ locusUrl,
3093
+ locusStateElements: [
3094
+ {
3095
+ htMeta: {
3096
+ elementId: {
3097
+ type: 'metadata' as const,
3098
+ id: 5,
3099
+ version: 51,
3100
+ },
3101
+ dataSetNames: ['self'],
3102
+ },
3103
+ data: {
3104
+ visibleDataSets: [
3105
+ {name: 'self', url: selfDataSet.url},
3106
+ {name: 'main', url: mainDataSet.url},
3107
+ // "unjoined" is no longer here
3108
+ ],
3109
+ },
3110
+ },
3111
+ {
3112
+ htMeta: {
3113
+ elementId: {
3114
+ type: 'info' as const,
3115
+ id: 42,
3116
+ version: 500, // same version as before
3117
+ view: ['main'], // now points to "main" instead of "unjoined"
3118
+ },
3119
+ dataSetNames: ['main', 'unjoined'], // still in both datasets, but only "main" is visible now
3120
+ },
3121
+ data: {someNewField: 'some-value'},
3122
+ },
3123
+ ],
3124
+ };
3125
+
3126
+ parser.handleMessage(message, 'visible dataset swap with same-version object');
3127
+
3128
+ // Verify "unjoined" is no longer visible and "main" is now visible
3129
+ expect(parser.visibleDataSets.some((vds) => vds.name === 'unjoined')).to.be.false;
3130
+ expect(parser.visibleDataSets.some((vds) => vds.name === 'main')).to.be.true;
3131
+
3132
+ // Verify the info object is now in the "main" hash tree
3133
+ assert.exists(parser.dataSets.main.hashTree);
3134
+ assert.equal(parser.dataSets.main.hashTree?.getItemVersion(42, 'info'), 500);
3135
+
3136
+ // The key assertion: callback should be called with the info object update even though
3137
+ // its version hasn't changed - because visible datasets changed (moved from unjoined to main)
3138
+ assert.calledOnce(callback);
3139
+ const callbackArgs = callback.firstCall.args[0];
3140
+ assert.equal(callbackArgs.updateType, LocusInfoUpdateType.OBJECTS_UPDATED);
3141
+
3142
+ // Should contain the info object update (with data)
3143
+ const infoUpdate = callbackArgs.updatedObjects.find(
3144
+ (obj) => obj.htMeta.elementId.type === 'info' && obj.htMeta.elementId.id === 42
3145
+ );
3146
+ assert.exists(infoUpdate);
3147
+ assert.deepEqual(infoUpdate.htMeta.elementId, {
3148
+ type: 'info',
3149
+ id: 42,
3150
+ version: 500,
3151
+ view: ['main'],
3152
+ });
3153
+ assert.deepEqual(infoUpdate.data, {someNewField: 'some-value'});
3154
+ });
3155
+ });
3156
+
3157
+ describe('heartbeat watchdog', () => {
3158
+ it('initiates sync immediately only for the specific data set whose heartbeat watchdog fires', async () => {
3159
+ const parser = createHashTreeParser();
3160
+ const heartbeatIntervalMs = 5000;
3161
+
3162
+ // Send initial heartbeat message for 'main' only
3163
+ const heartbeatMessage = {
3164
+ dataSets: [
3165
+ {
3166
+ ...createDataSet('main', 16, 1100),
3167
+ root: parser.dataSets.main.hashTree.getRootHash(),
3168
+ },
3169
+ ],
3170
+ visibleDataSetsUrl,
3171
+ locusUrl,
3172
+ };
3173
+
3174
+ parser.handleMessage(heartbeatMessage, 'initial heartbeat');
3175
+
3176
+ // Verify only 'main' watchdog timer is set
3177
+ expect(parser.dataSets.main.heartbeatWatchdogTimer).to.not.be.undefined;
3178
+ expect(parser.dataSets.self.heartbeatWatchdogTimer).to.be.undefined;
3179
+ expect(parser.dataSets['atd-unmuted'].heartbeatWatchdogTimer).to.be.undefined;
3180
+
3181
+ // Mock responses for performSync (GET hashtree then POST sync for leafCount > 1)
3182
+ const mainDataSetUrl = parser.dataSets.main.url;
3183
+ mockGetHashesFromLocusResponse(
3184
+ mainDataSetUrl,
3185
+ new Array(16).fill('00000000000000000000000000000000'),
3186
+ createDataSet('main', 16, 1101)
3187
+ );
3188
+ mockSendSyncRequestResponse(mainDataSetUrl, null);
3189
+
3190
+ // Advance time past heartbeatIntervalMs + backoff (Math.random returns 0, so backoff = 0)
3191
+ // performSync is called immediately when the watchdog fires - no additional delay
3192
+ await clock.tickAsync(heartbeatIntervalMs);
3193
+
3194
+ // Verify sync request was sent immediately for 'main' (GET hashtree + POST sync)
3195
+ assert.calledWith(
3196
+ webexRequest,
3197
+ sinon.match({
3198
+ method: 'GET',
3199
+ uri: `${mainDataSetUrl}/hashtree`,
3200
+ })
3201
+ );
3202
+
3203
+ // Verify behavioral metric was sent for the watchdog expiration
3204
+ assert.calledWith(metricsStub, BEHAVIORAL_METRICS.HASH_TREE_HEARTBEAT_WATCHDOG_EXPIRED, {
3205
+ debugId: 'test',
3206
+ dataSetName: 'main',
3207
+ });
3208
+
3209
+ // Verify no sync requests were sent for other datasets
3210
+ assert.neverCalledWith(
3211
+ webexRequest,
2572
3212
  sinon.match({
2573
3213
  method: 'POST',
2574
3214
  uri: `${parser.dataSets.self.url}/sync`,
@@ -2583,6 +3223,106 @@ describe('HashTreeParser', () => {
2583
3223
  );
2584
3224
  });
2585
3225
 
3226
+ it('uses the watchdog random backoff when reporting sync metrics', async () => {
3227
+ const syncLatencyTracker = {
3228
+ saveLatency: sinon.stub(),
3229
+ saveTimestamp: sinon.stub(),
3230
+ getLocusSyncLatency: sinon.stub(),
3231
+ clearLocusSyncLatency: sinon.stub(),
3232
+ completeLocusSyncLatency: sinon.stub(),
3233
+ };
3234
+ const parser = createHashTreeParser(
3235
+ undefined,
3236
+ undefined,
3237
+ undefined,
3238
+ syncLatencyTracker
3239
+ );
3240
+ const heartbeatIntervalMs = 5000;
3241
+ const mainDataSetUrl = parser.dataSets.main.url;
3242
+
3243
+ mathRandomStub.onFirstCall().returns(0.1); // root-hash timer backoff = 10ms
3244
+ mathRandomStub.onSecondCall().returns(0.5); // watchdog backoff = 250ms
3245
+ mathRandomStub.returns(0);
3246
+
3247
+ parser.handleMessage(
3248
+ {
3249
+ dataSets: [
3250
+ {
3251
+ ...createDataSet('main', 16, 1100),
3252
+ root: parser.dataSets.main.hashTree.getRootHash(),
3253
+ },
3254
+ ],
3255
+ visibleDataSetsUrl,
3256
+ locusUrl,
3257
+ },
3258
+ 'initial heartbeat'
3259
+ );
3260
+
3261
+ mockGetHashesFromLocusResponse(
3262
+ mainDataSetUrl,
3263
+ new Array(16).fill('00000000000000000000000000000000'),
3264
+ createDataSet('main', 16, 1101)
3265
+ );
3266
+ mockSendSyncRequestResponse(mainDataSetUrl, null);
3267
+
3268
+ await clock.tickAsync(heartbeatIntervalMs + 250);
3269
+
3270
+ assert.calledWithExactly(
3271
+ syncLatencyTracker.saveLatency,
3272
+ 'internal.client.locus.sync.random.backoff',
3273
+ 250,
3274
+ {
3275
+ meetingId: 'meeting-1',
3276
+ dataSetName: 'main',
3277
+ }
3278
+ );
3279
+ });
3280
+
3281
+ it('uses the root sync random backoff when root timer fires before watchdog', async () => {
3282
+ const syncLatencyTracker = {
3283
+ saveLatency: sinon.stub(),
3284
+ saveTimestamp: sinon.stub(),
3285
+ getLocusSyncLatency: sinon.stub(),
3286
+ clearLocusSyncLatency: sinon.stub(),
3287
+ completeLocusSyncLatency: sinon.stub(),
3288
+ };
3289
+ const parser = createHashTreeParser(
3290
+ undefined,
3291
+ undefined,
3292
+ undefined,
3293
+ syncLatencyTracker
3294
+ );
3295
+ const mainDataSetUrl = parser.dataSets.main.url;
3296
+
3297
+ mathRandomStub.onFirstCall().returns(0.1); // root-hash timer backoff = 10ms
3298
+ mathRandomStub.onSecondCall().returns(0.5); // watchdog backoff = 250ms
3299
+ mathRandomStub.returns(0);
3300
+
3301
+ parser.handleMessage(
3302
+ createHeartbeatMessage('main', 16, 1100, 'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa1'),
3303
+ 'root mismatch heartbeat'
3304
+ );
3305
+
3306
+ mockGetHashesFromLocusResponse(
3307
+ mainDataSetUrl,
3308
+ new Array(16).fill('00000000000000000000000000000000'),
3309
+ createDataSet('main', 16, 1101)
3310
+ );
3311
+ mockSendSyncRequestResponse(mainDataSetUrl, null);
3312
+
3313
+ await clock.tickAsync(1010);
3314
+
3315
+ assert.calledWithExactly(
3316
+ syncLatencyTracker.saveLatency,
3317
+ 'internal.client.locus.sync.random.backoff',
3318
+ 10,
3319
+ {
3320
+ meetingId: 'meeting-1',
3321
+ dataSetName: 'main',
3322
+ }
3323
+ );
3324
+ });
3325
+
2586
3326
  it('calls POST sync directly for leafCount === 1 data sets', async () => {
2587
3327
  const parser = createHashTreeParser();
2588
3328
  const heartbeatIntervalMs = 5000;
@@ -2598,7 +3338,6 @@ describe('HashTreeParser', () => {
2598
3338
  ],
2599
3339
  visibleDataSetsUrl,
2600
3340
  locusUrl,
2601
- heartbeatIntervalMs,
2602
3341
  };
2603
3342
 
2604
3343
  parser.handleMessage(heartbeatMessage, 'self heartbeat');
@@ -2609,6 +3348,12 @@ describe('HashTreeParser', () => {
2609
3348
  // Advance time past watchdog delay
2610
3349
  await clock.tickAsync(heartbeatIntervalMs);
2611
3350
 
3351
+ // Verify behavioral metric was sent for the watchdog expiration
3352
+ assert.calledWith(metricsStub, BEHAVIORAL_METRICS.HASH_TREE_HEARTBEAT_WATCHDOG_EXPIRED, {
3353
+ debugId: 'test',
3354
+ dataSetName: 'self',
3355
+ });
3356
+
2612
3357
  // For leafCount === 1, performSync skips GET hashtree and goes straight to POST sync
2613
3358
  assert.neverCalledWith(
2614
3359
  webexRequest,
@@ -2628,7 +3373,6 @@ describe('HashTreeParser', () => {
2628
3373
 
2629
3374
  it('sets watchdog timers for each data set in the message', async () => {
2630
3375
  const parser = createHashTreeParser();
2631
- const heartbeatIntervalMs = 5000;
2632
3376
 
2633
3377
  // Send heartbeat with multiple datasets
2634
3378
  const heartbeatMessage = {
@@ -2645,7 +3389,6 @@ describe('HashTreeParser', () => {
2645
3389
  ],
2646
3390
  visibleDataSetsUrl,
2647
3391
  locusUrl,
2648
- heartbeatIntervalMs,
2649
3392
  };
2650
3393
 
2651
3394
  parser.handleMessage(heartbeatMessage, 'multi-dataset heartbeat');
@@ -2659,7 +3402,6 @@ describe('HashTreeParser', () => {
2659
3402
 
2660
3403
  it('resets the watchdog timer for a specific data set when a new heartbeat for it is received', async () => {
2661
3404
  const parser = createHashTreeParser();
2662
- const heartbeatIntervalMs = 5000;
2663
3405
 
2664
3406
  // Send first heartbeat for 'main'
2665
3407
  const heartbeat1 = {
@@ -2671,7 +3413,6 @@ describe('HashTreeParser', () => {
2671
3413
  ],
2672
3414
  visibleDataSetsUrl,
2673
3415
  locusUrl,
2674
- heartbeatIntervalMs,
2675
3416
  };
2676
3417
 
2677
3418
  parser.handleMessage(heartbeat1, 'first heartbeat');
@@ -2692,7 +3433,6 @@ describe('HashTreeParser', () => {
2692
3433
  ],
2693
3434
  visibleDataSetsUrl,
2694
3435
  locusUrl,
2695
- heartbeatIntervalMs,
2696
3436
  };
2697
3437
 
2698
3438
  parser.handleMessage(heartbeat2, 'second heartbeat');
@@ -2711,7 +3451,6 @@ describe('HashTreeParser', () => {
2711
3451
 
2712
3452
  it('resets the watchdog timer when a normal message (with locusStateElements) is received', async () => {
2713
3453
  const parser = createHashTreeParser();
2714
- const heartbeatIntervalMs = 5000;
2715
3454
 
2716
3455
  // Send initial heartbeat to start the watchdog for 'main'
2717
3456
  const heartbeat = {
@@ -2723,7 +3462,6 @@ describe('HashTreeParser', () => {
2723
3462
  ],
2724
3463
  visibleDataSetsUrl,
2725
3464
  locusUrl,
2726
- heartbeatIntervalMs,
2727
3465
  };
2728
3466
 
2729
3467
  parser.handleMessage(heartbeat, 'initial heartbeat');
@@ -2751,7 +3489,6 @@ describe('HashTreeParser', () => {
2751
3489
  data: {someData: 'value'},
2752
3490
  },
2753
3491
  ],
2754
- heartbeatIntervalMs,
2755
3492
  };
2756
3493
 
2757
3494
  parser.handleMessage(normalMessage, 'normal message');
@@ -2765,12 +3502,17 @@ describe('HashTreeParser', () => {
2765
3502
  const parser = createHashTreeParser();
2766
3503
 
2767
3504
  // Send a heartbeat message without heartbeatIntervalMs
2768
- const heartbeatMessage = createHeartbeatMessage(
2769
- 'main',
2770
- 16,
2771
- 1100,
2772
- parser.dataSets.main.hashTree.getRootHash()
2773
- );
3505
+ const heartbeatMessage = {
3506
+ dataSets: [
3507
+ {
3508
+ ...createDataSet('main', 16, 1100),
3509
+ root: parser.dataSets.main.hashTree.getRootHash(),
3510
+ heartbeatIntervalMs: undefined,
3511
+ },
3512
+ ],
3513
+ visibleDataSetsUrl,
3514
+ locusUrl,
3515
+ };
2774
3516
 
2775
3517
  parser.handleMessage(heartbeatMessage, 'heartbeat without interval');
2776
3518
 
@@ -2779,7 +3521,6 @@ describe('HashTreeParser', () => {
2779
3521
 
2780
3522
  it('stops all watchdog timers when meeting ends via sentinel message', async () => {
2781
3523
  const parser = createHashTreeParser();
2782
- const heartbeatIntervalMs = 5000;
2783
3524
 
2784
3525
  // Send heartbeat for multiple datasets
2785
3526
  const heartbeat = {
@@ -2796,7 +3537,6 @@ describe('HashTreeParser', () => {
2796
3537
  ],
2797
3538
  visibleDataSetsUrl,
2798
3539
  locusUrl,
2799
- heartbeatIntervalMs,
2800
3540
  };
2801
3541
 
2802
3542
  parser.handleMessage(heartbeat, 'initial heartbeat');
@@ -2847,7 +3587,6 @@ describe('HashTreeParser', () => {
2847
3587
  };
2848
3588
 
2849
3589
  const parser = createHashTreeParser(initialLocus, metadata);
2850
- const heartbeatIntervalMs = 5000;
2851
3590
 
2852
3591
  // Set Math.random to return 1 so that backoff = 1^exponent * maxMs = maxMs
2853
3592
  mathRandomStub.returns(1);
@@ -2869,7 +3608,6 @@ describe('HashTreeParser', () => {
2869
3608
  ],
2870
3609
  visibleDataSetsUrl,
2871
3610
  locusUrl,
2872
- heartbeatIntervalMs,
2873
3611
  };
2874
3612
 
2875
3613
  parser.handleMessage(heartbeat, 'heartbeat');
@@ -2919,7 +3657,6 @@ describe('HashTreeParser', () => {
2919
3657
 
2920
3658
  it('does not set watchdog for data sets without a hash tree', async () => {
2921
3659
  const parser = createHashTreeParser();
2922
- const heartbeatIntervalMs = 5000;
2923
3660
 
2924
3661
  // 'atd-active' is in the initial locus but is not visible (no hash tree)
2925
3662
  // Send heartbeat mentioning a non-visible dataset
@@ -2933,7 +3670,6 @@ describe('HashTreeParser', () => {
2933
3670
  ],
2934
3671
  visibleDataSetsUrl,
2935
3672
  locusUrl,
2936
- heartbeatIntervalMs,
2937
3673
  };
2938
3674
 
2939
3675
  parser.handleMessage(heartbeatMessage, 'heartbeat with non-visible dataset');
@@ -2942,85 +3678,270 @@ describe('HashTreeParser', () => {
2942
3678
  expect(parser.dataSets.main.heartbeatWatchdogTimer).to.not.be.undefined;
2943
3679
  expect(parser.dataSets['atd-active']?.heartbeatWatchdogTimer).to.be.undefined;
2944
3680
  });
2945
- });
2946
- });
2947
-
2948
- describe('#callLocusInfoUpdateCallback filtering', () => {
2949
- // Helper to setup parser with initial objects and reset callback history
2950
- function setupParserWithObjects(locusStateElements: any[]) {
2951
- const parser = createHashTreeParser();
2952
-
2953
- if (locusStateElements.length > 0) {
2954
- // Determine which datasets to include based on the objects' dataSetNames
2955
- const dataSetNames = new Set<string>();
2956
- locusStateElements.forEach((element) => {
2957
- element.htMeta?.dataSetNames?.forEach((name) => dataSetNames.add(name));
2958
- });
2959
3681
 
2960
- const dataSets = [];
2961
- if (dataSetNames.has('main')) dataSets.push(createDataSet('main', 16, 1100));
2962
- if (dataSetNames.has('self')) dataSets.push(createDataSet('self', 1, 2100));
2963
- if (dataSetNames.has('atd-unmuted')) dataSets.push(createDataSet('atd-unmuted', 16, 3100));
3682
+ it('restarts the watchdog timer after it fires so that future missed heartbeats still trigger syncs', async () => {
3683
+ const parser = createHashTreeParser();
3684
+ const heartbeatIntervalMs = 5000;
2964
3685
 
2965
- const setupMessage = {
2966
- dataSets,
3686
+ // Send initial heartbeat for 'main'
3687
+ const heartbeatMessage = {
3688
+ dataSets: [
3689
+ {
3690
+ ...createDataSet('main', 16, 1100),
3691
+ root: parser.dataSets.main.hashTree.getRootHash(),
3692
+ },
3693
+ ],
2967
3694
  visibleDataSetsUrl,
2968
3695
  locusUrl,
2969
- locusStateElements,
2970
3696
  };
2971
3697
 
2972
- parser.handleMessage(setupMessage, 'setup');
2973
- }
3698
+ parser.handleMessage(heartbeatMessage, 'initial heartbeat');
3699
+ expect(parser.dataSets.main.heartbeatWatchdogTimer).to.not.be.undefined;
2974
3700
 
2975
- callback.resetHistory();
2976
- return parser;
2977
- }
3701
+ // Mock responses for performSync - return null (204/empty body)
3702
+ const mainDataSetUrl = parser.dataSets.main.url;
3703
+ mockGetHashesFromLocusResponse(
3704
+ mainDataSetUrl,
3705
+ new Array(16).fill('00000000000000000000000000000000'),
3706
+ createDataSet('main', 16, 1101)
3707
+ );
3708
+ mockSendSyncRequestResponse(mainDataSetUrl, null);
2978
3709
 
2979
- it('filters out updates when a dataset has a higher version', () => {
2980
- const parser = setupParserWithObjects([
2981
- {
2982
- htMeta: {
2983
- elementId: {type: 'locus' as const, id: 5, version: 100},
2984
- dataSetNames: ['main'],
2985
- },
2986
- data: {existingField: 'existing'},
2987
- },
2988
- ]);
3710
+ // Advance time past heartbeatIntervalMs to fire the watchdog
3711
+ await clock.tickAsync(heartbeatIntervalMs);
2989
3712
 
2990
- // Try to update with an older version (90)
2991
- const updateMessage = {
2992
- dataSets: [createDataSet('main', 16, 1101)],
2993
- visibleDataSetsUrl,
2994
- locusUrl,
2995
- locusStateElements: [
2996
- {
2997
- htMeta: {
2998
- elementId: {type: 'locus' as const, id: 5, version: 90},
2999
- dataSetNames: ['main'],
3000
- },
3001
- data: {someField: 'value'},
3002
- },
3003
- ],
3004
- };
3713
+ // Verify sync was triggered
3714
+ assert.calledWith(
3715
+ webexRequest,
3716
+ sinon.match({
3717
+ method: 'GET',
3718
+ uri: `${mainDataSetUrl}/hashtree`,
3719
+ })
3720
+ );
3005
3721
 
3006
- parser.handleMessage(updateMessage, 'update with older version');
3722
+ // The watchdog timer should have been restarted after firing
3723
+ expect(parser.dataSets.main.heartbeatWatchdogTimer).to.not.be.undefined;
3007
3724
 
3008
- // Callback should not be called because the update was filtered out
3009
- assert.notCalled(callback);
3010
- });
3725
+ // Reset call history and set up new mock responses for the second sync
3726
+ webexRequest.resetHistory();
3727
+ mockGetHashesFromLocusResponse(
3728
+ mainDataSetUrl,
3729
+ new Array(16).fill('00000000000000000000000000000000'),
3730
+ createDataSet('main', 16, 1102)
3731
+ );
3732
+ mockSendSyncRequestResponse(mainDataSetUrl, null);
3011
3733
 
3012
- it('allows updates when version is newer than existing', () => {
3013
- const parser = setupParserWithObjects([
3014
- {
3015
- htMeta: {
3016
- elementId: {type: 'locus' as const, id: 5, version: 100},
3017
- dataSetNames: ['main'],
3018
- },
3019
- data: {existingField: 'existing'},
3020
- },
3021
- ]);
3734
+ // Advance time again to fire the watchdog a second time
3735
+ await clock.tickAsync(heartbeatIntervalMs);
3022
3736
 
3023
- // Try to update with a newer version (110)
3737
+ // Verify a second sync was triggered
3738
+ assert.calledWith(
3739
+ webexRequest,
3740
+ sinon.match({
3741
+ method: 'GET',
3742
+ uri: `${mainDataSetUrl}/hashtree`,
3743
+ })
3744
+ );
3745
+
3746
+ // And the watchdog should still be running
3747
+ expect(parser.dataSets.main.heartbeatWatchdogTimer).to.not.be.undefined;
3748
+ });
3749
+
3750
+ it('uses dataset-level heartbeatIntervalMs over top-level value', async () => {
3751
+ const parser = createHashTreeParser();
3752
+ const datasetLevelInterval = 3000;
3753
+ const topLevelInterval = 8000;
3754
+
3755
+ // Send heartbeat with both top-level and dataset-level heartbeatIntervalMs
3756
+ const heartbeatMessage = {
3757
+ dataSets: [
3758
+ {
3759
+ ...createDataSet('main', 16, 1100),
3760
+ root: parser.dataSets.main.hashTree.getRootHash(),
3761
+ heartbeatIntervalMs: datasetLevelInterval,
3762
+ },
3763
+ ],
3764
+ visibleDataSetsUrl,
3765
+ locusUrl,
3766
+ heartbeatIntervalMs: topLevelInterval,
3767
+ };
3768
+
3769
+ parser.handleMessage(heartbeatMessage, 'heartbeat with both levels');
3770
+
3771
+ expect(parser.dataSets.main.heartbeatWatchdogTimer).to.not.be.undefined;
3772
+
3773
+ // Mock sync responses
3774
+ const mainDataSetUrl = parser.dataSets.main.url;
3775
+ mockGetHashesFromLocusResponse(
3776
+ mainDataSetUrl,
3777
+ new Array(16).fill('00000000000000000000000000000000'),
3778
+ createDataSet('main', 16, 1101)
3779
+ );
3780
+ mockSendSyncRequestResponse(mainDataSetUrl, null);
3781
+
3782
+ // Watchdog should NOT fire at the top-level interval (8000ms)
3783
+ // It should fire at the dataset-level interval (3000ms)
3784
+ await clock.tickAsync(datasetLevelInterval - 1);
3785
+ assert.notCalled(webexRequest);
3786
+
3787
+ await clock.tickAsync(1);
3788
+ // Now at datasetLevelInterval, watchdog should have fired
3789
+ assert.calledWith(
3790
+ webexRequest,
3791
+ sinon.match({
3792
+ method: 'GET',
3793
+ uri: `${mainDataSetUrl}/hashtree`,
3794
+ })
3795
+ );
3796
+ });
3797
+
3798
+ it('falls back to top-level heartbeatIntervalMs when dataset-level is missing', async () => {
3799
+ const parser = createHashTreeParser();
3800
+ const topLevelInterval = 7000;
3801
+
3802
+ // Send heartbeat with top-level heartbeatIntervalMs but no dataset-level
3803
+ const heartbeatMessage = {
3804
+ dataSets: [
3805
+ {
3806
+ ...createDataSet('main', 16, 1100),
3807
+ root: parser.dataSets.main.hashTree.getRootHash(),
3808
+ heartbeatIntervalMs: undefined,
3809
+ },
3810
+ ],
3811
+ visibleDataSetsUrl,
3812
+ locusUrl,
3813
+ heartbeatIntervalMs: topLevelInterval,
3814
+ };
3815
+
3816
+ parser.handleMessage(heartbeatMessage, 'heartbeat with top-level only');
3817
+
3818
+ expect(parser.dataSets.main.heartbeatWatchdogTimer).to.not.be.undefined;
3819
+
3820
+ // Mock sync responses
3821
+ const mainDataSetUrl = parser.dataSets.main.url;
3822
+ mockGetHashesFromLocusResponse(
3823
+ mainDataSetUrl,
3824
+ new Array(16).fill('00000000000000000000000000000000'),
3825
+ createDataSet('main', 16, 1101)
3826
+ );
3827
+ mockSendSyncRequestResponse(mainDataSetUrl, null);
3828
+
3829
+ // Should fire at the top-level interval
3830
+ await clock.tickAsync(topLevelInterval - 1);
3831
+ assert.notCalled(webexRequest);
3832
+
3833
+ await clock.tickAsync(1);
3834
+ assert.calledWith(
3835
+ webexRequest,
3836
+ sinon.match({
3837
+ method: 'GET',
3838
+ uri: `${mainDataSetUrl}/hashtree`,
3839
+ })
3840
+ );
3841
+ });
3842
+
3843
+ it('does not start watchdog when dataset-level heartbeatIntervalMs is 0 even if top-level is set', async () => {
3844
+ const parser = createHashTreeParser();
3845
+
3846
+ // Send heartbeat with dataset-level 0 and a top-level value
3847
+ const heartbeatMessage = {
3848
+ dataSets: [
3849
+ {
3850
+ ...createDataSet('main', 16, 1100),
3851
+ root: parser.dataSets.main.hashTree.getRootHash(),
3852
+ heartbeatIntervalMs: 0,
3853
+ },
3854
+ ],
3855
+ visibleDataSetsUrl,
3856
+ locusUrl,
3857
+ heartbeatIntervalMs: 5000,
3858
+ };
3859
+
3860
+ parser.handleMessage(heartbeatMessage, 'heartbeat with dataset-level 0');
3861
+
3862
+ // Dataset-level 0 means no watchdog, should NOT fall back to top-level
3863
+ expect(parser.dataSets.main.heartbeatWatchdogTimer).to.be.undefined;
3864
+ });
3865
+ });
3866
+
3867
+ });
3868
+
3869
+ describe('#callLocusInfoUpdateCallback filtering', () => {
3870
+ // Helper to setup parser with initial objects and reset callback history
3871
+ function setupParserWithObjects(locusStateElements: any[]) {
3872
+ const parser = createHashTreeParser();
3873
+
3874
+ if (locusStateElements.length > 0) {
3875
+ // Determine which datasets to include based on the objects' dataSetNames
3876
+ const dataSetNames = new Set<string>();
3877
+ locusStateElements.forEach((element) => {
3878
+ element.htMeta?.dataSetNames?.forEach((name) => dataSetNames.add(name));
3879
+ });
3880
+
3881
+ const dataSets = [];
3882
+ if (dataSetNames.has('main')) dataSets.push(createDataSet('main', 16, 1100));
3883
+ if (dataSetNames.has('self')) dataSets.push(createDataSet('self', 1, 2100));
3884
+ if (dataSetNames.has('atd-unmuted')) dataSets.push(createDataSet('atd-unmuted', 16, 3100));
3885
+
3886
+ const setupMessage = {
3887
+ dataSets,
3888
+ visibleDataSetsUrl,
3889
+ locusUrl,
3890
+ locusStateElements,
3891
+ };
3892
+
3893
+ parser.handleMessage(setupMessage, 'setup');
3894
+ }
3895
+
3896
+ callback.resetHistory();
3897
+ return parser;
3898
+ }
3899
+
3900
+ it('filters out updates when a dataset has a higher version', () => {
3901
+ const parser = setupParserWithObjects([
3902
+ {
3903
+ htMeta: {
3904
+ elementId: {type: 'locus' as const, id: 5, version: 100},
3905
+ dataSetNames: ['main'],
3906
+ },
3907
+ data: {existingField: 'existing'},
3908
+ },
3909
+ ]);
3910
+
3911
+ // Try to update with an older version (90)
3912
+ const updateMessage = {
3913
+ dataSets: [createDataSet('main', 16, 1101)],
3914
+ visibleDataSetsUrl,
3915
+ locusUrl,
3916
+ locusStateElements: [
3917
+ {
3918
+ htMeta: {
3919
+ elementId: {type: 'locus' as const, id: 5, version: 90},
3920
+ dataSetNames: ['main'],
3921
+ },
3922
+ data: {someField: 'value'},
3923
+ },
3924
+ ],
3925
+ };
3926
+
3927
+ parser.handleMessage(updateMessage, 'update with older version');
3928
+
3929
+ // Callback should not be called because the update was filtered out
3930
+ assert.notCalled(callback);
3931
+ });
3932
+
3933
+ it('allows updates when version is newer than existing', () => {
3934
+ const parser = setupParserWithObjects([
3935
+ {
3936
+ htMeta: {
3937
+ elementId: {type: 'locus' as const, id: 5, version: 100},
3938
+ dataSetNames: ['main'],
3939
+ },
3940
+ data: {existingField: 'existing'},
3941
+ },
3942
+ ]);
3943
+
3944
+ // Try to update with a newer version (110)
3024
3945
  const updateMessage = {
3025
3946
  dataSets: [createDataSet('main', 16, 1101)],
3026
3947
  visibleDataSetsUrl,
@@ -3399,6 +4320,9 @@ describe('HashTreeParser', () => {
3399
4320
  parser.handleMessage(emptyMessage, 'empty elements');
3400
4321
 
3401
4322
  assert.notCalled(callback);
4323
+ assert.calledWith(metricsStub, BEHAVIORAL_METRICS.HASH_TREE_EMPTY_LOCUS_STATE_ELEMENTS, {
4324
+ debugId: 'test',
4325
+ });
3402
4326
  });
3403
4327
 
3404
4328
  it('always calls callback for MEETING_ENDED regardless of filtering', () => {
@@ -3629,7 +4553,7 @@ describe('HashTreeParser', () => {
3629
4553
  });
3630
4554
  });
3631
4555
 
3632
- describe('#resume', () => {
4556
+ describe('#resumeFromMessage', () => {
3633
4557
  const createResumeMessage = (visibleDataSets?, dataSets?) => ({
3634
4558
  locusUrl,
3635
4559
  visibleDataSetsUrl,
@@ -3656,7 +4580,7 @@ describe('HashTreeParser', () => {
3656
4580
 
3657
4581
  expect(parser.state).to.equal('stopped');
3658
4582
 
3659
- parser.resume(createResumeMessage());
4583
+ parser.resumeFromMessage(createResumeMessage());
3660
4584
 
3661
4585
  expect(parser.state).to.equal('active');
3662
4586
  });
@@ -3665,7 +4589,7 @@ describe('HashTreeParser', () => {
3665
4589
  const parser = createHashTreeParser();
3666
4590
  parser.stop();
3667
4591
 
3668
- parser.resume({
4592
+ parser.resumeFromMessage({
3669
4593
  locusUrl,
3670
4594
  visibleDataSetsUrl,
3671
4595
  dataSets: [createDataSet('main', 16, 2000)],
@@ -3684,7 +4608,7 @@ describe('HashTreeParser', () => {
3684
4608
  createDataSet('self', 2, 6000),
3685
4609
  ];
3686
4610
 
3687
- parser.resume(createResumeMessage(undefined, newDataSets));
4611
+ parser.resumeFromMessage(createResumeMessage(undefined, newDataSets));
3688
4612
 
3689
4613
  expect(Object.keys(parser.dataSets)).to.have.lengthOf(2);
3690
4614
  expect(parser.dataSets.main.leafCount).to.equal(8);
@@ -3706,7 +4630,7 @@ describe('HashTreeParser', () => {
3706
4630
  {name: 'self', url: 'https://locus-a.wbx2.com/locus/api/v1/loci/97d64a5f/participant/713e9f99/datasets/self'},
3707
4631
  ];
3708
4632
 
3709
- parser.resume(createResumeMessage(visibleDataSets, dataSets));
4633
+ parser.resumeFromMessage(createResumeMessage(visibleDataSets, dataSets));
3710
4634
 
3711
4635
  expect(parser.dataSets.main.hashTree).to.be.instanceOf(HashTree);
3712
4636
  expect(parser.dataSets.self.hashTree).to.be.instanceOf(HashTree);
@@ -3720,7 +4644,7 @@ describe('HashTreeParser', () => {
3720
4644
  const handleMessageStub = sinon.stub(parser, 'handleMessage');
3721
4645
 
3722
4646
  const message = createResumeMessage();
3723
- parser.resume(message);
4647
+ parser.resumeFromMessage(message);
3724
4648
 
3725
4649
  assert.calledOnceWithExactly(handleMessageStub, message, 'on resume');
3726
4650
  });
@@ -3740,7 +4664,7 @@ describe('HashTreeParser', () => {
3740
4664
  {name: 'atd-unmuted', url: 'https://locus-a.wbx2.com/locus/api/v1/loci/97d64a5f/datasets/atd-unmuted'},
3741
4665
  ];
3742
4666
 
3743
- parser.resume(createResumeMessage(visibleDataSets, dataSets));
4667
+ parser.resumeFromMessage(createResumeMessage(visibleDataSets, dataSets));
3744
4668
 
3745
4669
  expect(parser.visibleDataSets.some((vds) => vds.name === 'atd-unmuted')).to.be.false;
3746
4670
  expect(parser.visibleDataSets.some((vds) => vds.name === 'main')).to.be.true;
@@ -3748,6 +4672,67 @@ describe('HashTreeParser', () => {
3748
4672
  });
3749
4673
  });
3750
4674
 
4675
+ describe('#resumeFromApiResponse', () => {
4676
+ const exampleLocus = {
4677
+ participants: [],
4678
+ } as any;
4679
+
4680
+ it('should set state to active', async () => {
4681
+ const parser = createHashTreeParser();
4682
+ parser.stop();
4683
+
4684
+ expect(parser.state).to.equal('stopped');
4685
+
4686
+ sinon.stub(parser, 'initializeFromGetLociResponse').resolves();
4687
+
4688
+ await parser.resumeFromApiResponse(exampleLocus);
4689
+
4690
+ expect(parser.state).to.equal('active');
4691
+ });
4692
+
4693
+ it('should reset dataSets to empty', async () => {
4694
+ const parser = createHashTreeParser();
4695
+
4696
+ expect(Object.keys(parser.dataSets).length).to.be.greaterThan(0);
4697
+
4698
+ parser.stop();
4699
+
4700
+ sinon.stub(parser, 'initializeFromGetLociResponse').resolves();
4701
+
4702
+ await parser.resumeFromApiResponse(exampleLocus);
4703
+
4704
+ expect(parser.dataSets).to.deep.equal({});
4705
+ });
4706
+
4707
+ it('should call initializeFromGetLociResponse with the provided locus', async () => {
4708
+ const parser = createHashTreeParser();
4709
+ parser.stop();
4710
+
4711
+ const initStub = sinon.stub(parser, 'initializeFromGetLociResponse').resolves();
4712
+
4713
+ await parser.resumeFromApiResponse(exampleLocus);
4714
+
4715
+ assert.calledOnceWithExactly(initStub, exampleLocus);
4716
+ });
4717
+
4718
+ it('should propagate errors from initializeFromGetLociResponse', async () => {
4719
+ const parser = createHashTreeParser();
4720
+ parser.stop();
4721
+
4722
+ const error = new Error('initialization failed');
4723
+ const initStub = sinon.stub(parser, 'initializeFromGetLociResponse').rejects(error);
4724
+
4725
+ let caughtError: Error | undefined;
4726
+ try {
4727
+ await parser.resumeFromApiResponse(exampleLocus);
4728
+ } catch (e) {
4729
+ caughtError = e;
4730
+ }
4731
+
4732
+ expect(caughtError).to.equal(error);
4733
+ });
4734
+ });
4735
+
3751
4736
  describe('#handleLocusUpdate when stopped', () => {
3752
4737
  it('should return early without processing when parser is stopped', () => {
3753
4738
  const parser = createHashTreeParser();
@@ -3783,37 +4768,822 @@ describe('HashTreeParser', () => {
3783
4768
  });
3784
4769
  });
3785
4770
 
3786
- describe('#cleanUp', () => {
3787
- it('should stop the parser, clear all timers and clear all dataSets', () => {
4771
+ describe('#syncAllDatasets', () => {
4772
+ it('should sync all datasets that have hash trees in priority order', async () => {
3788
4773
  const parser = createHashTreeParser();
3789
4774
 
3790
- // Send a message to set up sync timers via runSyncAlgorithm
3791
- const message = {
3792
- dataSets: [
3793
- {
3794
- ...createDataSet('main', 16, 1100),
3795
- root: 'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa1',
3796
- },
3797
- ],
4775
+ // parser starts with main (leafCount=16) and self (leafCount=1) as visible datasets with hash trees
4776
+ // atd-unmuted has no hash tree (not visible)
4777
+ expect(parser.dataSets.main.hashTree).to.be.instanceOf(HashTree);
4778
+ expect(parser.dataSets.self.hashTree).to.be.instanceOf(HashTree);
4779
+
4780
+ const mainUrl = parser.dataSets.main.url;
4781
+ const selfUrl = parser.dataSets.self.url;
4782
+
4783
+ // Mock GET hashtree for main (leafCount > 1, so it does GET first)
4784
+ mockGetHashesFromLocusResponse(
4785
+ mainUrl,
4786
+ new Array(16).fill(EMPTY_HASH),
4787
+ createDataSet('main', 16, 1100)
4788
+ );
4789
+
4790
+ // Mock POST sync for main - return matching root hash so no further sync needed
4791
+ const mainSyncDataSet = createDataSet('main', 16, 1100);
4792
+ mainSyncDataSet.root = parser.dataSets.main.hashTree.getRootHash();
4793
+ mockSendSyncRequestResponse(mainUrl, {
4794
+ dataSets: [mainSyncDataSet],
3798
4795
  visibleDataSetsUrl,
3799
4796
  locusUrl,
3800
- heartbeatIntervalMs: 5000,
3801
- locusStateElements: [
3802
- {
3803
- htMeta: {
3804
- elementId: {type: 'locus' as const, id: 0, version: 201},
3805
- dataSetNames: ['main'],
3806
- },
3807
- data: {someData: 'value'},
3808
- },
3809
- ],
3810
- };
4797
+ locusStateElements: [],
4798
+ });
3811
4799
 
3812
- parser.handleMessage(message, 'setup timers');
4800
+ // Mock POST sync for self (leafCount=1, skips GET hashtree)
4801
+ const selfSyncDataSet = createDataSet('self', 1, 2100);
4802
+ selfSyncDataSet.root = parser.dataSets.self.hashTree.getRootHash();
4803
+ mockSendSyncRequestResponse(selfUrl, {
4804
+ dataSets: [selfSyncDataSet],
4805
+ visibleDataSetsUrl,
4806
+ locusUrl,
4807
+ locusStateElements: [],
4808
+ });
3813
4809
 
3814
- // Verify timers were set by handleMessage
3815
- expect(parser.dataSets.main.timer).to.not.be.undefined;
3816
- expect(parser.dataSets.main.heartbeatWatchdogTimer).to.not.be.undefined;
4810
+ await parser.syncAllDatasets();
4811
+
4812
+ // Verify GET hashtree was called for main only (not self, because leafCount=1)
4813
+ assert.calledWith(webexRequest, sinon.match({method: 'GET', uri: `${mainUrl}/hashtree`}));
4814
+ assert.neverCalledWith(webexRequest, sinon.match({method: 'GET', uri: `${selfUrl}/hashtree`}));
4815
+
4816
+ // Verify POST sync was called for both
4817
+ assert.calledWith(webexRequest, sinon.match({method: 'POST', uri: `${mainUrl}/sync`}));
4818
+ assert.calledWith(webexRequest, sinon.match({method: 'POST', uri: `${selfUrl}/sync`}));
4819
+
4820
+ // Verify main was synced before self (priority order)
4821
+ const mainSyncCallIndex = webexRequest.args.findIndex(
4822
+ (args) => args[0]?.method === 'GET' && args[0]?.uri === `${mainUrl}/hashtree`
4823
+ );
4824
+ const selfSyncCallIndex = webexRequest.args.findIndex(
4825
+ (args) => args[0]?.method === 'POST' && args[0]?.uri === `${selfUrl}/sync`
4826
+ );
4827
+ expect(mainSyncCallIndex).to.be.lessThan(selfSyncCallIndex);
4828
+
4829
+ // Verify syncAllBackoffType is reset
4830
+ expect(parser.syncAllBackoffType).to.equal(SyncAllBackoffType.NONE);
4831
+ });
4832
+
4833
+ it('should return immediately when state is stopped', async () => {
4834
+ const parser = createHashTreeParser();
4835
+ parser.stop();
4836
+
4837
+ await parser.syncAllDatasets();
4838
+
4839
+ // No sync requests should have been made (only the initial sync from constructor)
4840
+ // Reset history to clear constructor calls then verify
4841
+ const callCountBefore = webexRequest.callCount;
4842
+ await parser.syncAllDatasets();
4843
+ assert.equal(webexRequest.callCount, callCountBefore);
4844
+ });
4845
+
4846
+ it('should guard against concurrent calls', async () => {
4847
+ const parser = createHashTreeParser();
4848
+
4849
+ const mainUrl = parser.dataSets.main.url;
4850
+ const selfUrl = parser.dataSets.self.url;
4851
+
4852
+ // Use a deferred promise for the main sync to control timing
4853
+ let resolveMainSync;
4854
+ webexRequest
4855
+ .withArgs(sinon.match({method: 'GET', uri: `${mainUrl}/hashtree`}))
4856
+ .returns(new Promise((resolve) => { resolveMainSync = resolve; }));
4857
+
4858
+ mockSendSyncRequestResponse(mainUrl, {
4859
+ dataSets: [createDataSet('main', 16, 1100)],
4860
+ visibleDataSetsUrl,
4861
+ locusUrl,
4862
+ locusStateElements: [],
4863
+ });
4864
+
4865
+ mockSendSyncRequestResponse(selfUrl, {
4866
+ dataSets: [createDataSet('self', 1, 2100)],
4867
+ visibleDataSetsUrl,
4868
+ locusUrl,
4869
+ locusStateElements: [],
4870
+ });
4871
+
4872
+ // Start first call
4873
+ const promise1 = parser.syncAllDatasets();
4874
+ // Start second call while first is in progress
4875
+ const promise2 = parser.syncAllDatasets();
4876
+
4877
+ // Resolve the pending request
4878
+ resolveMainSync({
4879
+ body: {
4880
+ hashes: new Array(16).fill(EMPTY_HASH),
4881
+ dataSet: createDataSet('main', 16, 1100),
4882
+ },
4883
+ });
4884
+
4885
+ await promise1;
4886
+ await promise2;
4887
+
4888
+ // GET hashtree for main should only be called once (second syncAllDatasets returned immediately)
4889
+ const getHashtreeCalls = webexRequest.args.filter(
4890
+ (args) => args[0]?.method === 'GET' && args[0]?.uri === `${mainUrl}/hashtree`
4891
+ );
4892
+ expect(getHashtreeCalls).to.have.lengthOf(1);
4893
+ });
4894
+
4895
+ it('should sync only LLM datasets when onlyLLM=true', async () => {
4896
+ const parser = createHashTreeParser();
4897
+
4898
+ const mainUrl = parser.dataSets.main.url;
4899
+ const selfUrl = parser.dataSets.self.url;
4900
+
4901
+ mockGetHashesFromLocusResponse(
4902
+ mainUrl,
4903
+ new Array(16).fill(EMPTY_HASH),
4904
+ createDataSet('main', 16, 1100)
4905
+ );
4906
+
4907
+ const mainSyncDs = createDataSet('main', 16, 1100);
4908
+ mainSyncDs.root = parser.dataSets.main.hashTree.getRootHash();
4909
+ mockSendSyncRequestResponse(mainUrl, {
4910
+ dataSets: [mainSyncDs],
4911
+ visibleDataSetsUrl,
4912
+ locusUrl,
4913
+ locusStateElements: [],
4914
+ });
4915
+
4916
+ await parser.syncAllDatasets({onlyLLM: true});
4917
+
4918
+ // main is an LLM dataset, so it should have been synced
4919
+ assert.calledWith(webexRequest, sinon.match({method: 'GET', uri: `${mainUrl}/hashtree`}));
4920
+
4921
+ // self is NOT an LLM dataset, so it should NOT have been synced
4922
+ assert.neverCalledWith(webexRequest, sinon.match({method: 'POST', uri: `${selfUrl}/sync`}));
4923
+ assert.neverCalledWith(webexRequest, sinon.match({method: 'GET', uri: `${selfUrl}/hashtree`}));
4924
+ });
4925
+
4926
+ it('uses the syncAll random backoff when reporting sync metrics', async () => {
4927
+ mathRandomStub.returns(0.5); // syncAll backoff = 0.5^2 * 1000 = 250ms
4928
+
4929
+ const syncLatencyTracker = {
4930
+ saveLatency: sinon.stub(),
4931
+ saveTimestamp: sinon.stub(),
4932
+ getLocusSyncLatency: sinon.stub(),
4933
+ clearLocusSyncLatency: sinon.stub(),
4934
+ completeLocusSyncLatency: sinon.stub(),
4935
+ };
4936
+ const parser = createHashTreeParser(
4937
+ undefined,
4938
+ undefined,
4939
+ ['atd-unmuted'],
4940
+ syncLatencyTracker
4941
+ );
4942
+ const mainUrl = parser.dataSets.main.url;
4943
+
4944
+ mockGetHashesFromLocusResponse(
4945
+ mainUrl,
4946
+ new Array(16).fill('00000000000000000000000000000000'),
4947
+ createDataSet('main', 16, 1100)
4948
+ );
4949
+ mockSendSyncRequestResponse(mainUrl, null);
4950
+
4951
+ const syncAllPromise = parser.syncAllDatasets({onlyLLM: true});
4952
+
4953
+ await clock.tickAsync(250);
4954
+ await syncAllPromise;
4955
+
4956
+ assert.calledWithExactly(
4957
+ syncLatencyTracker.saveLatency,
4958
+ 'internal.client.locus.sync.random.backoff',
4959
+ 250,
4960
+ {
4961
+ meetingId: 'meeting-1',
4962
+ dataSetName: 'main',
4963
+ }
4964
+ );
4965
+ });
4966
+
4967
+ it('should upgrade scope from onlyLLM=true to all datasets when onlyLLM=false call arrives during backoff', async () => {
4968
+ // Make Math.random return 1 so backoff = 1^2 * 1000 = 1000ms (non-zero delay for interleaving)
4969
+ mathRandomStub.returns(1);
4970
+
4971
+ const parser = createHashTreeParser();
4972
+
4973
+ const mainUrl = parser.dataSets.main.url;
4974
+ const selfUrl = parser.dataSets.self.url;
4975
+
4976
+ mockGetHashesFromLocusResponse(
4977
+ mainUrl,
4978
+ new Array(16).fill(EMPTY_HASH),
4979
+ createDataSet('main', 16, 1100)
4980
+ );
4981
+
4982
+ const mainSyncDs = createDataSet('main', 16, 1100);
4983
+ mainSyncDs.root = parser.dataSets.main.hashTree.getRootHash();
4984
+ mockSendSyncRequestResponse(mainUrl, {
4985
+ dataSets: [mainSyncDs],
4986
+ visibleDataSetsUrl,
4987
+ locusUrl,
4988
+ locusStateElements: [],
4989
+ });
4990
+
4991
+ const selfSyncDs = createDataSet('self', 1, 2100);
4992
+ selfSyncDs.root = parser.dataSets.self.hashTree.getRootHash();
4993
+ mockSendSyncRequestResponse(selfUrl, {
4994
+ dataSets: [selfSyncDs],
4995
+ visibleDataSetsUrl,
4996
+ locusUrl,
4997
+ locusStateElements: [],
4998
+ });
4999
+
5000
+ // First call with onlyLLM=true starts backoff
5001
+ const promise1 = parser.syncAllDatasets({onlyLLM: true});
5002
+ expect(parser.syncAllBackoffType).to.equal(SyncAllBackoffType.ONLY_LLM);
5003
+
5004
+ // Second call with onlyLLM=false upgrades the scope during backoff
5005
+ const promise2 = parser.syncAllDatasets({onlyLLM: false});
5006
+ expect(parser.syncAllBackoffType).to.equal(SyncAllBackoffType.ALL);
5007
+
5008
+ // Advance clock past the backoff delay (1000ms)
5009
+ await clock.tickAsync(1000);
5010
+
5011
+ await promise1;
5012
+ await promise2;
5013
+
5014
+ // Both main (LLM) and self (non-LLM) should have been synced
5015
+ assert.calledWith(webexRequest, sinon.match({method: 'GET', uri: `${mainUrl}/hashtree`}));
5016
+ assert.calledWith(webexRequest, sinon.match({method: 'POST', uri: `${selfUrl}/sync`}));
5017
+ });
5018
+
5019
+ it('should not downgrade scope from onlyLLM=false when onlyLLM=true call arrives during backoff', async () => {
5020
+ // Make Math.random return 1 so backoff = 1^2 * 1000 = 1000ms (non-zero delay for interleaving)
5021
+ mathRandomStub.returns(1);
5022
+
5023
+ const parser = createHashTreeParser();
5024
+
5025
+ const mainUrl = parser.dataSets.main.url;
5026
+ const selfUrl = parser.dataSets.self.url;
5027
+
5028
+ mockGetHashesFromLocusResponse(
5029
+ mainUrl,
5030
+ new Array(16).fill(EMPTY_HASH),
5031
+ createDataSet('main', 16, 1100)
5032
+ );
5033
+
5034
+ const mainSyncDs = createDataSet('main', 16, 1100);
5035
+ mainSyncDs.root = parser.dataSets.main.hashTree.getRootHash();
5036
+ mockSendSyncRequestResponse(mainUrl, {
5037
+ dataSets: [mainSyncDs],
5038
+ visibleDataSetsUrl,
5039
+ locusUrl,
5040
+ locusStateElements: [],
5041
+ });
5042
+
5043
+ const selfSyncDs = createDataSet('self', 1, 2100);
5044
+ selfSyncDs.root = parser.dataSets.self.hashTree.getRootHash();
5045
+ mockSendSyncRequestResponse(selfUrl, {
5046
+ dataSets: [selfSyncDs],
5047
+ visibleDataSetsUrl,
5048
+ locusUrl,
5049
+ locusStateElements: [],
5050
+ });
5051
+
5052
+ // First call with onlyLLM=false starts backoff with all-datasets scope
5053
+ const promise1 = parser.syncAllDatasets({onlyLLM: false});
5054
+ expect(parser.syncAllBackoffType).to.equal(SyncAllBackoffType.ALL);
5055
+
5056
+ // Second call with onlyLLM=true should NOT downgrade the scope
5057
+ const promise2 = parser.syncAllDatasets({onlyLLM: true});
5058
+ expect(parser.syncAllBackoffType).to.equal(SyncAllBackoffType.ALL);
5059
+
5060
+ // Advance clock past the backoff delay (1000ms)
5061
+ await clock.tickAsync(1000);
5062
+
5063
+ await promise1;
5064
+ await promise2;
5065
+
5066
+ // Both main (LLM) and self (non-LLM) should have been synced (scope was not downgraded)
5067
+ assert.calledWith(webexRequest, sinon.match({method: 'GET', uri: `${mainUrl}/hashtree`}));
5068
+ assert.calledWith(webexRequest, sinon.match({method: 'POST', uri: `${selfUrl}/sync`}));
5069
+ });
5070
+
5071
+ it('should skip datasets that received messages during the backoff sleep', async () => {
5072
+ // Make Math.random return 1 so backoff = 1^2 * 1000 = 1000ms
5073
+ mathRandomStub.returns(1);
5074
+
5075
+ const parser = createHashTreeParser();
5076
+
5077
+ const mainUrl = parser.dataSets.main.url;
5078
+ const selfUrl = parser.dataSets.self.url;
5079
+ const atdUnmutedUrl = parser.dataSets['atd-unmuted'].url;
5080
+
5081
+ // Setup mocks only for self (main and atd-unmuted should be skipped)
5082
+ mockSendSyncRequestResponse(selfUrl, {
5083
+ dataSets: [createDataSet('self', 1, 2100)],
5084
+ visibleDataSetsUrl,
5085
+ locusUrl,
5086
+ locusStateElements: [],
5087
+ });
5088
+
5089
+ // Start syncAllDatasets - begins backoff sleep
5090
+ const promise = parser.syncAllDatasets();
5091
+ expect(parser.syncAllBackoffType).to.equal(SyncAllBackoffType.ALL);
5092
+
5093
+ // Simulate a normal message arriving for "main" during the backoff sleep
5094
+ parser.handleMessage({
5095
+ dataSets: [createDataSet('main', 16, 1100)],
5096
+ visibleDataSetsUrl,
5097
+ locusUrl,
5098
+ locusStateElements: [
5099
+ {
5100
+ htMeta: {
5101
+ elementId: {type: 'locus' as const, id: 0, version: 201},
5102
+ dataSetNames: ['main'],
5103
+ },
5104
+ data: {someData: 'value'},
5105
+ },
5106
+ ],
5107
+ });
5108
+
5109
+ // Simulate a heartbeat message arriving for "atd-unmuted" during the backoff sleep
5110
+ parser.handleMessage(
5111
+ createHeartbeatMessage('atd-unmuted', 1, 1100, parser.dataSets['atd-unmuted'].root)
5112
+ );
5113
+
5114
+ // Advance clock past the backoff delay
5115
+ await clock.tickAsync(1000);
5116
+ await promise;
5117
+
5118
+ // main should NOT have been synced (it received a normal message during backoff)
5119
+ assert.neverCalledWith(webexRequest, sinon.match({method: 'GET', uri: `${mainUrl}/hashtree`}));
5120
+ assert.neverCalledWith(webexRequest, sinon.match({method: 'POST', uri: `${mainUrl}/sync`}));
5121
+
5122
+ // atd-unmuted should NOT have been synced (it received a heartbeat during backoff)
5123
+ assert.neverCalledWith(webexRequest, sinon.match({method: 'GET', uri: `${atdUnmutedUrl}/hashtree`}));
5124
+ assert.neverCalledWith(webexRequest, sinon.match({method: 'POST', uri: `${atdUnmutedUrl}/sync`}));
5125
+
5126
+ // self SHOULD have been synced (no messages received for it during backoff)
5127
+ assert.calledWith(webexRequest, sinon.match({method: 'POST', uri: `${selfUrl}/sync`}));
5128
+ });
5129
+
5130
+ it('should skip datasets that do not have a hash tree', async () => {
5131
+ // Create parser with metadata that only has main and self as visible (not atd-unmuted)
5132
+ const metadataWithoutAtd = {
5133
+ ...exampleMetadata,
5134
+ visibleDataSets: exampleMetadata.visibleDataSets.filter((ds) => ds.name !== 'atd-unmuted'),
5135
+ };
5136
+ const parser = createHashTreeParser(exampleInitialLocus, metadataWithoutAtd);
5137
+
5138
+ // atd-unmuted is in dataSets but has no hashTree (not visible)
5139
+ expect(parser.dataSets['atd-unmuted']).to.exist;
5140
+ expect(parser.dataSets['atd-unmuted'].hashTree).to.be.undefined;
5141
+
5142
+ const atdUrl = parser.dataSets['atd-unmuted'].url;
5143
+ const mainUrl = parser.dataSets.main.url;
5144
+ const selfUrl = parser.dataSets.self.url;
5145
+
5146
+ mockGetHashesFromLocusResponse(
5147
+ mainUrl,
5148
+ new Array(16).fill(EMPTY_HASH),
5149
+ createDataSet('main', 16, 1100)
5150
+ );
5151
+
5152
+ const mainSyncDs = createDataSet('main', 16, 1100);
5153
+ mainSyncDs.root = parser.dataSets.main.hashTree.getRootHash();
5154
+ mockSendSyncRequestResponse(mainUrl, {
5155
+ dataSets: [mainSyncDs],
5156
+ visibleDataSetsUrl,
5157
+ locusUrl,
5158
+ locusStateElements: [],
5159
+ });
5160
+
5161
+ const selfSyncDs = createDataSet('self', 1, 2100);
5162
+ selfSyncDs.root = parser.dataSets.self.hashTree.getRootHash();
5163
+ mockSendSyncRequestResponse(selfUrl, {
5164
+ dataSets: [selfSyncDs],
5165
+ visibleDataSetsUrl,
5166
+ locusUrl,
5167
+ locusStateElements: [],
5168
+ });
5169
+
5170
+ await parser.syncAllDatasets();
5171
+
5172
+ // No requests should have been made for atd-unmuted
5173
+ assert.neverCalledWith(webexRequest, sinon.match({uri: sinon.match(atdUrl)}));
5174
+ });
5175
+ });
5176
+
5177
+ describe('#handleMessage sync queue', () => {
5178
+ it('should deduplicate: not sync the same dataset twice when enqueued multiple times', async () => {
5179
+ const parser = createHashTreeParser();
5180
+
5181
+ const mainUrl = parser.dataSets.main.url;
5182
+
5183
+ // Setup mocks before triggering syncs
5184
+ mockGetHashesFromLocusResponse(
5185
+ mainUrl,
5186
+ new Array(16).fill(EMPTY_HASH),
5187
+ createDataSet('main', 16, 1101)
5188
+ );
5189
+
5190
+ const mainSyncDs = createDataSet('main', 16, 1101);
5191
+ mainSyncDs.root = parser.dataSets.main.hashTree.getRootHash();
5192
+ mockSendSyncRequestResponse(mainUrl, {
5193
+ dataSets: [mainSyncDs],
5194
+ visibleDataSetsUrl,
5195
+ locusUrl,
5196
+ locusStateElements: [],
5197
+ });
5198
+
5199
+ // Send two heartbeat messages (no locusStateElements) with different root hashes for main
5200
+ parser.handleMessage(createHeartbeatMessage('main', 16, 1100, 'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa1'), 'first');
5201
+ parser.handleMessage(createHeartbeatMessage('main', 16, 1101, 'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa2'), 'second');
5202
+
5203
+ // The second call resets the timer. After 1000ms, only one sync fires.
5204
+ await clock.tickAsync(1000);
5205
+
5206
+ // Only one GET hashtree call should have been made for main
5207
+ const getHashtreeCalls = webexRequest.args.filter(
5208
+ (args) => args[0]?.method === 'GET' && args[0]?.uri === `${mainUrl}/hashtree`
5209
+ );
5210
+ expect(getHashtreeCalls).to.have.lengthOf(1);
5211
+ });
5212
+
5213
+ it('should stop processing the sync queue when parser is stopped mid-queue', async () => {
5214
+ const parser = createHashTreeParser();
5215
+
5216
+ const mainUrl = parser.dataSets.main.url;
5217
+ const selfUrl = parser.dataSets.self.url;
5218
+
5219
+ // Mock main GET hashtree with a deferred promise so we can control when it resolves
5220
+ let resolveMainHashtree;
5221
+ webexRequest
5222
+ .withArgs(sinon.match({method: 'GET', uri: `${mainUrl}/hashtree`}))
5223
+ .callsFake(() => new Promise((resolve) => { resolveMainHashtree = resolve; }));
5224
+
5225
+ // Send a heartbeat message that triggers sync timers for both main and self
5226
+ parser.handleMessage(
5227
+ createHeartbeatMessage('main', 16, 1100, 'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa1'),
5228
+ 'trigger main sync'
5229
+ );
5230
+ parser.handleMessage(
5231
+ createHeartbeatMessage('self', 1, 2100, 'bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb1'),
5232
+ 'trigger self sync'
5233
+ );
5234
+
5235
+ // Fire the timers - main sync starts (calls GET hashtree, which blocks)
5236
+ await clock.tickAsync(1000);
5237
+
5238
+ // Stop the parser while main sync is in progress
5239
+ parser.stop();
5240
+
5241
+ // Resolve the pending main GET request
5242
+ resolveMainHashtree({
5243
+ body: {
5244
+ hashes: new Array(16).fill(EMPTY_HASH),
5245
+ dataSet: createDataSet('main', 16, 1100),
5246
+ },
5247
+ });
5248
+
5249
+ await clock.tickAsync(0);
5250
+
5251
+ // Self sync should NOT have been triggered because parser was stopped
5252
+ assert.neverCalledWith(webexRequest, sinon.match({method: 'POST', uri: `${selfUrl}/sync`}));
5253
+ assert.neverCalledWith(webexRequest, sinon.match({method: 'GET', uri: `${selfUrl}/hashtree`}));
5254
+ });
5255
+ });
5256
+
5257
+ describe('#stop sync queue', () => {
5258
+ it('should clear the syncQueue when stopped so remaining queued items are not processed', async () => {
5259
+ const parser = createHashTreeParser();
5260
+
5261
+ const mainUrl = parser.dataSets.main.url;
5262
+ const selfUrl = parser.dataSets.self.url;
5263
+
5264
+ // Mock main GET hashtree with a deferred promise so we can control when it resolves
5265
+ let resolveMainHashtree;
5266
+ webexRequest
5267
+ .withArgs(sinon.match({method: 'GET', uri: `${mainUrl}/hashtree`}))
5268
+ .callsFake(() => new Promise((resolve) => { resolveMainHashtree = resolve; }));
5269
+
5270
+ // Enqueue syncs for both main and self by sending heartbeat messages
5271
+ parser.handleMessage(
5272
+ createHeartbeatMessage('main', 16, 1100, 'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa1'),
5273
+ 'trigger main sync'
5274
+ );
5275
+ parser.handleMessage(
5276
+ createHeartbeatMessage('self', 1, 2100, 'bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb1'),
5277
+ 'trigger self sync'
5278
+ );
5279
+
5280
+ // Fire the timers - main sync starts and blocks on GET hashtree
5281
+ await clock.tickAsync(1000);
5282
+
5283
+ // Verify that self is still in the queue (main is being processed, self is waiting)
5284
+ // Now stop the parser - this should clear the syncQueue
5285
+ parser.stop();
5286
+
5287
+ // Resolve the pending main GET request so the in-flight sync can finish
5288
+ resolveMainHashtree({
5289
+ body: {
5290
+ hashes: new Array(16).fill(EMPTY_HASH),
5291
+ dataSet: createDataSet('main', 16, 1100),
5292
+ },
5293
+ });
5294
+
5295
+ await clock.tickAsync(0);
5296
+
5297
+ // Self should never have been synced because stop() cleared the queue
5298
+ const selfGetCalls = webexRequest.args.filter(
5299
+ (args) => args[0]?.method === 'GET' && args[0]?.uri === `${selfUrl}/hashtree`
5300
+ );
5301
+ expect(selfGetCalls).to.have.lengthOf(0);
5302
+ });
5303
+ });
5304
+
5305
+ describe('#performSync abort controller', () => {
5306
+ it('should reuse an existing syncAbortController if one is already set on the dataset', async () => {
5307
+ const parser = createHashTreeParser();
5308
+ const mainUrl = parser.dataSets.main.url;
5309
+
5310
+ // Pre-set an AbortController on the dataset before sync starts
5311
+ const existingController = new AbortController();
5312
+ parser.dataSets.main.syncAbortController = existingController;
5313
+
5314
+ // Use a deferred promise for GET hashtree so we can inspect the controller mid-sync
5315
+ let resolveGetHashtree;
5316
+ webexRequest.withArgs(sinon.match({method: 'GET', uri: `${mainUrl}/hashtree`})).callsFake(
5317
+ () =>
5318
+ new Promise((resolve) => {
5319
+ resolveGetHashtree = resolve;
5320
+ })
5321
+ );
5322
+
5323
+ // Trigger sync for main
5324
+ parser.handleMessage(
5325
+ createHeartbeatMessage('main', 16, 1100, 'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa1'),
5326
+ 'trigger main sync'
5327
+ );
5328
+
5329
+ await clock.tickAsync(1000);
5330
+
5331
+ // While sync is in-flight, verify the controller is the same one we pre-set
5332
+ expect(parser.dataSets.main.syncAbortController).to.equal(existingController);
5333
+
5334
+ // Resolve GET hashtree with matching hashes (no sync needed)
5335
+ resolveGetHashtree({body: {}});
5336
+ await testUtils.flushPromises();
5337
+
5338
+ // After sync completes, syncAbortController is cleared in finally
5339
+ expect(parser.dataSets.main.syncAbortController).to.be.undefined;
5340
+ });
5341
+
5342
+ it('should abort the sync before /sync request when the controller is aborted during getHashesFromLocus', async () => {
5343
+ const parser = createHashTreeParser();
5344
+ const mainUrl = parser.dataSets.main.url;
5345
+
5346
+ // Use a deferred promise for GET hashtree so we can abort while it's pending
5347
+ let resolveGetHashtree;
5348
+ webexRequest.withArgs(sinon.match({method: 'GET', uri: `${mainUrl}/hashtree`})).callsFake(
5349
+ () =>
5350
+ new Promise((resolve) => {
5351
+ resolveGetHashtree = resolve;
5352
+ })
5353
+ );
5354
+
5355
+ // Mock POST sync - should NOT be called if abort works
5356
+ mockSendSyncRequestResponse(mainUrl, null);
5357
+
5358
+ // Trigger sync for main via heartbeat with mismatched root hash
5359
+ parser.handleMessage(
5360
+ createHeartbeatMessage('main', 16, 1100, 'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa1'),
5361
+ 'trigger main sync'
5362
+ );
5363
+
5364
+ // Fire the timer to start the sync
5365
+ await clock.tickAsync(1000);
5366
+
5367
+ // Now abort the controller while getHashesFromLocus is pending
5368
+ expect(parser.dataSets.main.syncAbortController).to.not.be.undefined;
5369
+ parser.dataSets.main.syncAbortController.abort();
5370
+
5371
+ // Resolve GET hashtree with mismatched hashes so the code would normally proceed to /sync
5372
+ resolveGetHashtree({
5373
+ body: {
5374
+ hashes: new Array(16).fill('aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa1'),
5375
+ dataSet: createDataSet('main', 16, 1100),
5376
+ },
5377
+ });
5378
+
5379
+ await testUtils.flushPromises();
5380
+
5381
+ // POST sync should NOT have been called because the controller was aborted
5382
+ assert.neverCalledWith(webexRequest, sinon.match({method: 'POST', uri: `${mainUrl}/sync`}));
5383
+ });
5384
+
5385
+ it('should abort the sync before /sync request when the controller is aborted for leafCount === 1 datasets', async () => {
5386
+ const parser = createHashTreeParser();
5387
+ const selfUrl = parser.dataSets.self.url;
5388
+
5389
+ // Pre-set an already-aborted controller so performSync picks it up via ??
5390
+ const abortedController = new AbortController();
5391
+ abortedController.abort();
5392
+ parser.dataSets.self.syncAbortController = abortedController;
5393
+
5394
+ // Mock POST sync - should NOT be called
5395
+ mockSendSyncRequestResponse(selfUrl, null);
5396
+
5397
+ // Trigger sync for self via heartbeat with mismatched root hash
5398
+ parser.handleMessage(
5399
+ {
5400
+ dataSets: [
5401
+ {
5402
+ ...createDataSet('self', 1, 2100),
5403
+ url: parser.dataSets.self.url,
5404
+ root: 'bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb1',
5405
+ },
5406
+ ],
5407
+ visibleDataSetsUrl,
5408
+ locusUrl,
5409
+ },
5410
+ 'trigger self sync'
5411
+ );
5412
+
5413
+ // Fire the timer to start the sync
5414
+ await clock.tickAsync(1000);
5415
+
5416
+ // GET hashtree should NOT have been called (leafCount === 1 skips it)
5417
+ assert.neverCalledWith(webexRequest, sinon.match({method: 'GET', uri: `${selfUrl}/hashtree`}));
5418
+
5419
+ // POST sync should NOT have been called because the controller was already aborted
5420
+ assert.neverCalledWith(webexRequest, sinon.match({method: 'POST', uri: `${selfUrl}/sync`}));
5421
+ });
5422
+
5423
+ it('should unconditionally clear syncAbortController in the finally block', async () => {
5424
+ const parser = createHashTreeParser();
5425
+ const mainUrl = parser.dataSets.main.url;
5426
+
5427
+ // Mock GET hashtree to return matching hashes (early return, no sync needed)
5428
+ webexRequest
5429
+ .withArgs(sinon.match({method: 'GET', uri: `${mainUrl}/hashtree`}))
5430
+ .resolves({body: {}});
5431
+
5432
+ // Trigger sync for main
5433
+ parser.handleMessage(
5434
+ createHeartbeatMessage('main', 16, 1100, 'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa1'),
5435
+ 'trigger main sync'
5436
+ );
5437
+
5438
+ await clock.tickAsync(1000);
5439
+
5440
+ // After sync completes (even via early return), syncAbortController should be cleared
5441
+ expect(parser.dataSets.main.syncAbortController).to.be.undefined;
5442
+ });
5443
+
5444
+ it('should unconditionally clear syncAbortController even when sync throws an error', async () => {
5445
+ const parser = createHashTreeParser();
5446
+ const mainUrl = parser.dataSets.main.url;
5447
+
5448
+ // Mock GET hashtree to reject with a non-409 error
5449
+ webexRequest
5450
+ .withArgs(sinon.match({method: 'GET', uri: `${mainUrl}/hashtree`}))
5451
+ .rejects({statusCode: 500, message: 'Internal Server Error'});
5452
+
5453
+ // Trigger sync for main
5454
+ parser.handleMessage(
5455
+ createHeartbeatMessage('main', 16, 1100, 'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa1'),
5456
+ 'trigger main sync'
5457
+ );
5458
+
5459
+ await clock.tickAsync(1000);
5460
+
5461
+ // After sync completes with error, syncAbortController should still be cleared
5462
+ expect(parser.dataSets.main.syncAbortController).to.be.undefined;
5463
+ });
5464
+
5465
+ it('should reuse a pre-existing abort controller and respect its aborted state', async () => {
5466
+ const parser = createHashTreeParser();
5467
+ const mainUrl = parser.dataSets.main.url;
5468
+
5469
+ // Pre-set an AbortController and abort it before sync starts
5470
+ const preAbortedController = new AbortController();
5471
+ preAbortedController.abort();
5472
+ parser.dataSets.main.syncAbortController = preAbortedController;
5473
+
5474
+ // Mock GET hashtree to return mismatched hashes
5475
+ mockGetHashesFromLocusResponse(
5476
+ mainUrl,
5477
+ new Array(16).fill('aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa1'),
5478
+ createDataSet('main', 16, 1100)
5479
+ );
5480
+
5481
+ // Mock POST sync - should NOT be called
5482
+ mockSendSyncRequestResponse(mainUrl, null);
5483
+
5484
+ // Trigger sync for main
5485
+ parser.handleMessage(
5486
+ createHeartbeatMessage('main', 16, 1100, 'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa1'),
5487
+ 'trigger main sync'
5488
+ );
5489
+
5490
+ await clock.tickAsync(1000);
5491
+
5492
+ // POST sync should NOT have been called because the reused controller was already aborted
5493
+ assert.neverCalledWith(webexRequest, sinon.match({method: 'POST', uri: `${mainUrl}/sync`}));
5494
+
5495
+ // syncAbortController should be cleaned up
5496
+ expect(parser.dataSets.main.syncAbortController).to.be.undefined;
5497
+ });
5498
+
5499
+ it('should allow cancelPendingSyncsForDataSets to abort an in-flight sync via the shared controller', async () => {
5500
+ const parser = createHashTreeParser();
5501
+ const mainUrl = parser.dataSets.main.url;
5502
+
5503
+ // Use a deferred promise for GET hashtree
5504
+ let resolveGetHashtree;
5505
+ webexRequest.withArgs(sinon.match({method: 'GET', uri: `${mainUrl}/hashtree`})).callsFake(
5506
+ () =>
5507
+ new Promise((resolve) => {
5508
+ resolveGetHashtree = resolve;
5509
+ })
5510
+ );
5511
+
5512
+ mockSendSyncRequestResponse(mainUrl, null);
5513
+
5514
+ // Trigger sync for main
5515
+ parser.handleMessage(
5516
+ createHeartbeatMessage('main', 16, 1100, 'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa1'),
5517
+ 'trigger main sync'
5518
+ );
5519
+
5520
+ // Fire the timer to start sync
5521
+ await clock.tickAsync(1000);
5522
+
5523
+ // Verify controller is set
5524
+ expect(parser.dataSets.main.syncAbortController).to.not.be.undefined;
5525
+
5526
+ // Simulate a new heartbeat arriving that cancels the in-flight sync
5527
+ // (this is what happens in production via parseMessage -> cancelPendingSyncsForDataSets)
5528
+ parser.handleMessage(
5529
+ {
5530
+ dataSets: [
5531
+ {
5532
+ ...createDataSet('main', 16, 1101),
5533
+ root: parser.dataSets.main.hashTree.getRootHash(), // matching hash so no new sync
5534
+ },
5535
+ ],
5536
+ visibleDataSetsUrl,
5537
+ locusUrl,
5538
+ },
5539
+ 'new heartbeat cancels sync'
5540
+ );
5541
+
5542
+ // Resolve the pending GET hashtree with mismatched hashes
5543
+ resolveGetHashtree({
5544
+ body: {
5545
+ hashes: new Array(16).fill('aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa1'),
5546
+ dataSet: createDataSet('main', 16, 1101),
5547
+ },
5548
+ });
5549
+
5550
+ await testUtils.flushPromises();
5551
+
5552
+ // POST sync should NOT have been called because cancelPendingSyncsForDataSets aborted the controller
5553
+ assert.neverCalledWith(webexRequest, sinon.match({method: 'POST', uri: `${mainUrl}/sync`}));
5554
+ });
5555
+ });
5556
+
5557
+ describe('#cleanUp', () => {
5558
+ it('should stop the parser, clear all timers and clear all dataSets', () => {
5559
+ const parser = createHashTreeParser();
5560
+
5561
+ // Send a message to set up sync timers via runSyncAlgorithm
5562
+ const message = {
5563
+ dataSets: [
5564
+ {
5565
+ ...createDataSet('main', 16, 1100),
5566
+ root: 'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa1',
5567
+ },
5568
+ ],
5569
+ visibleDataSetsUrl,
5570
+ locusUrl,
5571
+ locusStateElements: [
5572
+ {
5573
+ htMeta: {
5574
+ elementId: {type: 'locus' as const, id: 0, version: 201},
5575
+ dataSetNames: ['main'],
5576
+ },
5577
+ data: {someData: 'value'},
5578
+ },
5579
+ ],
5580
+ };
5581
+
5582
+ parser.handleMessage(message, 'setup timers');
5583
+
5584
+ // Verify timers were set by handleMessage
5585
+ expect(parser.dataSets.main.timer).to.not.be.undefined;
5586
+ expect(parser.dataSets.main.heartbeatWatchdogTimer).to.not.be.undefined;
3817
5587
 
3818
5588
  parser.cleanUp();
3819
5589
 
@@ -3822,4 +5592,290 @@ describe('HashTreeParser', () => {
3822
5592
  expect(parser.dataSets).to.deep.equal({});
3823
5593
  });
3824
5594
  });
5595
+
5596
+ describe('#syncMetrics', () => {
5597
+ it('records sync latency timestamps when sync response has empty body', async () => {
5598
+ const syncLatencyTracker = {
5599
+ saveLatency: sinon.stub(),
5600
+ saveTimestamp: sinon.stub(),
5601
+ getLocusSyncLatency: sinon.stub(),
5602
+ clearLocusSyncLatency: sinon.stub(),
5603
+ completeLocusSyncLatency: sinon.stub(),
5604
+ };
5605
+ const parser = createHashTreeParser(
5606
+ undefined,
5607
+ undefined,
5608
+ undefined,
5609
+ syncLatencyTracker
5610
+ );
5611
+ const mainDataSetUrl = parser.dataSets.main.url;
5612
+
5613
+ mockGetHashesFromLocusResponse(
5614
+ mainDataSetUrl,
5615
+ new Array(16).fill('00000000000000000000000000000000'),
5616
+ createDataSet('main', 16, 1101)
5617
+ );
5618
+ mockSendSyncRequestResponse(mainDataSetUrl, null);
5619
+
5620
+ parser.handleMessage(
5621
+ createHeartbeatMessage('main', 16, 1100, 'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa1'),
5622
+ 'trigger sync metrics'
5623
+ );
5624
+
5625
+ await clock.tickAsync(1000);
5626
+
5627
+ assert.calledWithExactly(syncLatencyTracker.saveTimestamp, {
5628
+ key: 'internal.client.locus.sync.start',
5629
+ options: {meetingId: 'meeting-1', dataSetName: 'main', trackingId: undefined},
5630
+ });
5631
+ assert.calledWithExactly(syncLatencyTracker.saveTimestamp, {
5632
+ key: 'internal.client.locus.hashtree.request',
5633
+ options: {meetingId: 'meeting-1', dataSetName: 'main', trackingId: undefined},
5634
+ });
5635
+ assert.calledWithExactly(syncLatencyTracker.saveTimestamp, {
5636
+ key: 'internal.client.locus.hashtree.response',
5637
+ options: {meetingId: 'meeting-1', dataSetName: 'main', trackingId: undefined},
5638
+ });
5639
+ assert.calledWithExactly(syncLatencyTracker.saveTimestamp, {
5640
+ key: 'internal.client.locus.sync.request',
5641
+ options: {meetingId: 'meeting-1', dataSetName: 'main', trackingId: undefined},
5642
+ });
5643
+ assert.calledWithExactly(syncLatencyTracker.saveTimestamp, {
5644
+ key: 'internal.client.locus.sync.response',
5645
+ options: {meetingId: 'meeting-1', dataSetName: 'main', trackingId: undefined},
5646
+ });
5647
+ assert.notCalled(syncLatencyTracker.getLocusSyncLatency);
5648
+ });
5649
+
5650
+ it('clears only the failed sync record (by tracking id) when the /sync request errors', async () => {
5651
+ const syncLatencyTracker = {
5652
+ saveLatency: sinon.stub(),
5653
+ saveTimestamp: sinon.stub(),
5654
+ getLocusSyncLatency: sinon.stub(),
5655
+ clearLocusSyncLatency: sinon.stub(),
5656
+ completeLocusSyncLatency: sinon.stub(),
5657
+ };
5658
+ const generateTrackingId = sinon.stub().returns('our-sync-tracking-id');
5659
+ const parser = createHashTreeParser(
5660
+ undefined,
5661
+ undefined,
5662
+ undefined,
5663
+ syncLatencyTracker,
5664
+ undefined,
5665
+ generateTrackingId
5666
+ );
5667
+ const mainDataSetUrl = parser.dataSets.main.url;
5668
+
5669
+ // Mismatched hashes so the flow proceeds to POST /sync, which then fails.
5670
+ mockGetHashesFromLocusResponse(
5671
+ mainDataSetUrl,
5672
+ new Array(16).fill('00000000000000000000000000000000'),
5673
+ createDataSet('main', 16, 1101)
5674
+ );
5675
+ webexRequest
5676
+ .withArgs(sinon.match({method: 'POST', uri: `${mainDataSetUrl}/sync`}))
5677
+ .rejects(new Error('sync failed'));
5678
+
5679
+ parser.handleMessage(
5680
+ createHeartbeatMessage('main', 16, 1100, 'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa1'),
5681
+ 'trigger sync metrics'
5682
+ );
5683
+
5684
+ await clock.tickAsync(1000);
5685
+
5686
+ // Because /sync failed, syncRequestSent stays false and the finally block drops the record,
5687
+ // passing the tracking id so only this in-progress record is removed (native onSyncError parity).
5688
+ assert.calledWithExactly(
5689
+ syncLatencyTracker.clearLocusSyncLatency,
5690
+ 'main',
5691
+ 'meeting-1',
5692
+ 'our-sync-tracking-id'
5693
+ );
5694
+ });
5695
+
5696
+ it('forces a pre-generated tracking id onto the sync request and records it', async () => {
5697
+ const syncLatencyTracker = {
5698
+ saveLatency: sinon.stub(),
5699
+ saveTimestamp: sinon.stub(),
5700
+ getLocusSyncLatency: sinon.stub(),
5701
+ clearLocusSyncLatency: sinon.stub(),
5702
+ completeLocusSyncLatency: sinon.stub(),
5703
+ };
5704
+ // two distinct tracking ids are generated: the first for the /hashtree request and the
5705
+ // second for the /sync request (which is also stored in metrics and used for LLM matching)
5706
+ const generateTrackingId = sinon.stub();
5707
+ generateTrackingId.onFirstCall().returns('our-hashtree-tracking-id');
5708
+ generateTrackingId.onSecondCall().returns('our-sync-tracking-id');
5709
+ const parser = createHashTreeParser(
5710
+ undefined,
5711
+ undefined,
5712
+ undefined,
5713
+ syncLatencyTracker,
5714
+ undefined,
5715
+ generateTrackingId
5716
+ );
5717
+ const mainDataSetUrl = parser.dataSets.main.url;
5718
+
5719
+ mockGetHashesFromLocusResponse(
5720
+ mainDataSetUrl,
5721
+ new Array(16).fill('00000000000000000000000000000000'),
5722
+ createDataSet('main', 16, 1102)
5723
+ );
5724
+ mockSendSyncRequestResponse(mainDataSetUrl, null);
5725
+
5726
+ parser.handleMessage(
5727
+ createHeartbeatMessage('main', 16, 1100, 'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa1'),
5728
+ 'trigger sync metrics'
5729
+ );
5730
+
5731
+ await clock.tickAsync(1000);
5732
+
5733
+ // two distinct tracking ids are generated up-front so the /hashtree and /sync requests do
5734
+ // not share a tracking id
5735
+ assert.calledTwice(generateTrackingId);
5736
+ // the /hashtree request carries its own (first) tracking id
5737
+ assert.calledWith(
5738
+ webexRequest,
5739
+ sinon.match({
5740
+ method: 'GET',
5741
+ uri: `${mainDataSetUrl}/hashtree`,
5742
+ headers: {trackingid: 'our-hashtree-tracking-id'},
5743
+ })
5744
+ );
5745
+ // the /sync request carries the second tracking id, which Locus echoes back on the resulting
5746
+ // LLM message so the Meeting object can match it to this sync
5747
+ assert.calledWith(
5748
+ webexRequest,
5749
+ sinon.match({
5750
+ method: 'POST',
5751
+ uri: `${mainDataSetUrl}/sync`,
5752
+ headers: {trackingid: 'our-sync-tracking-id'},
5753
+ })
5754
+ );
5755
+
5756
+ // the same tracking id is stamped on the sync milestones so the Meeting object can later
5757
+ // match the LLM event to this sync
5758
+ assert.calledWithExactly(syncLatencyTracker.saveTimestamp, {
5759
+ key: 'internal.client.locus.sync.start',
5760
+ options: {meetingId: 'meeting-1', dataSetName: 'main', trackingId: 'our-sync-tracking-id'},
5761
+ });
5762
+ assert.calledWithExactly(syncLatencyTracker.saveTimestamp, {
5763
+ key: 'internal.client.locus.hashtree.request',
5764
+ options: {meetingId: 'meeting-1', dataSetName: 'main', trackingId: 'our-sync-tracking-id'},
5765
+ });
5766
+ assert.calledWithExactly(syncLatencyTracker.saveTimestamp, {
5767
+ key: 'internal.client.locus.hashtree.response',
5768
+ options: {meetingId: 'meeting-1', dataSetName: 'main', trackingId: 'our-sync-tracking-id'},
5769
+ });
5770
+ assert.calledWithExactly(syncLatencyTracker.saveTimestamp, {
5771
+ key: 'internal.client.locus.sync.request',
5772
+ options: {meetingId: 'meeting-1', dataSetName: 'main', trackingId: 'our-sync-tracking-id'},
5773
+ });
5774
+ assert.calledWithExactly(syncLatencyTracker.saveTimestamp, {
5775
+ key: 'internal.client.locus.sync.response',
5776
+ options: {meetingId: 'meeting-1', dataSetName: 'main', trackingId: 'our-sync-tracking-id'},
5777
+ });
5778
+ assert.notCalled(syncLatencyTracker.getLocusSyncLatency);
5779
+ });
5780
+
5781
+ it('does not complete or clear metrics when matching dataset message arrives', () => {
5782
+ const syncLatencyTracker = {
5783
+ saveLatency: sinon.stub(),
5784
+ saveTimestamp: sinon.stub(),
5785
+ getLocusSyncLatency: sinon.stub(),
5786
+ clearLocusSyncLatency: sinon.stub(),
5787
+ completeLocusSyncLatency: sinon.stub(),
5788
+ };
5789
+ const parser = createHashTreeParser(
5790
+ undefined,
5791
+ undefined,
5792
+ undefined,
5793
+ syncLatencyTracker
5794
+ );
5795
+
5796
+ parser.handleMessage({
5797
+ dataSets: [
5798
+ {
5799
+ ...createDataSet('main', 16, 1001),
5800
+ root: 'newroot',
5801
+ },
5802
+ ],
5803
+ visibleDataSetsUrl,
5804
+ locusUrl,
5805
+ locusStateElements: [],
5806
+ });
5807
+
5808
+ assert.notCalled(syncLatencyTracker.getLocusSyncLatency);
5809
+ assert.notCalled(syncLatencyTracker.clearLocusSyncLatency);
5810
+ assert.notCalled(syncLatencyTracker.completeLocusSyncLatency);
5811
+ });
5812
+
5813
+ it('does not complete sync metrics when sync response has body (completion is LLM-only)', async () => {
5814
+ const syncLatencyTracker = {
5815
+ saveLatency: sinon.stub(),
5816
+ saveTimestamp: sinon.stub(),
5817
+ getLocusSyncLatency: sinon.stub(),
5818
+ clearLocusSyncLatency: sinon.stub(),
5819
+ completeLocusSyncLatency: sinon.stub(),
5820
+ };
5821
+ const generateTrackingId = sinon.stub().returns('our-sync-tracking-id');
5822
+ const parser = createHashTreeParser(
5823
+ undefined,
5824
+ undefined,
5825
+ undefined,
5826
+ syncLatencyTracker,
5827
+ undefined,
5828
+ generateTrackingId
5829
+ );
5830
+ const mainDataSetUrl = parser.dataSets.main.url;
5831
+ const syncResponse = {
5832
+ dataSets: [
5833
+ {
5834
+ ...createDataSet('main', 16, 1102),
5835
+ root: 'newroot',
5836
+ },
5837
+ ],
5838
+ visibleDataSetsUrl,
5839
+ locusUrl,
5840
+ locusStateElements: [],
5841
+ };
5842
+
5843
+ mockGetHashesFromLocusResponse(
5844
+ mainDataSetUrl,
5845
+ new Array(16).fill('00000000000000000000000000000000'),
5846
+ createDataSet('main', 16, 1102)
5847
+ );
5848
+ mockSendSyncRequestResponse(mainDataSetUrl, syncResponse);
5849
+
5850
+ parser.handleMessage(
5851
+ createHeartbeatMessage('main', 16, 1100, 'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa1'),
5852
+ 'trigger sync metrics'
5853
+ );
5854
+
5855
+ await clock.tickAsync(1000);
5856
+
5857
+ assert.calledWithExactly(syncLatencyTracker.saveTimestamp, {
5858
+ key: 'internal.client.locus.sync.response',
5859
+ options: {
5860
+ meetingId: 'meeting-1',
5861
+ dataSetName: 'main',
5862
+ trackingId: 'our-sync-tracking-id',
5863
+ },
5864
+ });
5865
+ // body-mode syncs return the state elements in the /sync HTTP response, but per the LLM-only
5866
+ // design the CA metric is completed solely from Meeting#processLocusLLMEvent once the matching
5867
+ // LLM message arrives. handleMessage must not record the message-received milestone nor
5868
+ // complete the metric here.
5869
+ assert.neverCalledWith(syncLatencyTracker.saveTimestamp, {
5870
+ key: 'internal.client.locus.sync.message.received',
5871
+ options: {
5872
+ meetingId: 'meeting-1',
5873
+ dataSetName: 'main',
5874
+ trackingId: 'our-sync-tracking-id',
5875
+ },
5876
+ });
5877
+ assert.notCalled(syncLatencyTracker.completeLocusSyncLatency);
5878
+ });
5879
+
5880
+ });
3825
5881
  });