@rocapine/react-native-onboarding 1.74.1 → 1.76.0

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 (105) hide show
  1. package/dist/evaluateCondition.d.ts.map +1 -1
  2. package/dist/evaluateCondition.js +103 -4
  3. package/dist/evaluateCondition.js.map +1 -1
  4. package/dist/index.d.ts +10 -2
  5. package/dist/index.d.ts.map +1 -1
  6. package/dist/index.js +39 -1
  7. package/dist/index.js.map +1 -1
  8. package/dist/onboarding-example.d.ts +375 -99
  9. package/dist/onboarding-example.d.ts.map +1 -1
  10. package/dist/onboarding-example.js +118 -1
  11. package/dist/onboarding-example.js.map +1 -1
  12. package/dist/paywalls/PaywallProvider.d.ts +71 -5
  13. package/dist/paywalls/PaywallProvider.d.ts.map +1 -1
  14. package/dist/paywalls/PaywallProvider.js +237 -57
  15. package/dist/paywalls/PaywallProvider.js.map +1 -1
  16. package/dist/paywalls/customScreens.d.ts +31 -0
  17. package/dist/paywalls/customScreens.d.ts.map +1 -1
  18. package/dist/paywalls/observer.d.ts +129 -0
  19. package/dist/paywalls/observer.d.ts.map +1 -0
  20. package/dist/paywalls/observer.js +211 -0
  21. package/dist/paywalls/observer.js.map +1 -0
  22. package/dist/paywalls/present.d.ts +19 -15
  23. package/dist/paywalls/present.d.ts.map +1 -1
  24. package/dist/paywalls/present.js +21 -17
  25. package/dist/paywalls/present.js.map +1 -1
  26. package/dist/paywalls/types.d.ts +3 -1
  27. package/dist/paywalls/types.d.ts.map +1 -1
  28. package/dist/products/adapters/expoIap.d.ts +38 -1
  29. package/dist/products/adapters/expoIap.d.ts.map +1 -1
  30. package/dist/products/adapters/expoIap.js +509 -75
  31. package/dist/products/adapters/expoIap.js.map +1 -1
  32. package/dist/products/index.d.ts +1 -0
  33. package/dist/products/index.d.ts.map +1 -1
  34. package/dist/products/index.js.map +1 -1
  35. package/dist/products/types.d.ts +13 -0
  36. package/dist/products/types.d.ts.map +1 -1
  37. package/dist/screens/completingActions.d.ts +95 -0
  38. package/dist/screens/completingActions.d.ts.map +1 -0
  39. package/dist/screens/completingActions.js +302 -0
  40. package/dist/screens/completingActions.js.map +1 -0
  41. package/dist/screens/elementTypeRegistry.d.ts +45 -0
  42. package/dist/screens/elementTypeRegistry.d.ts.map +1 -0
  43. package/dist/screens/elementTypeRegistry.js +119 -0
  44. package/dist/screens/elementTypeRegistry.js.map +1 -0
  45. package/dist/screens/elements/ButtonElement.d.ts +3 -2
  46. package/dist/screens/elements/ButtonElement.d.ts.map +1 -1
  47. package/dist/screens/elements/ButtonElement.js +5 -1
  48. package/dist/screens/elements/ButtonElement.js.map +1 -1
  49. package/dist/screens/resolveRenderableStep.d.ts +42 -0
  50. package/dist/screens/resolveRenderableStep.d.ts.map +1 -0
  51. package/dist/screens/resolveRenderableStep.js +28 -0
  52. package/dist/screens/resolveRenderableStep.js.map +1 -0
  53. package/dist/screens/types.d.ts +2 -2
  54. package/dist/screens/types.d.ts.map +1 -1
  55. package/dist/screens/types.js +5 -1
  56. package/dist/screens/types.js.map +1 -1
  57. package/dist/screens/unknownElementTypes.d.ts +94 -0
  58. package/dist/screens/unknownElementTypes.d.ts.map +1 -0
  59. package/dist/screens/unknownElementTypes.js +141 -0
  60. package/dist/screens/unknownElementTypes.js.map +1 -0
  61. package/dist/screens/unknownKeys.d.ts +30 -6
  62. package/dist/screens/unknownKeys.d.ts.map +1 -1
  63. package/dist/screens/unknownKeys.js +88 -54
  64. package/dist/screens/unknownKeys.js.map +1 -1
  65. package/dist/steps/common.types.d.ts +262 -9
  66. package/dist/steps/common.types.d.ts.map +1 -1
  67. package/dist/steps/common.types.js +64 -3
  68. package/dist/steps/common.types.js.map +1 -1
  69. package/package.json +1 -1
  70. package/src/__tests__/authoringDocEscapes.test.ts +59 -0
  71. package/src/__tests__/completingActions.test.ts +509 -0
  72. package/src/__tests__/customActionHooks.test.ts +224 -0
  73. package/src/__tests__/elementTypeRegistry.test.ts +48 -0
  74. package/src/__tests__/evaluateCondition.test.ts +228 -3
  75. package/src/__tests__/onboardingExampleElements.test.ts +74 -0
  76. package/src/__tests__/requestPermissionAction.test.ts +138 -0
  77. package/src/__tests__/resolveRenderableStep.test.ts +117 -0
  78. package/src/__tests__/retryIdempotencyDocs.test.ts +57 -0
  79. package/src/__tests__/unknownElementTypes.test.ts +240 -0
  80. package/src/__tests__/unknownKeys.test.ts +110 -0
  81. package/src/evaluateCondition.ts +107 -4
  82. package/src/index.ts +55 -0
  83. package/src/onboarding-example.ts +119 -1
  84. package/src/paywalls/PaywallProvider.tsx +370 -66
  85. package/src/paywalls/__tests__/PaywallProvider.observer.test.tsx +866 -0
  86. package/src/paywalls/__tests__/observer.test.ts +401 -0
  87. package/src/paywalls/__tests__/present.test.ts +0 -18
  88. package/src/paywalls/customScreens.ts +34 -1
  89. package/src/paywalls/observer.ts +308 -0
  90. package/src/paywalls/present.ts +24 -18
  91. package/src/paywalls/types.ts +3 -1
  92. package/src/products/adapters/__tests__/expoIap.contract.test.ts +648 -0
  93. package/src/products/adapters/__tests__/expoIap.test.ts +25 -11
  94. package/src/products/adapters/__tests__/expoIap5Fake.ts +288 -0
  95. package/src/products/adapters/expoIap.ts +609 -78
  96. package/src/products/index.ts +1 -0
  97. package/src/products/types.ts +13 -0
  98. package/src/screens/completingActions.ts +316 -0
  99. package/src/screens/elementTypeRegistry.ts +122 -0
  100. package/src/screens/elements/ButtonElement.ts +9 -1
  101. package/src/screens/resolveRenderableStep.ts +59 -0
  102. package/src/screens/types.ts +2 -2
  103. package/src/screens/unknownElementTypes.ts +204 -0
  104. package/src/screens/unknownKeys.ts +119 -56
  105. package/src/steps/common.types.ts +297 -9
@@ -0,0 +1,509 @@
1
+ import { describe, it, expect } from "vitest";
2
+ import {
3
+ actionsCanComplete,
4
+ completingActionKind,
5
+ hasCompletingAction,
6
+ } from "../screens/completingActions";
7
+
8
+ /**
9
+ * "Can the user still get off this screen?" (#209, review finding 1).
10
+ *
11
+ * The unknown-element strip removes a subtree, and a ComposableScreen's CTA is
12
+ * authored INSIDE that tree — `ComposableScreenRenderer` passes no `button` to
13
+ * `OnboardingTemplate`, so nothing outside `ScreenRenderer` can call
14
+ * `onContinue`. Strip the element that happened to be the screen's root
15
+ * container and the payload parses cleanly to `elements: []`: a blank screen,
16
+ * no CTA, and with `displayProgressHeader: false` no back chevron either. The
17
+ * throw that at least reached an error boundary became a silent trap.
18
+ *
19
+ * This predicate is what the renderer consults to decide whether it must supply
20
+ * its own escape. `runActions` is the only thing in the runtime that ever calls
21
+ * `onContinue`, and it does so for exactly two actions — `"continue"` and
22
+ * `{type:"dismiss"}` — so those two, wherever they are reachable from a press,
23
+ * are the whole definition of "this screen can be completed".
24
+ */
25
+
26
+ const button = (id: string, actions: unknown[]) => ({
27
+ id,
28
+ type: "Button",
29
+ props: { label: "Go", actions },
30
+ });
31
+
32
+ describe("hasCompletingAction", () => {
33
+ it("finds a Button whose actions continue", () => {
34
+ expect(hasCompletingAction([button("cta", ["continue"])])).toBe(true);
35
+ });
36
+
37
+ it("finds a continue nested inside a container", () => {
38
+ const tree = [
39
+ { id: "root", type: "YStack", props: {}, children: [button("cta", ["continue"])] },
40
+ ];
41
+ expect(hasCompletingAction(tree)).toBe(true);
42
+ });
43
+
44
+ it("reports no way forward for a screen of static content", () => {
45
+ const tree = [
46
+ {
47
+ id: "root",
48
+ type: "YStack",
49
+ props: {},
50
+ children: [{ id: "t", type: "Text", props: { content: "hello" } }],
51
+ },
52
+ ];
53
+ expect(hasCompletingAction(tree)).toBe(false);
54
+ });
55
+
56
+ it("reports no way forward for an empty screen — the exact post-strip case", () => {
57
+ expect(hasCompletingAction([])).toBe(false);
58
+ });
59
+
60
+ it("accepts the deprecated `action: \"continue\"` shorthand", () => {
61
+ expect(hasCompletingAction([{ id: "cta", type: "Button", props: { label: "Go", action: "continue" } }])).toBe(
62
+ true
63
+ );
64
+ });
65
+
66
+ it("accepts the generic `onPress` any element can carry", () => {
67
+ const tree = [{ id: "card", type: "YStack", props: { onPress: ["continue"] }, children: [] }];
68
+ expect(hasCompletingAction(tree)).toBe(true);
69
+ });
70
+
71
+ it("ignores an `onPress` on a Button, which renderElement never wires", () => {
72
+ // `PRESS_HANDLED_TYPES` in `renderElement.tsx`: Button and the other
73
+ // self-handling elements dispatch their own actions, so the generic
74
+ // `onPress` from BaseBoxProps is not wired for them. Counting it would read
75
+ // as "the user can leave" on a screen whose only control does nothing.
76
+ const tree = [{ id: "cta", type: "Button", props: { label: "Go", onPress: ["continue"] } }];
77
+ expect(hasCompletingAction(tree)).toBe(false);
78
+ });
79
+
80
+ it("counts `dismiss`, which completes the screen just as `continue` does", () => {
81
+ expect(hasCompletingAction([button("x", [{ type: "dismiss" }])])).toBe(true);
82
+ });
83
+
84
+ it("finds a continue in a purchase action's onSuccess branch", () => {
85
+ const tree = [
86
+ button("buy", [
87
+ { type: "purchase", product: "p1", onSuccess: ["continue"] },
88
+ ]),
89
+ ];
90
+ expect(hasCompletingAction(tree)).toBe(true);
91
+ });
92
+
93
+ it("finds a continue in a restore action's onNothingToRestore branch", () => {
94
+ const tree = [
95
+ button("restore", [{ type: "restore", onNothingToRestore: ["continue"] }]),
96
+ ];
97
+ expect(hasCompletingAction(tree)).toBe(true);
98
+ });
99
+
100
+ it("does not count setVariable, which leaves the user on the screen", () => {
101
+ const tree = [button("pick", [{ type: "setVariable", name: "goal", value: "lose" }])];
102
+ expect(hasCompletingAction(tree)).toBe(false);
103
+ });
104
+
105
+ it("does not count presentPaywall — a modal opens over the screen, the step does not advance", () => {
106
+ const tree = [button("open", [{ type: "presentPaywall", placement: "hard_paywall" }])];
107
+ expect(hasCompletingAction(tree)).toBe(false);
108
+ });
109
+
110
+ it("does not count a host `custom` action, whose effect this SDK cannot know", () => {
111
+ // Deliberate, and the safer of the two errors: a host handler that
112
+ // navigates by itself would get a redundant escape CTA on an
113
+ // already-degraded screen, whereas guessing the other way re-creates the
114
+ // trap. `runActions` does not call `onContinue` for `custom`.
115
+ const tree = [button("skip", [{ type: "custom", name: "skipOnboarding" }])];
116
+ expect(hasCompletingAction(tree)).toBe(false);
117
+ });
118
+
119
+ it("looks inside a Repeat's children, where a CTA can legitimately live", () => {
120
+ const tree = [
121
+ {
122
+ id: "rep",
123
+ type: "Repeat",
124
+ props: { over: "goals" },
125
+ children: [button("cta", ["continue"])],
126
+ },
127
+ ];
128
+ expect(hasCompletingAction(tree)).toBe(true);
129
+ });
130
+
131
+ it("survives a malformed payload rather than throwing", () => {
132
+ expect(hasCompletingAction([null, 3, "x", { id: "a" }, { props: null }])).toBe(false);
133
+ expect(hasCompletingAction(undefined)).toBe(false);
134
+ expect(hasCompletingAction({ not: "an array" })).toBe(false);
135
+ });
136
+
137
+ it("ignores a bare `{type:\"continue\"}` object — that is not an action this runtime runs", () => {
138
+ // `ButtonActionSchema` declares continue as the string literal `"continue"`.
139
+ // An object is not it, so the runtime would never advance on it; reading it
140
+ // as a way forward would leave the user stuck with no escape.
141
+ expect(hasCompletingAction([button("cta", [{ type: "continue" }])])).toBe(false);
142
+ });
143
+ });
144
+
145
+ /**
146
+ * `requestPermission` (#196) is the one action whose branch lists must NOT be
147
+ * read with the generic "any nested list completes it" rule, and review round 1
148
+ * caught the first version doing exactly that.
149
+ *
150
+ * The question this predicate answers is "can the user still get off this
151
+ * screen?", and for a permission ask the honest answer is "only on the outcomes
152
+ * the author covered". The runtime has three: a grant runs `onGranted`, a
153
+ * refusal runs `onDenied`, and "this build cannot ask" runs
154
+ * `onUnavailable ?? onDenied`. A CTA holding its only `"continue"` in
155
+ * `onGranted` traps every user who refuses — and traps EVERY user on a build
156
+ * that never installed the optional Expo module, which is a packaging fact the
157
+ * person pressing the button cannot do anything about.
158
+ *
159
+ * So the rule is AND across the outcomes, not OR: the action counts as a way
160
+ * forward only when a grant AND a non-grant both reach `"continue"` /
161
+ * `{dismiss}`. That is the file's stated bias ("errs toward no") applied to the
162
+ * one action whose result the user does not fully control. `purchase` and
163
+ * `restore` keep the OR reading deliberately — a cancelled purchase leaves the
164
+ * user free to press again, whereas a standing OS denial cannot be retried.
165
+ */
166
+ describe("hasCompletingAction — requestPermission outcome hooks", () => {
167
+ const ask = (hooks: Record<string, unknown[]>) => [
168
+ button("cta", [{ type: "requestPermission", kind: "notifications", ...hooks }]),
169
+ ];
170
+
171
+ it("counts an ask that advances on a grant AND on a refusal", () => {
172
+ expect(hasCompletingAction(ask({ onGranted: ["continue"], onDenied: ["continue"] }))).toBe(true);
173
+ });
174
+
175
+ it("counts a grant path that continues and a refusal path that dismisses", () => {
176
+ expect(
177
+ hasCompletingAction(ask({ onGranted: ["continue"], onDenied: [{ type: "dismiss" }] }))
178
+ ).toBe(true);
179
+ });
180
+
181
+ // The trap. `onGranted` alone reads as NO way forward, so the #209 strip
182
+ // supplies its own escape CTA.
183
+ it("reports no way forward when only the grant path advances", () => {
184
+ expect(hasCompletingAction(ask({ onGranted: ["continue"] }))).toBe(false);
185
+ });
186
+
187
+ it("reports no way forward when only the refusal path advances", () => {
188
+ expect(hasCompletingAction(ask({ onDenied: ["continue"] }))).toBe(false);
189
+ });
190
+
191
+ // `onUnavailable` covers the module-absent outcome only; a denial still needs
192
+ // `onDenied`, so this shape strands the user who taps "Don't Allow".
193
+ it("reports no way forward when onDenied is missing but onUnavailable advances", () => {
194
+ expect(
195
+ hasCompletingAction(ask({ onGranted: ["continue"], onUnavailable: ["continue"] }))
196
+ ).toBe(false);
197
+ });
198
+
199
+ // All three declared: every runtime path advances.
200
+ it("counts an ask that covers all three outcomes", () => {
201
+ expect(
202
+ hasCompletingAction(
203
+ ask({ onGranted: ["continue"], onDenied: ["continue"], onUnavailable: ["continue"] })
204
+ )
205
+ ).toBe(true);
206
+ });
207
+
208
+ // `onUnavailable` present but dead, while `onDenied` advances: the
209
+ // module-absent build runs onUnavailable and stays put, so this is a trap the
210
+ // OR reading would have missed too.
211
+ it("reports no way forward when a declared onUnavailable does not advance", () => {
212
+ expect(
213
+ hasCompletingAction(
214
+ ask({
215
+ onGranted: ["continue"],
216
+ onDenied: ["continue"],
217
+ onUnavailable: [{ type: "setVariable", name: "push", value: "n/a" }],
218
+ })
219
+ )
220
+ ).toBe(false);
221
+ });
222
+
223
+ // A typo'd hook name is stripped by the (deliberately non-strict) schema, so
224
+ // the payload validates clean and the denial path is dead. The AND rule is
225
+ // what turns that into a visible escape CTA rather than a silent trap.
226
+ it("reports no way forward when the refusal hook is misspelled", () => {
227
+ expect(
228
+ hasCompletingAction(ask({ onGranted: ["continue"], onDeneid: ["continue"] }))
229
+ ).toBe(false);
230
+ });
231
+
232
+ it("reports no way forward for a permission ask with no terminal hook", () => {
233
+ expect(
234
+ hasCompletingAction(ask({ onGranted: [{ type: "setVariable", name: "push", value: "on" }] }))
235
+ ).toBe(false);
236
+ });
237
+
238
+ // A separate CTA elsewhere on the screen is still a way forward — the rule
239
+ // narrows what the ASK itself counts for, nothing else.
240
+ it("still finds a sibling skip button", () => {
241
+ expect(
242
+ hasCompletingAction([
243
+ button("cta", [{ type: "requestPermission", kind: "notifications", onGranted: ["continue"] }]),
244
+ button("skip", ["continue"]),
245
+ ])
246
+ ).toBe(true);
247
+ });
248
+
249
+ // Nesting: an ask inside another action's branch list is walked the same way.
250
+ it("counts a fully covered ask nested inside purchase.onSuccess", () => {
251
+ expect(
252
+ hasCompletingAction([
253
+ button("cta", [
254
+ {
255
+ type: "purchase",
256
+ product: "yearly",
257
+ onSuccess: [
258
+ {
259
+ type: "requestPermission",
260
+ kind: "notifications",
261
+ onGranted: ["continue"],
262
+ onDenied: ["continue"],
263
+ },
264
+ ],
265
+ },
266
+ ]),
267
+ ])
268
+ ).toBe(true);
269
+ });
270
+ });
271
+
272
+ /**
273
+ * `actionsCanComplete` — the same walk, exposed for ONE action list rather than
274
+ * a whole element tree, so the runtime can consult the SDK's own definition of
275
+ * "this was a way off the screen" instead of re-deriving it (review round 1,
276
+ * finding 1).
277
+ *
278
+ * `runActions` needs it at press time for exactly one decision: a
279
+ * `requestPermission` whose build cannot ask at all, with no `onUnavailable`
280
+ * declared. Whether that press was the screen's only way forward is the
281
+ * difference between "log and move on" and "the user is stuck", and it is the
282
+ * same question this module already answers statically.
283
+ *
284
+ * OR across the list, unlike `permissionAskCompletes`' AND across one ask's
285
+ * outcomes: the caller asks "did the author intend this press to move the user
286
+ * on", not "does every outcome move them on".
287
+ */
288
+ describe("actionsCanComplete", () => {
289
+ it("is true for a list holding continue or dismiss", () => {
290
+ expect(actionsCanComplete(["continue"])).toBe(true);
291
+ expect(actionsCanComplete([{ type: "dismiss" }])).toBe(true);
292
+ expect(actionsCanComplete([{ type: "setVariable", name: "a", value: "b" }, "continue"])).toBe(
293
+ true
294
+ );
295
+ });
296
+
297
+ it("is false for a list that leaves the user on the screen", () => {
298
+ expect(actionsCanComplete([{ type: "setVariable", name: "a", value: "b" }])).toBe(false);
299
+ expect(actionsCanComplete([{ type: "custom", function: "doThing" }])).toBe(false);
300
+ expect(actionsCanComplete([{ type: "presentPaywall", placement: "hard" }])).toBe(false);
301
+ });
302
+
303
+ it("walks nested branch lists", () => {
304
+ expect(
305
+ actionsCanComplete([{ type: "purchase", product: "yearly", onSuccess: ["continue"] }])
306
+ ).toBe(true);
307
+ });
308
+
309
+ // Total on junk: it runs on a payload the runtime has already parsed, but the
310
+ // predicate is the one thing that must not throw while deciding whether a
311
+ // user is trapped.
312
+ it("is false for anything that is not an action list", () => {
313
+ expect(actionsCanComplete(undefined)).toBe(false);
314
+ expect(actionsCanComplete(null)).toBe(false);
315
+ expect(actionsCanComplete("continue")).toBe(false);
316
+ expect(actionsCanComplete([null, 3, { type: "continue" }])).toBe(false);
317
+ });
318
+ });
319
+
320
+ /**
321
+ * Review round 2, finding 1. `actionsCanComplete`'s yes/no was not enough: the
322
+ * runtime substitutes the author's escape for an ask it could not perform, and
323
+ * the two completing actions report DIFFERENT outcomes to the host.
324
+ * `complete()` (bare) is what `Pages/Paywall/Renderer`'s hard gate reads as
325
+ * "advance", so standing in for an authored `{dismiss}` with a bare advance
326
+ * handed out paid content. `"dismiss"` therefore wins whenever both are
327
+ * reachable — nobody was asked anything, so the SDK claims the LESS permissive
328
+ * of the two answers the author authored.
329
+ */
330
+ describe("completingActionKind", () => {
331
+ it("names the completing action a list reaches", () => {
332
+ expect(completingActionKind(["continue"])).toBe("continue");
333
+ expect(completingActionKind([{ type: "dismiss" }])).toBe("dismiss");
334
+ });
335
+
336
+ it("prefers dismiss when both are reachable, in either order", () => {
337
+ expect(completingActionKind(["continue", { type: "dismiss" }])).toBe("dismiss");
338
+ expect(completingActionKind([{ type: "dismiss" }, "continue"])).toBe("dismiss");
339
+ });
340
+
341
+ it("walks nested branch lists like the predicate does", () => {
342
+ expect(
343
+ completingActionKind([
344
+ { type: "purchase", product: "yearly", onSuccess: [{ type: "dismiss" }] },
345
+ ])
346
+ ).toBe("dismiss");
347
+ expect(
348
+ completingActionKind([{ type: "restore", onSuccess: ["continue"] }])
349
+ ).toBe("continue");
350
+ });
351
+
352
+ // A nested ask keeps the AND-across-outcomes rule: it contributes an escape
353
+ // only when it is one on EVERY path.
354
+ it("respects the requestPermission AND rule when nested", () => {
355
+ expect(
356
+ completingActionKind([
357
+ { type: "requestPermission", kind: "notifications", onGranted: ["continue"] },
358
+ ])
359
+ ).toBeUndefined();
360
+ expect(
361
+ completingActionKind([
362
+ {
363
+ type: "requestPermission",
364
+ kind: "notifications",
365
+ onGranted: ["continue"],
366
+ onDenied: [{ type: "dismiss" }],
367
+ },
368
+ ])
369
+ ).toBe("dismiss");
370
+ });
371
+
372
+ it("is undefined for a list that leaves the user on the screen, and for junk", () => {
373
+ expect(completingActionKind([{ type: "setVariable", name: "a", value: "b" }])).toBeUndefined();
374
+ expect(completingActionKind([])).toBeUndefined();
375
+ expect(completingActionKind(undefined)).toBeUndefined();
376
+ expect(completingActionKind(null)).toBeUndefined();
377
+ expect(completingActionKind("continue")).toBeUndefined();
378
+ expect(completingActionKind([null, 3, { type: "continue" }])).toBeUndefined();
379
+ });
380
+
381
+ // The two must never disagree about WHETHER there is an escape — one walk
382
+ // answers both, and this is the assertion that keeps it that way.
383
+ it("agrees with actionsCanComplete on every shape", () => {
384
+ for (const actions of [
385
+ ["continue"],
386
+ [{ type: "dismiss" }],
387
+ [{ type: "setVariable", name: "a", value: "b" }],
388
+ [{ type: "purchase", product: "yearly", onSuccess: ["continue"] }],
389
+ [{ type: "requestPermission", kind: "camera", onGranted: ["continue"] }],
390
+ undefined,
391
+ null,
392
+ [],
393
+ ]) {
394
+ expect(completingActionKind(actions) !== undefined).toBe(actionsCanComplete(actions));
395
+ }
396
+ });
397
+ });
398
+
399
+ /**
400
+ * `custom` is read with AND across its outcomes, like `requestPermission` and
401
+ * unlike everything else (#191, review round 1, finding 6).
402
+ *
403
+ * The async gate this SDK documents puts the screen's only `"continue"` inside
404
+ * `onResolve`. That is the exact shape `permissionAskCompletes` was carved out
405
+ * to refuse: `onResolve` runs on the resolve path and NOWHERE else, so a
406
+ * `"continue"` reachable only there is not a way off the screen for a user
407
+ * whose backend is down — nor for one running a host with `customActions: {}`,
408
+ * which is `ScreenHost`'s own default. The generic OR read it as one, which is
409
+ * what let the walk report "this screen has a CTA" for a screen nobody could
410
+ * leave.
411
+ *
412
+ * The AND is over the action's TWO paths — the handler resolved, and the
413
+ * handler failed (a throw with the budget spent, an attempt past
414
+ * `retry.timeoutMs`, or a name the host never registered: one rule since the
415
+ * semantics decision of 2026-09-11, #191 / #266). Both leave the enclosing list
416
+ * running, so whatever follows the action counts for both terms, and
417
+ * `[{custom}, "continue"]` IS a way off the screen — on every path, not on two
418
+ * of three as it was while a throw aborted. Round 2 of this PR required
419
+ * `onError` on its own and therefore read that shape — the only `custom` shape
420
+ * Studio can author today — as a trap; see
421
+ * `onboarding-ui/src/UI/Runtime/__tests__/mergeBaseEscapeParity.test.ts`, and
422
+ * `customActionEscapeCoherence.test.ts` beside it for the check that this walk
423
+ * and `runActions` agree.
424
+ */
425
+ describe("completingActions — custom is AND across its outcome hooks", () => {
426
+ const gate = (extra: Record<string, unknown>) => [
427
+ { type: "custom", function: "generatePlan", ...extra },
428
+ ];
429
+
430
+ it("does not count a continue reachable only when the handler resolves", () => {
431
+ expect(actionsCanComplete(gate({ onResolve: ["continue"] }))).toBe(false);
432
+ expect(
433
+ actionsCanComplete(
434
+ gate({
435
+ onResolve: ["continue"],
436
+ onError: [{ type: "setVariable", name: "planError", value: "true" }],
437
+ })
438
+ )
439
+ ).toBe(false);
440
+ });
441
+
442
+ it("counts it when BOTH outcomes reach a way off the screen", () => {
443
+ expect(
444
+ actionsCanComplete(gate({ onResolve: ["continue"], onError: ["continue"] }))
445
+ ).toBe(true);
446
+ expect(
447
+ completingActionKind(gate({ onResolve: ["continue"], onError: [{ type: "dismiss" }] }))
448
+ ).toBe("dismiss");
449
+ });
450
+
451
+ it("does not count a bare custom action, nor one whose `variables` are named like actions", () => {
452
+ expect(actionsCanComplete(gate({}))).toBe(false);
453
+ // `variables: ["continue"]` used to satisfy the generic OR walk.
454
+ expect(actionsCanComplete(gate({ variables: ["continue"] }))).toBe(false);
455
+ });
456
+
457
+ it("counts a sibling AFTER the custom action (retro round 2, finding 2)", () => {
458
+ // `[{custom}, "continue"]` is the shape an author writes when Studio cannot
459
+ // spell `onResolve` — which is every `custom` payload in the field until
460
+ // `rocapine/onboarding-studio#288` lands. The trailing `"continue"` runs on
461
+ // BOTH of the action's paths — the handler resolved, or it failed — so it
462
+ // is a way off the screen, and reading it as a trap bolted a duplicate CTA
463
+ // onto stripped screens that already had one.
464
+ expect(actionsCanComplete([...gate({}), "continue"])).toBe(true);
465
+ expect(
466
+ actionsCanComplete([
467
+ ...gate({ onError: [{ type: "setVariable", name: "planError", value: "true" }] }),
468
+ "continue",
469
+ ])
470
+ ).toBe(true);
471
+ // An `onError` that escapes is a way off the screen on its own terms, so it
472
+ // does not need the sibling — but the sibling does not disqualify it either.
473
+ expect(actionsCanComplete([...gate({ onError: ["continue"] }), "continue"])).toBe(true);
474
+ });
475
+
476
+ it("still refuses a custom whose ONLY escape is on the resolve path", () => {
477
+ // The sibling rule above must not launder round 1's finding 6 back in, and
478
+ // neither does removing the abort: with nothing trailing the action, a host
479
+ // running `customActions: {}` — the `ScreenHost` default — reaches neither
480
+ // `onResolve` nor anything after it. (#266 costed this decision as
481
+ // "reverts to the generic OR walk". OR would credit this `onResolve` and
482
+ // re-open finding 6; what the decision removes is a third term the code
483
+ // never had.)
484
+ expect(actionsCanComplete(gate({ onResolve: ["continue"] }))).toBe(false);
485
+ expect(actionsCanComplete([...gate({ onResolve: ["continue"] })])).toBe(false);
486
+ });
487
+
488
+ it("counts a sibling BEFORE it, which runs whatever the handler does", () => {
489
+ // `runActions` returns at the first completing action, so the custom never
490
+ // runs and the escape is unconditional — which is why everything before the
491
+ // barrier keeps the plain OR reading.
492
+ expect(actionsCanComplete(["continue", ...gate({})])).toBe(true);
493
+ expect(completingActionKind([{ type: "dismiss" }, ...gate({})])).toBe("dismiss");
494
+ });
495
+
496
+ it("reads the classic shape the same way inside an element tree", () => {
497
+ expect(hasCompletingAction([button("cta", [...gate({}), "continue"])])).toBe(true);
498
+ // And still strands when the only escape is behind the handler.
499
+ expect(hasCompletingAction([button("cta", gate({ onResolve: ["continue"] }))])).toBe(false);
500
+ });
501
+
502
+ it("reads a whole element tree the same way", () => {
503
+ const screen = [button("cta", gate({ onResolve: ["continue"] }))];
504
+ expect(hasCompletingAction(screen)).toBe(false);
505
+ expect(
506
+ hasCompletingAction([button("cta", gate({ onResolve: ["continue"], onError: ["continue"] }))])
507
+ ).toBe(true);
508
+ });
509
+ });