@jsb188/mday 1.1.2

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 (202) hide show
  1. package/package.json +142 -0
  2. package/src/constants/agentMemory.ts +166 -0
  3. package/src/constants/agentNote.ts +212 -0
  4. package/src/constants/aiChat.ts +10 -0
  5. package/src/constants/billing.ts +126 -0
  6. package/src/constants/campaign.ts +236 -0
  7. package/src/constants/contact.ts +72 -0
  8. package/src/constants/csvExport.ts +133 -0
  9. package/src/constants/dataTable.ts +22 -0
  10. package/src/constants/dataTableFieldTypes.generated.ts +59 -0
  11. package/src/constants/docAccess.ts +33 -0
  12. package/src/constants/dt.ts +234 -0
  13. package/src/constants/email.ts +146 -0
  14. package/src/constants/fieldDoc.ts +104 -0
  15. package/src/constants/graphqlReactivity.ts +196 -0
  16. package/src/constants/inboundContact.ts +8 -0
  17. package/src/constants/integration.ts +13 -0
  18. package/src/constants/log.ts +21 -0
  19. package/src/constants/logDisplay/README.md +88 -0
  20. package/src/constants/logDisplay/defaults.ts +39 -0
  21. package/src/constants/logDisplay/index.ts +27 -0
  22. package/src/constants/logDisplay/operations/arable.ts +16 -0
  23. package/src/constants/logDisplay/operations/farmersMarket.ts +10 -0
  24. package/src/constants/logDisplay/operations/foodManufacturing.ts +13 -0
  25. package/src/constants/logDisplay/shared/accounting.ts +13 -0
  26. package/src/constants/logDisplay/shared/interactions.ts +13 -0
  27. package/src/constants/logDisplay/shared/rackTemperatures.ts +42 -0
  28. package/src/constants/logTaxonomy.generated.ts +2199 -0
  29. package/src/constants/noteDoc.ts +77 -0
  30. package/src/constants/organization.ts +60 -0
  31. package/src/constants/pageRoute.ts +23 -0
  32. package/src/constants/qrCode.ts +30 -0
  33. package/src/constants/sheet.ts +132 -0
  34. package/src/constants/sms.ts +18 -0
  35. package/src/constants/square.ts +16 -0
  36. package/src/constants/storage.ts +85 -0
  37. package/src/constants/usage.ts +82 -0
  38. package/src/constants/workflowSteps.ts +60 -0
  39. package/src/schemas/editLogEntry.ts +879 -0
  40. package/src/schemas/inboundContact.ts +77 -0
  41. package/src/schemas/logsQuery.ts +93 -0
  42. package/src/types/account.d.ts +81 -0
  43. package/src/types/agentMemory.d.ts +100 -0
  44. package/src/types/agentNote.d.ts +441 -0
  45. package/src/types/billing.d.ts +537 -0
  46. package/src/types/campaign.d.ts +1533 -0
  47. package/src/types/contact.d.ts +15 -0
  48. package/src/types/csvExport.d.ts +213 -0
  49. package/src/types/dataAnalysis.d.ts +44 -0
  50. package/src/types/dataTable.d.ts +159 -0
  51. package/src/types/definitionElement.d.ts +35 -0
  52. package/src/types/docAccess.d.ts +96 -0
  53. package/src/types/dt.d.ts +257 -0
  54. package/src/types/email.d.ts +231 -0
  55. package/src/types/emailReplyReport.d.ts +76 -0
  56. package/src/types/fieldDoc.d.ts +702 -0
  57. package/src/types/fieldDocContract.d.ts +90 -0
  58. package/src/types/inboundContact.d.ts +65 -0
  59. package/src/types/integration.d.ts +42 -0
  60. package/src/types/log.d.ts +338 -0
  61. package/src/types/logDisplay.types.ts +85 -0
  62. package/src/types/organization.d.ts +350 -0
  63. package/src/types/pageRoute.d.ts +48 -0
  64. package/src/types/qrCode.d.ts +96 -0
  65. package/src/types/richText.d.ts +81 -0
  66. package/src/types/sheet.d.ts +847 -0
  67. package/src/types/sms.d.ts +38 -0
  68. package/src/types/storage.d.ts +481 -0
  69. package/src/types/usage.d.ts +106 -0
  70. package/src/types/workflow.d.ts +435 -0
  71. package/src/utils/agentMemory.ts +15 -0
  72. package/src/utils/agentNote.ts +850 -0
  73. package/src/utils/aiChat.ts +43 -0
  74. package/src/utils/aiChatWork.ts +64 -0
  75. package/src/utils/billing.ts +37 -0
  76. package/src/utils/campaign.ts +1173 -0
  77. package/src/utils/campaignAI.ts +72 -0
  78. package/src/utils/campaignAccess.ts +239 -0
  79. package/src/utils/campaignEmail.ts +601 -0
  80. package/src/utils/campaignEmailCompiler.ts +372 -0
  81. package/src/utils/campaignEmailImages.ts +60 -0
  82. package/src/utils/campaignEmailStyles.ts +544 -0
  83. package/src/utils/campaignLifecycle.ts +104 -0
  84. package/src/utils/campaignPreview.ts +285 -0
  85. package/src/utils/contact.ts +50 -0
  86. package/src/utils/csvExport.ts +19 -0
  87. package/src/utils/dataTable.ts +311 -0
  88. package/src/utils/dataTableFieldTypeRegistry.ts +106 -0
  89. package/src/utils/dataTableRelativeDate.ts +447 -0
  90. package/src/utils/definitionElement.ts +84 -0
  91. package/src/utils/docAccess.ts +383 -0
  92. package/src/utils/documentName.ts +53 -0
  93. package/src/utils/email.ts +379 -0
  94. package/src/utils/emailReplyReport.test.ts +187 -0
  95. package/src/utils/emailReplyReport.ts +143 -0
  96. package/src/utils/fieldDoc.ts +157 -0
  97. package/src/utils/fieldDocAnswers.ts +128 -0
  98. package/src/utils/fieldDocDefaults.ts +36 -0
  99. package/src/utils/fieldDocProgram.ts +36 -0
  100. package/src/utils/fieldDocSummary.ts +30 -0
  101. package/src/utils/log.ts +357 -0
  102. package/src/utils/logDisplay.helpers.ts +177 -0
  103. package/src/utils/logDisplay.ts +87 -0
  104. package/src/utils/logRegistryValue.ts +90 -0
  105. package/src/utils/logStoreRead.ts +262 -0
  106. package/src/utils/logTaxonomy.helpers.ts +17 -0
  107. package/src/utils/logTaxonomy.ts +76 -0
  108. package/src/utils/logTaxonomyDisplay.ts +395 -0
  109. package/src/utils/noteDoc.ts +609 -0
  110. package/src/utils/organization.ts +669 -0
  111. package/src/utils/pageRoute.ts +71 -0
  112. package/src/utils/qrCode.helpers.ts +189 -0
  113. package/src/utils/qrCode.test.ts +519 -0
  114. package/src/utils/qrCode.ts +273 -0
  115. package/src/utils/richTextHTML.ts +385 -0
  116. package/src/utils/sheet.ts +262 -0
  117. package/src/utils/sheetAxisMove.ts +616 -0
  118. package/src/utils/sheetBootstrap.ts +1402 -0
  119. package/src/utils/sheetCellLiteral.ts +101 -0
  120. package/src/utils/sheetCommand.ts +358 -0
  121. package/src/utils/sheetDesign.ts +705 -0
  122. package/src/utils/sheetExport.ts +186 -0
  123. package/src/utils/sheetFeatureReference.ts +183 -0
  124. package/src/utils/sheetFormulaArgs.ts +168 -0
  125. package/src/utils/sheetFormulaCompile.ts +475 -0
  126. package/src/utils/sheetFormulaConditionalAggregate.ts +254 -0
  127. package/src/utils/sheetFormulaCriteria.ts +656 -0
  128. package/src/utils/sheetFormulaDate.ts +444 -0
  129. package/src/utils/sheetFormulaEvaluation.ts +899 -0
  130. package/src/utils/sheetFormulaEvaluator.ts +997 -0
  131. package/src/utils/sheetFormulaFunctionHandlers.ts +403 -0
  132. package/src/utils/sheetFormulaLogical.ts +116 -0
  133. package/src/utils/sheetFormulaLookup.ts +488 -0
  134. package/src/utils/sheetFormulaMath.ts +48 -0
  135. package/src/utils/sheetFormulaParser.ts +729 -0
  136. package/src/utils/sheetFormulaRange.ts +330 -0
  137. package/src/utils/sheetFormulaReference.ts +703 -0
  138. package/src/utils/sheetFormulaReferenceAggregates.ts +313 -0
  139. package/src/utils/sheetFormulaReferenceDates.ts +237 -0
  140. package/src/utils/sheetFormulaReferenceLogical.ts +330 -0
  141. package/src/utils/sheetFormulaReferenceLookup.ts +341 -0
  142. package/src/utils/sheetFormulaReferenceMath.ts +95 -0
  143. package/src/utils/sheetFormulaReferenceRewrite.ts +220 -0
  144. package/src/utils/sheetFormulaReferenceText.ts +462 -0
  145. package/src/utils/sheetFormulaSyntax.ts +1027 -0
  146. package/src/utils/sheetFormulaText.ts +430 -0
  147. package/src/utils/sheetJournal.ts +200 -0
  148. package/src/utils/sheetNumberFormat.ts +1012 -0
  149. package/src/utils/sheetPreview.ts +68 -0
  150. package/src/utils/sheetSequence.ts +118 -0
  151. package/src/utils/sheetSnapshot.ts +739 -0
  152. package/src/utils/sheetStructureEdit.ts +914 -0
  153. package/src/utils/sheetStructureReferences.ts +389 -0
  154. package/src/utils/square.ts +32 -0
  155. package/src/utils/storage.ts +198 -0
  156. package/src/utils/table-route.ts +262 -0
  157. package/src/utils/time.ts +12 -0
  158. package/src/utils/workflow.ts +506 -0
  159. package/src/utils/workflowLogFingerprint.ts +302 -0
  160. package/src/utils/workflowLogRevisionSnapshot.ts +424 -0
  161. package/src/utils/workflowProgress.ts +280 -0
  162. package/src/utils/workflowTriggers.ts +61 -0
  163. package/tests/agentNote.test.ts +395 -0
  164. package/tests/campaignAI.test.ts +119 -0
  165. package/tests/campaignAccess.test.ts +239 -0
  166. package/tests/campaignEmail.test.ts +441 -0
  167. package/tests/campaignLifecycle.test.ts +134 -0
  168. package/tests/campaignPublication.test.ts +309 -0
  169. package/tests/dataTableFieldTypeRegistry.test.ts +111 -0
  170. package/tests/dataTableRelativeDate.test.ts +412 -0
  171. package/tests/docAccess.test.ts +525 -0
  172. package/tests/editLogEntry.test.ts +112 -0
  173. package/tests/email.test.ts +39 -0
  174. package/tests/fieldDocProgram.test.ts +114 -0
  175. package/tests/logDisplay.fixtures.ts +67 -0
  176. package/tests/logDisplay.test.ts +227 -0
  177. package/tests/noteDoc.test.ts +514 -0
  178. package/tests/richTextHTML.test.ts +185 -0
  179. package/tests/sheetAxisMove.test.ts +352 -0
  180. package/tests/sheetBootstrap.test.ts +1967 -0
  181. package/tests/sheetFeatureReference.test.ts +22 -0
  182. package/tests/sheetFormulaCriteria.test.ts +269 -0
  183. package/tests/sheetFormulaEvaluator.test.ts +468 -0
  184. package/tests/sheetFormulaFunctions.test.ts +538 -0
  185. package/tests/sheetFormulaLanguage.test.ts +361 -0
  186. package/tests/sheetFormulaParity.fixtures.ts +872 -0
  187. package/tests/sheetFormulaParity.test.ts +188 -0
  188. package/tests/sheetFormulaRange.test.ts +167 -0
  189. package/tests/sheetFormulaReference.test.ts +78 -0
  190. package/tests/sheetFormulaReferenceRewrite.test.ts +117 -0
  191. package/tests/sheetFormulaTextDate.test.ts +512 -0
  192. package/tests/sheetSequence.test.ts +22 -0
  193. package/tests/sheetSnapshot.test.ts +134 -0
  194. package/tests/sheetStructureEdit.test.ts +537 -0
  195. package/tests/sheetStructureReferences.test.ts +589 -0
  196. package/tests/workflowLifecycleStatus.test.ts +60 -0
  197. package/tests/workflowLogFingerprint.test.ts +203 -0
  198. package/tests/workflowLogRevisionSnapshot.test.ts +96 -0
  199. package/tests/workflowProgress.test.ts +180 -0
  200. package/tests/workflowTriggers.test.ts +29 -0
  201. package/tsconfig.json +12 -0
  202. package/vitest.config.ts +8 -0
@@ -0,0 +1,872 @@
1
+ /**
2
+ * Shared client/server formula parity fixtures.
3
+ *
4
+ * One list of (formula, cells, expected) cases runs through three resolvers:
5
+ * the mday stored-value runner (tests/sheetFormulaParity.test.ts), the client
6
+ * resolver (@jsb188:sheet tests/sheet-formula-parity.test.ts) and the server
7
+ * resolver (server sheetOps-formulaParity.test.ts). Resolver drift (range
8
+ * density, referenced-error policy, clamping, cycle codes) shows up as a
9
+ * mismatch, which a pure-core test cannot catch.
10
+ *
11
+ * Formula cells carry the result the recalc engine would have stored for
12
+ * them: the server and mday runners read it, the client re-evaluates the
13
+ * formula (same tab) and must arrive at the same answer. Cycle members store
14
+ * the engine's CYCLE result.
15
+ */
16
+
17
+ export type SheetFormulaParityScalar = string | number | boolean | null;
18
+
19
+ /* The stored computed result of one formula cell. */
20
+ export type SheetFormulaParityStoredResult = { value: SheetFormulaParityScalar } | { errorCode: string; errorMessage?: string };
21
+
22
+ export type SheetFormulaParityCell = SheetFormulaParityScalar | { formula: string; stored: SheetFormulaParityStoredResult };
23
+
24
+ export type SheetFormulaParityExpected = { value: SheetFormulaParityScalar } | { display: string; errorCode: string };
25
+
26
+ export type SheetFormulaParityRunner = 'client' | 'mday' | 'server';
27
+
28
+ export type SheetFormulaParityCase = {
29
+ /* A1 coordinate of the evaluated cell (defaults to Z100) */
30
+ at?: string;
31
+ cells?: Record<string, SheetFormulaParityCell>;
32
+ expected: SheetFormulaParityExpected;
33
+ formula: string;
34
+ name: string;
35
+ now?: string;
36
+ /* Runners that cannot reproduce the case, with the reason */
37
+ skip?: Partial<Record<SheetFormulaParityRunner, string>>;
38
+ timeZone?: string;
39
+ };
40
+
41
+ export const SHEET_FORMULA_PARITY_DEFAULTS = {
42
+ at: 'Z100',
43
+ now: '2026-01-02T03:04:05.000Z',
44
+ timeZone: 'UTC',
45
+ };
46
+
47
+ /* Stored DIVIDE_BY_ZERO result of =1/0 */
48
+ const DIVIDE_BY_ZERO_CELL: SheetFormulaParityCell = {
49
+ formula: '=1/0',
50
+ stored: {
51
+ errorCode: 'DIVIDE_BY_ZERO',
52
+ errorMessage: 'Formula cannot divide by zero.',
53
+ },
54
+ };
55
+
56
+ /* Stored CYCLE result the recalc engine writes for cycle members */
57
+ const CYCLE_STORED: SheetFormulaParityStoredResult = {
58
+ errorCode: 'CYCLE',
59
+ errorMessage: 'Formula is part of a circular reference chain.',
60
+ };
61
+
62
+ export const SHEET_FORMULA_PARITY_CASES: SheetFormulaParityCase[] = [
63
+ {
64
+ name: 'SUM over a sparse range skips blanks',
65
+ formula: '=SUM(A1:A5)',
66
+ cells: { A1: 1, A3: 3 },
67
+ expected: { value: 4 },
68
+ },
69
+ {
70
+ name: 'COUNTA counts nonblank values only',
71
+ formula: '=COUNTA(A1:A4)',
72
+ cells: { A1: 1, A2: 'x', A4: '' },
73
+ expected: { value: 2 },
74
+ },
75
+ {
76
+ name: 'IFERROR catches a referenced formula error',
77
+ formula: '=IFERROR(A1, 7)',
78
+ cells: { A1: DIVIDE_BY_ZERO_CELL },
79
+ expected: { value: 7 },
80
+ },
81
+ {
82
+ name: 'a single reference propagates the referenced error',
83
+ formula: '=A1',
84
+ cells: { A1: DIVIDE_BY_ZERO_CELL },
85
+ expected: { display: '#DIV/0!', errorCode: 'DIVIDE_BY_ZERO' },
86
+ },
87
+ {
88
+ name: 'arithmetic over a referenced error propagates it',
89
+ formula: '=A1+1',
90
+ cells: { A1: DIVIDE_BY_ZERO_CELL },
91
+ expected: { display: '#DIV/0!', errorCode: 'DIVIDE_BY_ZERO' },
92
+ },
93
+ {
94
+ name: 'IFNA catches a referenced NOT_FOUND',
95
+ formula: '=IFNA(A1, "none")',
96
+ cells: {
97
+ A1: {
98
+ formula: '=REGEXMATCH(B1:B2, "zzz")',
99
+ stored: {
100
+ errorCode: 'NOT_FOUND',
101
+ errorMessage: 'REGEXMATCH found no matching value.',
102
+ },
103
+ },
104
+ B1: 'abc',
105
+ },
106
+ expected: { value: 'none' },
107
+ },
108
+ {
109
+ name: 'IFNA does not catch a referenced DIV/0',
110
+ formula: '=IFNA(A1, 0)',
111
+ cells: { A1: DIVIDE_BY_ZERO_CELL },
112
+ expected: { display: '#DIV/0!', errorCode: 'DIVIDE_BY_ZERO' },
113
+ },
114
+ {
115
+ name: 'SUM reads error cells in a range as blank',
116
+ formula: '=SUM(A1:A3)',
117
+ cells: { A1: 1, A2: DIVIDE_BY_ZERO_CELL, A3: 2 },
118
+ expected: { value: 3 },
119
+ },
120
+ {
121
+ name: 'COUNTA does not count error cells in a range',
122
+ formula: '=COUNTA(A1:A3)',
123
+ cells: { A1: 1, A2: DIVIDE_BY_ZERO_CELL, A3: 2 },
124
+ expected: { value: 2 },
125
+ },
126
+ {
127
+ name: 'COUNTA of a range holding only an error cell is 0',
128
+ formula: '=COUNTA(A1:A3)',
129
+ cells: { A1: DIVIDE_BY_ZERO_CELL },
130
+ expected: { value: 0 },
131
+ },
132
+ {
133
+ name: 'MAX skips error cells in a range',
134
+ formula: '=MAX(A1:A3)',
135
+ cells: { A1: 3, A2: DIVIDE_BY_ZERO_CELL, A3: 9 },
136
+ expected: { value: 9 },
137
+ },
138
+ {
139
+ name: 'a NOT_FOUND cell in a range reads as blank',
140
+ formula: '=SUM(A1:A3)',
141
+ cells: {
142
+ A1: 1,
143
+ A2: {
144
+ formula: '=REGEXMATCH(B1:B1, "x")',
145
+ stored: {
146
+ errorCode: 'NOT_FOUND',
147
+ errorMessage: 'REGEXMATCH found no matching value.',
148
+ },
149
+ },
150
+ A3: 2,
151
+ },
152
+ expected: { value: 3 },
153
+ },
154
+ {
155
+ name: 'INCLUDES never matches the display text of an error cell',
156
+ formula: '=INCLUDES("#DIV/0!", A1:A2)',
157
+ cells: { A1: DIVIDE_BY_ZERO_CELL, A2: 5 },
158
+ expected: { value: false },
159
+ },
160
+ {
161
+ name: 'INCLUDES still matches values next to an error cell',
162
+ formula: '=INCLUDES(5, A1:A2)',
163
+ cells: { A1: DIVIDE_BY_ZERO_CELL, A2: 5 },
164
+ expected: { value: true },
165
+ },
166
+ {
167
+ name: 'REGEXMATCH skips error cells in a range',
168
+ formula: '=REGEXMATCH(A1:A2, "#|match")',
169
+ cells: { A1: DIVIDE_BY_ZERO_CELL, A2: 'match me' },
170
+ expected: { value: 'match me' },
171
+ },
172
+ {
173
+ name: 'literal error text is a value, not an error',
174
+ formula: '=IFERROR(A1, 0)',
175
+ cells: { A1: '#N/A' },
176
+ expected: { value: '#N/A' },
177
+ },
178
+ {
179
+ name: 'a referenced formula value flows through',
180
+ formula: '=A1+1',
181
+ cells: { A1: { formula: '=B1*2', stored: { value: 10 } }, B1: 5 },
182
+ expected: { value: 11 },
183
+ },
184
+ {
185
+ name: '& joins text and booleans',
186
+ formula: '=A1&" "&B1',
187
+ cells: { A1: 'Jane', B1: true },
188
+ expected: { value: 'Jane TRUE' },
189
+ },
190
+ {
191
+ name: '& prints numbers at 15 significant digits',
192
+ formula: '=(A1+B1)&""',
193
+ cells: { A1: 0.1, B1: 0.2 },
194
+ expected: { value: '0.3' },
195
+ },
196
+ {
197
+ name: '& binds looser than +',
198
+ formula: '=1+2&3',
199
+ expected: { value: '33' },
200
+ },
201
+ {
202
+ name: '& over a blank cell joins nothing',
203
+ formula: '=A1&"x"',
204
+ expected: { value: 'x' },
205
+ },
206
+ {
207
+ name: '^ is left-associative and binds looser than unary minus',
208
+ formula: '=-2^2+2^3^2',
209
+ expected: { value: 68 },
210
+ },
211
+ {
212
+ name: '^ over a referenced cell',
213
+ formula: '=A1^2',
214
+ cells: { A1: 3 },
215
+ expected: { value: 9 },
216
+ },
217
+ {
218
+ name: 'zero to a negative power is #DIV/0!',
219
+ formula: '=0^-1',
220
+ expected: { display: '#DIV/0!', errorCode: 'DIVIDE_BY_ZERO' },
221
+ },
222
+ {
223
+ name: 'POWER with a non-real result is #NUM!',
224
+ formula: '=POWER(-8, 1/3)',
225
+ expected: { display: '#NUM!', errorCode: 'INVALID_NUMBER' },
226
+ },
227
+ {
228
+ name: 'IFERROR catches the #REF! literal',
229
+ formula: '=IFERROR(#REF!, 0)',
230
+ expected: { value: 0 },
231
+ },
232
+ {
233
+ name: 'the #REF! literal displays #REF!',
234
+ formula: '=#REF!',
235
+ expected: { display: '#REF!', errorCode: 'INVALID_REFERENCE' },
236
+ },
237
+ {
238
+ name: 'SUM propagates a #REF! argument',
239
+ formula: '=SUM(A1, #REF!)',
240
+ cells: { A1: 1 },
241
+ expected: { display: '#REF!', errorCode: 'INVALID_REFERENCE' },
242
+ },
243
+ {
244
+ name: 'a huge range is clamped to the sheet caps',
245
+ at: 'A1',
246
+ formula: '=SUM(B2:ZZZ99999999)',
247
+ cells: { B2: 2, C3: 5 },
248
+ expected: { value: 7 },
249
+ },
250
+ {
251
+ name: 'a range past the row cap is empty',
252
+ formula: '=SUM(A600:A700)',
253
+ expected: { value: 0 },
254
+ },
255
+ {
256
+ name: 'a range crossing the row cap is clamped',
257
+ formula: '=COUNTA(A490:A700)',
258
+ cells: { A495: 'x' },
259
+ expected: { value: 1 },
260
+ },
261
+ {
262
+ name: 'a range containing the evaluated cell is circular',
263
+ at: 'A2',
264
+ formula: '=SUM(A1:A3)',
265
+ cells: { A1: 1 },
266
+ expected: { display: '#ERROR!', errorCode: 'CIRCULAR_REFERENCE' },
267
+ },
268
+ {
269
+ name: 'a direct self reference is circular',
270
+ at: 'A1',
271
+ formula: '=A1+1',
272
+ expected: { display: '#ERROR!', errorCode: 'CIRCULAR_REFERENCE' },
273
+ },
274
+ {
275
+ name: 'a reference to a cycle member is CYCLE',
276
+ formula: '=B1',
277
+ cells: {
278
+ B1: { formula: '=C1', stored: CYCLE_STORED },
279
+ C1: { formula: '=B1', stored: CYCLE_STORED },
280
+ },
281
+ expected: { display: '#ERROR!', errorCode: 'CYCLE' },
282
+ },
283
+ {
284
+ name: 'IFERROR catches a referenced cycle',
285
+ formula: '=IFERROR(B1, 5)',
286
+ cells: {
287
+ B1: { formula: '=C1', stored: CYCLE_STORED },
288
+ C1: { formula: '=B1', stored: CYCLE_STORED },
289
+ },
290
+ expected: { value: 5 },
291
+ },
292
+ {
293
+ name: 'a range containing cycle members is CYCLE',
294
+ formula: '=SUM(A1:A3)',
295
+ cells: {
296
+ A1: 1,
297
+ A2: { formula: '=A3', stored: CYCLE_STORED },
298
+ A3: { formula: '=A2', stored: CYCLE_STORED },
299
+ },
300
+ expected: { display: '#ERROR!', errorCode: 'CYCLE' },
301
+ },
302
+ {
303
+ name: 'ROUND rounds halves away from zero',
304
+ formula: '=ROUND(-2.5)',
305
+ expected: { value: -3 },
306
+ },
307
+ {
308
+ name: 'ROUND uses the decimal value as written',
309
+ formula: '=ROUND(1.005, 2)',
310
+ expected: { value: 1.01 },
311
+ },
312
+ {
313
+ name: 'ROUNDDOWN keeps exact decimals',
314
+ formula: '=ROUNDDOWN(0.29, 2)',
315
+ expected: { value: 0.29 },
316
+ },
317
+ {
318
+ name: 'TODAY uses the organization time zone (Toronto)',
319
+ formula: '=TODAY()',
320
+ timeZone: 'America/Toronto',
321
+ expected: { value: '2026-01-01' },
322
+ },
323
+ {
324
+ name: 'TODAY uses the organization time zone (UTC)',
325
+ formula: '=TODAY()',
326
+ timeZone: 'UTC',
327
+ expected: { value: '2026-01-02' },
328
+ },
329
+ {
330
+ name: 'the legacy @ builtin spelling still evaluates',
331
+ formula: '=@sum(1, 2)',
332
+ expected: { value: 3 },
333
+ },
334
+ {
335
+ name: 'an unknown function displays #ERROR!',
336
+ formula: '=NOPE(1)',
337
+ expected: { display: '#ERROR!', errorCode: 'UNKNOWN_FUNCTION' },
338
+ },
339
+ {
340
+ name: 'division by zero displays #DIV/0!',
341
+ formula: '=1/0',
342
+ expected: { display: '#DIV/0!', errorCode: 'DIVIDE_BY_ZERO' },
343
+ },
344
+ ...getSheetFormulaFunctionParityCases(),
345
+ ...getSheetFormulaTextDateParityCases(),
346
+ ];
347
+
348
+ /*
349
+ * Return the parity cases for the logical, conditional aggregate, lookup and
350
+ * UNIQUE builtins. Ranges have gaps on purpose: a resolver that returned only
351
+ * stored cells would shift every position after a gap.
352
+ */
353
+ function getSheetFormulaFunctionParityCases(): SheetFormulaParityCase[] {
354
+ const priceCells: Record<string, SheetFormulaParityCell> = {
355
+ A1: 'apple',
356
+ B1: 1.5,
357
+ A3: 'Banana',
358
+ B3: 2,
359
+ A4: 'cherry',
360
+ A6: 10,
361
+ B6: 'ten',
362
+ A7: 'date',
363
+ B7: 4,
364
+ };
365
+ const salesCells: Record<string, SheetFormulaParityCell> = {
366
+ A1: 'East',
367
+ B1: 10,
368
+ C1: '2026-01-01',
369
+ A2: 'west',
370
+ B2: 20,
371
+ C2: '2026-01-05',
372
+ A4: 'east',
373
+ B4: 5,
374
+ C4: '2026-01-09',
375
+ A5: 'EAST',
376
+ C5: '2026-01-02T03:00:00.000Z',
377
+ B5: 7,
378
+ };
379
+
380
+ return [
381
+ {
382
+ name: 'AND over a range skips blanks and text',
383
+ formula: '=AND(A1:A4)',
384
+ cells: { A1: true, A3: 'note', A4: 2 },
385
+ expected: { value: true },
386
+ },
387
+ {
388
+ name: 'OR reads an error cell in a range as blank',
389
+ formula: '=OR(A1:A3)',
390
+ cells: { A1: false, A2: DIVIDE_BY_ZERO_CELL, A3: 0 },
391
+ expected: { value: false },
392
+ },
393
+ {
394
+ name: 'XOR counts TRUE values',
395
+ formula: '=XOR(A1, A2, A3)',
396
+ cells: { A1: true, A2: true, A3: true },
397
+ expected: { value: true },
398
+ },
399
+ {
400
+ name: 'NOT of a blank cell is TRUE',
401
+ formula: '=NOT(A1)',
402
+ expected: { value: true },
403
+ },
404
+ {
405
+ name: 'AND with only blank arguments is #VALUE!',
406
+ formula: '=AND(A1)',
407
+ expected: { display: '#VALUE!', errorCode: 'INVALID_VALUE' },
408
+ },
409
+ {
410
+ name: 'AND propagates a referenced error',
411
+ formula: '=AND(TRUE, A1)',
412
+ cells: { A1: DIVIDE_BY_ZERO_CELL },
413
+ expected: { display: '#DIV/0!', errorCode: 'DIVIDE_BY_ZERO' },
414
+ },
415
+ {
416
+ name: 'IFS skips a referenced error in a branch it never takes',
417
+ formula: '=IFS(A2 > 1, A1, TRUE, "fallback")',
418
+ cells: { A1: DIVIDE_BY_ZERO_CELL, A2: 0 },
419
+ expected: { value: 'fallback' },
420
+ },
421
+ {
422
+ name: 'IFS with no TRUE condition is #N/A',
423
+ formula: '=IFS(A1 > 1, "big")',
424
+ cells: { A1: 0 },
425
+ expected: { display: '#N/A', errorCode: 'NOT_FOUND' },
426
+ },
427
+ {
428
+ name: 'SWITCH matches case-insensitively and lazily',
429
+ formula: '=SWITCH(A1, "n", "North", "s", A2, "Other")',
430
+ cells: { A1: 'N', A2: DIVIDE_BY_ZERO_CELL },
431
+ expected: { value: 'North' },
432
+ },
433
+ {
434
+ name: 'SWITCH over a formula-fed expression',
435
+ formula: '=SWITCH(A1, 2, "two", "other")',
436
+ cells: { A1: { formula: '=B1+1', stored: { value: 2 } }, B1: 1 },
437
+ expected: { value: 'two' },
438
+ },
439
+ {
440
+ name: 'COUNTIF counts case-insensitive text over a sparse range',
441
+ formula: '=COUNTIF(A1:A5, "east")',
442
+ cells: salesCells,
443
+ expected: { value: 3 },
444
+ },
445
+ {
446
+ name: 'COUNTIF with a wildcard criterion',
447
+ formula: '=COUNTIF(A1:A7, "*e*")',
448
+ cells: priceCells,
449
+ expected: { value: 3 },
450
+ },
451
+ {
452
+ name: 'COUNTIF "" counts gaps and error cells as blank',
453
+ formula: '=COUNTIF(A1:A4, "")',
454
+ cells: { A1: 1, A2: DIVIDE_BY_ZERO_CELL, A4: '' },
455
+ expected: { value: 3 },
456
+ },
457
+ {
458
+ name: 'SUMIF sums a separate range aligned across gaps',
459
+ formula: '=SUMIF(A1:A5, "east", B1:B5)',
460
+ cells: salesCells,
461
+ expected: { value: 22 },
462
+ },
463
+ {
464
+ name: 'SUMIF over a formula-fed sum range',
465
+ formula: '=SUMIF(A1:A3, "x", B1:B3)',
466
+ cells: {
467
+ A1: 'x',
468
+ A3: 'x',
469
+ B1: { formula: '=C1*2', stored: { value: 6 } },
470
+ B3: 4,
471
+ C1: 3,
472
+ },
473
+ expected: { value: 10 },
474
+ },
475
+ {
476
+ name: 'SUMIFS with an ISO date criterion (UTC)',
477
+ formula: '=SUMIFS(B1:B5, A1:A5, "east", C1:C5, ">=2026-01-02")',
478
+ cells: salesCells,
479
+ expected: { value: 12 },
480
+ },
481
+ {
482
+ name: 'SUMIFS reads datetimes in the organization time zone (Toronto)',
483
+ formula: '=SUMIFS(B1:B5, A1:A5, "east", C1:C5, ">=2026-01-02")',
484
+ cells: salesCells,
485
+ timeZone: 'America/Toronto',
486
+ expected: { value: 5 },
487
+ },
488
+ {
489
+ name: 'COUNTIFS against TODAY() in the organization time zone (UTC)',
490
+ formula: '=COUNTIFS(C1:C5, "<"&TODAY(), A1:A5, "<>west")',
491
+ cells: salesCells,
492
+ expected: { value: 1 },
493
+ },
494
+ {
495
+ name: 'COUNTIFS against TODAY() in the organization time zone (Toronto)',
496
+ formula: '=COUNTIFS(C1:C5, "<"&TODAY(), A1:A5, "<>west")',
497
+ cells: salesCells,
498
+ timeZone: 'America/Toronto',
499
+ expected: { value: 0 },
500
+ },
501
+ {
502
+ name: 'AVERAGEIF averages matched numbers',
503
+ formula: '=AVERAGEIF(A1:A5, "e*", B1:B5)',
504
+ cells: salesCells,
505
+ expected: { value: 22 / 3 },
506
+ },
507
+ {
508
+ name: 'AVERAGEIFS with no numeric match is #DIV/0!',
509
+ formula: '=AVERAGEIFS(B1:B5, A1:A5, "north")',
510
+ cells: salesCells,
511
+ expected: { display: '#DIV/0!', errorCode: 'DIVIDE_BY_ZERO' },
512
+ },
513
+ {
514
+ name: 'SUMIF with ranges of different sizes is #VALUE!',
515
+ formula: '=SUMIF(A1:A5, "east", B1:B4)',
516
+ cells: salesCells,
517
+ expected: { display: '#VALUE!', errorCode: 'INVALID_VALUE' },
518
+ },
519
+ {
520
+ name: 'COUNTBLANK counts every gap of a sparse range',
521
+ formula: '=COUNTBLANK(A1:B7)',
522
+ cells: priceCells,
523
+ expected: { value: 5 },
524
+ },
525
+ {
526
+ name: 'SUMPRODUCT multiplies aligned positions across gaps',
527
+ formula: '=SUMPRODUCT(A1:A4, B1:B4)',
528
+ cells: { A1: 2, B1: 3, A3: 4, B2: 100, B3: 5 },
529
+ expected: { value: 26 },
530
+ },
531
+ {
532
+ name: 'VLOOKUP exact match finds the row after gaps',
533
+ formula: '=VLOOKUP("date", A1:B7, 2, FALSE)',
534
+ cells: priceCells,
535
+ expected: { value: 4 },
536
+ },
537
+ {
538
+ name: 'VLOOKUP returns a blank result cell as blank',
539
+ formula: '=VLOOKUP("CHERRY", A1:B7, 2, FALSE)',
540
+ cells: priceCells,
541
+ expected: { value: null },
542
+ },
543
+ {
544
+ name: 'VLOOKUP matches a number key to numeric text',
545
+ formula: '=VLOOKUP("10", A1:B7, 2, FALSE)',
546
+ cells: priceCells,
547
+ expected: { value: 'ten' },
548
+ },
549
+ {
550
+ name: 'VLOOKUP miss is #N/A',
551
+ formula: '=VLOOKUP("kiwi", A1:B7, 2, FALSE)',
552
+ cells: priceCells,
553
+ expected: { display: '#N/A', errorCode: 'NOT_FOUND' },
554
+ },
555
+ {
556
+ name: 'VLOOKUP index beyond the range is #REF!',
557
+ formula: '=VLOOKUP("date", A1:B7, 3, FALSE)',
558
+ cells: priceCells,
559
+ expected: { display: '#REF!', errorCode: 'INVALID_REFERENCE' },
560
+ },
561
+ {
562
+ name: 'VLOOKUP approximate match over sorted keys with a gap',
563
+ formula: '=VLOOKUP(250, A1:B5, 2)',
564
+ cells: {
565
+ A1: 0,
566
+ B1: 'bronze',
567
+ A2: 100,
568
+ B2: 'silver',
569
+ A4: 500,
570
+ B4: 'gold',
571
+ A5: 1000,
572
+ B5: 'platinum',
573
+ },
574
+ expected: { value: 'silver' },
575
+ },
576
+ {
577
+ name: 'VLOOKUP over a formula-fed key column',
578
+ formula: '=VLOOKUP(6, A1:B2, 2, FALSE)',
579
+ cells: {
580
+ A1: { formula: '=C1*2', stored: { value: 6 } },
581
+ B1: 'six',
582
+ A2: 7,
583
+ B2: 'seven',
584
+ C1: 3,
585
+ },
586
+ expected: { value: 'six' },
587
+ },
588
+ {
589
+ name: 'VLOOKUP over a cycle range is CYCLE',
590
+ formula: '=VLOOKUP(1, A1:B2, 2, FALSE)',
591
+ cells: {
592
+ A1: 1,
593
+ B1: { formula: '=B2', stored: CYCLE_STORED },
594
+ B2: { formula: '=B1', stored: CYCLE_STORED },
595
+ },
596
+ expected: { display: '#ERROR!', errorCode: 'CYCLE' },
597
+ },
598
+ {
599
+ name: 'HLOOKUP across a sparse first row',
600
+ formula: '=HLOOKUP("q3", A1:D2, 2, FALSE)',
601
+ cells: { A1: 'Q1', A2: 10, C1: 'Q3', C2: 30, D2: 40 },
602
+ expected: { value: 30 },
603
+ },
604
+ {
605
+ name: 'INDEX reads a 2-D position past gaps',
606
+ formula: '=INDEX(A1:C3, 3, 2)',
607
+ cells: { A1: 1, C3: 9, B3: 'target' },
608
+ expected: { value: 'target' },
609
+ },
610
+ {
611
+ name: 'INDEX outside the range is #REF!',
612
+ formula: '=INDEX(A1:B2, 3, 1)',
613
+ expected: { display: '#REF!', errorCode: 'INVALID_REFERENCE' },
614
+ },
615
+ {
616
+ name: 'MATCH returns the position counted across gaps',
617
+ formula: '=MATCH("date", A1:A7, 0)',
618
+ cells: priceCells,
619
+ expected: { value: 7 },
620
+ },
621
+ {
622
+ name: 'INDEX/MATCH left lookup',
623
+ formula: '=INDEX(A1:A7, MATCH(4, B1:B7, 0))',
624
+ cells: priceCells,
625
+ expected: { value: 'date' },
626
+ },
627
+ {
628
+ name: 'XLOOKUP returns the aligned result across gaps',
629
+ formula: '=XLOOKUP("cherry", A1:A7, B1:B7, "none")',
630
+ cells: { ...priceCells, B4: 'red' },
631
+ expected: { value: 'red' },
632
+ },
633
+ {
634
+ name: 'XLOOKUP evaluates if_not_found only on a miss',
635
+ formula: '=XLOOKUP("apple", A1:A7, B1:B7, C1)',
636
+ cells: { ...priceCells, C1: DIVIDE_BY_ZERO_CELL },
637
+ expected: { value: 1.5 },
638
+ },
639
+ {
640
+ name: 'XLOOKUP falls back on a miss',
641
+ formula: '=XLOOKUP("kiwi", A1:A7, B1:B7, "none")',
642
+ cells: priceCells,
643
+ expected: { value: 'none' },
644
+ },
645
+ {
646
+ name: 'XLOOKUP next smaller value on unsorted data',
647
+ formula: '=XLOOKUP(25, A1:A4, B1:B4, "none", -1)',
648
+ cells: { A1: 30, B1: 'c', A2: 10, B2: 'a', A4: 20, B4: 'b' },
649
+ expected: { value: 'b' },
650
+ },
651
+ {
652
+ name: 'COUNTA(UNIQUE()) counts distinct values ignoring case',
653
+ formula: '=COUNTA(UNIQUE(A1:A7))',
654
+ cells: { A1: 'a', A2: 'A', A4: 'b', A5: DIVIDE_BY_ZERO_CELL, A7: 'b' },
655
+ expected: { value: 2 },
656
+ },
657
+ {
658
+ name: 'INDEX(UNIQUE()) reads the distinct list',
659
+ formula: '=INDEX(UNIQUE(A1:A5), 2)',
660
+ cells: { A1: 'x', A3: 'X', A5: 'y' },
661
+ expected: { value: 'y' },
662
+ },
663
+ {
664
+ name: 'UNIQUE cannot be the whole formula result',
665
+ formula: '=UNIQUE(A1:A3)',
666
+ cells: { A1: 1 },
667
+ expected: { display: '#ERROR!', errorCode: 'INVALID_FORMULA' },
668
+ },
669
+ ];
670
+ }
671
+
672
+ /*
673
+ * Return the parity cases for the text, date, math and IS* builtins. Ranges
674
+ * have gaps and error cells, and zoned datetimes run in two time zones.
675
+ */
676
+ function getSheetFormulaTextDateParityCases(): SheetFormulaParityCase[] {
677
+ return [
678
+ {
679
+ name: 'TEXTJOIN skips gaps and error cells when ignoring empties',
680
+ formula: '=TEXTJOIN(", ", TRUE, A1:A5)',
681
+ cells: { A1: 'red', A2: DIVIDE_BY_ZERO_CELL, A4: 'blue', A5: 3 },
682
+ expected: { value: 'red, blue, 3' },
683
+ },
684
+ {
685
+ name: 'CONCAT keeps range positions and text forms',
686
+ formula: '=CONCAT(A1:A3, "|", B1)',
687
+ cells: {
688
+ A1: true,
689
+ A3: 0.1,
690
+ B1: { formula: '=0.1+0.2', stored: { value: 0.30000000000000004 } },
691
+ },
692
+ expected: { value: 'TRUE0.1|0.3' },
693
+ },
694
+ {
695
+ name: 'LEFT, MID and RIGHT over a formula-fed text',
696
+ formula: '=LEFT(A1, 3) & MID(A1, 5, 2) & RIGHT(A1, 2)',
697
+ cells: {
698
+ A1: { formula: '="INV-42-XY"', stored: { value: 'INV-42-XY' } },
699
+ },
700
+ expected: { value: 'INV42XY' },
701
+ },
702
+ {
703
+ name: 'SEARCH with a wildcard reports the match position',
704
+ formula: '=SEARCH("b*d", A1)',
705
+ cells: { A1: 'xxBcD' },
706
+ expected: { value: 3 },
707
+ },
708
+ {
709
+ name: 'ISNUMBER(SEARCH()) is FALSE when nothing matches',
710
+ formula: '=ISNUMBER(SEARCH("zz", A1))',
711
+ cells: { A1: 'abc' },
712
+ expected: { value: false },
713
+ },
714
+ {
715
+ name: 'FIND not found is #VALUE!',
716
+ formula: '=FIND("Z", A1)',
717
+ cells: { A1: 'abc' },
718
+ expected: { display: '#VALUE!', errorCode: 'INVALID_VALUE' },
719
+ },
720
+ {
721
+ name: 'SUBSTITUTE and PROPER compose',
722
+ formula: '=PROPER(SUBSTITUTE(A1, "_", " "))',
723
+ cells: { A1: 'north_west REGION' },
724
+ expected: { value: 'North West Region' },
725
+ },
726
+ {
727
+ name: 'TEXT formats a zoned datetime in the organization time zone',
728
+ formula: '=TEXT(A1, "yyyy-mm-dd hh:mm")',
729
+ cells: { A1: '2026-01-02T03:04:05.000Z' },
730
+ timeZone: 'America/Toronto',
731
+ expected: { value: '2026-01-01 22:04' },
732
+ },
733
+ {
734
+ name: 'TEXT formats numbers and ISO dates',
735
+ formula: '=TEXT(A1, "#,##0.0") & " on " & TEXT(A2, "mmm d")',
736
+ cells: { A1: 1234.56, A2: '2026-03-09' },
737
+ expected: { value: '1,234.6 on Mar 9' },
738
+ },
739
+ {
740
+ name: 'VALUE reads formatted numeric text',
741
+ formula: '=VALUE(A1) * 2',
742
+ cells: { A1: '$1,250.50' },
743
+ expected: { value: 2501 },
744
+ },
745
+ {
746
+ name: 'ISERROR catches a referenced error cell',
747
+ formula: '=ISERROR(A1)',
748
+ cells: { A1: DIVIDE_BY_ZERO_CELL },
749
+ expected: { value: true },
750
+ },
751
+ {
752
+ name: 'ISNA is FALSE for a referenced DIV/0',
753
+ formula: '=ISNA(A1)',
754
+ cells: { A1: DIVIDE_BY_ZERO_CELL },
755
+ expected: { value: false },
756
+ },
757
+ {
758
+ name: 'ISNA is TRUE for a referenced NOT_FOUND',
759
+ formula: '=ISNA(C5)',
760
+ cells: {
761
+ C5: {
762
+ formula: '=REGEXMATCH(B1:B2, "zzz")',
763
+ stored: {
764
+ errorCode: 'NOT_FOUND',
765
+ errorMessage: 'REGEXMATCH found no matching value.',
766
+ },
767
+ },
768
+ B1: 'abc',
769
+ },
770
+ expected: { value: true },
771
+ },
772
+ {
773
+ name: 'ISBLANK and ISTEXT over literal cells',
774
+ formula: '=IF(ISBLANK(A1), "blank", "") & IF(ISTEXT(A2), "text", "")',
775
+ cells: { A2: '2026-01-05' },
776
+ expected: { value: 'blanktext' },
777
+ },
778
+ {
779
+ name: 'NETWORKDAYS with a holiday range that has gaps and a weekend date',
780
+ formula: '=NETWORKDAYS("2026-01-01", "2026-01-31", A1:A4)',
781
+ cells: { A1: '2026-01-01', A3: '2026-01-03', A4: '2026-01-19' },
782
+ expected: { value: 20 },
783
+ },
784
+ {
785
+ name: 'WORKDAY skips weekends and a holiday cell',
786
+ formula: '=WORKDAY(A1, 3, B1:B2)',
787
+ cells: { A1: '2026-01-02', B2: '2026-01-06' },
788
+ expected: { value: '2026-01-08' },
789
+ },
790
+ {
791
+ name: 'DAYS reads zoned datetimes as calendar dates (UTC)',
792
+ formula: '=DAYS(A1, "2026-01-01")',
793
+ cells: { A1: '2026-01-02T03:00:00.000Z' },
794
+ expected: { value: 1 },
795
+ },
796
+ {
797
+ name: 'DAYS reads zoned datetimes as calendar dates (Toronto)',
798
+ formula: '=DAYS(A1, "2026-01-01")',
799
+ cells: { A1: '2026-01-02T03:00:00.000Z' },
800
+ timeZone: 'America/Toronto',
801
+ expected: { value: 0 },
802
+ },
803
+ {
804
+ name: 'EDATE and EOMONTH from TODAY in the organization time zone',
805
+ formula: '=EDATE(TODAY(), 1) & " " & EOMONTH(TODAY(), 0)',
806
+ timeZone: 'America/Toronto',
807
+ expected: { value: '2026-02-01 2026-01-31' },
808
+ },
809
+ {
810
+ name: 'WEEKDAY, WEEKNUM and DATEDIF over date cells',
811
+ formula: '=WEEKDAY(A1, 2) & "/" & WEEKNUM(A1, 21) & "/" & DATEDIF(A2, A1, "M")',
812
+ cells: { A1: '2026-01-04', A2: '2025-02-10' },
813
+ expected: { value: '7/1/10' },
814
+ },
815
+ {
816
+ name: 'a date function over a non-date is #VALUE!',
817
+ formula: '=EDATE(A1, 1)',
818
+ cells: { A1: 45000 },
819
+ expected: { display: '#VALUE!', errorCode: 'INVALID_VALUE' },
820
+ },
821
+ {
822
+ name: 'INT, SIGN, TRUNC and SQRT',
823
+ formula: '=INT(A1) + SIGN(A1) + TRUNC(A2, 1) + SQRT(A3)',
824
+ cells: { A1: -2.5, A2: 1.99, A3: 9 },
825
+ expected: { value: -3 - 1 + 1.9 + 3 },
826
+ },
827
+ {
828
+ name: 'SQRT of a negative number is #NUM!',
829
+ formula: '=SQRT(A1)',
830
+ cells: { A1: -4 },
831
+ expected: { display: '#NUM!', errorCode: 'INVALID_NUMBER' },
832
+ },
833
+ {
834
+ name: 'TEXTJOIN over UNIQUE joins distinct values',
835
+ formula: '=TEXTJOIN("+", TRUE, UNIQUE(A1:A5))',
836
+ cells: { A1: 'b', A2: 'B', A4: 'a', A5: 'b' },
837
+ expected: { value: 'b+a' },
838
+ },
839
+ ];
840
+ }
841
+
842
+ /* One runner's normalized outcome for a parity case. */
843
+ export type SheetFormulaParityActual = {
844
+ display?: string | null;
845
+ errorCode?: string | null;
846
+ value: unknown;
847
+ };
848
+
849
+ /*
850
+ * Return a readable mismatch between one expected and one actual parity
851
+ * outcome, or null when they agree (numbers compare within 1e-9). Shared by
852
+ * all three runners so they assert exactly the same thing.
853
+ */
854
+ export function getSheetFormulaParityMismatch(expected: SheetFormulaParityExpected, actual: SheetFormulaParityActual): string | null {
855
+ if ('errorCode' in expected) {
856
+ return actual.errorCode === expected.errorCode && actual.display === expected.display
857
+ ? null
858
+ : `expected error ${expected.errorCode} (${expected.display}), got ${JSON.stringify(actual)}`;
859
+ }
860
+
861
+ if (actual.errorCode) {
862
+ return `expected value ${JSON.stringify(expected.value)}, got error ${actual.errorCode}`;
863
+ }
864
+
865
+ if (typeof expected.value === 'number' && typeof actual.value === 'number') {
866
+ return Math.abs(expected.value - actual.value) <= 1e-9 ? null : `expected ${expected.value}, got ${actual.value}`;
867
+ }
868
+
869
+ return (actual.value ?? null) === expected.value
870
+ ? null
871
+ : `expected ${JSON.stringify(expected.value)}, got ${JSON.stringify(actual.value)}`;
872
+ }