vouchington-tooling 0.53.0 → 0.55.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 (197) hide show
  1. package/README.md +99 -12
  2. package/dist/agent-blackboard/index.d.mts +0 -1
  3. package/dist/agent-blackboard/index.mjs +0 -23
  4. package/dist/cli/commands/agent-blackboard-flags.d.mts +0 -1
  5. package/dist/cli/commands/agent-blackboard-flags.mjs +0 -9
  6. package/dist/cli/commands/agent-blackboard.d.mts +0 -2
  7. package/dist/cli/commands/agent-blackboard.mjs +7 -121
  8. package/dist/cli/commands/story-coverage.d.mts +2 -0
  9. package/dist/cli/commands/story-coverage.mjs +56 -0
  10. package/dist/cli/index.mjs +6 -0
  11. package/dist/cli/optional-peer.d.mts +5 -0
  12. package/dist/cli/optional-peer.mjs +17 -0
  13. package/dist/cli/parse-forwarded-commands.d.mts +3 -0
  14. package/dist/cli/parse-forwarded-commands.mjs +2 -0
  15. package/dist/cli/parse-story-coverage-fields.d.mts +19 -0
  16. package/dist/cli/parse-story-coverage-fields.mjs +69 -0
  17. package/dist/cli/parse-story-coverage.d.mts +8 -0
  18. package/dist/cli/parse-story-coverage.mjs +34 -0
  19. package/dist/cli/parse.d.mts +5 -1
  20. package/dist/cli/parse.mjs +3 -0
  21. package/dist/cli/story-coverage-lazy.d.mts +3 -0
  22. package/dist/cli/story-coverage-lazy.mjs +6 -0
  23. package/dist/cli/usage.d.mts +1 -1
  24. package/dist/cli/usage.mjs +8 -7
  25. package/dist/host-storage/check.d.mts +38 -0
  26. package/dist/host-storage/check.mjs +109 -0
  27. package/dist/host-storage/cli.d.mts +7 -0
  28. package/dist/host-storage/cli.mjs +102 -0
  29. package/dist/host-storage/host-storage.test-helpers.d.mts +26 -0
  30. package/dist/host-storage/host-storage.test-helpers.mjs +58 -0
  31. package/dist/host-storage/index.d.mts +3 -0
  32. package/dist/host-storage/index.mjs +3 -0
  33. package/dist/host-storage/preflight.d.mts +22 -0
  34. package/dist/host-storage/preflight.mjs +105 -0
  35. package/dist/index.d.mts +2 -0
  36. package/dist/index.mjs +1 -0
  37. package/dist/playwright/assertions.d.mts +1 -0
  38. package/dist/playwright/assertions.mjs +5 -0
  39. package/dist/playwright/blocked-external-network.d.mts +15 -0
  40. package/dist/playwright/blocked-external-network.mjs +73 -0
  41. package/dist/playwright/browser-dialog-issues.d.mts +12 -0
  42. package/dist/playwright/browser-dialog-issues.mjs +29 -0
  43. package/dist/playwright/browser-errors.d.mts +23 -0
  44. package/dist/playwright/browser-errors.mjs +130 -0
  45. package/dist/playwright/browser-issue-monitor.test-helpers.d.mts +31 -0
  46. package/dist/playwright/browser-issue-monitor.test-helpers.mjs +51 -0
  47. package/dist/playwright/browser-issue-records.d.mts +42 -0
  48. package/dist/playwright/browser-issue-records.mjs +148 -0
  49. package/dist/playwright/browser-test.d.mts +22 -0
  50. package/dist/playwright/browser-test.mjs +68 -0
  51. package/dist/playwright/expect-no-broken-images.d.mts +17 -0
  52. package/dist/playwright/expect-no-broken-images.mjs +39 -0
  53. package/dist/playwright/index.d.mts +32 -0
  54. package/dist/playwright/index.mjs +22 -0
  55. package/dist/playwright/mobile-assertions.d.mts +14 -0
  56. package/dist/playwright/mobile-assertions.mjs +43 -0
  57. package/dist/playwright/monitored-test-info.d.mts +14 -0
  58. package/dist/playwright/monitored-test-info.mjs +1 -0
  59. package/dist/playwright/navigate-to.d.mts +27 -0
  60. package/dist/playwright/navigate-to.mjs +39 -0
  61. package/dist/playwright/radix-select.d.mts +18 -0
  62. package/dist/playwright/radix-select.mjs +19 -0
  63. package/dist/playwright/random-id.d.mts +34 -0
  64. package/dist/playwright/random-id.mjs +37 -0
  65. package/dist/playwright/retry-on-connection-lost.d.mts +7 -0
  66. package/dist/playwright/retry-on-connection-lost.mjs +107 -0
  67. package/dist/playwright/scroll-to-load-more.d.mts +37 -0
  68. package/dist/playwright/scroll-to-load-more.mjs +158 -0
  69. package/dist/playwright/storybook.d.mts +2 -0
  70. package/dist/playwright/storybook.mjs +13 -0
  71. package/dist/playwright/test-fixtures.d.mts +1 -0
  72. package/dist/playwright/test-fixtures.mjs +2 -0
  73. package/dist/playwright/test-lifecycle-reporter.d.mts +27 -0
  74. package/dist/playwright/test-lifecycle-reporter.mjs +57 -0
  75. package/dist/playwright/totp.d.mts +6 -0
  76. package/dist/playwright/totp.mjs +37 -0
  77. package/dist/playwright/turnstile-stub.d.mts +8 -0
  78. package/dist/playwright/turnstile-stub.mjs +61 -0
  79. package/dist/playwright/viewport-constants.d.mts +30 -0
  80. package/dist/playwright/viewport-constants.mjs +9 -0
  81. package/dist/playwright/virtual-authenticator.d.mts +5 -0
  82. package/dist/playwright/virtual-authenticator.mjs +15 -0
  83. package/dist/playwright/wait-for-hydration.d.mts +29 -0
  84. package/dist/playwright/wait-for-hydration.mjs +81 -0
  85. package/dist/shell-parse/ansi-c-string.d.mts +12 -0
  86. package/dist/shell-parse/ansi-c-string.mjs +80 -0
  87. package/dist/shell-parse/index.d.mts +20 -0
  88. package/dist/shell-parse/index.mjs +15 -0
  89. package/dist/shell-parse/shell-command-substitution-reads.d.mts +8 -0
  90. package/dist/shell-parse/shell-command-substitution-reads.mjs +53 -0
  91. package/dist/shell-parse/shell-command-substitutions.d.mts +8 -0
  92. package/dist/shell-parse/shell-command-substitutions.mjs +52 -0
  93. package/dist/shell-parse/shell-command-wrappers.d.mts +26 -0
  94. package/dist/shell-parse/shell-command-wrappers.mjs +143 -0
  95. package/dist/shell-parse/shell-commands.d.mts +24 -0
  96. package/dist/shell-parse/shell-commands.mjs +155 -0
  97. package/dist/shell-parse/shell-heredoc-delimiter.d.mts +5 -0
  98. package/dist/shell-parse/shell-heredoc-delimiter.mjs +52 -0
  99. package/dist/shell-parse/shell-heredoc-parser.d.mts +7 -0
  100. package/dist/shell-parse/shell-heredoc-parser.mjs +49 -0
  101. package/dist/shell-parse/shell-heredoc-quote-state.d.mts +19 -0
  102. package/dist/shell-parse/shell-heredoc-quote-state.mjs +40 -0
  103. package/dist/shell-parse/shell-heredoc.d.mts +10 -0
  104. package/dist/shell-parse/shell-heredoc.mjs +90 -0
  105. package/dist/shell-parse/shell-redirections.d.mts +5 -0
  106. package/dist/shell-parse/shell-redirections.mjs +34 -0
  107. package/dist/shell-parse/shell-script-operand.d.mts +13 -0
  108. package/dist/shell-parse/shell-script-operand.mjs +103 -0
  109. package/dist/shell-parse/shell-stdin-script.d.mts +6 -0
  110. package/dist/shell-parse/shell-stdin-script.mjs +61 -0
  111. package/dist/shell-parse/shell-token-utils.d.mts +9 -0
  112. package/dist/shell-parse/shell-token-utils.mjs +33 -0
  113. package/dist/shell-parse/shell-tokenizer-comments.d.mts +1 -0
  114. package/dist/shell-parse/shell-tokenizer-comments.mjs +57 -0
  115. package/dist/shell-parse/shell-tokenizer-operators.d.mts +14 -0
  116. package/dist/shell-parse/shell-tokenizer-operators.mjs +47 -0
  117. package/dist/shell-parse/shell-tokenizer.d.mts +12 -0
  118. package/dist/shell-parse/shell-tokenizer.mjs +104 -0
  119. package/dist/story-coverage/analyze.d.mts +8 -0
  120. package/dist/story-coverage/analyze.mjs +24 -0
  121. package/dist/story-coverage/check.d.mts +11 -0
  122. package/dist/story-coverage/check.mjs +42 -0
  123. package/dist/story-coverage/components.d.mts +10 -0
  124. package/dist/story-coverage/components.mjs +40 -0
  125. package/dist/story-coverage/coverage.d.mts +10 -0
  126. package/dist/story-coverage/coverage.mjs +43 -0
  127. package/dist/story-coverage/index.d.mts +13 -0
  128. package/dist/story-coverage/index.mjs +7 -0
  129. package/dist/story-coverage/messages.d.mts +10 -0
  130. package/dist/story-coverage/messages.mjs +42 -0
  131. package/dist/story-coverage/options.d.mts +27 -0
  132. package/dist/story-coverage/options.mjs +51 -0
  133. package/dist/story-coverage/workspace.d.mts +2 -0
  134. package/dist/story-coverage/workspace.mjs +27 -0
  135. package/dist/test-helpers/cancel-runs.test-helpers.d.mts +39 -0
  136. package/dist/test-helpers/cancel-runs.test-helpers.mjs +124 -0
  137. package/dist/test-helpers/run-bounded-exit-observer.test-helpers.d.mts +12 -0
  138. package/dist/test-helpers/run-bounded-exit-observer.test-helpers.mjs +68 -0
  139. package/dist/test-helpers/run-bounded-output-fixture.test-helpers.d.mts +18 -0
  140. package/dist/test-helpers/run-bounded-output-fixture.test-helpers.mjs +162 -0
  141. package/dist/vitest-diagnostics/browser.d.mts +2 -0
  142. package/dist/vitest-diagnostics/browser.mjs +6 -0
  143. package/dist/vitest-diagnostics/index.d.mts +14 -23
  144. package/dist/vitest-diagnostics/index.mjs +8 -124
  145. package/dist/vitest-diagnostics/report-summary.d.mts +22 -0
  146. package/dist/vitest-diagnostics/report-summary.mjs +123 -0
  147. package/dist/vitest-diagnostics/vitest-fake-timer-guard.d.mts +6 -0
  148. package/dist/vitest-diagnostics/vitest-fake-timer-guard.mjs +34 -0
  149. package/dist/vitest-diagnostics/vitest-fork-leak-detection.d.mts +1 -0
  150. package/dist/vitest-diagnostics/vitest-fork-leak-detection.mjs +8 -0
  151. package/dist/vitest-diagnostics/vitest-fork-leak-diagnostics.d.mts +17 -1
  152. package/dist/vitest-diagnostics/vitest-fork-leak-diagnostics.mjs +44 -2
  153. package/dist/vitest-diagnostics/vitest-fork-leak-handshake-samples.d.mts +55 -0
  154. package/dist/vitest-diagnostics/vitest-fork-leak-handshake-samples.mjs +74 -0
  155. package/dist/vitest-diagnostics/vitest-fork-leak-handshake.d.mts +19 -0
  156. package/dist/vitest-diagnostics/vitest-fork-leak-handshake.mjs +136 -0
  157. package/dist/vitest-diagnostics/vitest-network-allowlist-dns.d.mts +7 -0
  158. package/dist/vitest-diagnostics/vitest-network-allowlist-dns.mjs +54 -0
  159. package/dist/vitest-diagnostics/vitest-network-allowlist-host.d.mts +8 -0
  160. package/dist/vitest-diagnostics/vitest-network-allowlist-host.mjs +48 -0
  161. package/dist/vitest-diagnostics/vitest-network-allowlist-socket.d.mts +14 -0
  162. package/dist/vitest-diagnostics/vitest-network-allowlist-socket.mjs +39 -0
  163. package/dist/vitest-diagnostics/vitest-network-allowlist.d.mts +7 -0
  164. package/dist/vitest-diagnostics/vitest-network-allowlist.mjs +72 -0
  165. package/dist/vitest-diagnostics/vitest-process-resources.d.mts +10 -0
  166. package/dist/vitest-diagnostics/vitest-process-resources.mjs +54 -0
  167. package/dist/vitest-effective-timeout/cap.d.mts +9 -0
  168. package/dist/vitest-effective-timeout/cap.mjs +28 -0
  169. package/dist/vitest-effective-timeout/check-profiles.d.mts +15 -0
  170. package/dist/vitest-effective-timeout/check-profiles.mjs +52 -0
  171. package/dist/vitest-effective-timeout/config-file.d.mts +6 -0
  172. package/dist/vitest-effective-timeout/config-file.mjs +23 -0
  173. package/dist/vitest-effective-timeout/fixtures.d.mts +2 -0
  174. package/dist/vitest-effective-timeout/fixtures.mjs +18 -0
  175. package/dist/vitest-effective-timeout/index.d.mts +7 -0
  176. package/dist/vitest-effective-timeout/index.mjs +4 -0
  177. package/dist/vitest-effective-timeout/profiles.d.mts +10 -0
  178. package/dist/vitest-effective-timeout/profiles.mjs +33 -0
  179. package/dist/vitest-effective-timeout/run-profile.d.mts +31 -0
  180. package/dist/vitest-effective-timeout/run-profile.mjs +95 -0
  181. package/docs/mcp-server.md +2 -13
  182. package/package.json +37 -2
  183. package/scripts/__pycache__/run_bounded_process.cpython-312.pyc +0 -0
  184. package/scripts/chromium-launch-probe.d.mts +7 -0
  185. package/scripts/chromium-launch-probe.mjs +101 -0
  186. package/scripts/run-bounded-fixtures/run-bounded-backpressure.py +186 -0
  187. package/scripts/run-bounded-fixtures/run-bounded-merged-output.py +75 -0
  188. package/scripts/run-bounded-fixtures/run-bounded-reset-socket.py +25 -0
  189. package/scripts/run-bounded.py +199 -0
  190. package/scripts/run_bounded_process.py +129 -0
  191. package/scripts/worktree/git-index-lock.sh +16 -0
  192. package/scripts/worktree/git-worktrees.sh +23 -20
  193. package/scripts/worktree/reset-worktree-run.sh +199 -0
  194. package/scripts/worktree/reset-worktree.sh +122 -0
  195. package/skills/blackboard/SKILL.md +4 -64
  196. package/skills/stacked-prs/SKILL.md +1 -1
  197. package/skills/stacked-prs/references/drain.md +2 -2
@@ -0,0 +1,107 @@
1
+ const CONNECTION_RETRY_DEFAULT_BACKOFF_MS = 5000;
2
+ const CONNECTION_RETRY_DEFAULT_DURATION_MS = 55_000;
3
+ const CONNECTION_RETRY_MINIMUM_BACKOFF_MS = 50;
4
+ const CONNECTION_RETRY_BUDGET_EXCEEDED_MESSAGE = 'connection retry budget exceeded';
5
+ function validateRetryInputs(backoffMs, maxDurationMs, maxRetries) {
6
+ if (!Number.isFinite(backoffMs) || backoffMs <= 0) {
7
+ throw new Error('connection retry backoffMs must be a finite number greater than 0');
8
+ }
9
+ if (!Number.isFinite(maxDurationMs) || maxDurationMs <= 0) {
10
+ throw new Error('connection retry maxDurationMs must be a finite number greater than 0');
11
+ }
12
+ if (maxRetries !== undefined &&
13
+ (!Number.isFinite(maxRetries) || maxRetries < 0 || !Number.isInteger(maxRetries))) {
14
+ throw new Error('connection retry maxRetries must be a finite non-negative integer');
15
+ }
16
+ }
17
+ function getDefaultMaxRetries(backoffMs, maxDurationMs) {
18
+ return Math.max(1, Math.ceil(maxDurationMs / backoffMs));
19
+ }
20
+ const CONNECTION_LOST_PATTERN = /\bERR_(CONNECTION_REFUSED|CONNECTION_RESET|CONNECTION_CLOSED|SOCKET_NOT_CONNECTED|NETWORK_CHANGED|EMPTY_RESPONSE|ABORTED|INCOMPLETE_CHUNKED_ENCODING)\b/i;
21
+ const NAVIGATION_TIMEOUT_PATTERN = /\bpage\.goto: Timeout \d+ms exceeded\b/;
22
+ function isLocalUrl(value) {
23
+ try {
24
+ const { hostname } = new URL(value);
25
+ const normalizedHostname = hostname.replace(/^\[(.*)]$/, '$1');
26
+ return ['', 'localhost', '127.0.0.1', '::1'].includes(normalizedHostname);
27
+ }
28
+ catch {
29
+ return false;
30
+ }
31
+ }
32
+ function isLocalNavigationTimeout(message) {
33
+ if (!NAVIGATION_TIMEOUT_PATTERN.test(message))
34
+ return false;
35
+ const navigatingMatch = message.match(/navigating to "([^"]+)"/);
36
+ const target = navigatingMatch?.[1];
37
+ return target !== undefined && isLocalUrl(target);
38
+ }
39
+ function isConnectionLostError(err) {
40
+ const message = err instanceof Error ? err.message : String(err);
41
+ return CONNECTION_LOST_PATTERN.test(message) || isLocalNavigationTimeout(message);
42
+ }
43
+ async function runWithDeadline(fn, deadlineMs) {
44
+ if (deadlineMs <= 0) {
45
+ throw new Error(CONNECTION_RETRY_BUDGET_EXCEEDED_MESSAGE);
46
+ }
47
+ let timedOut = false;
48
+ let timerId;
49
+ const timeout = new Promise((_, reject) => {
50
+ timerId = setTimeout(() => {
51
+ timedOut = true;
52
+ reject(new Error(CONNECTION_RETRY_BUDGET_EXCEEDED_MESSAGE));
53
+ }, deadlineMs);
54
+ });
55
+ let attempt;
56
+ try {
57
+ attempt = Promise.resolve().then(fn);
58
+ const result = await Promise.race([attempt, timeout]);
59
+ return result;
60
+ }
61
+ catch (err) {
62
+ if (timedOut && attempt) {
63
+ attempt.catch(() => undefined);
64
+ }
65
+ throw err;
66
+ }
67
+ finally {
68
+ clearTimeout(timerId);
69
+ }
70
+ }
71
+ // Retries fn on transient network/worker errors matched by CONNECTION_LOST_PATTERN
72
+ // for a bounded recovery window, using configurable backoff sleeps and a total
73
+ // elapsed-time budget to absorb process restart windows, OS-level
74
+ // network changes (ERR_NETWORK_CHANGED), and related cold-start races.
75
+ export function retryOnConnectionLost(fn, options = {}) {
76
+ const backoffMs = options.backoffMs ?? CONNECTION_RETRY_DEFAULT_BACKOFF_MS;
77
+ const maxDurationMs = options.maxDurationMs ?? CONNECTION_RETRY_DEFAULT_DURATION_MS;
78
+ validateRetryInputs(backoffMs, maxDurationMs, options.maxRetries);
79
+ const effectiveBackoffMs = Math.max(CONNECTION_RETRY_MINIMUM_BACKOFF_MS, backoffMs);
80
+ const maxRetries = options.maxRetries ?? getDefaultMaxRetries(effectiveBackoffMs, maxDurationMs);
81
+ const deadline = Date.now() + maxDurationMs;
82
+ const retry = async (remainingRetries) => {
83
+ try {
84
+ return await runWithDeadline(fn, deadline - Date.now());
85
+ }
86
+ catch (err) {
87
+ if (!isConnectionLostError(err) || remainingRetries <= 0)
88
+ throw err;
89
+ const remainingMs = Math.max(0, deadline - Date.now());
90
+ if (remainingMs <= 0)
91
+ throw err;
92
+ await new Promise((resolve) => setTimeout(resolve, Math.min(effectiveBackoffMs, remainingMs)));
93
+ if (Date.now() >= deadline) {
94
+ throw new Error(CONNECTION_RETRY_BUDGET_EXCEEDED_MESSAGE, { cause: err });
95
+ }
96
+ return retry(remainingRetries - 1);
97
+ }
98
+ };
99
+ return retry(maxRetries).catch((err) => {
100
+ if (err instanceof Error && err.message === CONNECTION_RETRY_BUDGET_EXCEEDED_MESSAGE) {
101
+ throw new Error(`retryOnConnectionLost: ${CONNECTION_RETRY_BUDGET_EXCEEDED_MESSAGE}`, {
102
+ cause: err,
103
+ });
104
+ }
105
+ throw err;
106
+ });
107
+ }
@@ -0,0 +1,37 @@
1
+ import type { Page } from '@playwright/test';
2
+ /**
3
+ * Trigger pagination with a real scroll gesture.
4
+ *
5
+ * The pagination control gates `onLoadMore` behind a one-shot window `scroll`
6
+ * listener plus IntersectionObserver, so this wheels a viewport at a time
7
+ * until the sentinel is on screen. Do not use `scrollIntoViewIfNeeded()`:
8
+ * it is a no-op on an already-visible element and emits no `scroll` event
9
+ * (`playwright-no-scroll-into-view-sentinel`).
10
+ *
11
+ * After the sentinel is in view, wait for below-fold hydration and issue a
12
+ * net-zero extra scroll so a deferred listener still sees a live event.
13
+ *
14
+ * Probe `count()` before `boundingBox()` and bound `boundingBox()` to
15
+ * {@link BOUNDING_BOX_TIMEOUT_MS} so a detached sentinel cannot consume the
16
+ * action timeout. The loop is also bounded by
17
+ * {@link SCROLL_LOOP_BUDGET_MS}; a detached attempt waits up to
18
+ * {@link DETACHED_REMOUNT_WAIT_MS} for remount.
19
+ *
20
+ * The pagination control unmounts the sentinel when `hasNextPage` becomes false.
21
+ * If this helper already saw the sentinel attached (typically below the fold)
22
+ * and it stays gone after that remount wait, pagination already loaded the
23
+ * last page. Treating that as failure flakes the scroll-gated specs.
24
+ */
25
+ export declare function scrollToLoadMore(page: Page, { sentinelTestId }?: {
26
+ sentinelTestId?: string;
27
+ }): Promise<void>;
28
+ /**
29
+ * Force `main` to exceed the viewport height before hydration, so
30
+ * the pagination control's short-page escape hatch (which auto-loads when
31
+ * `document.documentElement.scrollHeight <= window.innerHeight`) cannot open
32
+ * the pagination gate on its own. Use this alongside `scrollToLoadMore(page)`
33
+ * so a scroll-triggered pagination test exercises the scroll-gated path
34
+ * deterministically rather than depending on whichever seeded content happens
35
+ * to render.
36
+ */
37
+ export declare function forceMainScrollableBeforeHydration(page: Page): Promise<void>;
@@ -0,0 +1,158 @@
1
+ import { waitForBelowFoldHydration } from "./wait-for-hydration.mjs";
2
+ const SENTINEL_TEST_ID = 'infinite-scroll-sentinel';
3
+ const MAX_SCROLL_ATTEMPTS = 30;
4
+ const POST_HYDRATION_SCROLL_RETRIES = 3;
5
+ const BOUNDING_BOX_TIMEOUT_MS = 2_000;
6
+ const SCROLL_LOOP_BUDGET_MS = 10_000;
7
+ const DETACHED_REMOUNT_WAIT_MS = 1_000;
8
+ function readScrollTop(page) {
9
+ return page.evaluate(() => globalThis.document.scrollingElement?.scrollTop ?? 0);
10
+ }
11
+ /**
12
+ * Trigger pagination with a real scroll gesture.
13
+ *
14
+ * The pagination control gates `onLoadMore` behind a one-shot window `scroll`
15
+ * listener plus IntersectionObserver, so this wheels a viewport at a time
16
+ * until the sentinel is on screen. Do not use `scrollIntoViewIfNeeded()`:
17
+ * it is a no-op on an already-visible element and emits no `scroll` event
18
+ * (`playwright-no-scroll-into-view-sentinel`).
19
+ *
20
+ * After the sentinel is in view, wait for below-fold hydration and issue a
21
+ * net-zero extra scroll so a deferred listener still sees a live event.
22
+ *
23
+ * Probe `count()` before `boundingBox()` and bound `boundingBox()` to
24
+ * {@link BOUNDING_BOX_TIMEOUT_MS} so a detached sentinel cannot consume the
25
+ * action timeout. The loop is also bounded by
26
+ * {@link SCROLL_LOOP_BUDGET_MS}; a detached attempt waits up to
27
+ * {@link DETACHED_REMOUNT_WAIT_MS} for remount.
28
+ *
29
+ * The pagination control unmounts the sentinel when `hasNextPage` becomes false.
30
+ * If this helper already saw the sentinel attached (typically below the fold)
31
+ * and it stays gone after that remount wait, pagination already loaded the
32
+ * last page. Treating that as failure flakes the scroll-gated specs.
33
+ */
34
+ export async function scrollToLoadMore(page, { sentinelTestId = SENTINEL_TEST_ID } = {}) {
35
+ const sentinel = page.getByTestId(sentinelTestId);
36
+ const viewport = page.viewportSize();
37
+ const centerX = (viewport?.width ?? 0) / 2;
38
+ const viewportHeight = viewport?.height ?? 0;
39
+ await page.mouse.move(centerX, viewportHeight / 2);
40
+ let sentinelInView = false;
41
+ let lastPageConsumedSentinel = false;
42
+ let sawSentinelAttached = false;
43
+ let lastCount = 0;
44
+ let lastBox = null;
45
+ const initialScrollTop = await readScrollTop(page);
46
+ const scrollTops = [initialScrollTop];
47
+ const attemptStates = [];
48
+ const loopDeadline = Date.now() + SCROLL_LOOP_BUDGET_MS;
49
+ for (let attempt = 0; attempt < MAX_SCROLL_ATTEMPTS && Date.now() < loopDeadline; attempt++) {
50
+ // oxlint-disable-next-line no-await-in-loop -- count() must resolve before deciding whether to probe further
51
+ lastCount = await sentinel.count();
52
+ if (lastCount > 0) {
53
+ sawSentinelAttached = true;
54
+ let boundingBoxTimedOut = false;
55
+ // oxlint-disable-next-line no-await-in-loop -- bounded so a count()/boundingBox() detach race can't consume the full action timeout
56
+ lastBox = await sentinel.boundingBox({ timeout: BOUNDING_BOX_TIMEOUT_MS }).catch(() => {
57
+ boundingBoxTimedOut = true;
58
+ return null;
59
+ });
60
+ if (lastBox && lastBox.y < viewportHeight) {
61
+ sentinelInView = true;
62
+ break;
63
+ }
64
+ attemptStates.push(lastBox ? 'below-fold' : boundingBoxTimedOut ? 'race-detach' : 'no-box');
65
+ }
66
+ else {
67
+ lastBox = null;
68
+ attemptStates.push('detached');
69
+ // oxlint-disable-next-line no-await-in-loop -- bounded wait gives a transient detach real time to remount
70
+ await sentinel
71
+ .waitFor({ state: 'attached', timeout: DETACHED_REMOUNT_WAIT_MS })
72
+ .catch(() => undefined);
73
+ // oxlint-disable-next-line no-await-in-loop -- remount vs last-page unmount must be distinguished before wheeling
74
+ lastCount = await sentinel.count();
75
+ if (lastCount > 0)
76
+ continue;
77
+ if (sawSentinelAttached) {
78
+ lastPageConsumedSentinel = true;
79
+ break;
80
+ }
81
+ }
82
+ // oxlint-disable-next-line no-await-in-loop -- scrolling all at once would overshoot the sentinel
83
+ await page.mouse.wheel(0, viewportHeight);
84
+ // oxlint-disable-next-line no-await-in-loop -- records this attempt's post-wheel position for diagnosis
85
+ scrollTops.push(await readScrollTop(page));
86
+ }
87
+ if (!sentinelInView && !lastPageConsumedSentinel) {
88
+ const documentState = await page.evaluate(() => ({
89
+ scrollHeight: globalThis.document.documentElement.scrollHeight,
90
+ innerHeight: globalThis.window
91
+ .innerHeight,
92
+ }));
93
+ const documentScrolled = scrollTops.at(-1) > initialScrollTop;
94
+ const tally = {
95
+ detached: 0,
96
+ 'race-detach': 0,
97
+ 'no-box': 0,
98
+ 'below-fold': 0,
99
+ };
100
+ for (const s of attemptStates)
101
+ tally[s] += 1;
102
+ const state = !documentScrolled
103
+ ? `the document never scrolled despite ${attemptStates.length} wheel events ` +
104
+ `(scrollTop stayed at ${initialScrollTop}) — the wheel target may have landed on a ` +
105
+ `nested scroll container instead of the document`
106
+ : tally.detached === attemptStates.length
107
+ ? `sentinel was detached from the DOM on every attempt (count()=0 all ` +
108
+ `${attemptStates.length} times) — it never (re)mounted during the scroll loop`
109
+ : `sentinel state varied across ${attemptStates.length} attempts: ` +
110
+ `${tally.detached} detached, ${tally['race-detach']} attached-but-boundingBox-timed-out, ` +
111
+ `${tally['no-box']} attached-but-invisible, ${tally['below-fold']} below-fold`;
112
+ throw new Error(`scrollToLoadMore: sentinel [data-testid="${sentinelTestId}"] did not enter the ` +
113
+ `viewport after ${attemptStates.length} scroll attempts: ${state}. ` +
114
+ `lastCount()=${lastCount}, lastBox=${JSON.stringify(lastBox)}, ` +
115
+ `scrollTop=${scrollTops[0]}->${scrollTops.at(-1)}, ` +
116
+ `documentScrollHeight=${documentState.scrollHeight}, windowInnerHeight=${documentState.innerHeight}`);
117
+ }
118
+ if (!sentinelInView)
119
+ return;
120
+ for (let retry = 0; retry < POST_HYDRATION_SCROLL_RETRIES; retry++) {
121
+ // oxlint-disable-next-line no-await-in-loop -- each retry must wait for hydration to catch up first
122
+ await waitForBelowFoldHydration(page);
123
+ // oxlint-disable-next-line no-await-in-loop -- must complete before the wheel-forward below
124
+ await page.mouse.wheel(0, -50);
125
+ // oxlint-disable-next-line no-await-in-loop -- closes the net-zero scroll pair for this retry
126
+ await page.mouse.wheel(0, 50);
127
+ }
128
+ }
129
+ /**
130
+ * Force `main` to exceed the viewport height before hydration, so
131
+ * the pagination control's short-page escape hatch (which auto-loads when
132
+ * `document.documentElement.scrollHeight <= window.innerHeight`) cannot open
133
+ * the pagination gate on its own. Use this alongside `scrollToLoadMore(page)`
134
+ * so a scroll-triggered pagination test exercises the scroll-gated path
135
+ * deterministically rather than depending on whichever seeded content happens
136
+ * to render.
137
+ */
138
+ export async function forceMainScrollableBeforeHydration(page) {
139
+ await page.addInitScript(() => {
140
+ const styleId = 'pw-force-scrollable-main';
141
+ const document = globalThis.document;
142
+ const installStyle = () => {
143
+ if (document.getElementById(styleId))
144
+ return;
145
+ const styleRoot = document.head ?? document.documentElement;
146
+ if (!styleRoot)
147
+ return;
148
+ const style = document.createElement('style');
149
+ style.id = styleId;
150
+ style.textContent = 'main { min-height: 180vh !important; }';
151
+ styleRoot.append(style);
152
+ };
153
+ if (document.readyState === 'loading') {
154
+ document.addEventListener('DOMContentLoaded', installStyle, { once: true });
155
+ }
156
+ installStyle();
157
+ });
158
+ }
@@ -0,0 +1,2 @@
1
+ import type { Page } from '@playwright/test';
2
+ export declare function storybookBundleHasStory(page: Page, id: string): Promise<boolean>;
@@ -0,0 +1,13 @@
1
+ export async function storybookBundleHasStory(page, id) {
2
+ let response;
3
+ try {
4
+ response = await page.request.get('/storybook/index.json', { timeout: 5000 });
5
+ }
6
+ catch {
7
+ return false;
8
+ }
9
+ if (!response.ok())
10
+ return false;
11
+ const storyIndex = (await response.json());
12
+ return id in (storyIndex.entries ?? {});
13
+ }
@@ -0,0 +1 @@
1
+ export declare const TEST_PNG: Buffer<ArrayBuffer>;
@@ -0,0 +1,2 @@
1
+ // Minimal 1x1 white PNG for image upload tests
2
+ export const TEST_PNG = Buffer.from('iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAADUlEQVR42mNkYPhfDwAChwGA60e6kgAAAABJRU5ErkJggg==', 'base64');
@@ -0,0 +1,27 @@
1
+ import type { FullConfig, FullResult, Reporter, TestCase, TestResult } from '@playwright/test/reporter';
2
+ export interface TestLifecycleReporterOptions {
3
+ /**
4
+ * Fail the run when any test ends with status `skipped`. This includes `test.fixme`,
5
+ * `test.skip`, and tests skipped at runtime, because Playwright reports all of them as
6
+ * `skipped`. Defaults to `false`; the caller decides, for example
7
+ * `failOnSkippedTests: Boolean(process.env.CI)`.
8
+ */
9
+ failOnSkippedTests?: boolean;
10
+ }
11
+ export default class TestLifecycleReporter implements Reporter {
12
+ static readonly modulePath: string;
13
+ private readonly failOnSkippedTests;
14
+ private readonly skipped;
15
+ private rootDir;
16
+ private shard;
17
+ constructor(options?: TestLifecycleReporterOptions);
18
+ onBegin(config: FullConfig): void;
19
+ onTestBegin(test: TestCase, result: TestResult): void;
20
+ onTestEnd(test: TestCase, result: TestResult): void;
21
+ onEnd(result: FullResult): Promise<{
22
+ status: FullResult['status'];
23
+ } | undefined>;
24
+ printsToStdio(): boolean;
25
+ private relativeFile;
26
+ private record;
27
+ }
@@ -0,0 +1,57 @@
1
+ import { relative } from 'node:path';
2
+ export default class TestLifecycleReporter {
3
+ static modulePath = import.meta.filename;
4
+ failOnSkippedTests;
5
+ skipped = new Map();
6
+ rootDir = '';
7
+ shard = null;
8
+ constructor(options = {}) {
9
+ this.failOnSkippedTests = options.failOnSkippedTests ?? false;
10
+ }
11
+ onBegin(config) {
12
+ this.rootDir = config.rootDir;
13
+ this.shard = config.shard;
14
+ }
15
+ onTestBegin(test, result) {
16
+ this.record('begin', test, result);
17
+ }
18
+ onTestEnd(test, result) {
19
+ this.record('end', test, result);
20
+ // Only a test's latest attempt counts: serial suites skip tests that a retry later runs.
21
+ if (result.status !== 'skipped') {
22
+ this.skipped.delete(test.id);
23
+ return;
24
+ }
25
+ const title = test.titlePath().filter(Boolean).join(' > ');
26
+ this.skipped.set(test.id, `${title} (${this.relativeFile(test)}:${test.location.line})`);
27
+ }
28
+ async onEnd(result) {
29
+ if (!this.failOnSkippedTests || this.skipped.size === 0)
30
+ return undefined;
31
+ const lines = [...this.skipped.values()].map((entry) => ` - ${entry}`).join('\n');
32
+ process.stderr.write(`${this.skipped.size} test(s) were skipped and failOnSkippedTests is enabled:\n${lines}\n`);
33
+ return result.status === 'passed' ? { status: 'failed' } : undefined;
34
+ }
35
+ printsToStdio() {
36
+ return true;
37
+ }
38
+ relativeFile(test) {
39
+ return relative(this.rootDir, test.location.file);
40
+ }
41
+ record(event, test, result) {
42
+ process.stdout.write(`${JSON.stringify({
43
+ marker: 'playwright-test-lifecycle',
44
+ event,
45
+ observedAt: new Date().toISOString(),
46
+ testId: test.id,
47
+ file: this.relativeFile(test),
48
+ line: test.location.line,
49
+ project: test.parent.project()?.name,
50
+ shard: this.shard,
51
+ retry: result.retry,
52
+ workerIndex: result.workerIndex,
53
+ parallelIndex: result.parallelIndex,
54
+ ...(event === 'end' ? { status: result.status, durationMs: result.duration } : {}),
55
+ })}\n`);
56
+ }
57
+ }
@@ -0,0 +1,6 @@
1
+ import type { Page } from '@playwright/test';
2
+ /**
3
+ * Generate a TOTP code using WebCrypto in the browser context.
4
+ * Uses SHA-1 HMAC with 6-digit output and 30-second period (RFC 6238).
5
+ */
6
+ export declare function generateTotpCode(page: Page, base32Secret: string): Promise<string>;
@@ -0,0 +1,37 @@
1
+ /**
2
+ * Generate a TOTP code using WebCrypto in the browser context.
3
+ * Uses SHA-1 HMAC with 6-digit output and 30-second period (RFC 6238).
4
+ */
5
+ export function generateTotpCode(page, base32Secret) {
6
+ return page.evaluate(async (secret) => {
7
+ const BASE32 = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ234567';
8
+ const BASE32_MAP = new Map(Array.from(BASE32).map((ch, i) => [ch, i]));
9
+ const upper = secret.toUpperCase().replace(/=+$/, '').replace(/\s/g, '');
10
+ let bits = '';
11
+ for (const c of upper) {
12
+ const idx = BASE32_MAP.get(c);
13
+ if (idx !== undefined)
14
+ bits += idx.toString(2).padStart(5, '0');
15
+ }
16
+ const bytes = [];
17
+ for (let i = 0; i + 8 <= bits.length; i += 8) {
18
+ bytes.push(parseInt(bits.slice(i, i + 8), 2));
19
+ }
20
+ const counter = Math.floor(Date.now() / 1000 / 30);
21
+ const counterBytes = new Uint8Array(8);
22
+ let rem = counter;
23
+ for (let i = 7; i >= 0; i--) {
24
+ counterBytes[i] = rem & 0xff;
25
+ rem = Math.floor(rem / 256);
26
+ }
27
+ const key = await crypto.subtle.importKey('raw', new Uint8Array(bytes), { name: 'HMAC', hash: 'SHA-1' }, false, ['sign']);
28
+ const sig = new Uint8Array(await crypto.subtle.sign('HMAC', key, counterBytes));
29
+ const offset = sig[19] & 0x0f;
30
+ const code = (((sig[offset] & 0x7f) << 24) |
31
+ ((sig[offset + 1] & 0xff) << 16) |
32
+ ((sig[offset + 2] & 0xff) << 8) |
33
+ (sig[offset + 3] & 0xff)) %
34
+ 1_000_000;
35
+ return String(code).padStart(6, '0');
36
+ }, base32Secret);
37
+ }
@@ -0,0 +1,8 @@
1
+ import type { Page } from '@playwright/test';
2
+ export declare const DEFAULT_TURNSTILE_STUB_TOKEN = "PLAYWRIGHT_TURNSTILE_TOKEN";
3
+ export declare const DEFAULT_TURNSTILE_STUB_ATTRIBUTE = "data-pw";
4
+ export interface TurnstileStubOptions {
5
+ attributeName?: string;
6
+ token?: string;
7
+ }
8
+ export declare function installTurnstileStub(page: Page, options?: TurnstileStubOptions): Promise<void>;
@@ -0,0 +1,61 @@
1
+ /**
2
+ * Fulfill the Cloudflare Turnstile script with a synthetic `window.turnstile`
3
+ * that resolves the widget synchronously. Background traffic from the real
4
+ * script can keep `networkidle` from settling. The synthetic widget implements
5
+ * render, reset, remove, and getResponse. Callers that reject the token on
6
+ * the server should mock that request.
7
+ */
8
+ const TURNSTILE_API_PATTERN = '**/turnstile/v0/api.js**';
9
+ export const DEFAULT_TURNSTILE_STUB_TOKEN = 'PLAYWRIGHT_TURNSTILE_TOKEN';
10
+ export const DEFAULT_TURNSTILE_STUB_ATTRIBUTE = 'data-pw';
11
+ function renderTurnstileStubScript(token, attributeName) {
12
+ return `
13
+ ;(function () {
14
+ if (window.turnstile) return
15
+ var fakeToken = ${JSON.stringify(token)}
16
+ var handlers = new Map()
17
+ window.turnstile = {
18
+ render: function (container, params) {
19
+ var id = 'pw-' + Math.random().toString(36).slice(2)
20
+ if (typeof container === 'string') container = document.querySelector(container)
21
+ if (!container) throw new Error('Turnstile container not found')
22
+ container.replaceChildren()
23
+ var widget = document.createElement('div')
24
+ widget.setAttribute('role', 'group')
25
+ widget.setAttribute('aria-label', 'Cloudflare Turnstile verification')
26
+ widget.setAttribute(${JSON.stringify(attributeName)}, 'turnstile-widget')
27
+ widget.textContent = 'Cloudflare Turnstile verification'
28
+ container.appendChild(widget)
29
+ handlers.set(id, params)
30
+ queueMicrotask(function () {
31
+ try { params && params.callback && params.callback(fakeToken) } catch (_) {}
32
+ })
33
+ return id
34
+ },
35
+ reset: function (id) {
36
+ var params = handlers.get(id)
37
+ if (!params) return
38
+ queueMicrotask(function () {
39
+ try { params.callback && params.callback(fakeToken) } catch (_) {}
40
+ })
41
+ },
42
+ remove: function (id) { handlers.delete(id) },
43
+ getResponse: function () { return fakeToken },
44
+ }
45
+ })();
46
+ `;
47
+ }
48
+ const stubbedPages = new WeakSet();
49
+ export async function installTurnstileStub(page, options = {}) {
50
+ if (stubbedPages.has(page))
51
+ return;
52
+ const token = options.token ?? DEFAULT_TURNSTILE_STUB_TOKEN;
53
+ const attributeName = options.attributeName ?? DEFAULT_TURNSTILE_STUB_ATTRIBUTE;
54
+ const body = renderTurnstileStubScript(token, attributeName);
55
+ await page.route(TURNSTILE_API_PATTERN, (route) => route.fulfill({
56
+ status: 200,
57
+ contentType: 'application/javascript',
58
+ body,
59
+ }));
60
+ stubbedPages.add(page);
61
+ }
@@ -0,0 +1,30 @@
1
+ export declare const MOBILE_VIEWPORTS: {
2
+ readonly 'iphone-se': {
3
+ readonly width: 375;
4
+ readonly height: 667;
5
+ };
6
+ readonly 'iphone-14-pro': {
7
+ readonly width: 393;
8
+ readonly height: 852;
9
+ };
10
+ readonly 'pixel-7': {
11
+ readonly width: 412;
12
+ readonly height: 915;
13
+ };
14
+ readonly 'iphone-14-plus': {
15
+ readonly width: 428;
16
+ readonly height: 926;
17
+ };
18
+ readonly 'galaxy-s21': {
19
+ readonly width: 360;
20
+ readonly height: 800;
21
+ };
22
+ readonly smallest: {
23
+ readonly width: 320;
24
+ readonly height: 568;
25
+ };
26
+ };
27
+ export declare const DESKTOP_VIEWPORT: {
28
+ width: number;
29
+ height: number;
30
+ };
@@ -0,0 +1,9 @@
1
+ export const MOBILE_VIEWPORTS = {
2
+ 'iphone-se': { width: 375, height: 667 },
3
+ 'iphone-14-pro': { width: 393, height: 852 },
4
+ 'pixel-7': { width: 412, height: 915 },
5
+ 'iphone-14-plus': { width: 428, height: 926 },
6
+ 'galaxy-s21': { width: 360, height: 800 },
7
+ smallest: { width: 320, height: 568 },
8
+ };
9
+ export const DESKTOP_VIEWPORT = { width: 1280, height: 720 };
@@ -0,0 +1,5 @@
1
+ import type { Page } from '@playwright/test';
2
+ export declare function setupVirtualAuthenticator(page: Page): Promise<{
3
+ client: import("@playwright/test").CDPSession;
4
+ authenticatorId: string;
5
+ }>;
@@ -0,0 +1,15 @@
1
+ export async function setupVirtualAuthenticator(page) {
2
+ const client = await page.context().newCDPSession(page);
3
+ await client.send('WebAuthn.enable', { enableUI: false });
4
+ const { authenticatorId } = await client.send('WebAuthn.addVirtualAuthenticator', {
5
+ options: {
6
+ protocol: 'ctap2',
7
+ transport: 'internal',
8
+ hasResidentKey: true,
9
+ hasUserVerification: true,
10
+ isUserVerified: true,
11
+ automaticPresenceSimulation: true,
12
+ },
13
+ });
14
+ return { client, authenticatorId };
15
+ }
@@ -0,0 +1,29 @@
1
+ import type { Page } from '@playwright/test';
2
+ /**
3
+ * Wait for React hydration of below-fold streaming components.
4
+ *
5
+ * React 19 prioritises above-fold hydration; components scrolled out of
6
+ * view receive lower-priority MessageChannel callbacks. The idle/animation
7
+ * probe is a bounded readiness heuristic, not proof that every client handler
8
+ * is attached. A control that cannot accept an early interaction must expose
9
+ * its own disabled-until-hydrated state; tests then wait for that state.
10
+ *
11
+ * Use this when navigateTo() alone is insufficient because the element you
12
+ * need to interact with lives inside a below-fold streaming boundary. Prefer
13
+ * scrolling the element into view first (element.scrollIntoViewIfNeeded())
14
+ * so React has a chance to bump its hydration priority before you call this.
15
+ *
16
+ * Tolerates a client-side redirect arriving mid-wait: the document the
17
+ * readiness probe started in can be replaced before the probe resolves, which
18
+ * destroys its execution context. Rather than failing, the wait restarts
19
+ * against the document that replaced it, so hydration is always measured
20
+ * against the document the caller ends up on. `waitUntil` is the load state to
21
+ * settle that replacement document to; callers that navigated under a stricter
22
+ * state should pass their own so a redirect does not silently weaken it.
23
+ *
24
+ * If you find yourself calling this frequently, consider fixing navigate-to.mts
25
+ * to use a more deterministic hydration signal instead.
26
+ */
27
+ export declare function waitForBelowFoldHydration(page: Page, { waitUntil }?: {
28
+ waitUntil?: "load" | "networkidle" | undefined;
29
+ }): Promise<void>;