@webex/contact-center 3.12.0-next.14 → 3.12.0-next.141

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 (317) hide show
  1. package/.sdd/manifest.json +885 -0
  2. package/AGENTS.md +94 -0
  3. package/ai-docs/ARCHITECTURE.md +168 -0
  4. package/ai-docs/CONTRACTS.md +59 -0
  5. package/ai-docs/GETTING_STARTED.md +168 -0
  6. package/ai-docs/GLOSSARY.md +43 -0
  7. package/ai-docs/README.md +138 -0
  8. package/ai-docs/REVIEW_CHECKLIST.md +41 -0
  9. package/ai-docs/RULES.md +444 -0
  10. package/ai-docs/SECURITY.md +52 -0
  11. package/ai-docs/SERVICE_STATE.md +52 -0
  12. package/ai-docs/SPEC_INDEX.md +65 -0
  13. package/ai-docs/adr/0001-spec-source-policy.md +55 -0
  14. package/ai-docs/adr/README.md +8 -0
  15. package/ai-docs/adr/_adr-template.md +31 -0
  16. package/ai-docs/contact-center-spec.md +382 -0
  17. package/ai-docs/features/consult-transfer-list-policy/spec/feature-spec.md +362 -0
  18. package/ai-docs/features/contact-owner-change-refactor.md +78 -0
  19. package/ai-docs/features/generated-spec-conformance-fidelity-remediation/spec/feature-spec.md +117 -0
  20. package/ai-docs/features/residual-warning-coverage-completion/spec/feature-spec.md +203 -0
  21. package/ai-docs/features/validator-code-fidelity-drift-fix/spec/feature-spec.md +315 -0
  22. package/ai-docs/patterns/event-driven-patterns.md +485 -0
  23. package/ai-docs/patterns/testing-patterns.md +480 -0
  24. package/ai-docs/patterns/typescript-patterns.md +365 -0
  25. package/ai-docs/templates/README.md +102 -0
  26. package/ai-docs/templates/documentation/create-agents-md.md +240 -0
  27. package/ai-docs/templates/documentation/create-architecture-md.md +295 -0
  28. package/ai-docs/templates/existing-service/bug-fix.md +254 -0
  29. package/ai-docs/templates/existing-service/feature-enhancement.md +450 -0
  30. package/ai-docs/templates/new-method/00-master.md +80 -0
  31. package/ai-docs/templates/new-method/01-requirements.md +232 -0
  32. package/ai-docs/templates/new-method/02-implementation.md +295 -0
  33. package/ai-docs/templates/new-method/03-tests.md +201 -0
  34. package/ai-docs/templates/new-method/04-validation.md +141 -0
  35. package/ai-docs/templates/new-service/00-master.md +109 -0
  36. package/ai-docs/templates/new-service/01-pre-questions.md +159 -0
  37. package/ai-docs/templates/new-service/02-code-generation.md +346 -0
  38. package/ai-docs/templates/new-service/03-integration.md +178 -0
  39. package/ai-docs/templates/new-service/04-test-generation.md +205 -0
  40. package/ai-docs/templates/new-service/05-validation.md +145 -0
  41. package/dist/cc.js +1004 -43
  42. package/dist/cc.js.map +1 -1
  43. package/dist/config.js +13 -0
  44. package/dist/config.js.map +1 -1
  45. package/dist/constants.js +31 -3
  46. package/dist/constants.js.map +1 -1
  47. package/dist/index.js +45 -15
  48. package/dist/index.js.map +1 -1
  49. package/dist/metrics/MetricsManager.js +16 -0
  50. package/dist/metrics/MetricsManager.js.map +1 -1
  51. package/dist/metrics/behavioral-events.js +211 -0
  52. package/dist/metrics/behavioral-events.js.map +1 -1
  53. package/dist/metrics/constants.js +49 -4
  54. package/dist/metrics/constants.js.map +1 -1
  55. package/dist/services/AddressBook.js +18 -15
  56. package/dist/services/AddressBook.js.map +1 -1
  57. package/dist/services/AnswerCallOnWebexService.js +202 -0
  58. package/dist/services/AnswerCallOnWebexService.js.map +1 -0
  59. package/dist/services/ApiAiAssistant.js +269 -9
  60. package/dist/services/ApiAiAssistant.js.map +1 -1
  61. package/dist/services/EntryPoint.js +46 -68
  62. package/dist/services/EntryPoint.js.map +1 -1
  63. package/dist/services/Queue.js +27 -22
  64. package/dist/services/Queue.js.map +1 -1
  65. package/dist/services/UserPreference.js +427 -0
  66. package/dist/services/UserPreference.js.map +1 -0
  67. package/dist/services/WebexCrossClientService.js +225 -0
  68. package/dist/services/WebexCrossClientService.js.map +1 -0
  69. package/dist/services/WxAppTelephonyMercurySync.js +111 -0
  70. package/dist/services/WxAppTelephonyMercurySync.js.map +1 -0
  71. package/dist/services/config/Util.js +11 -4
  72. package/dist/services/config/Util.js.map +1 -1
  73. package/dist/services/config/constants.js +41 -7
  74. package/dist/services/config/constants.js.map +1 -1
  75. package/dist/services/config/index.js +51 -0
  76. package/dist/services/config/index.js.map +1 -1
  77. package/dist/services/config/types.js +57 -12
  78. package/dist/services/config/types.js.map +1 -1
  79. package/dist/services/core/Err.js.map +1 -1
  80. package/dist/services/core/Utils.js +111 -32
  81. package/dist/services/core/Utils.js.map +1 -1
  82. package/dist/services/core/WebexRequest.js +6 -2
  83. package/dist/services/core/WebexRequest.js.map +1 -1
  84. package/dist/services/core/aqm-reqs.js +28 -14
  85. package/dist/services/core/aqm-reqs.js.map +1 -1
  86. package/dist/services/core/types.js.map +1 -1
  87. package/dist/services/core/websocket/WebSocketManager.js +2 -1
  88. package/dist/services/core/websocket/WebSocketManager.js.map +1 -1
  89. package/dist/services/core/websocket/types.js.map +1 -1
  90. package/dist/services/index.js +1 -1
  91. package/dist/services/index.js.map +1 -1
  92. package/dist/services/task/Task.js +754 -0
  93. package/dist/services/task/Task.js.map +1 -0
  94. package/dist/services/task/TaskFactory.js +50 -0
  95. package/dist/services/task/TaskFactory.js.map +1 -0
  96. package/dist/services/task/TaskManager.js +1183 -521
  97. package/dist/services/task/TaskManager.js.map +1 -1
  98. package/dist/services/task/TaskUtils.js +211 -27
  99. package/dist/services/task/TaskUtils.js.map +1 -1
  100. package/dist/services/task/WebexCallingUtils.js +70 -0
  101. package/dist/services/task/WebexCallingUtils.js.map +1 -0
  102. package/dist/services/task/constants.js +12 -2
  103. package/dist/services/task/constants.js.map +1 -1
  104. package/dist/services/task/contact.js +29 -0
  105. package/dist/services/task/contact.js.map +1 -1
  106. package/dist/services/task/dialer.js +78 -0
  107. package/dist/services/task/dialer.js.map +1 -1
  108. package/dist/services/task/digital/Digital.js +78 -0
  109. package/dist/services/task/digital/Digital.js.map +1 -0
  110. package/dist/services/task/state-machine/TaskStateMachine.js +982 -0
  111. package/dist/services/task/state-machine/TaskStateMachine.js.map +1 -0
  112. package/dist/services/task/state-machine/actions.js +572 -0
  113. package/dist/services/task/state-machine/actions.js.map +1 -0
  114. package/dist/services/task/state-machine/constants.js +161 -0
  115. package/dist/services/task/state-machine/constants.js.map +1 -0
  116. package/dist/services/task/state-machine/guards.js +379 -0
  117. package/dist/services/task/state-machine/guards.js.map +1 -0
  118. package/dist/services/task/state-machine/index.js +53 -0
  119. package/dist/services/task/state-machine/index.js.map +1 -0
  120. package/dist/services/task/state-machine/types.js +54 -0
  121. package/dist/services/task/state-machine/types.js.map +1 -0
  122. package/dist/services/task/state-machine/uiControlsComputer.js +703 -0
  123. package/dist/services/task/state-machine/uiControlsComputer.js.map +1 -0
  124. package/dist/services/task/taskDataNormalizer.js +99 -0
  125. package/dist/services/task/taskDataNormalizer.js.map +1 -0
  126. package/dist/services/task/types.js +228 -5
  127. package/dist/services/task/types.js.map +1 -1
  128. package/dist/services/task/voice/Voice.js +1504 -0
  129. package/dist/services/task/voice/Voice.js.map +1 -0
  130. package/dist/services/task/voice/WebRTC.js +152 -0
  131. package/dist/services/task/voice/WebRTC.js.map +1 -0
  132. package/dist/services/task/voice/wxAppOfferObservability.js +145 -0
  133. package/dist/services/task/voice/wxAppOfferObservability.js.map +1 -0
  134. package/dist/services/task/voice/wxAppVoiceMethods.js +395 -0
  135. package/dist/services/task/voice/wxAppVoiceMethods.js.map +1 -0
  136. package/dist/services/wxAppDiagnosticLogging.js +159 -0
  137. package/dist/services/wxAppDiagnosticLogging.js.map +1 -0
  138. package/dist/services/wxAppTelephonyUtils.js +19 -0
  139. package/dist/services/wxAppTelephonyUtils.js.map +1 -0
  140. package/dist/types/cc.d.ts +193 -6
  141. package/dist/types/config.d.ts +13 -0
  142. package/dist/types/constants.d.ts +29 -1
  143. package/dist/types/index.d.ts +35 -8
  144. package/dist/types/metrics/MetricsManager.d.ts +6 -0
  145. package/dist/types/metrics/constants.d.ts +44 -1
  146. package/dist/types/services/AddressBook.d.ts +2 -1
  147. package/dist/types/services/AnswerCallOnWebexService.d.ts +38 -0
  148. package/dist/types/services/ApiAiAssistant.d.ts +56 -5
  149. package/dist/types/services/EntryPoint.d.ts +7 -5
  150. package/dist/types/services/Queue.d.ts +5 -3
  151. package/dist/types/services/UserPreference.d.ts +118 -0
  152. package/dist/types/services/WebexCrossClientService.d.ts +32 -0
  153. package/dist/types/services/WxAppTelephonyMercurySync.d.ts +28 -0
  154. package/dist/types/services/config/constants.d.ts +34 -5
  155. package/dist/types/services/config/types.d.ts +199 -12
  156. package/dist/types/services/core/Err.d.ts +6 -0
  157. package/dist/types/services/core/Utils.d.ts +35 -13
  158. package/dist/types/services/core/WebexRequest.d.ts +1 -0
  159. package/dist/types/services/core/types.d.ts +2 -0
  160. package/dist/types/services/core/websocket/WebSocketManager.d.ts +1 -0
  161. package/dist/types/services/core/websocket/types.d.ts +1 -1
  162. package/dist/types/services/index.d.ts +1 -1
  163. package/dist/types/services/task/Task.d.ts +175 -0
  164. package/dist/types/services/task/TaskFactory.d.ts +13 -0
  165. package/dist/types/services/task/TaskUtils.d.ts +48 -2
  166. package/dist/types/services/task/WebexCallingUtils.d.ts +11 -0
  167. package/dist/types/services/task/constants.d.ts +10 -0
  168. package/dist/types/services/task/contact.d.ts +4 -0
  169. package/dist/types/services/task/dialer.d.ts +30 -0
  170. package/dist/types/services/task/digital/Digital.d.ts +22 -0
  171. package/dist/types/services/task/state-machine/TaskStateMachine.d.ts +1442 -0
  172. package/dist/types/services/task/state-machine/actions.d.ts +10 -0
  173. package/dist/types/services/task/state-machine/constants.d.ts +107 -0
  174. package/dist/types/services/task/state-machine/guards.d.ts +103 -0
  175. package/dist/types/services/task/state-machine/index.d.ts +13 -0
  176. package/dist/types/services/task/state-machine/types.d.ts +277 -0
  177. package/dist/types/services/task/state-machine/uiControlsComputer.d.ts +9 -0
  178. package/dist/types/services/task/taskDataNormalizer.d.ts +10 -0
  179. package/dist/types/services/task/types.d.ts +682 -66
  180. package/dist/types/services/task/voice/Voice.d.ts +240 -0
  181. package/dist/types/services/task/voice/WebRTC.d.ts +53 -0
  182. package/dist/types/services/task/voice/wxAppOfferObservability.d.ts +39 -0
  183. package/dist/types/services/task/voice/wxAppVoiceMethods.d.ts +68 -0
  184. package/dist/types/services/wxAppDiagnosticLogging.d.ts +63 -0
  185. package/dist/types/services/wxAppTelephonyUtils.d.ts +5 -0
  186. package/dist/types/types.d.ts +205 -9
  187. package/dist/types/utils/PageCache.d.ts +20 -3
  188. package/dist/types/webex.d.ts +1 -0
  189. package/dist/types.js +162 -4
  190. package/dist/types.js.map +1 -1
  191. package/dist/utils/PageCache.js +19 -5
  192. package/dist/utils/PageCache.js.map +1 -1
  193. package/dist/webex.js +22 -2
  194. package/dist/webex.js.map +1 -1
  195. package/package.json +16 -12
  196. package/src/cc.ts +1330 -117
  197. package/src/config.ts +13 -0
  198. package/src/constants.ts +29 -1
  199. package/src/index.ts +36 -5
  200. package/src/metrics/MetricsManager.ts +16 -0
  201. package/src/metrics/ai-docs/AGENTS.md +350 -0
  202. package/src/metrics/ai-docs/ARCHITECTURE.md +338 -0
  203. package/src/metrics/ai-docs/metrics-spec.md +963 -0
  204. package/src/metrics/behavioral-events.ts +218 -0
  205. package/src/metrics/constants.ts +53 -4
  206. package/src/services/AddressBook.ts +17 -6
  207. package/src/services/AnswerCallOnWebexService.ts +239 -0
  208. package/src/services/ApiAiAssistant.ts +356 -9
  209. package/src/services/EntryPoint.ts +59 -60
  210. package/src/services/Queue.ts +29 -12
  211. package/src/services/UserPreference.ts +509 -0
  212. package/src/services/WebexCrossClientService.ts +298 -0
  213. package/src/services/WxAppTelephonyMercurySync.ts +142 -0
  214. package/src/services/agent/ai-docs/AGENTS.md +240 -0
  215. package/src/services/agent/ai-docs/ARCHITECTURE.md +304 -0
  216. package/src/services/agent/ai-docs/agent-spec.md +505 -0
  217. package/src/services/ai-docs/AGENTS.md +386 -0
  218. package/src/services/ai-docs/services-spec.md +505 -0
  219. package/src/services/config/Util.ts +12 -3
  220. package/src/services/config/ai-docs/AGENTS.md +255 -0
  221. package/src/services/config/ai-docs/ARCHITECTURE.md +426 -0
  222. package/src/services/config/ai-docs/config-spec.md +686 -0
  223. package/src/services/config/constants.ts +46 -6
  224. package/src/services/config/index.ts +65 -0
  225. package/src/services/config/types.ts +199 -13
  226. package/src/services/core/Err.ts +3 -0
  227. package/src/services/core/Utils.ts +127 -37
  228. package/src/services/core/WebexRequest.ts +3 -1
  229. package/src/services/core/ai-docs/AGENTS.md +381 -0
  230. package/src/services/core/ai-docs/ARCHITECTURE.md +698 -0
  231. package/src/services/core/ai-docs/core-spec.md +787 -0
  232. package/src/services/core/aqm-reqs.ts +30 -15
  233. package/src/services/core/types.ts +2 -0
  234. package/src/services/core/websocket/WebSocketManager.ts +2 -0
  235. package/src/services/core/websocket/types.ts +1 -1
  236. package/src/services/index.ts +1 -1
  237. package/src/services/task/Task.ts +908 -0
  238. package/src/services/task/TaskFactory.ts +61 -0
  239. package/src/services/task/TaskManager.ts +1430 -608
  240. package/src/services/task/TaskUtils.ts +303 -25
  241. package/src/services/task/WebexCallingUtils.ts +136 -0
  242. package/src/services/task/ai-docs/AGENTS.md +457 -0
  243. package/src/services/task/ai-docs/ARCHITECTURE.md +595 -0
  244. package/src/services/task/ai-docs/task-spec.md +1476 -0
  245. package/src/services/task/constants.ts +10 -0
  246. package/src/services/task/contact.ts +30 -0
  247. package/src/services/task/dialer.ts +80 -0
  248. package/src/services/task/digital/Digital.ts +97 -0
  249. package/src/services/task/state-machine/TaskStateMachine.ts +1320 -0
  250. package/src/services/task/state-machine/actions.ts +741 -0
  251. package/src/services/task/state-machine/ai-docs/AGENTS.md +460 -0
  252. package/src/services/task/state-machine/ai-docs/ARCHITECTURE.md +1156 -0
  253. package/src/services/task/state-machine/ai-docs/task-state-machine-spec.md +2247 -0
  254. package/src/services/task/state-machine/constants.ts +172 -0
  255. package/src/services/task/state-machine/guards.ts +442 -0
  256. package/src/services/task/state-machine/index.ts +28 -0
  257. package/src/services/task/state-machine/types.ts +258 -0
  258. package/src/services/task/state-machine/uiControlsComputer.ts +1135 -0
  259. package/src/services/task/taskDataNormalizer.ts +137 -0
  260. package/src/services/task/types.ts +835 -70
  261. package/src/services/task/voice/Voice.ts +1873 -0
  262. package/src/services/task/voice/WebRTC.ts +191 -0
  263. package/src/services/task/voice/wxAppOfferObservability.ts +204 -0
  264. package/src/services/task/voice/wxAppVoiceMethods.ts +575 -0
  265. package/src/services/wxAppDiagnosticLogging.ts +286 -0
  266. package/src/services/wxAppTelephonyUtils.ts +14 -0
  267. package/src/types.ts +264 -11
  268. package/src/utils/AGENTS.md +289 -0
  269. package/src/utils/PageCache.ts +38 -5
  270. package/src/utils/ai-docs/utils-spec.md +391 -0
  271. package/src/webex.js +10 -0
  272. package/test/unit/spec/cc.ts +2371 -98
  273. package/test/unit/spec/logger-proxy.ts +70 -0
  274. package/test/unit/spec/metrics/MetricsManager.ts +25 -0
  275. package/test/unit/spec/metrics/behavioral-events.ts +60 -0
  276. package/test/unit/spec/services/AddressBook.ts +37 -6
  277. package/test/unit/spec/services/AnswerCallOnWebexService.ts +264 -0
  278. package/test/unit/spec/services/ApiAiAssistant.ts +311 -21
  279. package/test/unit/spec/services/EntryPoint.ts +87 -40
  280. package/test/unit/spec/services/Queue.ts +123 -12
  281. package/test/unit/spec/services/UserPreference.ts +401 -0
  282. package/test/unit/spec/services/WebCallingService.ts +7 -1
  283. package/test/unit/spec/services/WebexCrossClientService.ts +509 -0
  284. package/test/unit/spec/services/WxAppTelephonyMercurySync.ts +136 -0
  285. package/test/unit/spec/services/config/Util.ts +129 -0
  286. package/test/unit/spec/services/config/index.ts +97 -29
  287. package/test/unit/spec/services/core/Utils.ts +425 -8
  288. package/test/unit/spec/services/core/WebexRequest.ts +3 -1
  289. package/test/unit/spec/services/core/aqm-reqs.ts +113 -1
  290. package/test/unit/spec/services/core/websocket/WebSocketManager.ts +66 -40
  291. package/test/unit/spec/services/task/AutoWrapup.ts +63 -0
  292. package/test/unit/spec/services/task/Task.ts +745 -0
  293. package/test/unit/spec/services/task/TaskFactory.ts +99 -0
  294. package/test/unit/spec/services/task/TaskManager.ts +2539 -1490
  295. package/test/unit/spec/services/task/TaskUtils.ts +235 -0
  296. package/test/unit/spec/services/task/WebexCallingUtils.ts +153 -0
  297. package/test/unit/spec/services/task/contact.ts +33 -0
  298. package/test/unit/spec/services/task/dialer.ts +190 -0
  299. package/test/unit/spec/services/task/digital/Digital.ts +105 -0
  300. package/test/unit/spec/services/task/state-machine/TaskStateMachine.ts +4060 -0
  301. package/test/unit/spec/services/task/state-machine/guards.ts +839 -0
  302. package/test/unit/spec/services/task/state-machine/types.ts +18 -0
  303. package/test/unit/spec/services/task/state-machine/uiControlsComputer.ts +3101 -0
  304. package/test/unit/spec/services/task/taskTestUtils.ts +87 -0
  305. package/test/unit/spec/services/task/voice/Voice.ts +2020 -0
  306. package/test/unit/spec/services/task/voice/WebRTC.ts +235 -0
  307. package/test/unit/spec/services/task/voice/wxAppOfferObservability.ts +361 -0
  308. package/test/unit/spec/services/task/voice/wxAppVoiceMethods.ts +719 -0
  309. package/test/unit/spec/services/wxAppDiagnosticLogging.ts +179 -0
  310. package/test/unit/spec/wellnessSampleUtils.ts +288 -0
  311. package/umd/contact-center.min.js +2 -2
  312. package/umd/contact-center.min.js.map +1 -1
  313. package/dist/services/task/index.js +0 -1530
  314. package/dist/services/task/index.js.map +0 -1
  315. package/dist/types/services/task/index.d.ts +0 -650
  316. package/src/services/task/index.ts +0 -1806
  317. package/test/unit/spec/services/task/index.ts +0 -2205
@@ -0,0 +1,235 @@
1
+ import 'jsdom-global/register';
2
+ import {LocalMicrophoneStream, CALL_EVENT_KEYS} from '@webex/calling';
3
+ import WebRTC from '../../../../../../src/services/task/voice/WebRTC';
4
+ import WebCallingService from '../../../../../../src/services/WebCallingService';
5
+ import {TaskData, TASK_EVENTS} from '../../../../../../src/services/task/types';
6
+ import type {WebexSDK} from '../../../../../../src/types';
7
+ import {TaskEvent, TaskEventPayload} from '../../../../../../src/services/task/state-machine';
8
+ import {createTaskData} from '../taskTestUtils';
9
+
10
+ jest.mock('@webex/calling', () => ({
11
+ LocalMicrophoneStream: class {
12
+ constructor(stream) {
13
+ this.outputStream = stream;
14
+ }
15
+ },
16
+ CALL_EVENT_KEYS: {REMOTE_MEDIA: 'remoteMedia'},
17
+ }));
18
+
19
+ beforeAll(() => {
20
+ navigator.mediaDevices = {getUserMedia: jest.fn()};
21
+ // @ts-ignore
22
+ global.MediaStream = class {
23
+ constructor(private tracks: MediaStreamTrack[]) {}
24
+ getAudioTracks() {
25
+ return this.tracks;
26
+ }
27
+ } as typeof MediaStream;
28
+ });
29
+
30
+ jest.mock('../../../../../../src/services/core/WebexRequest', () => ({
31
+ __esModule: true,
32
+ default: {
33
+ getInstance: jest.fn().mockReturnValue({uploadLogs: jest.fn()}),
34
+ },
35
+ }));
36
+
37
+ const sendStateEvents = (task: WebRTC, events: TaskEventPayload[]) => {
38
+ events.forEach((event) => {
39
+ if (!event) {
40
+ throw new Error('Task event payload is required');
41
+ }
42
+ task.stateMachineService?.send(event);
43
+ });
44
+ };
45
+
46
+ describe('WebRTC Task', () => {
47
+ const dummyContact = {} as any;
48
+ let taskData: TaskData;
49
+ let webCallingService: WebCallingService;
50
+ let onSpy: jest.SpyInstance;
51
+ let offSpy: jest.SpyInstance;
52
+ let answerSpy: jest.SpyInstance;
53
+ let declineSpy: jest.SpyInstance;
54
+ let muteSpy: jest.SpyInstance;
55
+
56
+ let webRtc: WebRTC;
57
+
58
+ beforeAll(() => {
59
+ const webex = {
60
+ logger: {
61
+ log: jest.fn(),
62
+ error: jest.fn(),
63
+ info: jest.fn(),
64
+ },
65
+ } as unknown as WebexSDK;
66
+
67
+ webCallingService = new WebCallingService(webex);
68
+ onSpy = jest.spyOn(webCallingService, 'on');
69
+ offSpy = jest.spyOn(webCallingService, 'off');
70
+ answerSpy = jest.spyOn(webCallingService, 'answerCall');
71
+ declineSpy = jest.spyOn(webCallingService, 'declineCall');
72
+ muteSpy = jest.spyOn(webCallingService, 'muteUnmuteCall');
73
+ });
74
+
75
+ beforeEach(() => {
76
+ taskData = createTaskData();
77
+ webRtc = new WebRTC(dummyContact, webCallingService, taskData, {
78
+ isEndTaskEnabled: true,
79
+ isEndConsultEnabled: true,
80
+ });
81
+ });
82
+
83
+ it('accept() obtains media and answers call', async () => {
84
+ const fakeTrack = {} as any;
85
+ const fakeStream = {getAudioTracks: () => [fakeTrack]} as any;
86
+ jest.spyOn(navigator.mediaDevices, 'getUserMedia').mockResolvedValue(fakeStream);
87
+ await webRtc.accept();
88
+ expect(answerSpy).toHaveBeenCalled();
89
+ const [[streamArg, interactionIdArg]] = webCallingService.answerCall.mock.calls;
90
+ expect(streamArg).toBeInstanceOf(LocalMicrophoneStream);
91
+ expect(interactionIdArg).toBe(taskData.interactionId);
92
+ });
93
+
94
+ it('decline() calls declineCall and unregisters listeners', async () => {
95
+ jest.spyOn(webRtc, 'unregisterWebCallListeners');
96
+ const res = await webRtc.decline();
97
+ expect(declineSpy).toHaveBeenCalledWith(taskData.interactionId);
98
+ expect(webRtc.unregisterWebCallListeners).toHaveBeenCalled();
99
+ expect(res).toBeUndefined();
100
+ });
101
+
102
+ it('toggleMute() calls muteUnmuteCall with stored localAudioStream', async () => {
103
+ const dummyStream = {} as any;
104
+ webRtc.localAudioStream = dummyStream;
105
+ await webRtc.toggleMute();
106
+ expect(muteSpy).toHaveBeenCalledWith(dummyStream);
107
+ });
108
+
109
+ describe('WebRTC internal methods', () => {
110
+ it('registerWebCallListeners binds remote media event', () => {
111
+ webRtc.registerWebCallListeners();
112
+ expect(onSpy).toHaveBeenCalledWith(CALL_EVENT_KEYS.REMOTE_MEDIA, webRtc.handleRemoteMedia);
113
+ });
114
+
115
+ it('handleRemoteMedia emits TASK_MEDIA event', () => {
116
+ const fakeTrack = {} as any;
117
+ jest.spyOn(webRtc, 'emit');
118
+ webRtc.handleRemoteMedia(fakeTrack);
119
+ expect(webRtc.emit).toHaveBeenCalledWith(TASK_EVENTS.TASK_MEDIA, fakeTrack);
120
+ });
121
+ });
122
+
123
+ describe('UI controls', () => {
124
+ beforeEach(() => {
125
+ taskData = createTaskData();
126
+ webRtc = new WebRTC(dummyContact, webCallingService, taskData, {
127
+ isEndTaskEnabled: true,
128
+ isEndConsultEnabled: true,
129
+ });
130
+ });
131
+
132
+ it('initialiseUIControls sets accept and decline visible', () => {
133
+ sendStateEvents(webRtc, [{type: TaskEvent.TASK_INCOMING, taskData}]);
134
+ expect(webRtc.uiControls.main.accept.isVisible).toBe(true);
135
+ expect(webRtc.uiControls.main.decline.isVisible).toBe(true);
136
+ });
137
+
138
+ it('setUIControls for AGENT_CONTACT_ASSIGNED shows mute enabled', () => {
139
+ sendStateEvents(webRtc, [
140
+ {type: TaskEvent.TASK_INCOMING, taskData},
141
+ {type: TaskEvent.ASSIGN, taskData},
142
+ ]);
143
+ expect(webRtc.uiControls.main.mute.isVisible).toBe(true);
144
+ expect(webRtc.uiControls.main.mute.isEnabled).toBe(true);
145
+ });
146
+
147
+ it('default setUIControls hides mute when wrapup visible', () => {
148
+ sendStateEvents(webRtc, [
149
+ {type: TaskEvent.TASK_INCOMING, taskData},
150
+ {type: TaskEvent.ASSIGN, taskData},
151
+ {type: TaskEvent.TASK_WRAPUP},
152
+ ]);
153
+ expect(webRtc.uiControls.main.wrapup.isVisible).toBe(true);
154
+ expect(webRtc.uiControls.main.mute.isVisible).toBe(false);
155
+ });
156
+
157
+ it('setUIControls for AGENT_CONTACT_HELD disables mute', () => {
158
+ sendStateEvents(webRtc, [
159
+ {type: TaskEvent.TASK_INCOMING, taskData},
160
+ {type: TaskEvent.ASSIGN, taskData},
161
+ {type: TaskEvent.HOLD_INITIATED, mediaResourceId: taskData.mediaResourceId},
162
+ {type: TaskEvent.HOLD_SUCCESS, mediaResourceId: taskData.mediaResourceId},
163
+ ]);
164
+ expect(webRtc.uiControls.main.mute.isVisible).toBe(true);
165
+ expect(webRtc.uiControls.main.mute.isEnabled).toBe(false);
166
+ });
167
+
168
+ it('setUIControls for AGENT_CONTACT_UNHELD re-enables mute', () => {
169
+ sendStateEvents(webRtc, [
170
+ {type: TaskEvent.TASK_INCOMING, taskData},
171
+ {type: TaskEvent.ASSIGN, taskData},
172
+ {type: TaskEvent.HOLD_INITIATED, mediaResourceId: taskData.mediaResourceId},
173
+ {type: TaskEvent.HOLD_SUCCESS, mediaResourceId: taskData.mediaResourceId},
174
+ {type: TaskEvent.UNHOLD_INITIATED, mediaResourceId: taskData.mediaResourceId},
175
+ {type: TaskEvent.UNHOLD_SUCCESS, mediaResourceId: taskData.mediaResourceId},
176
+ ]);
177
+ expect(webRtc.uiControls.main.mute.isVisible).toBe(true);
178
+ expect(webRtc.uiControls.main.mute.isEnabled).toBe(true);
179
+ });
180
+
181
+ it('setUIControls for AGENT_OFFER_CONTACT shows accept and decline', () => {
182
+ sendStateEvents(webRtc, [{type: TaskEvent.TASK_INCOMING, taskData}]);
183
+ expect(webRtc.uiControls.main.accept.isVisible).toBe(true);
184
+ expect(webRtc.uiControls.main.decline.isVisible).toBe(true);
185
+ });
186
+
187
+ it('setUIControls for AGENT_OFFER_CONSULT shows accept and decline', () => {
188
+ const consultedTaskData = {...taskData, isConsulted: true};
189
+ sendStateEvents(webRtc, [
190
+ {type: TaskEvent.TASK_INCOMING, taskData},
191
+ {type: TaskEvent.OFFER_CONSULT, taskData: consultedTaskData},
192
+ ]);
193
+ expect(webRtc.uiControls.main.accept.isVisible).toBe(true);
194
+ expect(webRtc.uiControls.main.decline.isVisible).toBe(true);
195
+ });
196
+
197
+ it('setUIControls for AGENT_CONSULTING hides accept/decline and shows mute when consulted', () => {
198
+ const consultedTaskData = {...taskData, isConsulted: true};
199
+ sendStateEvents(webRtc, [
200
+ {type: TaskEvent.TASK_INCOMING, taskData},
201
+ {type: TaskEvent.OFFER_CONSULT, taskData: consultedTaskData},
202
+ {
203
+ type: TaskEvent.CONSULTING_ACTIVE,
204
+ consultDestinationAgentJoined: true,
205
+ taskData: consultedTaskData,
206
+ },
207
+ ]);
208
+ expect(webRtc.uiControls.main.accept.isVisible).toBe(false);
209
+ expect(webRtc.uiControls.main.decline.isVisible).toBe(false);
210
+ expect(webRtc.uiControls.main.mute.isVisible).toBe(true);
211
+ expect(webRtc.uiControls.main.mute.isEnabled).toBe(true);
212
+ });
213
+
214
+ it('setUIControls for AGENT_CONSULT_ENDED returns mute to connected state behavior', () => {
215
+ const consultedTaskData = {...taskData, isConsulted: true};
216
+ sendStateEvents(webRtc, [
217
+ {type: TaskEvent.TASK_INCOMING, taskData},
218
+ {type: TaskEvent.OFFER_CONSULT, taskData: consultedTaskData},
219
+ {
220
+ type: TaskEvent.CONSULTING_ACTIVE,
221
+ consultDestinationAgentJoined: true,
222
+ taskData: consultedTaskData,
223
+ },
224
+ {type: TaskEvent.CONSULT_END},
225
+ ]);
226
+ expect(webRtc.uiControls.main.mute.isVisible).toBe(false);
227
+ });
228
+
229
+ it('setUIControls for AGENT_CONTACT_OFFER_RONA hides accept and decline', () => {
230
+ sendStateEvents(webRtc, [{type: TaskEvent.TASK_INCOMING, taskData}, {type: TaskEvent.RONA}]);
231
+ expect(webRtc.uiControls.main.accept.isVisible).toBe(false);
232
+ expect(webRtc.uiControls.main.decline.isVisible).toBe(false);
233
+ });
234
+ });
235
+ });
@@ -0,0 +1,361 @@
1
+ import MetricsManager from '../../../../../../src/metrics/MetricsManager';
2
+ import {METRIC_EVENT_NAMES} from '../../../../../../src/metrics/constants';
3
+ import {TaskState} from '../../../../../../src/services/task/state-machine';
4
+ import {TaskData, VOICE_VARIANT} from '../../../../../../src/services/task/types';
5
+ import {
6
+ WxAppOfferObservability,
7
+ WxAppOfferObservabilityContext,
8
+ WXAPP_PARTICIPANT_MISMATCH_GRACE_MS,
9
+ } from '../../../../../../src/services/task/voice/wxAppOfferObservability';
10
+ import {WxAppVoiceDependencies} from '../../../../../../src/services/task/voice/wxAppVoiceMethods';
11
+ import * as wxAppDiagnosticLogging from '../../../../../../src/services/wxAppDiagnosticLogging';
12
+ import {createTaskData} from '../taskTestUtils';
13
+
14
+ const wxAppParticipant = {
15
+ deviceType: 'wxApp',
16
+ deviceId: 'device-id-1',
17
+ deviceCallId: 'call-id-1',
18
+ };
19
+
20
+ function makeTaskDataWithoutWxAppFields(): TaskData {
21
+ return createTaskData({
22
+ agentId: 'agent-1',
23
+ interaction: {
24
+ participants: {
25
+ 'agent-1': {id: 'agent-1'},
26
+ },
27
+ } as TaskData['interaction'],
28
+ });
29
+ }
30
+
31
+ function makeTaskDataWithWxAppFields(): TaskData {
32
+ return createTaskData({
33
+ agentId: 'agent-1',
34
+ interaction: {
35
+ participants: {
36
+ 'agent-1': {id: 'agent-1', ...wxAppParticipant},
37
+ },
38
+ } as TaskData['interaction'],
39
+ });
40
+ }
41
+
42
+ function makeMockMetricsManager(): jest.Mocked<Pick<MetricsManager, 'trackEvent'>> {
43
+ return {trackEvent: jest.fn()};
44
+ }
45
+
46
+ function makeContext(
47
+ overrides: {
48
+ taskData?: TaskData;
49
+ taskState?: TaskState;
50
+ usersubPublished?: boolean;
51
+ wxAppAcceptInFlight?: boolean;
52
+ wxAppAnswerPending?: boolean;
53
+ voiceVariant?: typeof VOICE_VARIANT.PSTN;
54
+ acceptEnabled?: boolean;
55
+ isOutdial?: boolean;
56
+ } = {}
57
+ ): WxAppOfferObservabilityContext & {
58
+ setTaskData: (data: TaskData) => void;
59
+ setTaskState: (s: TaskState) => void;
60
+ setUsersubPublished: (value: boolean) => void;
61
+ } {
62
+ let taskData = overrides.taskData ?? makeTaskDataWithoutWxAppFields();
63
+ let taskState = overrides.taskState ?? TaskState.OFFERED;
64
+ let usersubPublished = overrides.usersubPublished ?? true;
65
+ const metricsManager = makeMockMetricsManager() as unknown as MetricsManager;
66
+
67
+ const deps = (): WxAppVoiceDependencies => ({
68
+ enableWxBetterTogether: true,
69
+ agentId: 'agent-1',
70
+ metricsManager,
71
+ getTaskData: () => taskData,
72
+ getTaskState: () => taskState,
73
+ getWxAppMuted: () => false,
74
+ setWxAppMuted: jest.fn(),
75
+ getUsersubPublished: () => usersubPublished,
76
+ });
77
+
78
+ return {
79
+ getInteractionId: () => taskData.interactionId,
80
+ getTaskState: () => taskState,
81
+ getAcceptControl: () => ({
82
+ isVisible: true,
83
+ isEnabled: overrides.acceptEnabled ?? false,
84
+ }),
85
+ getVoiceVariant: () => overrides.voiceVariant ?? VOICE_VARIANT.PSTN,
86
+ isOutdial: () => overrides.isOutdial ?? false,
87
+ isWxAppInboundOffer: () => {
88
+ const p = taskData.interaction?.participants?.['agent-1'] as
89
+ | {deviceType?: string; deviceCallId?: string; deviceId?: string}
90
+ | undefined;
91
+ return (
92
+ p?.deviceType === 'wxApp' &&
93
+ typeof p.deviceCallId === 'string' &&
94
+ p.deviceCallId.trim() !== '' &&
95
+ typeof p.deviceId === 'string' &&
96
+ p.deviceId.trim() !== ''
97
+ );
98
+ },
99
+ isWxAppCallingOffer: () => {
100
+ const p = taskData.interaction?.participants?.['agent-1'] as
101
+ | {deviceType?: string; deviceCallId?: string; deviceId?: string}
102
+ | undefined;
103
+ return (
104
+ p?.deviceType === 'wxApp' &&
105
+ typeof p.deviceCallId === 'string' &&
106
+ p.deviceCallId.trim() !== '' &&
107
+ typeof p.deviceId === 'string' &&
108
+ p.deviceId.trim() !== ''
109
+ );
110
+ },
111
+ getWxAppAcceptInFlight: () => overrides.wxAppAcceptInFlight ?? false,
112
+ getWxAppAnswerPending: () => overrides.wxAppAnswerPending ?? false,
113
+ getEnableWxBetterTogether: () => true,
114
+ getUsersubPublished: () => usersubPublished,
115
+ getWxAppVoiceDependencies: deps,
116
+ getMetricsManager: () => metricsManager,
117
+ setTaskData: (data: TaskData) => {
118
+ taskData = data;
119
+ },
120
+ setTaskState: (state: TaskState) => {
121
+ taskState = state;
122
+ },
123
+ setUsersubPublished: (value: boolean) => {
124
+ usersubPublished = value;
125
+ },
126
+ };
127
+ }
128
+
129
+ describe('WxAppOfferObservability', () => {
130
+ beforeEach(() => {
131
+ jest.useFakeTimers();
132
+ });
133
+
134
+ afterEach(() => {
135
+ jest.useRealTimers();
136
+ });
137
+
138
+ describe('offer decision logging', () => {
139
+ it('logs wxApp_offer_ready when participant fields are present', () => {
140
+ const logSpy = jest.spyOn(wxAppDiagnosticLogging, 'logWxAppOfferDecision');
141
+ const observability = new WxAppOfferObservability();
142
+ const ctx = makeContext({taskData: makeTaskDataWithWxAppFields(), acceptEnabled: true});
143
+
144
+ observability.handleUiControlsUpdate(ctx);
145
+
146
+ expect(logSpy).toHaveBeenCalledWith(
147
+ expect.objectContaining({acceptReason: 'wxApp_offer_ready'})
148
+ );
149
+ });
150
+
151
+ it('logs accept reason transitions only once per reason', () => {
152
+ const logSpy = jest.spyOn(wxAppDiagnosticLogging, 'logWxAppOfferDecision');
153
+ const observability = new WxAppOfferObservability();
154
+ const ctx = makeContext({
155
+ taskData: makeTaskDataWithWxAppFields(),
156
+ wxAppAcceptInFlight: true,
157
+ });
158
+
159
+ observability.handleUiControlsUpdate(ctx);
160
+ observability.handleUiControlsUpdate(ctx);
161
+
162
+ expect(logSpy).toHaveBeenCalledTimes(1);
163
+ expect(logSpy).toHaveBeenCalledWith(
164
+ expect.objectContaining({acceptReason: 'wxApp_accept_in_flight'})
165
+ );
166
+ });
167
+
168
+ it('logs browser_webrtc_offer for WebRTC variant without wxApp participant', () => {
169
+ const logSpy = jest.spyOn(wxAppDiagnosticLogging, 'logWxAppOfferDecision');
170
+ const observability = new WxAppOfferObservability();
171
+ const ctx = makeContext({
172
+ taskData: createTaskData({
173
+ agentId: 'agent-1',
174
+ interaction: {
175
+ participants: {
176
+ 'agent-1': {id: 'agent-1', deviceType: 'phone', deviceId: 'device-id-1'},
177
+ },
178
+ } as TaskData['interaction'],
179
+ }),
180
+ voiceVariant: VOICE_VARIANT.WEBRTC,
181
+ });
182
+
183
+ observability.handleUiControlsUpdate(ctx);
184
+
185
+ expect(logSpy).toHaveBeenCalledWith(
186
+ expect.objectContaining({acceptReason: 'browser_webrtc_offer'})
187
+ );
188
+ });
189
+ });
190
+
191
+ describe('deferred participant mismatch', () => {
192
+ it('does not warn when wxApp fields arrive before grace period elapses', () => {
193
+ const warnSpy = jest.spyOn(wxAppDiagnosticLogging, 'logWxAppOfferParticipantMismatch');
194
+ const observability = new WxAppOfferObservability();
195
+ const ctx = makeContext();
196
+
197
+ observability.handleUiControlsUpdate(ctx);
198
+ expect(warnSpy).not.toHaveBeenCalled();
199
+
200
+ ctx.setTaskData(makeTaskDataWithWxAppFields());
201
+ observability.handleUiControlsUpdate(ctx);
202
+
203
+ jest.advanceTimersByTime(WXAPP_PARTICIPANT_MISMATCH_GRACE_MS);
204
+
205
+ expect(warnSpy).not.toHaveBeenCalled();
206
+ expect(ctx.getMetricsManager().trackEvent).not.toHaveBeenCalledWith(
207
+ METRIC_EVENT_NAMES.WXAPP_OFFER_PARTICIPANT_FIELDS_MISSING,
208
+ expect.anything(),
209
+ expect.anything()
210
+ );
211
+ });
212
+
213
+ it('warns and emits metric when fields remain missing after grace period', () => {
214
+ const warnSpy = jest.spyOn(wxAppDiagnosticLogging, 'logWxAppOfferParticipantMismatch');
215
+ const observability = new WxAppOfferObservability();
216
+ const ctx = makeContext();
217
+
218
+ observability.handleUiControlsUpdate(ctx);
219
+ expect(warnSpy).not.toHaveBeenCalled();
220
+
221
+ jest.advanceTimersByTime(WXAPP_PARTICIPANT_MISMATCH_GRACE_MS);
222
+
223
+ expect(warnSpy).toHaveBeenCalledWith(
224
+ expect.objectContaining({
225
+ interactionId: 'interaction-1',
226
+ usersubPublished: true,
227
+ hasDeviceCallId: false,
228
+ hasDeviceId: false,
229
+ acceptReason: 'extension_non_wxApp_offer',
230
+ })
231
+ );
232
+ expect(ctx.getMetricsManager().trackEvent).toHaveBeenCalledWith(
233
+ METRIC_EVENT_NAMES.WXAPP_OFFER_PARTICIPANT_FIELDS_MISSING,
234
+ expect.objectContaining({
235
+ taskId: 'interaction-1',
236
+ usersubPublished: true,
237
+ hasDeviceCallId: false,
238
+ hasDeviceId: false,
239
+ acceptReason: 'extension_non_wxApp_offer',
240
+ }),
241
+ ['operational', 'behavioral']
242
+ );
243
+ });
244
+
245
+ it('cancels pending mismatch when task leaves OFFERED before grace period', () => {
246
+ const warnSpy = jest.spyOn(wxAppDiagnosticLogging, 'logWxAppOfferParticipantMismatch');
247
+ const observability = new WxAppOfferObservability();
248
+ const ctx = makeContext();
249
+
250
+ observability.handleUiControlsUpdate(ctx);
251
+ ctx.setTaskState(TaskState.TERMINATED);
252
+ observability.handleUiControlsUpdate(ctx);
253
+
254
+ jest.advanceTimersByTime(WXAPP_PARTICIPANT_MISMATCH_GRACE_MS);
255
+
256
+ expect(warnSpy).not.toHaveBeenCalled();
257
+ });
258
+
259
+ it('clears grace timer on dispose', () => {
260
+ const warnSpy = jest.spyOn(wxAppDiagnosticLogging, 'logWxAppOfferParticipantMismatch');
261
+ const observability = new WxAppOfferObservability();
262
+ const ctx = makeContext();
263
+
264
+ observability.handleUiControlsUpdate(ctx);
265
+ observability.dispose();
266
+
267
+ jest.advanceTimersByTime(WXAPP_PARTICIPANT_MISMATCH_GRACE_MS);
268
+
269
+ expect(warnSpy).not.toHaveBeenCalled();
270
+ });
271
+
272
+ it('does not reschedule diagnostics after dispose', () => {
273
+ const logSpy = jest.spyOn(wxAppDiagnosticLogging, 'logWxAppOfferDecision');
274
+ const warnSpy = jest.spyOn(wxAppDiagnosticLogging, 'logWxAppOfferParticipantMismatch');
275
+ const observability = new WxAppOfferObservability();
276
+ const ctx = makeContext();
277
+
278
+ observability.dispose();
279
+ observability.handleUiControlsUpdate(ctx);
280
+ jest.advanceTimersByTime(WXAPP_PARTICIPANT_MISMATCH_GRACE_MS);
281
+
282
+ expect(logSpy).not.toHaveBeenCalled();
283
+ expect(warnSpy).not.toHaveBeenCalled();
284
+ expect(ctx.getMetricsManager().trackEvent).not.toHaveBeenCalledWith(
285
+ METRIC_EVENT_NAMES.WXAPP_OFFER_PARTICIPANT_FIELDS_MISSING,
286
+ expect.anything(),
287
+ expect.anything()
288
+ );
289
+ });
290
+
291
+ it('does not warn or emit metric for outdial offers with missing wxApp fields', () => {
292
+ const warnSpy = jest.spyOn(wxAppDiagnosticLogging, 'logWxAppOfferParticipantMismatch');
293
+ const observability = new WxAppOfferObservability();
294
+ const ctx = makeContext({isOutdial: true});
295
+
296
+ observability.handleUiControlsUpdate(ctx);
297
+ jest.advanceTimersByTime(WXAPP_PARTICIPANT_MISMATCH_GRACE_MS);
298
+
299
+ expect(warnSpy).not.toHaveBeenCalled();
300
+ expect(ctx.getMetricsManager().trackEvent).not.toHaveBeenCalledWith(
301
+ METRIC_EVENT_NAMES.WXAPP_OFFER_PARTICIPANT_FIELDS_MISSING,
302
+ expect.anything(),
303
+ expect.anything()
304
+ );
305
+ });
306
+
307
+ it('does not schedule mismatch while usersub is unpublished, then emits after refresh when usersub becomes active', () => {
308
+ const warnSpy = jest.spyOn(wxAppDiagnosticLogging, 'logWxAppOfferParticipantMismatch');
309
+ const observability = new WxAppOfferObservability();
310
+ const ctx = makeContext({usersubPublished: false});
311
+
312
+ observability.handleUiControlsUpdate(ctx);
313
+ jest.advanceTimersByTime(WXAPP_PARTICIPANT_MISMATCH_GRACE_MS);
314
+ expect(warnSpy).not.toHaveBeenCalled();
315
+
316
+ ctx.setUsersubPublished(true);
317
+ observability.handleUiControlsUpdate(ctx);
318
+ expect(warnSpy).not.toHaveBeenCalled();
319
+
320
+ jest.advanceTimersByTime(WXAPP_PARTICIPANT_MISMATCH_GRACE_MS);
321
+
322
+ expect(warnSpy).toHaveBeenCalledWith(
323
+ expect.objectContaining({
324
+ usersubPublished: true,
325
+ hasDeviceCallId: false,
326
+ hasDeviceId: false,
327
+ })
328
+ );
329
+ expect(ctx.getMetricsManager().trackEvent).toHaveBeenCalledWith(
330
+ METRIC_EVENT_NAMES.WXAPP_OFFER_PARTICIPANT_FIELDS_MISSING,
331
+ expect.objectContaining({
332
+ usersubPublished: true,
333
+ hasDeviceCallId: false,
334
+ hasDeviceId: false,
335
+ }),
336
+ ['operational', 'behavioral']
337
+ );
338
+ });
339
+
340
+ it('does not emit mismatch after usersub refresh when participant fields are already valid', () => {
341
+ const warnSpy = jest.spyOn(wxAppDiagnosticLogging, 'logWxAppOfferParticipantMismatch');
342
+ const observability = new WxAppOfferObservability();
343
+ const ctx = makeContext({
344
+ taskData: makeTaskDataWithWxAppFields(),
345
+ usersubPublished: false,
346
+ });
347
+
348
+ observability.handleUiControlsUpdate(ctx);
349
+ ctx.setUsersubPublished(true);
350
+ observability.handleUiControlsUpdate(ctx);
351
+ jest.advanceTimersByTime(WXAPP_PARTICIPANT_MISMATCH_GRACE_MS);
352
+
353
+ expect(warnSpy).not.toHaveBeenCalled();
354
+ expect(ctx.getMetricsManager().trackEvent).not.toHaveBeenCalledWith(
355
+ METRIC_EVENT_NAMES.WXAPP_OFFER_PARTICIPANT_FIELDS_MISSING,
356
+ expect.anything(),
357
+ expect.anything()
358
+ );
359
+ });
360
+ });
361
+ });