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,105 @@
1
+ import { execFile } from 'node:child_process';
2
+ import { realpath, stat, statfs } from 'node:fs/promises';
3
+ import { homedir, platform } from 'node:os';
4
+ import { join } from 'node:path';
5
+ import { promisify } from 'node:util';
6
+ import { errorMessage, HOST_STORAGE_MINIMUM_FREE_BYTES, makeResolutionIssue, probeHostStorage, } from "./check.mjs";
7
+ export const HOST_STORAGE_DISCOVERY_TIMEOUT_MS = 5_000;
8
+ export const MAX_DISCOVERY_TIMEOUT_MS = 2_147_483_647;
9
+ export const DOCKER_DESKTOP_STORAGE_RELATIVE_PATH = 'Library/Containers/com.docker.docker/Data/vms/0/data/Docker.raw';
10
+ const execFileAsync = promisify(execFile);
11
+ const defaultDependencies = {
12
+ execFile: async (command, args, options) => {
13
+ const { stdout } = await execFileAsync(command, args, {
14
+ encoding: 'utf8',
15
+ maxBuffer: 1024 * 1024,
16
+ timeout: options.timeout,
17
+ });
18
+ return { stdout };
19
+ },
20
+ homedir,
21
+ platform: platform(),
22
+ realpath,
23
+ stat: async (path) => ({ dev: (await stat(path, { bigint: true })).dev }),
24
+ statfs: async (path) => {
25
+ const result = await statfs(path, { bigint: true });
26
+ return { bavail: result.bavail, bsize: result.bsize };
27
+ },
28
+ };
29
+ async function discoverCommandPath(command, args, label, recovery, dependencies, timeoutMs) {
30
+ const fallback = { label, path: `${command} ${args.join(' ')}`, recovery, required: false };
31
+ try {
32
+ const { stdout } = await dependencies.execFile(command, args, { timeout: timeoutMs });
33
+ const path = stdout.trim();
34
+ if (!path)
35
+ throw new Error('command returned an empty path');
36
+ return { candidate: { ...fallback, path } };
37
+ }
38
+ catch (err) {
39
+ return { issue: makeResolutionIssue(fallback, errorMessage(err)) };
40
+ }
41
+ }
42
+ function resolveDiscoveryTimeout(timeoutMs) {
43
+ const timeout = timeoutMs ?? HOST_STORAGE_DISCOVERY_TIMEOUT_MS;
44
+ if (!Number.isInteger(timeout) || timeout < 1 || timeout > MAX_DISCOVERY_TIMEOUT_MS) {
45
+ throw new Error(`discoveryTimeoutMs requires an integer from 1 through ${MAX_DISCOVERY_TIMEOUT_MS}`);
46
+ }
47
+ return timeout;
48
+ }
49
+ function dockerDesktopCandidate(path) {
50
+ return {
51
+ label: 'Docker Desktop storage',
52
+ path,
53
+ recovery: 'Review Docker Desktop disk usage and reclaim unused images, containers, or volumes intentionally.',
54
+ required: false,
55
+ };
56
+ }
57
+ async function discoverOptionalStorage(options, dependencies) {
58
+ const candidates = [];
59
+ const issues = [];
60
+ const timeoutMs = resolveDiscoveryTimeout(options.discoveryTimeoutMs);
61
+ if (options.discoverPnpmStore) {
62
+ const result = await discoverCommandPath('pnpm', ['store', 'path'], 'pnpm store', 'Confirm pnpm is installed; after reviewing its contents, `pnpm store prune` can remove unused packages.', dependencies, timeoutMs);
63
+ if (result.candidate)
64
+ candidates.push(result.candidate);
65
+ if (result.issue)
66
+ issues.push(result.issue);
67
+ }
68
+ if (!options.discoverDockerRoot)
69
+ return { candidates, issues };
70
+ if (dependencies.platform === 'darwin') {
71
+ candidates.push(dockerDesktopCandidate(options.dockerDesktopPath ??
72
+ join(dependencies.homedir(), DOCKER_DESKTOP_STORAGE_RELATIVE_PATH)));
73
+ }
74
+ else if (dependencies.platform === 'linux') {
75
+ const result = await discoverCommandPath('docker', ['info', '--format', '{{.DockerRootDir}}'], 'Docker root', 'Run `docker system df`, then reclaim only Docker images, containers, or volumes you have confirmed are unused.', dependencies, timeoutMs);
76
+ if (result.candidate)
77
+ candidates.push(result.candidate);
78
+ if (result.issue)
79
+ issues.push(result.issue);
80
+ }
81
+ else {
82
+ issues.push(makeResolutionIssue({
83
+ label: 'Docker root',
84
+ path: 'Docker host storage',
85
+ recovery: 'Inspect Docker storage using the platform-specific Docker tooling.',
86
+ required: false,
87
+ }, `unsupported host platform ${dependencies.platform}`));
88
+ }
89
+ return { candidates, issues };
90
+ }
91
+ export async function inspectHostStorage(options, dependencies = defaultDependencies) {
92
+ const minimumFreeBytes = options.minimumFreeBytes ?? HOST_STORAGE_MINIMUM_FREE_BYTES;
93
+ const required = await probeHostStorage(options.paths, dependencies, minimumFreeBytes);
94
+ if (!required.ok)
95
+ return required;
96
+ const optional = await discoverOptionalStorage(options, dependencies);
97
+ const result = optional.candidates.length === 0
98
+ ? required
99
+ : await probeHostStorage([...options.paths, ...optional.candidates], dependencies, minimumFreeBytes);
100
+ return {
101
+ ...result,
102
+ issues: [...optional.issues, ...result.issues],
103
+ ok: ![...optional.issues, ...result.issues].some((issue) => issue.severity === 'error'),
104
+ };
105
+ }
package/dist/index.d.mts CHANGED
@@ -107,3 +107,5 @@ export { formatReferenceKey, hasClosingIssueReference, parseClosingIssueReferenc
107
107
  export type { ClosingIssueReference } from './gh-cli/index.mts';
108
108
  export { countDiffLineChanges, DEFAULT_LARGE_DIFF_THRESHOLDS, exceedsLargeDiffThreshold, } from './pull-request-diff/index.mts';
109
109
  export type { DiffLineChanges, LargeDiffThresholds } from './pull-request-diff/index.mts';
110
+ export { tokenizeShellWords, tokenizeShellWordsDetailed } from './shell-parse/index.mts';
111
+ export type { ShellWord } from './shell-parse/index.mts';
package/dist/index.mjs CHANGED
@@ -58,3 +58,4 @@ export { GITHUB_BODY_MAX_CHARACTERS, validateGitHubBodyLength } from "./gh-cli/i
58
58
  export { assertHeadPushed, buildGhPrCreateArgs, createPullRequest, DetachedHeadError, HeadNotPushedError, HeadOutOfDateError, resolveHeadBranch, } from "./gh-cli/index.mjs";
59
59
  export { formatReferenceKey, hasClosingIssueReference, parseClosingIssueReferences, parseNonClosingRefs, } from "./gh-cli/index.mjs";
60
60
  export { countDiffLineChanges, DEFAULT_LARGE_DIFF_THRESHOLDS, exceedsLargeDiffThreshold, } from "./pull-request-diff/index.mjs";
61
+ export { tokenizeShellWords, tokenizeShellWordsDetailed } from "./shell-parse/index.mjs";
@@ -0,0 +1 @@
1
+ export declare function requireTestValue<T>(value: T | null | undefined, message: string): T;
@@ -0,0 +1,5 @@
1
+ export function requireTestValue(value, message) {
2
+ if (value === null || value === undefined)
3
+ throw new Error(message);
4
+ return value;
5
+ }
@@ -0,0 +1,15 @@
1
+ import type { BrowserContext, Route } from '@playwright/test';
2
+ import type { BrowserIssueAllowlistEntry } from './browser-issue-records.mts';
3
+ export interface BlockedExternalNetworkRule {
4
+ pattern: RegExp;
5
+ reason: string;
6
+ response: Parameters<Route['fulfill']>[0];
7
+ }
8
+ export declare const BLOCKED_EXTERNAL_NETWORK_RULES: BlockedExternalNetworkRule[];
9
+ export declare function blockedExternalRequestFailureAllowlist(extra?: readonly BrowserIssueAllowlistEntry[], rules?: readonly BlockedExternalNetworkRule[]): BrowserIssueAllowlistEntry[];
10
+ export declare function isBlockedExternalNetworkUrl(url: string, rules?: readonly BlockedExternalNetworkRule[]): boolean;
11
+ /**
12
+ * Playwright prefers the most recently registered matching route, so when two rules match the same
13
+ * URL the later rule in `rules` wins.
14
+ */
15
+ export declare function installBlockedExternalNetwork(context: BrowserContext, rules?: readonly BlockedExternalNetworkRule[]): Promise<() => Promise<void>>;
@@ -0,0 +1,73 @@
1
+ const NOOP_ANALYTICS_SCRIPT = [
2
+ 'window.dataLayer = window.dataLayer || [];',
3
+ 'window.gtag = window.gtag || function(){ window.dataLayer.push(arguments); };',
4
+ ].join('\n');
5
+ export const BLOCKED_EXTERNAL_NETWORK_RULES = [
6
+ {
7
+ pattern: /^https:\/\/www\.googletagmanager\.com\/(?:gtm\.js|gtag\/js)(?:[?#].*)?$/,
8
+ reason: 'Google Tag Manager is external telemetry and should not affect Playwright determinism',
9
+ response: {
10
+ body: NOOP_ANALYTICS_SCRIPT,
11
+ contentType: 'application/javascript',
12
+ status: 200,
13
+ },
14
+ },
15
+ {
16
+ pattern: /^https:\/\/(?:www\.|region1\.)?google-analytics\.com\/(?:collect|g\/collect|j\/collect|mp\/collect)(?:[?#].*)?$/,
17
+ reason: 'Google Analytics collection is external telemetry and should not affect Playwright determinism',
18
+ response: {
19
+ body: '',
20
+ contentType: 'text/plain',
21
+ status: 204,
22
+ },
23
+ },
24
+ {
25
+ pattern: /^https:\/\/analytics\.google\.com\/.*$/,
26
+ reason: 'Google Analytics UI endpoints are external telemetry and should not affect Playwright determinism',
27
+ response: {
28
+ body: '',
29
+ contentType: 'text/plain',
30
+ status: 204,
31
+ },
32
+ },
33
+ {
34
+ pattern: /^https:\/\/stats\.g\.doubleclick\.net\/.*$/,
35
+ reason: 'DoubleClick analytics requests are external telemetry and should not affect Playwright determinism',
36
+ response: {
37
+ body: '',
38
+ contentType: 'text/plain',
39
+ status: 204,
40
+ },
41
+ },
42
+ ];
43
+ export function blockedExternalRequestFailureAllowlist(extra = [], rules = BLOCKED_EXTERNAL_NETWORK_RULES) {
44
+ return [
45
+ ...rules.map((rule) => ({
46
+ pattern: rule.pattern,
47
+ reason: rule.reason,
48
+ type: 'requestfailed',
49
+ })),
50
+ ...extra,
51
+ ];
52
+ }
53
+ export function isBlockedExternalNetworkUrl(url, rules = BLOCKED_EXTERNAL_NETWORK_RULES) {
54
+ return rules.some((rule) => {
55
+ rule.pattern.lastIndex = 0;
56
+ return rule.pattern.test(url);
57
+ });
58
+ }
59
+ /**
60
+ * Playwright prefers the most recently registered matching route, so when two rules match the same
61
+ * URL the later rule in `rules` wins.
62
+ */
63
+ export async function installBlockedExternalNetwork(context, rules = BLOCKED_EXTERNAL_NETWORK_RULES) {
64
+ const installed = rules.map((rule) => {
65
+ const handler = (route) => route.fulfill(rule.response);
66
+ return { handler, pattern: rule.pattern };
67
+ });
68
+ await Promise.all(installed.map(({ handler, pattern }) => context.route(pattern, handler)));
69
+ // Removes only the routes installed here, leaving caller-owned routes in place.
70
+ return async () => {
71
+ await Promise.all(installed.map(({ handler, pattern }) => context.unroute(pattern, handler).catch(() => undefined)));
72
+ };
73
+ }
@@ -0,0 +1,12 @@
1
+ import type { Dialog, Page } from '@playwright/test';
2
+ export type BrowserDialogIssue = {
3
+ defaultValue: string;
4
+ dialogType: string;
5
+ message: string;
6
+ pageUrl: string;
7
+ type: 'dialog';
8
+ };
9
+ export declare function getPageUrl(page: null | Page): string;
10
+ export declare function createDialogIssue(dialog: Dialog): BrowserDialogIssue;
11
+ export declare function formatBrowserDialogIssue(issue: BrowserDialogIssue): string;
12
+ export declare function getBrowserDialogIssueSearchableValues(issue: BrowserDialogIssue): string[];
@@ -0,0 +1,29 @@
1
+ export function getPageUrl(page) {
2
+ if (!page)
3
+ return '(no page)';
4
+ try {
5
+ return page.url();
6
+ }
7
+ catch {
8
+ return '(page URL unavailable)';
9
+ }
10
+ }
11
+ export function createDialogIssue(dialog) {
12
+ return {
13
+ defaultValue: dialog.defaultValue(),
14
+ dialogType: dialog.type(),
15
+ message: dialog.message(),
16
+ pageUrl: getPageUrl(dialog.page()),
17
+ type: 'dialog',
18
+ };
19
+ }
20
+ export function formatBrowserDialogIssue(issue) {
21
+ const details = ['[dialog]', `Page: ${issue.pageUrl}`, `Type: ${issue.dialogType}`];
22
+ if (issue.defaultValue)
23
+ details.push(`Default: ${issue.defaultValue}`);
24
+ details.push(issue.message);
25
+ return details.join('\n');
26
+ }
27
+ export function getBrowserDialogIssueSearchableValues(issue) {
28
+ return [issue.message, issue.pageUrl, issue.dialogType, issue.defaultValue];
29
+ }
@@ -0,0 +1,23 @@
1
+ import type { BrowserContext } from '@playwright/test';
2
+ import { type BrowserIssueAllowlistEntry } from './browser-issue-records.mts';
3
+ import type { MonitoredTestInfo } from './monitored-test-info.mts';
4
+ interface BrowserIssueMonitorOptions {
5
+ allowlist?: BrowserIssueAllowlistEntry[];
6
+ warningPattern?: RegExp;
7
+ }
8
+ export declare class BrowserIssueMonitor {
9
+ private readonly allowlist;
10
+ private readonly issues;
11
+ private readonly monitoredContexts;
12
+ private readonly testInfo;
13
+ private readonly warningPattern;
14
+ constructor(testInfo: MonitoredTestInfo, options?: BrowserIssueMonitorOptions);
15
+ monitorContext(context: BrowserContext): void;
16
+ dispose(): void;
17
+ attachIssuesIfAny(): Promise<boolean>;
18
+ assertNoIssues(): Promise<void>;
19
+ private formatIssues;
20
+ private formatIssueSummary;
21
+ private recordIssue;
22
+ }
23
+ export {};
@@ -0,0 +1,130 @@
1
+ import { createConsoleErrorIssue, createDialogIssue, createPageCrashIssue, createRequestFailedIssue, createWebErrorIssue, formatBrowserIssue, isBrowserSynthesizedResourceLoadError, isExpectedBrowserCancellation, isRetryableLocalConnectionLoss, matchesAllowlist, validateAllowlist, } from "./browser-issue-records.mjs";
2
+ const REACT_RENDER_WARNING_PATTERN = /hydration|Encountered a script tag|Text content (?:does|did) not match|prop\b.*\bdid not match\b|\bdid not match\.\s*Server\b|Warning: An update to/i;
3
+ export class BrowserIssueMonitor {
4
+ allowlist;
5
+ issues = [];
6
+ monitoredContexts = [];
7
+ testInfo;
8
+ warningPattern;
9
+ constructor(testInfo, options = {}) {
10
+ this.allowlist = options.allowlist ?? [];
11
+ this.warningPattern = options.warningPattern ?? REACT_RENDER_WARNING_PATTERN;
12
+ validateAllowlist(this.allowlist);
13
+ this.testInfo = testInfo;
14
+ }
15
+ monitorContext(context) {
16
+ if (this.monitoredContexts.some((monitored) => monitored.context === context))
17
+ return;
18
+ const consoleListener = (message) => {
19
+ if (
20
+ // `console.assert(false, ...)` fires a console event with type `assert`.
21
+ // We treat these the same as `console.error`: both are browser-side failures
22
+ // that should fail the test. Both are recorded as `type: 'consoleerror'` in the
23
+ // issue record, so allowlist entries of type `'consoleerror'` cover both.
24
+ (message.type() === 'assert' || message.type() === 'error') &&
25
+ !isBrowserSynthesizedResourceLoadError(message)) {
26
+ this.recordIssue(createConsoleErrorIssue(message));
27
+ }
28
+ else if (message.type() === 'warning') {
29
+ // Global and sticky patterns keep lastIndex between test() calls.
30
+ this.warningPattern.lastIndex = 0;
31
+ if (this.warningPattern.test(message.text())) {
32
+ this.recordIssue(createConsoleErrorIssue(message));
33
+ }
34
+ }
35
+ };
36
+ const webErrorListener = (webError) => {
37
+ this.recordIssue(createWebErrorIssue(webError));
38
+ };
39
+ const dialogListener = (dialog) => {
40
+ const issue = createDialogIssue(dialog);
41
+ if (!matchesAllowlist(issue, this.allowlist))
42
+ this.recordIssue(issue);
43
+ void dialog.dismiss().catch(() => undefined);
44
+ };
45
+ const requestFailedListener = (request) => {
46
+ this.recordIssue(createRequestFailedIssue(request));
47
+ };
48
+ const pages = [];
49
+ const monitorPage = (page) => {
50
+ if (pages.some((monitored) => monitored.page === page))
51
+ return;
52
+ const crashListener = () => {
53
+ this.recordIssue(createPageCrashIssue(page));
54
+ };
55
+ const closeListener = () => {
56
+ page.off('crash', crashListener);
57
+ page.off('close', closeListener);
58
+ const pageIndex = pages.findIndex((monitored) => monitored.page === page);
59
+ if (pageIndex !== -1) {
60
+ pages.splice(pageIndex, 1);
61
+ }
62
+ };
63
+ page.on('crash', crashListener);
64
+ page.on('close', closeListener);
65
+ pages.push({ closeListener, crashListener, page });
66
+ };
67
+ context.on('console', consoleListener);
68
+ context.on('dialog', dialogListener);
69
+ context.on('page', monitorPage);
70
+ context.on('weberror', webErrorListener);
71
+ context.on('requestfailed', requestFailedListener);
72
+ for (const page of context.pages()) {
73
+ monitorPage(page);
74
+ }
75
+ this.monitoredContexts.push({
76
+ consoleListener,
77
+ context,
78
+ dialogListener,
79
+ pageListener: monitorPage,
80
+ pages,
81
+ requestFailedListener,
82
+ webErrorListener,
83
+ });
84
+ }
85
+ dispose() {
86
+ for (const monitored of this.monitoredContexts.splice(0)) {
87
+ const { context } = monitored;
88
+ context.off('console', monitored.consoleListener);
89
+ context.off('dialog', monitored.dialogListener);
90
+ context.off('page', monitored.pageListener);
91
+ context.off('weberror', monitored.webErrorListener);
92
+ context.off('requestfailed', monitored.requestFailedListener);
93
+ for (const monitoredPage of monitored.pages) {
94
+ monitoredPage.page.off('crash', monitoredPage.crashListener);
95
+ monitoredPage.page.off('close', monitoredPage.closeListener);
96
+ }
97
+ }
98
+ }
99
+ async attachIssuesIfAny() {
100
+ if (this.issues.length === 0)
101
+ return false;
102
+ await this.testInfo.attach('browser-issues.txt', {
103
+ body: Buffer.from(this.formatIssues()),
104
+ contentType: 'text/plain',
105
+ });
106
+ return true;
107
+ }
108
+ async assertNoIssues() {
109
+ if (!(await this.attachIssuesIfAny()))
110
+ return;
111
+ const issueCount = this.issues.length;
112
+ const issueWord = issueCount === 1 ? 'issue' : 'issues';
113
+ throw new Error(`Unhandled browser ${issueWord} detected (${issueCount}). See browser-issues.txt attachment.\n\n${this.formatIssueSummary()}`);
114
+ }
115
+ formatIssues() {
116
+ return this.issues.map(formatBrowserIssue).join('\n\n---\n\n');
117
+ }
118
+ formatIssueSummary() {
119
+ return this.issues.slice(0, 3).map(formatBrowserIssue).join('\n\n---\n\n');
120
+ }
121
+ recordIssue(issue) {
122
+ if (isExpectedBrowserCancellation(issue))
123
+ return;
124
+ if (isRetryableLocalConnectionLoss(issue))
125
+ return;
126
+ if (matchesAllowlist(issue, this.allowlist))
127
+ return;
128
+ this.issues.push(issue);
129
+ }
130
+ }
@@ -0,0 +1,31 @@
1
+ import type { Page, Request, TestInfo } from '@playwright/test';
2
+ type Listener = (...args: never[]) => void;
3
+ declare class MockBrowserContext {
4
+ readonly listeners: Map<string, Set<Listener>>;
5
+ emit(event: string, ...args: never[]): void;
6
+ off(event: string, listener: Listener): this;
7
+ on(event: string, listener: Listener): this;
8
+ pages(): never[];
9
+ }
10
+ declare function createTestInfo(): {
11
+ attach: import("vitest").Mock<(name: string, options: {
12
+ body: Buffer;
13
+ contentType: string;
14
+ }) => Promise<void>>;
15
+ attachments: {
16
+ body: Buffer;
17
+ contentType: string;
18
+ name: string;
19
+ }[];
20
+ testInfo: TestInfo;
21
+ };
22
+ declare function createPage(url?: string): Page;
23
+ declare function createRequest(overrides?: Partial<{
24
+ failureText: null | string;
25
+ frameThrows: boolean;
26
+ frameUrl: string;
27
+ method: string;
28
+ resourceType: string;
29
+ url: string;
30
+ }>): Request;
31
+ export { createPage, createRequest, createTestInfo, MockBrowserContext };
@@ -0,0 +1,51 @@
1
+ import { vi } from 'vitest';
2
+ class MockBrowserContext {
3
+ listeners = new Map();
4
+ emit(event, ...args) {
5
+ for (const listener of this.listeners.get(event) ?? []) {
6
+ listener(...args);
7
+ }
8
+ }
9
+ off(event, listener) {
10
+ this.listeners.get(event)?.delete(listener);
11
+ return this;
12
+ }
13
+ on(event, listener) {
14
+ const listeners = this.listeners.get(event) ?? new Set();
15
+ listeners.add(listener);
16
+ this.listeners.set(event, listeners);
17
+ return this;
18
+ }
19
+ pages() {
20
+ return [];
21
+ }
22
+ }
23
+ function createTestInfo() {
24
+ const attachments = [];
25
+ const attach = vi.fn((name, options) => {
26
+ attachments.push({ name, ...options });
27
+ return Promise.resolve();
28
+ });
29
+ const testInfo = { attach };
30
+ return { attach, attachments, testInfo };
31
+ }
32
+ function createPage(url = 'http://localhost:8787/path') {
33
+ return {
34
+ url: () => url,
35
+ };
36
+ }
37
+ function createRequest(overrides = {}) {
38
+ const { failureText = 'net::ERR_FAILED', frameThrows = false, frameUrl = 'http://localhost:8787/frame', method = 'GET', resourceType = 'script', url = 'https://example.com/script.js', } = overrides;
39
+ return {
40
+ failure: () => (failureText === null ? null : { errorText: failureText }),
41
+ frame: () => {
42
+ if (frameThrows)
43
+ throw new Error('frame unavailable');
44
+ return { url: () => frameUrl };
45
+ },
46
+ method: () => method,
47
+ resourceType: () => resourceType,
48
+ url: () => url,
49
+ };
50
+ }
51
+ export { createPage, createRequest, createTestInfo, MockBrowserContext };
@@ -0,0 +1,42 @@
1
+ import type { ConsoleMessage, Page, Request, WebError } from '@playwright/test';
2
+ import { type BrowserDialogIssue } from './browser-dialog-issues.mts';
3
+ type BrowserWebErrorIssue = {
4
+ error: Error;
5
+ pageUrl: string;
6
+ type: 'weberror';
7
+ };
8
+ type BrowserRequestFailedIssue = {
9
+ failureText: string;
10
+ frameUrl: string;
11
+ method: string;
12
+ resourceType: string;
13
+ type: 'requestfailed';
14
+ url: string;
15
+ };
16
+ type BrowserConsoleErrorIssue = {
17
+ location: string;
18
+ pageUrl: string;
19
+ text: string;
20
+ type: 'consoleerror';
21
+ };
22
+ type BrowserPageCrashIssue = {
23
+ pageUrl: string;
24
+ type: 'pagecrash';
25
+ };
26
+ export type BrowserIssue = BrowserConsoleErrorIssue | BrowserDialogIssue | BrowserPageCrashIssue | BrowserRequestFailedIssue | BrowserWebErrorIssue;
27
+ export type BrowserIssueAllowlistEntry = {
28
+ pattern: RegExp;
29
+ reason: string;
30
+ type: BrowserIssue['type'];
31
+ };
32
+ export { createDialogIssue } from './browser-dialog-issues.mts';
33
+ export declare function validateAllowlist(entries: BrowserIssueAllowlistEntry[]): void;
34
+ export declare function createWebErrorIssue(webError: WebError): BrowserWebErrorIssue;
35
+ export declare function createRequestFailedIssue(request: Request): BrowserRequestFailedIssue;
36
+ export declare function createConsoleErrorIssue(message: ConsoleMessage): BrowserConsoleErrorIssue;
37
+ export declare function createPageCrashIssue(page: Page): BrowserPageCrashIssue;
38
+ export declare function formatBrowserIssue(issue: BrowserIssue): string;
39
+ export declare function matchesAllowlist(issue: BrowserIssue, allowlist: BrowserIssueAllowlistEntry[]): boolean;
40
+ export declare function isExpectedBrowserCancellation(issue: BrowserIssue): boolean;
41
+ export declare function isBrowserSynthesizedResourceLoadError(message: ConsoleMessage): boolean;
42
+ export declare function isRetryableLocalConnectionLoss(issue: BrowserIssue): boolean;