@prosopo/procaptcha-frictionless 2.18.6 → 2.19.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 (52) hide show
  1. package/.turbo/turbo-build$colon$cjs.log +6 -9
  2. package/.turbo/turbo-build$colon$tsc.log +24 -27
  3. package/.turbo/turbo-build.log +6 -12
  4. package/CHANGELOG.md +73 -0
  5. package/LICENSE +201 -0
  6. package/dist/authenticatedBadge.d.ts +7 -0
  7. package/dist/authenticatedBadge.d.ts.map +1 -1
  8. package/dist/authenticatedBadge.js +14 -11
  9. package/dist/authenticatedBadge.js.map +1 -1
  10. package/dist/cjs/authenticatedBadge.cjs +14 -11
  11. package/dist/cjs/customDetectBot.cjs +3 -3
  12. package/dist/cjs/procaptchaFrictionless.cjs +16 -4
  13. package/dist/customDetectBot.d.ts.map +1 -1
  14. package/dist/customDetectBot.js +3 -3
  15. package/dist/customDetectBot.js.map +1 -1
  16. package/dist/procaptchaFrictionless.d.ts.map +1 -1
  17. package/dist/procaptchaFrictionless.js +17 -5
  18. package/dist/procaptchaFrictionless.js.map +1 -1
  19. package/dist/tests/authenticatedBadge.unit.test.d.ts +2 -0
  20. package/dist/tests/authenticatedBadge.unit.test.d.ts.map +1 -0
  21. package/dist/tests/authenticatedBadge.unit.test.js +66 -0
  22. package/dist/tests/authenticatedBadge.unit.test.js.map +1 -0
  23. package/dist/tests/procaptchaFrictionless.test.js +33 -2
  24. package/dist/tests/procaptchaFrictionless.test.js.map +1 -1
  25. package/dist/tests/sessionInvalidatedRemint.test.js +26 -0
  26. package/dist/tests/sessionInvalidatedRemint.test.js.map +1 -1
  27. package/package.json +70 -69
  28. package/src/authenticatedBadge.ts +0 -151
  29. package/src/customDetectBot.ts +0 -392
  30. package/src/detectorLoader.ts +0 -133
  31. package/src/detectorPrefetch.ts +0 -115
  32. package/src/frictionlessResultGuard.ts +0 -110
  33. package/src/index.ts +0 -15
  34. package/src/procaptchaFrictionless.ts +0 -613
  35. package/src/sessionInvalidatedRecovery.ts +0 -110
  36. package/src/tests/customDetectBot.test.ts +0 -77
  37. package/src/tests/customDetectBotAssignTimeout.test.ts +0 -185
  38. package/src/tests/customDetectBotSimd.test.ts +0 -173
  39. package/src/tests/detectorLoader.test.ts +0 -108
  40. package/src/tests/detectorPrefetch.test.ts +0 -114
  41. package/src/tests/escalationClientSession.test.ts +0 -216
  42. package/src/tests/escalationHandoff.integration.test.ts +0 -356
  43. package/src/tests/executeBeforeMount.test.ts +0 -233
  44. package/src/tests/frictionlessResultGuard.test.ts +0 -179
  45. package/src/tests/manualStart.test.ts +0 -391
  46. package/src/tests/procaptchaFrictionless.test.ts +0 -408
  47. package/src/tests/sessionInvalidatedRecovery.test.ts +0 -181
  48. package/src/tests/sessionInvalidatedRemint.test.ts +0 -272
  49. package/tsconfig.cjs.json +0 -41
  50. package/tsconfig.json +0 -49
  51. package/tsconfig.tsbuildinfo +0 -1
  52. package/tsconfig.types.json +0 -9
@@ -1,408 +0,0 @@
1
- // Copyright 2021-2026 Prosopo (UK) Ltd.
2
- //
3
- // Licensed under the Apache License, Version 2.0 (the "License");
4
- // you may not use this file except in compliance with the License.
5
- // You may obtain a copy of the License at
6
- //
7
- // http://www.apache.org/licenses/LICENSE-2.0
8
- //
9
- // Unless required by applicable law or agreed to in writing, software
10
- // distributed under the License is distributed on an "AS IS" BASIS,
11
- // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
- // See the License for the specific language governing permissions and
13
- // limitations under the License.
14
-
15
- import type { Ti18n } from "@prosopo/locale";
16
- import {
17
- type BotDetectionFunction,
18
- type BotDetectionFunctionResult,
19
- CaptchaType,
20
- type ProcaptchaClientConfigOutput,
21
- type ProcaptchaFrictionlessProps,
22
- type ProcaptchaProps,
23
- } from "@prosopo/types";
24
- import { afterEach, beforeEach, describe, expect, test, vi } from "vitest";
25
-
26
- /**
27
- * The orchestrator decides which solver to mount, tears the previous one down,
28
- * and owns the recovery paths. Each solver package is stubbed to a probe so a
29
- * test can read the props it was handed and assert the mount/unmount ordering
30
- * that used to come free from the reconciler.
31
- */
32
- const mocks = vi.hoisted(() => {
33
- const mounted: { solver: string; props: ProcaptchaProps }[] = [];
34
- const destroyed: string[] = [];
35
- const probe =
36
- (solver: string) => (container: HTMLElement, props: ProcaptchaProps) => {
37
- mounted.push({ solver, props });
38
- const element = container.ownerDocument.createElement("div");
39
- element.setAttribute("data-solver", solver);
40
- container.appendChild(element);
41
- return {
42
- destroy: () => {
43
- element.remove();
44
- destroyed.push(solver);
45
- },
46
- };
47
- };
48
- return { mounted, destroyed, probe };
49
- });
50
-
51
- // jsdom serves the suite over http, so the widget's own HTTPS guard would
52
- // short-circuit every test before detection ran.
53
- vi.mock("@prosopo/procaptcha-common", async (importOriginal) => ({
54
- ...(await importOriginal<typeof import("@prosopo/procaptcha-common")>()),
55
- isSecureBrowserContext: () => true,
56
- }));
57
-
58
- vi.mock("@prosopo/procaptcha-react", () => ({
59
- mountProcaptchaImageWidget: mocks.probe("image"),
60
- }));
61
- vi.mock("@prosopo/procaptcha-puzzle", () => ({
62
- mountProcaptchaPuzzleWidget: mocks.probe("puzzle"),
63
- }));
64
- vi.mock("@prosopo/procaptcha-pow", () => ({
65
- mountProcaptchaPowWidget: mocks.probe("pow"),
66
- }));
67
-
68
- const { mountProcaptchaFrictionless } = await import(
69
- "../procaptchaFrictionless.js"
70
- );
71
- const { MAX_SESSION_INVALIDATED_RETRIES } = await import(
72
- "../sessionInvalidatedRecovery.js"
73
- );
74
-
75
- const SITE_KEY = "5CcNvLUdiXFpzKDMjThGLSK9rhWHA1H4EF3zrgkpkjAdqmuP";
76
-
77
- const config = (): ProcaptchaClientConfigOutput =>
78
- ({
79
- account: { address: SITE_KEY },
80
- defaultEnvironment: "staging",
81
- mode: "visible",
82
- theme: "light",
83
- }) as unknown as ProcaptchaClientConfigOutput;
84
-
85
- const i18n = (): Ti18n =>
86
- ({
87
- isInitialized: true,
88
- t: (key: string) => key,
89
- language: "en",
90
- changeLanguage: () => Promise.resolve(),
91
- }) as unknown as Ti18n;
92
-
93
- const detection = (
94
- captchaType: CaptchaType,
95
- overrides: Partial<BotDetectionFunctionResult> = {},
96
- ): BotDetectionFunctionResult =>
97
- ({
98
- captchaType,
99
- sessionId: "session-1",
100
- provider: { providerAccount: "acc", provider: { url: "https://p.one" } },
101
- userAccount: { account: { address: "user" } },
102
- ...overrides,
103
- }) as unknown as BotDetectionFunctionResult;
104
-
105
- let container: HTMLDivElement;
106
- let widget: { destroy: () => void } | undefined;
107
-
108
- const props = (
109
- detectBot: BotDetectionFunction,
110
- overrides: Partial<ProcaptchaFrictionlessProps> = {},
111
- ): ProcaptchaFrictionlessProps => ({
112
- config: config(),
113
- callbacks: {},
114
- i18n: i18n(),
115
- restart: () => undefined,
116
- detectBot,
117
- ...overrides,
118
- });
119
-
120
- const settle = async (): Promise<void> => {
121
- await new Promise<void>((resolve: () => void) => setTimeout(resolve, 0));
122
- await Promise.resolve();
123
- };
124
-
125
- const waitFor = async (condition: () => boolean): Promise<void> => {
126
- for (let poll = 0; poll < 100 && !condition(); poll++) {
127
- await new Promise<void>((resolve: () => void) => setTimeout(resolve, 20));
128
- }
129
- };
130
-
131
- const solvers = (): string[] =>
132
- Array.from(container.querySelectorAll("[data-solver]")).map(
133
- (element: Element) => element.getAttribute("data-solver") ?? "",
134
- );
135
-
136
- beforeEach(() => {
137
- mocks.mounted.length = 0;
138
- mocks.destroyed.length = 0;
139
- widget = undefined;
140
- container = document.createElement("div");
141
- document.body.appendChild(container);
142
- });
143
-
144
- afterEach(() => {
145
- widget?.destroy();
146
- widget = undefined;
147
- container.remove();
148
- });
149
-
150
- describe("choosing a solver", () => {
151
- test("mounts the image widget when the provider asks for one", async () => {
152
- widget = mountProcaptchaFrictionless(
153
- container,
154
- props(() => Promise.resolve(detection(CaptchaType.image))),
155
- );
156
- await settle();
157
- expect(solvers()).toEqual(["image"]);
158
- });
159
-
160
- test("mounts the puzzle widget when the provider asks for one", async () => {
161
- widget = mountProcaptchaFrictionless(
162
- container,
163
- props(() => Promise.resolve(detection(CaptchaType.puzzle))),
164
- );
165
- await settle();
166
- expect(solvers()).toEqual(["puzzle"]);
167
- });
168
-
169
- test("falls through to PoW for anything else", async () => {
170
- widget = mountProcaptchaFrictionless(
171
- container,
172
- props(() => Promise.resolve(detection(CaptchaType.pow))),
173
- );
174
- await settle();
175
- expect(solvers()).toEqual(["pow"]);
176
- });
177
-
178
- test("hands the solver the session the frictionless call minted", async () => {
179
- widget = mountProcaptchaFrictionless(
180
- container,
181
- props(() => Promise.resolve(detection(CaptchaType.image))),
182
- );
183
- await settle();
184
- expect(mocks.mounted[0]?.props.frictionlessState).toMatchObject({
185
- sessionId: "session-1",
186
- });
187
- });
188
-
189
- test("only PoW is given an escalation handler", async () => {
190
- widget = mountProcaptchaFrictionless(
191
- container,
192
- props(() => Promise.resolve(detection(CaptchaType.pow))),
193
- );
194
- await settle();
195
- expect(mocks.mounted[0]?.props.onEscalate).toBeTypeOf("function");
196
- });
197
- });
198
-
199
- describe("the loading placeholder", () => {
200
- test("shows a checkbox before detection resolves", () => {
201
- widget = mountProcaptchaFrictionless(
202
- container,
203
- props(() => new Promise<BotDetectionFunctionResult>(() => undefined)),
204
- );
205
- // The spinner is the checkbox's loading state; either way there must be
206
- // something widget-shaped on the page while the round trip is in flight.
207
- expect(container.querySelector('[role="status"]')).not.toBe(null);
208
- });
209
-
210
- test("is replaced by the solver, not left behind it", async () => {
211
- widget = mountProcaptchaFrictionless(
212
- container,
213
- props(() => Promise.resolve(detection(CaptchaType.image))),
214
- );
215
- await settle();
216
- expect(container.querySelector('[role="status"]')).toBeNull();
217
- expect(solvers()).toEqual(["image"]);
218
- });
219
-
220
- test("shows a terminal detection error instead of a solver", async () => {
221
- const onError = vi.fn<(error: Error) => void>();
222
- widget = mountProcaptchaFrictionless(
223
- container,
224
- props(
225
- () =>
226
- Promise.resolve(
227
- detection(CaptchaType.image, {
228
- error: {
229
- message: "site key not registered",
230
- key: "API.SITE_KEY_NOT_REGISTERED",
231
- },
232
- } as Partial<BotDetectionFunctionResult>),
233
- ),
234
- { callbacks: { onError } },
235
- ),
236
- );
237
- await settle();
238
- expect(solvers()).toEqual([]);
239
- expect(container.textContent).toContain("site key not registered");
240
- expect(onError).toHaveBeenCalledWith(expect.any(Error));
241
- });
242
-
243
- test("re-rolls onto another provider for a failure that is not the caller's fault", async () => {
244
- // An unrecognised key means the provider broke in a way it has no
245
- // vocabulary for; another node may well be healthy, so the user should
246
- // not be stranded on the first answer.
247
- const detectBot = vi
248
- .fn<BotDetectionFunction>()
249
- .mockResolvedValueOnce(
250
- detection(CaptchaType.image, {
251
- error: { message: "no capacity", key: "API.UNKNOWN_ERROR" },
252
- } as Partial<BotDetectionFunctionResult>),
253
- )
254
- .mockResolvedValue(detection(CaptchaType.image));
255
- widget = mountProcaptchaFrictionless(container, props(detectBot));
256
- // providerRetry backs off before re-rolling, so the second call lands a
257
- // randomised delay later rather than on the next tick.
258
- await waitFor(() => detectBot.mock.calls.length > 1);
259
- await settle();
260
- expect(solvers()).toEqual(["image"]);
261
- });
262
-
263
- test("refuses to mount anything when the response names no captcha type", async () => {
264
- // A hard block short-circuits the request and answers with a bare
265
- // `{ error: "..." }`; mounting the PoW default against it only earns an
266
- // API.INCORRECT_CAPTCHA_TYPE from the next call.
267
- const onError = vi.fn<(error: Error) => void>();
268
- widget = mountProcaptchaFrictionless(
269
- container,
270
- props(
271
- () =>
272
- Promise.resolve({
273
- sessionId: "session-1",
274
- } as unknown as BotDetectionFunctionResult),
275
- { callbacks: { onError } },
276
- ),
277
- );
278
- await settle();
279
- expect(solvers()).toEqual([]);
280
- expect(onError).toHaveBeenCalledWith(expect.any(Error));
281
- });
282
- });
283
-
284
- describe("escalating from PoW", () => {
285
- test("swaps PoW for the escalated solver rather than stacking them", async () => {
286
- // Nothing reconciles this for us: without the explicit teardown the page
287
- // ends up with two live widgets, two modals and two sets of document
288
- // listeners.
289
- widget = mountProcaptchaFrictionless(
290
- container,
291
- props(() => Promise.resolve(detection(CaptchaType.pow))),
292
- );
293
- await settle();
294
-
295
- mocks.mounted[0]?.props.onEscalate?.(CaptchaType.image, "session-2", {
296
- x: 4,
297
- y: 5,
298
- });
299
- await settle();
300
-
301
- expect(solvers()).toEqual(["image"]);
302
- expect(mocks.destroyed).toContain("pow");
303
- });
304
-
305
- test("carries the new session and the original click into the escalation", async () => {
306
- widget = mountProcaptchaFrictionless(
307
- container,
308
- props(() => Promise.resolve(detection(CaptchaType.pow))),
309
- );
310
- await settle();
311
-
312
- mocks.mounted[0]?.props.onEscalate?.(CaptchaType.image, "session-2", {
313
- x: 4,
314
- y: 5,
315
- });
316
- await settle();
317
-
318
- expect(mocks.mounted[1]?.props).toMatchObject({
319
- autoStart: true,
320
- startCoords: { x: 4, y: 5 },
321
- });
322
- expect(mocks.mounted[1]?.props.frictionlessState).toMatchObject({
323
- sessionId: "session-2",
324
- });
325
- });
326
- });
327
-
328
- describe("recovering an invalidated session", () => {
329
- test("re-runs detection and remounts with the preserved coordinates", async () => {
330
- const detectBot = vi
331
- .fn<BotDetectionFunction>()
332
- .mockResolvedValueOnce(detection(CaptchaType.image))
333
- .mockResolvedValue(
334
- detection(CaptchaType.image, {
335
- sessionId: "session-2",
336
- } as Partial<BotDetectionFunctionResult>),
337
- );
338
- widget = mountProcaptchaFrictionless(container, props(detectBot));
339
- await settle();
340
-
341
- mocks.mounted[0]?.props.onSessionInvalidated?.(11, 22);
342
- await settle();
343
-
344
- expect(detectBot).toHaveBeenCalledTimes(2);
345
- expect(solvers()).toEqual(["image"]);
346
- expect(mocks.mounted[1]?.props).toMatchObject({
347
- autoStart: true,
348
- startCoords: { x: 11, y: 22 },
349
- });
350
- });
351
-
352
- test("stops re-minting once the budget is spent, so a persistently broken session cannot loop", async () => {
353
- const detectBot = vi
354
- .fn<BotDetectionFunction>()
355
- .mockResolvedValue(detection(CaptchaType.image));
356
- widget = mountProcaptchaFrictionless(container, props(detectBot));
357
- await settle();
358
-
359
- // One more failure than the budget allows; the last one falls over
360
- // visibly rather than asking for yet another session.
361
- for (
362
- let attempt = 0;
363
- attempt <= MAX_SESSION_INVALIDATED_RETRIES;
364
- attempt++
365
- ) {
366
- mocks.mounted.at(-1)?.props.onSessionInvalidated?.(11, 22);
367
- await settle();
368
- }
369
-
370
- expect(detectBot).toHaveBeenCalledTimes(
371
- MAX_SESSION_INVALIDATED_RETRIES + 1,
372
- );
373
- });
374
- });
375
-
376
- describe("tearing down", () => {
377
- test("takes the mounted solver with it", async () => {
378
- widget = mountProcaptchaFrictionless(
379
- container,
380
- props(() => Promise.resolve(detection(CaptchaType.image))),
381
- );
382
- await settle();
383
- widget.destroy();
384
- widget = undefined;
385
- expect(mocks.destroyed).toContain("image");
386
- expect(container.querySelector("[data-solver]")).toBeNull();
387
- });
388
-
389
- test("does not mount a solver that resolves after destroy", async () => {
390
- let release: (result: BotDetectionFunctionResult) => void = () => undefined;
391
- widget = mountProcaptchaFrictionless(
392
- container,
393
- props(
394
- () =>
395
- new Promise<BotDetectionFunctionResult>(
396
- (resolve: (result: BotDetectionFunctionResult) => void) => {
397
- release = resolve;
398
- },
399
- ),
400
- ),
401
- );
402
- widget.destroy();
403
- widget = undefined;
404
- release(detection(CaptchaType.image));
405
- await settle();
406
- expect(mocks.mounted).toHaveLength(0);
407
- });
408
- });
@@ -1,181 +0,0 @@
1
- // Copyright 2021-2026 Prosopo (UK) Ltd.
2
- //
3
- // Licensed under the Apache License, Version 2.0 (the "License");
4
- // you may not use this file except in compliance with the License.
5
- // You may obtain a copy of the License at
6
- //
7
- // http://www.apache.org/licenses/LICENSE-2.0
8
- //
9
- // Unless required by applicable law or agreed to in writing, software
10
- // distributed under the License is distributed on an "AS IS" BASIS,
11
- // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
- // See the License for the specific language governing permissions and
13
- // limitations under the License.
14
-
15
- import { describe, expect, it } from "vitest";
16
- import {
17
- MAX_SESSION_INVALIDATED_RETRIES,
18
- type MutableRef,
19
- type RetryCoords,
20
- consumeRetryMountProps,
21
- handleSessionInvalidated,
22
- normaliseRetryCoords,
23
- } from "../sessionInvalidatedRecovery.js";
24
-
25
- const ref = <T>(initial: T): MutableRef<T> => ({ current: initial });
26
-
27
- describe("handleSessionInvalidated", () => {
28
- it("records both coords and signals a restart on the first fire", () => {
29
- const attemptsRef = ref(0);
30
- const coordsRef = ref<RetryCoords | null>(null);
31
-
32
- const result = handleSessionInvalidated(120, 340, attemptsRef, coordsRef);
33
-
34
- expect(result).toEqual({ shouldRestart: true, exhausted: false });
35
- expect(attemptsRef.current).toBe(1);
36
- expect(coordsRef.current).toEqual({ x: 120, y: 340 });
37
- });
38
-
39
- it("treats (0, 0) as 'no coords' — that's the autoStart / untrusted-event default, not a real click", () => {
40
- const attemptsRef = ref(0);
41
- const coordsRef = ref<RetryCoords | null>(null);
42
-
43
- const result = handleSessionInvalidated(0, 0, attemptsRef, coordsRef);
44
-
45
- expect(result).toEqual({ shouldRestart: true, exhausted: false });
46
- expect(coordsRef.current).toBeNull();
47
- });
48
-
49
- it("carries a real click even if only one axis is at the origin", () => {
50
- const attemptsRef = ref(0);
51
- const coordsRef = ref<RetryCoords | null>(null);
52
-
53
- handleSessionInvalidated(0, 340, attemptsRef, coordsRef);
54
-
55
- expect(coordsRef.current).toEqual({ x: 0, y: 340 });
56
- });
57
-
58
- it("stores no coords when x or y is undefined (autoStart / non-trusted event)", () => {
59
- const attemptsRef = ref(0);
60
- const coordsRef = ref<RetryCoords | null>(null);
61
-
62
- const result = handleSessionInvalidated(
63
- undefined,
64
- undefined,
65
- attemptsRef,
66
- coordsRef,
67
- );
68
-
69
- expect(result).toEqual({ shouldRestart: true, exhausted: false });
70
- expect(attemptsRef.current).toBe(1);
71
- expect(coordsRef.current).toBeNull();
72
- });
73
-
74
- it("stores no coords when only one axis is present — never emit NaN into the salt", () => {
75
- const attemptsRef = ref(0);
76
- const coordsRef = ref<RetryCoords | null>(null);
77
-
78
- handleSessionInvalidated(120, undefined, attemptsRef, coordsRef);
79
-
80
- expect(coordsRef.current).toBeNull();
81
- });
82
-
83
- it("keeps re-minting up to the retry budget — a reload press is a legitimate new session", () => {
84
- const attemptsRef = ref(0);
85
- const coordsRef = ref<RetryCoords | null>(null);
86
-
87
- for (let i = 0; i < MAX_SESSION_INVALIDATED_RETRIES; i++) {
88
- expect(
89
- handleSessionInvalidated(100 + i, 200 + i, attemptsRef, coordsRef),
90
- ).toEqual({ shouldRestart: true, exhausted: false });
91
- }
92
-
93
- expect(attemptsRef.current).toBe(MAX_SESSION_INVALIDATED_RETRIES);
94
- });
95
-
96
- it("reports exhausted once the budget is spent so the caller can fall over visibly", () => {
97
- const attemptsRef = ref(MAX_SESSION_INVALIDATED_RETRIES);
98
- const coordsRef = ref<RetryCoords | null>({ x: 100, y: 200 });
99
-
100
- const result = handleSessionInvalidated(500, 600, attemptsRef, coordsRef);
101
-
102
- expect(result).toEqual({ shouldRestart: false, exhausted: true });
103
- // An exhausted call must not overwrite the pending attempt's coords.
104
- expect(coordsRef.current).toEqual({ x: 100, y: 200 });
105
- expect(attemptsRef.current).toBe(MAX_SESSION_INVALIDATED_RETRIES);
106
- });
107
-
108
- it("honours a caller-supplied budget", () => {
109
- const attemptsRef = ref(0);
110
- const coordsRef = ref<RetryCoords | null>(null);
111
-
112
- expect(handleSessionInvalidated(1, 2, attemptsRef, coordsRef, 1)).toEqual({
113
- shouldRestart: true,
114
- exhausted: false,
115
- });
116
- expect(handleSessionInvalidated(3, 4, attemptsRef, coordsRef, 1)).toEqual({
117
- shouldRestart: false,
118
- exhausted: true,
119
- });
120
- });
121
- });
122
-
123
- describe("consumeRetryMountProps", () => {
124
- it("returns pending retry coords and forces autoStart", () => {
125
- const coordsRef = ref<RetryCoords | null>({ x: 42, y: 99 });
126
-
127
- const mount = consumeRetryMountProps(coordsRef, false);
128
-
129
- expect(mount).toEqual({
130
- autoStart: true,
131
- startCoords: { x: 42, y: 99 },
132
- });
133
- });
134
-
135
- it("clears the coords ref so a subsequent render doesn't re-inject stale values", () => {
136
- const coordsRef = ref<RetryCoords | null>({ x: 42, y: 99 });
137
-
138
- consumeRetryMountProps(coordsRef, false);
139
-
140
- expect(coordsRef.current).toBeNull();
141
- });
142
-
143
- it("propagates escalationAutoStart when no retry is pending (post-PoW escalation path)", () => {
144
- const coordsRef = ref<RetryCoords | null>(null);
145
-
146
- const mount = consumeRetryMountProps(coordsRef, true);
147
-
148
- expect(mount).toEqual({ autoStart: true, startCoords: undefined });
149
- });
150
-
151
- it("returns autoStart=false, startCoords=undefined for the initial checkbox mount", () => {
152
- const coordsRef = ref<RetryCoords | null>(null);
153
-
154
- const mount = consumeRetryMountProps(coordsRef, false);
155
-
156
- expect(mount).toEqual({ autoStart: false, startCoords: undefined });
157
- });
158
- });
159
-
160
- describe("normaliseRetryCoords", () => {
161
- it("keeps a real click", () => {
162
- expect(normaliseRetryCoords(120, 340)).toEqual({ x: 120, y: 340 });
163
- });
164
-
165
- it("keeps a click that sits on one axis", () => {
166
- expect(normaliseRetryCoords(0, 340)).toEqual({ x: 0, y: 340 });
167
- });
168
-
169
- it("drops (0, 0) — the autoStart / untrusted-event default, not a click", () => {
170
- expect(normaliseRetryCoords(0, 0)).toBeNull();
171
- });
172
-
173
- it("drops a half-pair rather than letting NaN reach the salt", () => {
174
- expect(normaliseRetryCoords(120, undefined)).toBeNull();
175
- expect(normaliseRetryCoords(undefined, 340)).toBeNull();
176
- });
177
-
178
- it("drops a missing pair", () => {
179
- expect(normaliseRetryCoords(undefined, undefined)).toBeNull();
180
- });
181
- });