@webex/contact-center 3.12.0-webex-services-ready.4 → 3.13.0-next.1

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 (250) hide show
  1. package/.sdd/manifest.json +24 -13
  2. package/ai-docs/ARCHITECTURE.md +1 -1
  3. package/ai-docs/CONTRACTS.md +21 -3
  4. package/ai-docs/SECURITY.md +1 -1
  5. package/ai-docs/SERVICE_STATE.md +4 -0
  6. package/ai-docs/contact-center-spec.md +53 -6
  7. package/ai-docs/features/consult-transfer-list-policy/spec/feature-spec.md +362 -0
  8. package/ai-docs/features/contact-owner-change-refactor.md +78 -0
  9. package/dist/cc.js +816 -26
  10. package/dist/cc.js.map +1 -1
  11. package/dist/config.js +7 -0
  12. package/dist/config.js.map +1 -1
  13. package/dist/constants.js +29 -2
  14. package/dist/constants.js.map +1 -1
  15. package/dist/index.js +66 -12
  16. package/dist/index.js.map +1 -1
  17. package/dist/metrics/MetricsManager.js +16 -0
  18. package/dist/metrics/MetricsManager.js.map +1 -1
  19. package/dist/metrics/behavioral-events.js +110 -0
  20. package/dist/metrics/behavioral-events.js.map +1 -1
  21. package/dist/metrics/constants.js +33 -0
  22. package/dist/metrics/constants.js.map +1 -1
  23. package/dist/services/AddressBook.js +18 -15
  24. package/dist/services/AddressBook.js.map +1 -1
  25. package/dist/services/AnswerCallOnWebexService.js +202 -0
  26. package/dist/services/AnswerCallOnWebexService.js.map +1 -0
  27. package/dist/services/ApiAiAssistant.js +221 -11
  28. package/dist/services/ApiAiAssistant.js.map +1 -1
  29. package/dist/services/EntryPoint.js +46 -68
  30. package/dist/services/EntryPoint.js.map +1 -1
  31. package/dist/services/Queue.js +27 -22
  32. package/dist/services/Queue.js.map +1 -1
  33. package/dist/services/WebCallingService.js +287 -37
  34. package/dist/services/WebCallingService.js.map +1 -1
  35. package/dist/services/WebexCrossClientService.js +225 -0
  36. package/dist/services/WebexCrossClientService.js.map +1 -0
  37. package/dist/services/WxAppTelephonyMercurySync.js +111 -0
  38. package/dist/services/WxAppTelephonyMercurySync.js.map +1 -0
  39. package/dist/services/config/Util.js +46 -46
  40. package/dist/services/config/Util.js.map +1 -1
  41. package/dist/services/config/constants.js +34 -77
  42. package/dist/services/config/constants.js.map +1 -1
  43. package/dist/services/config/index.js +100 -226
  44. package/dist/services/config/index.js.map +1 -1
  45. package/dist/services/config/types.js +55 -35
  46. package/dist/services/config/types.js.map +1 -1
  47. package/dist/services/constants.js +11 -1
  48. package/dist/services/constants.js.map +1 -1
  49. package/dist/services/core/Err.js.map +1 -1
  50. package/dist/services/core/Utils.js +25 -1
  51. package/dist/services/core/Utils.js.map +1 -1
  52. package/dist/services/core/WebexRequest.js +6 -2
  53. package/dist/services/core/WebexRequest.js.map +1 -1
  54. package/dist/services/core/aqm-reqs.js +17 -11
  55. package/dist/services/core/aqm-reqs.js.map +1 -1
  56. package/dist/services/core/constants.js +9 -1
  57. package/dist/services/core/constants.js.map +1 -1
  58. package/dist/services/core/types.js.map +1 -1
  59. package/dist/services/core/websocket/WebSocketManager.js +17 -1
  60. package/dist/services/core/websocket/WebSocketManager.js.map +1 -1
  61. package/dist/services/task/Task.js +275 -8
  62. package/dist/services/task/Task.js.map +1 -1
  63. package/dist/services/task/TaskFactory.js +11 -6
  64. package/dist/services/task/TaskFactory.js.map +1 -1
  65. package/dist/services/task/TaskManager.js +590 -42
  66. package/dist/services/task/TaskManager.js.map +1 -1
  67. package/dist/services/task/TaskUtils.js +11 -1
  68. package/dist/services/task/TaskUtils.js.map +1 -1
  69. package/dist/services/task/WebexCallingUtils.js +70 -0
  70. package/dist/services/task/WebexCallingUtils.js.map +1 -0
  71. package/dist/services/task/constants.js +14 -2
  72. package/dist/services/task/constants.js.map +1 -1
  73. package/dist/services/task/contact.js +29 -0
  74. package/dist/services/task/contact.js.map +1 -1
  75. package/dist/services/task/digital/Digital.js +4 -3
  76. package/dist/services/task/digital/Digital.js.map +1 -1
  77. package/dist/services/task/state-machine/TaskStateMachine.js +162 -53
  78. package/dist/services/task/state-machine/TaskStateMachine.js.map +1 -1
  79. package/dist/services/task/state-machine/actions.js +6 -1
  80. package/dist/services/task/state-machine/actions.js.map +1 -1
  81. package/dist/services/task/state-machine/guards.js +7 -10
  82. package/dist/services/task/state-machine/guards.js.map +1 -1
  83. package/dist/services/task/state-machine/types.js.map +1 -1
  84. package/dist/services/task/state-machine/uiControlsComputer.js +118 -18
  85. package/dist/services/task/state-machine/uiControlsComputer.js.map +1 -1
  86. package/dist/services/task/types.js +47 -1
  87. package/dist/services/task/types.js.map +1 -1
  88. package/dist/services/task/voice/Voice.js +477 -17
  89. package/dist/services/task/voice/Voice.js.map +1 -1
  90. package/dist/services/task/voice/WebRTC.js +6 -3
  91. package/dist/services/task/voice/WebRTC.js.map +1 -1
  92. package/dist/services/task/voice/wxAppOfferObservability.js +145 -0
  93. package/dist/services/task/voice/wxAppOfferObservability.js.map +1 -0
  94. package/dist/services/task/voice/wxAppVoiceMethods.js +395 -0
  95. package/dist/services/task/voice/wxAppVoiceMethods.js.map +1 -0
  96. package/dist/services/wxAppDiagnosticLogging.js +159 -0
  97. package/dist/services/wxAppDiagnosticLogging.js.map +1 -0
  98. package/dist/services/wxAppTelephonyUtils.js +19 -0
  99. package/dist/services/wxAppTelephonyUtils.js.map +1 -0
  100. package/dist/types/cc.d.ts +127 -9
  101. package/dist/types/config.d.ts +7 -0
  102. package/dist/types/constants.d.ts +23 -0
  103. package/dist/types/index.d.ts +38 -17
  104. package/dist/types/metrics/MetricsManager.d.ts +6 -0
  105. package/dist/types/metrics/constants.d.ts +31 -0
  106. package/dist/types/services/AddressBook.d.ts +2 -1
  107. package/dist/types/services/AnswerCallOnWebexService.d.ts +38 -0
  108. package/dist/types/services/ApiAiAssistant.d.ts +48 -4
  109. package/dist/types/services/EntryPoint.d.ts +7 -5
  110. package/dist/types/services/Queue.d.ts +5 -3
  111. package/dist/types/services/WebexCrossClientService.d.ts +32 -0
  112. package/dist/types/services/WxAppTelephonyMercurySync.d.ts +28 -0
  113. package/dist/types/services/config/Util.d.ts +4 -8
  114. package/dist/types/services/config/constants.d.ts +28 -76
  115. package/dist/types/services/config/index.d.ts +16 -64
  116. package/dist/types/services/config/types.d.ts +150 -173
  117. package/dist/types/services/constants.d.ts +9 -0
  118. package/dist/types/services/core/Err.d.ts +2 -0
  119. package/dist/types/services/core/Utils.d.ts +10 -0
  120. package/dist/types/services/core/WebexRequest.d.ts +1 -0
  121. package/dist/types/services/core/constants.d.ts +7 -0
  122. package/dist/types/services/core/types.d.ts +2 -0
  123. package/dist/types/services/task/Task.d.ts +34 -5
  124. package/dist/types/services/task/TaskFactory.d.ts +4 -2
  125. package/dist/types/services/task/TaskUtils.d.ts +6 -0
  126. package/dist/types/services/task/WebexCallingUtils.d.ts +11 -0
  127. package/dist/types/services/task/constants.d.ts +12 -0
  128. package/dist/types/services/task/contact.d.ts +4 -0
  129. package/dist/types/services/task/digital/Digital.d.ts +4 -3
  130. package/dist/types/services/task/state-machine/TaskStateMachine.d.ts +304 -56
  131. package/dist/types/services/task/state-machine/guards.d.ts +6 -5
  132. package/dist/types/services/task/state-machine/types.d.ts +9 -1
  133. package/dist/types/services/task/types.d.ts +192 -5
  134. package/dist/types/services/task/voice/Voice.d.ts +68 -11
  135. package/dist/types/services/task/voice/WebRTC.d.ts +5 -4
  136. package/dist/types/services/task/voice/wxAppOfferObservability.d.ts +39 -0
  137. package/dist/types/services/task/voice/wxAppVoiceMethods.d.ts +68 -0
  138. package/dist/types/services/wxAppDiagnosticLogging.d.ts +63 -0
  139. package/dist/types/services/wxAppTelephonyUtils.d.ts +5 -0
  140. package/dist/types/types.d.ts +125 -13
  141. package/dist/types/utils/PageCache.d.ts +20 -3
  142. package/dist/types.js +90 -8
  143. package/dist/types.js.map +1 -1
  144. package/dist/utils/PageCache.js +19 -5
  145. package/dist/utils/PageCache.js.map +1 -1
  146. package/dist/webex.js +9 -1
  147. package/dist/webex.js.map +1 -1
  148. package/package.json +10 -9
  149. package/src/cc.ts +1047 -48
  150. package/src/config.ts +7 -0
  151. package/src/constants.ts +36 -0
  152. package/src/index.ts +49 -11
  153. package/src/metrics/MetricsManager.ts +16 -0
  154. package/src/metrics/ai-docs/metrics-spec.md +138 -21
  155. package/src/metrics/behavioral-events.ts +112 -0
  156. package/src/metrics/constants.ts +36 -0
  157. package/src/services/AddressBook.ts +17 -6
  158. package/src/services/AnswerCallOnWebexService.ts +239 -0
  159. package/src/services/ApiAiAssistant.ts +297 -13
  160. package/src/services/EntryPoint.ts +59 -60
  161. package/src/services/Queue.ts +29 -12
  162. package/src/services/WebCallingService.ts +362 -40
  163. package/src/services/WebexCrossClientService.ts +298 -0
  164. package/src/services/WxAppTelephonyMercurySync.ts +142 -0
  165. package/src/services/agent/ai-docs/AGENTS.md +1 -1
  166. package/src/services/agent/ai-docs/agent-spec.md +1 -0
  167. package/src/services/ai-docs/AGENTS.md +11 -11
  168. package/src/services/ai-docs/services-spec.md +25 -5
  169. package/src/services/config/Util.ts +52 -82
  170. package/src/services/config/ai-docs/AGENTS.md +35 -40
  171. package/src/services/config/ai-docs/ARCHITECTURE.md +90 -103
  172. package/src/services/config/ai-docs/config-spec.md +132 -132
  173. package/src/services/config/constants.ts +39 -85
  174. package/src/services/config/index.ts +116 -277
  175. package/src/services/config/types.ts +145 -195
  176. package/src/services/constants.ts +10 -0
  177. package/src/services/core/Err.ts +1 -0
  178. package/src/services/core/Utils.ts +28 -0
  179. package/src/services/core/WebexRequest.ts +3 -1
  180. package/src/services/core/ai-docs/core-spec.md +25 -11
  181. package/src/services/core/aqm-reqs.ts +18 -12
  182. package/src/services/core/constants.ts +8 -0
  183. package/src/services/core/types.ts +33 -1
  184. package/src/services/core/websocket/WebSocketManager.ts +26 -2
  185. package/src/services/task/Task.ts +386 -12
  186. package/src/services/task/TaskFactory.ts +33 -6
  187. package/src/services/task/TaskManager.ts +857 -41
  188. package/src/services/task/TaskUtils.ts +13 -0
  189. package/src/services/task/WebexCallingUtils.ts +136 -0
  190. package/src/services/task/ai-docs/ARCHITECTURE.md +1 -0
  191. package/src/services/task/ai-docs/task-spec.md +190 -8
  192. package/src/services/task/constants.ts +13 -0
  193. package/src/services/task/contact.ts +30 -0
  194. package/src/services/task/digital/Digital.ts +11 -4
  195. package/src/services/task/state-machine/TaskStateMachine.ts +235 -81
  196. package/src/services/task/state-machine/actions.ts +5 -2
  197. package/src/services/task/state-machine/ai-docs/AGENTS.md +6 -4
  198. package/src/services/task/state-machine/ai-docs/ARCHITECTURE.md +35 -16
  199. package/src/services/task/state-machine/ai-docs/task-state-machine-spec.md +103 -33
  200. package/src/services/task/state-machine/guards.ts +7 -10
  201. package/src/services/task/state-machine/types.ts +16 -1
  202. package/src/services/task/state-machine/uiControlsComputer.ts +206 -32
  203. package/src/services/task/types.ts +269 -4
  204. package/src/services/task/voice/Voice.ts +625 -17
  205. package/src/services/task/voice/WebRTC.ts +11 -4
  206. package/src/services/task/voice/wxAppOfferObservability.ts +204 -0
  207. package/src/services/task/voice/wxAppVoiceMethods.ts +575 -0
  208. package/src/services/wxAppDiagnosticLogging.ts +286 -0
  209. package/src/services/wxAppTelephonyUtils.ts +14 -0
  210. package/src/types.ts +159 -13
  211. package/src/utils/AGENTS.md +21 -10
  212. package/src/utils/PageCache.ts +38 -5
  213. package/src/utils/ai-docs/utils-spec.md +21 -11
  214. package/src/webex.js +8 -0
  215. package/test/unit/fixtures/aiSummaryTestUtils.ts +40 -0
  216. package/test/unit/spec/cc.ts +3595 -120
  217. package/test/unit/spec/index.ts +891 -0
  218. package/test/unit/spec/metrics/MetricsManager.ts +25 -0
  219. package/test/unit/spec/metrics/behavioral-events.ts +60 -0
  220. package/test/unit/spec/services/AddressBook.ts +37 -6
  221. package/test/unit/spec/services/AnswerCallOnWebexService.ts +264 -0
  222. package/test/unit/spec/services/ApiAiAssistant.ts +269 -8
  223. package/test/unit/spec/services/EntryPoint.ts +87 -40
  224. package/test/unit/spec/services/Queue.ts +123 -12
  225. package/test/unit/spec/services/WebCallingService.ts +483 -54
  226. package/test/unit/spec/services/WebexCrossClientService.ts +509 -0
  227. package/test/unit/spec/services/WxAppTelephonyMercurySync.ts +136 -0
  228. package/test/unit/spec/services/config/Util.ts +501 -0
  229. package/test/unit/spec/services/config/index.ts +313 -543
  230. package/test/unit/spec/services/core/Utils.ts +22 -0
  231. package/test/unit/spec/services/core/WebexRequest.ts +8 -7
  232. package/test/unit/spec/services/core/aqm-reqs.ts +142 -1
  233. package/test/unit/spec/services/core/websocket/WebSocketManager.ts +64 -14
  234. package/test/unit/spec/services/task/Task.ts +2257 -11
  235. package/test/unit/spec/services/task/TaskFactory.ts +56 -2
  236. package/test/unit/spec/services/task/TaskManager.ts +5559 -1493
  237. package/test/unit/spec/services/task/TaskUtils.ts +72 -0
  238. package/test/unit/spec/services/task/WebexCallingUtils.ts +153 -0
  239. package/test/unit/spec/services/task/contact.ts +33 -0
  240. package/test/unit/spec/services/task/state-machine/TaskStateMachine.ts +1501 -92
  241. package/test/unit/spec/services/task/state-machine/guards.ts +210 -8
  242. package/test/unit/spec/services/task/state-machine/uiControlsComputer.ts +445 -7
  243. package/test/unit/spec/services/task/voice/Voice.ts +1710 -4
  244. package/test/unit/spec/services/task/voice/wxAppOfferObservability.ts +361 -0
  245. package/test/unit/spec/services/task/voice/wxAppVoiceMethods.ts +719 -0
  246. package/test/unit/spec/services/wxAppDiagnosticLogging.ts +179 -0
  247. package/test/unit/spec/wellnessSampleUtils.ts +288 -0
  248. package/typedoc.md +1 -1
  249. package/umd/contact-center.min.js +2 -2
  250. package/umd/contact-center.min.js.map +1 -1
@@ -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
+ });