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,27 @@
1
+ import { existsSync, readdirSync } from 'node:fs';
2
+ import { join } from 'node:path';
3
+ export function workspaceFiles(config) {
4
+ return [...filesUnder(config, config.componentRoot), ...filesUnder(config, config.storyRoot)];
5
+ }
6
+ function filesUnder(config, directory) {
7
+ const relative = directory.slice(0, -1);
8
+ if (!existsSync(join(config.root, relative)))
9
+ return [];
10
+ const files = [];
11
+ const queue = [relative];
12
+ let current = queue.shift();
13
+ while (current !== undefined) {
14
+ for (const entry of readdirSync(join(config.root, current), { withFileTypes: true })) {
15
+ const child = `${current}/${entry.name}`;
16
+ if (entry.isDirectory())
17
+ queue.push(child);
18
+ else if (isSourceFile(config, child))
19
+ files.push(child);
20
+ }
21
+ current = queue.shift();
22
+ }
23
+ return files.toSorted();
24
+ }
25
+ function isSourceFile(config, file) {
26
+ return config.sourceExtensions.some((extension) => file.endsWith(extension));
27
+ }
@@ -0,0 +1,39 @@
1
+ type Run = {
2
+ id: number;
3
+ name: string;
4
+ head_branch: string | null;
5
+ };
6
+ type Status = 'queued' | 'in_progress' | 'waiting' | 'requested' | 'pending';
7
+ export type Scenario = {
8
+ reason?: string;
9
+ pr?: string;
10
+ queueBase?: string;
11
+ merged?: boolean;
12
+ runId?: number;
13
+ pages?: Partial<Record<Status, string[]>>;
14
+ jobs?: Record<number, string>;
15
+ conflicts?: number[];
16
+ errors?: number[];
17
+ jobErrors?: number[];
18
+ transient?: number[];
19
+ transientFailures?: number;
20
+ env?: Record<string, string>;
21
+ };
22
+ export declare const sha: (digit: string) => string;
23
+ export declare const branch: (pr: number, digit: string) => string;
24
+ export declare const run: (id: number, name: string, head_branch: string | null) => Run;
25
+ export declare const page: (...runs: Run[]) => string;
26
+ export declare const jobsOf: (...conclusions: string[]) => string;
27
+ export declare function createHarness(script: string, defaultEnv?: Record<string, string>): {
28
+ setup: () => void;
29
+ teardown: () => void;
30
+ execute: (scenario: Scenario) => {
31
+ status: number | null;
32
+ stdout: string;
33
+ stderr: string;
34
+ cancelled: number[];
35
+ calls: string[];
36
+ summary: string;
37
+ };
38
+ };
39
+ export {};
@@ -0,0 +1,124 @@
1
+ import { spawnSync } from 'node:child_process';
2
+ import { chmodSync, mkdtempSync, readFileSync, rmSync, writeFileSync } from 'node:fs';
3
+ import { tmpdir } from 'node:os';
4
+ import { join } from 'node:path';
5
+ // Synthetic queue refs: real shas would trip the repository's no-test-git-sha rule.
6
+ export const sha = (digit) => digit.repeat(40);
7
+ export const branch = (pr, digit) => `gh-readonly-queue/main/pr-${pr}-${sha(digit)}`;
8
+ export const run = (id, name, head_branch) => ({
9
+ id,
10
+ name,
11
+ head_branch,
12
+ });
13
+ export const page = (...runs) => JSON.stringify({ total_count: runs.length, workflow_runs: runs });
14
+ export const jobsOf = (...conclusions) => JSON.stringify({ jobs: conclusions.map((conclusion, i) => ({ name: `job-${i}`, conclusion })) });
15
+ // A fake `gh` serves stored run lists, job lists and merge state, and records cancel requests; the
16
+ // real `jq` and the real workflow script run unchanged.
17
+ const fakeGh = `#!/bin/bash
18
+ set -euo pipefail
19
+ printf '%s\\n' "$*" >> "$FAKE_GH_DIR/calls"
20
+ url="\${!#}"
21
+ case "$*" in
22
+ *"--method POST"*)
23
+ id="\${url#*/runs/}"
24
+ id="\${id%/cancel}"
25
+ case " $FAKE_CONFLICT_IDS " in *" $id "*) echo 'gh: Cannot cancel a workflow run that is completed. (HTTP 409)' >&2; exit 1 ;; esac
26
+ case " $FAKE_ERROR_IDS " in *" $id "*) echo 'gh: Internal Server Error (HTTP 500)' >&2; exit 1 ;; esac
27
+ case " $FAKE_TRANSIENT_IDS " in
28
+ *" $id "*)
29
+ count_file="$FAKE_GH_DIR/transient-$id"
30
+ count=0
31
+ if [[ -f "$count_file" ]]; then count=$(cat "$count_file"); fi
32
+ count=$((count + 1))
33
+ printf '%s\\n' "$count" > "$count_file"
34
+ if [[ "$count" -le "\${FAKE_TRANSIENT_FAILURES:-1}" ]]; then
35
+ echo 'gh: Server Error (HTTP 502)' >&2
36
+ exit 1
37
+ fi
38
+ ;;
39
+ esac
40
+ printf '%s\\n' "$id" >> "$FAKE_GH_DIR/cancelled"
41
+ exit 0 ;;
42
+ *"/jobs?"*)
43
+ id="\${url#*/runs/}"
44
+ id="\${id%%/jobs*}"
45
+ case " $FAKE_JOB_ERROR_IDS " in *" $id "*) echo 'gh: Bad Gateway (HTTP 502)' >&2; exit 1 ;; esac
46
+ file="$FAKE_GH_DIR/jobs-$id.json"
47
+ if [[ -f "$file" ]]; then cat "$file"; else echo '{"jobs":[{"name":"build","conclusion":"success"}]}'; fi
48
+ exit 0 ;;
49
+ *"/pulls/"*)
50
+ echo "$FAKE_MERGED"
51
+ exit 0 ;;
52
+ esac
53
+ [[ "$1 $2" == "api --paginate" ]] || { echo "unexpected gh call: $*" >&2; exit 99; }
54
+ status="\${url#*status=}"
55
+ status="\${status%%&*}"
56
+ file="$FAKE_GH_DIR/list-$status.json"
57
+ if [[ -f "$file" ]]; then cat "$file"; else echo '{"total_count":0,"workflow_runs":[]}'; fi
58
+ `;
59
+ export function createHarness(script, defaultEnv = {}) {
60
+ let directory = '';
61
+ const lines = (name) => {
62
+ try {
63
+ return readFileSync(join(directory, name), 'utf8').split('\n').filter(Boolean);
64
+ }
65
+ catch {
66
+ return [];
67
+ }
68
+ };
69
+ return {
70
+ setup: () => {
71
+ directory = mkdtempSync(join(tmpdir(), 'cancel-runs-'));
72
+ writeFileSync(join(directory, 'gh'), fakeGh);
73
+ chmodSync(join(directory, 'gh'), 0o755);
74
+ },
75
+ teardown: () => {
76
+ rmSync(directory, { recursive: true, force: true });
77
+ },
78
+ execute: (scenario) => {
79
+ for (const name of ['cancelled', 'calls', 'summary.md']) {
80
+ rmSync(join(directory, name), { force: true });
81
+ }
82
+ for (const [status, pages] of Object.entries(scenario.pages ?? {})) {
83
+ writeFileSync(join(directory, `list-${status}.json`), (pages ?? []).join('\n'));
84
+ }
85
+ for (const [id, body] of Object.entries(scenario.jobs ?? {})) {
86
+ writeFileSync(join(directory, `jobs-${id}.json`), body);
87
+ }
88
+ const result = spawnSync('/bin/bash', ['-c', script], {
89
+ encoding: 'utf8',
90
+ env: {
91
+ PATH: `${directory}:${process.env.PATH ?? ''}`,
92
+ FAKE_GH_DIR: directory,
93
+ FAKE_CONFLICT_IDS: (scenario.conflicts ?? []).join(' '),
94
+ FAKE_ERROR_IDS: (scenario.errors ?? []).join(' '),
95
+ FAKE_JOB_ERROR_IDS: (scenario.jobErrors ?? []).join(' '),
96
+ FAKE_TRANSIENT_IDS: (scenario.transient ?? []).join(' '),
97
+ FAKE_TRANSIENT_FAILURES: String(scenario.transientFailures ?? 1),
98
+ FAKE_MERGED: String(scenario.merged ?? false),
99
+ GH_TOKEN: 'token',
100
+ PR_NUMBER: scenario.pr ?? '14',
101
+ QUEUE_BASE: scenario.queueBase ?? 'main',
102
+ REASON: scenario.reason ?? 'CI_FAILURE',
103
+ GITHUB_REPOSITORY: 'example/repo',
104
+ GITHUB_RUN_ID: String(scenario.runId ?? 500),
105
+ GITHUB_SERVER_URL: 'https://github.test',
106
+ GITHUB_STEP_SUMMARY: join(directory, 'summary.md'),
107
+ RUNNER_TEMP: directory,
108
+ ...defaultEnv,
109
+ ...scenario.env,
110
+ },
111
+ });
112
+ return {
113
+ status: result.status,
114
+ stdout: result.stdout,
115
+ stderr: result.stderr,
116
+ cancelled: lines('cancelled')
117
+ .map(Number)
118
+ .toSorted((a, b) => a - b),
119
+ calls: lines('calls'),
120
+ summary: lines('summary.md').join('\n'),
121
+ };
122
+ },
123
+ };
124
+ }
@@ -0,0 +1,12 @@
1
+ import { type Socket } from 'node:net';
2
+ export declare function observeFixtureExit(path: string): {
3
+ started: Promise<void>;
4
+ closed: Promise<void>;
5
+ connected: () => boolean;
6
+ open: () => boolean;
7
+ error: () => unknown;
8
+ failStartup: (failure: Error) => void;
9
+ listen: () => Promise<void>;
10
+ releaseConnection: () => Socket | undefined;
11
+ closeListener: () => Promise<void>;
12
+ };
@@ -0,0 +1,68 @@
1
+ import { createServer } from 'node:net';
2
+ export function observeFixtureExit(path) {
3
+ let socket;
4
+ let error;
5
+ const recordError = (failure) => {
6
+ error ??= failure;
7
+ };
8
+ let ready = () => { };
9
+ let failReady = () => { };
10
+ const started = new Promise((resolve, reject) => {
11
+ ready = resolve;
12
+ failReady = reject;
13
+ });
14
+ let exited = () => { };
15
+ const closed = new Promise((resolve) => {
16
+ exited = resolve;
17
+ });
18
+ const server = createServer((connection) => {
19
+ socket = connection;
20
+ let message = '';
21
+ connection.on('data', (data) => {
22
+ message += data.toString();
23
+ if (message === 'ready\n')
24
+ ready();
25
+ else if (!'ready\n'.startsWith(message)) {
26
+ const failure = new Error('Invalid owned process readiness');
27
+ recordError(failure);
28
+ failReady(failure);
29
+ }
30
+ });
31
+ connection.once('error', (failure) => {
32
+ recordError(failure);
33
+ failReady(failure);
34
+ });
35
+ connection.once('close', () => {
36
+ if (message !== 'ready\n') {
37
+ const failure = new Error('Owned process closed before readiness');
38
+ recordError(failure);
39
+ failReady(failure);
40
+ }
41
+ exited();
42
+ });
43
+ connection.resume();
44
+ });
45
+ server.on('error', (failure) => {
46
+ recordError(failure);
47
+ failReady(failure);
48
+ });
49
+ void started.catch(recordError);
50
+ return {
51
+ started,
52
+ closed,
53
+ connected: () => socket !== undefined,
54
+ open: () => socket?.destroyed === false,
55
+ error: () => error,
56
+ failStartup: failReady,
57
+ listen: () => new Promise((resolve, reject) => {
58
+ server.once('error', reject);
59
+ server.listen(path, resolve);
60
+ }),
61
+ releaseConnection: () => socket?.destroy(),
62
+ closeListener: () => new Promise((resolve, reject) => {
63
+ if (!server.listening)
64
+ return resolve();
65
+ server.close((failure) => (failure ? reject(failure) : resolve()));
66
+ }),
67
+ };
68
+ }
@@ -0,0 +1,18 @@
1
+ export declare function createOutputFixtures(script: string): {
2
+ cleanup: () => Promise<void>;
3
+ launch: (seconds: string, mode: "exit" | "hang") => Promise<{
4
+ result: Promise<{
5
+ code: number | null;
6
+ stdout: string;
7
+ stderr: string;
8
+ }>;
9
+ started: Promise<undefined>;
10
+ dir: string;
11
+ descendantClosed: Promise<void>;
12
+ commandClosed: Promise<void>;
13
+ wrapperClosed: Promise<void>;
14
+ wrapperRunning: () => boolean;
15
+ commandOpen: () => boolean;
16
+ descendantOpen: () => boolean;
17
+ }>;
18
+ };
@@ -0,0 +1,162 @@
1
+ import { spawn } from 'node:child_process';
2
+ import { mkdtempSync, rmSync } from 'node:fs';
3
+ import { tmpdir } from 'node:os';
4
+ import { join } from 'node:path';
5
+ import { observeFixtureExit } from "./run-bounded-exit-observer.test-helpers.mjs";
6
+ export function createOutputFixtures(script) {
7
+ const fixtures = [];
8
+ async function cleanup() {
9
+ const outcomes = await Promise.allSettled(fixtures.map(async (fixture) => {
10
+ const errors = [];
11
+ try {
12
+ fixture.child?.stdin.end();
13
+ }
14
+ catch (err) {
15
+ errors.push(err);
16
+ fixture.child?.stdin.destroy();
17
+ }
18
+ try {
19
+ await fixture.wrapperClosed;
20
+ }
21
+ catch (err) {
22
+ errors.push(err);
23
+ }
24
+ if (fixture.child) {
25
+ for (const observer of [fixture.command, fixture.descendant]) {
26
+ if (!observer.connected())
27
+ errors.push(new Error('Owned process startup/exit was not observed'));
28
+ else
29
+ await observer.closed;
30
+ if (observer.error())
31
+ errors.push(observer.error());
32
+ }
33
+ }
34
+ const closures = await Promise.allSettled([
35
+ fixture.command.closeListener(),
36
+ fixture.descendant.closeListener(),
37
+ ]);
38
+ for (const closure of closures)
39
+ if (closure.status === 'rejected')
40
+ errors.push(closure.reason);
41
+ if (fixture.observedError)
42
+ errors.unshift(fixture.observedError);
43
+ if (errors.length)
44
+ throw new AggregateError(errors, 'Owned fixture disposal failed', { cause: errors[0] });
45
+ rmSync(fixture.dir, { recursive: true, force: true });
46
+ fixtures.splice(fixtures.indexOf(fixture), 1);
47
+ }));
48
+ const errors = outcomes.flatMap((result) => result.status === 'rejected' ? [result.reason] : []);
49
+ if (errors.length)
50
+ throw new AggregateError(errors, 'Fixture cleanup failed', { cause: errors[0] });
51
+ }
52
+ async function launch(seconds, mode) {
53
+ const dir = mkdtempSync(join(tmpdir(), 'run-bounded-'));
54
+ const fixture = {
55
+ dir,
56
+ command: observeFixtureExit(join(dir, 'command.sock')),
57
+ descendant: observeFixtureExit(join(dir, 'exit.sock')),
58
+ };
59
+ fixtures.push(fixture);
60
+ const observeError = (error) => {
61
+ fixture.observedError ??= error;
62
+ };
63
+ const starts = await Promise.allSettled([fixture.command.listen(), fixture.descendant.listen()]);
64
+ const failures = starts.flatMap((result) => result.status === 'rejected' ? [result.reason] : []);
65
+ if (failures.length)
66
+ throw new AggregateError(failures, 'Fixture listener setup failed', { cause: failures[0] });
67
+ const stopAtEof = [
68
+ 'import os, sys, threading',
69
+ 'def stop_at_eof():',
70
+ ' while os.read(0, 4096): pass',
71
+ ' os._exit(0)',
72
+ 'threading.Thread(target=stop_at_eof, daemon=True).start()',
73
+ ].join('\n');
74
+ const grandchild = [
75
+ 'import socket, signal',
76
+ 'exit_socket = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM)',
77
+ 'exit_socket.connect(os.environ["EXIT_SOCKET"])',
78
+ 'exit_socket.sendall(b"ready\\n")',
79
+ 'os.write(int(os.environ["READY_FD"]), b"ready"); os.close(int(os.environ["READY_FD"]))',
80
+ stopAtEof,
81
+ 'signal.pause()',
82
+ ].join('\n');
83
+ const command = [
84
+ 'import os, socket',
85
+ 'command_exit = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM)',
86
+ 'command_exit.connect(os.environ["COMMAND_SOCKET"])',
87
+ 'command_exit.sendall(b"ready\\n")',
88
+ stopAtEof,
89
+ 'import signal, subprocess',
90
+ 'ready_read, ready_write = os.pipe()',
91
+ `subprocess.Popen([sys.executable, "-c", ${JSON.stringify(`import os\n${grandchild}`)}], start_new_session=True, stderr=subprocess.DEVNULL, env={**os.environ, "READY_FD": str(ready_write)}, pass_fds=(ready_write,))`,
92
+ 'os.close(ready_write); assert os.read(ready_read, 5) == b"ready"; os.close(ready_read)',
93
+ 'sys.stdout.write("out\\n"); sys.stdout.flush()',
94
+ 'sys.stderr.write("err\\n"); sys.stderr.flush()',
95
+ 'if os.environ["MODE"] == "hang": signal.pause()',
96
+ ].join('\n');
97
+ const child = spawn('python3', [script, seconds, 'python3', '-c', command], {
98
+ env: {
99
+ ...process.env,
100
+ EXIT_SOCKET: join(dir, 'exit.sock'),
101
+ COMMAND_SOCKET: join(dir, 'command.sock'),
102
+ MODE: mode,
103
+ },
104
+ stdio: ['pipe', 'pipe', 'pipe'],
105
+ });
106
+ child.stdin.on('error', observeError);
107
+ fixture.child = child;
108
+ fixture.wrapperClosed = new Promise((resolve) => child.once('close', () => resolve()));
109
+ let stdout = '';
110
+ let stderr = '';
111
+ let outputReady = () => { };
112
+ let failOutput = () => { };
113
+ const output = new Promise((resolve, reject) => {
114
+ outputReady = resolve;
115
+ failOutput = reject;
116
+ });
117
+ const readyIfComplete = () => {
118
+ if (stdout.includes('out\n') && stderr.includes('err\n'))
119
+ outputReady();
120
+ };
121
+ child.stdout.on('data', (chunk) => {
122
+ stdout += chunk;
123
+ readyIfComplete();
124
+ });
125
+ child.stderr.on('data', (chunk) => {
126
+ stderr += chunk;
127
+ readyIfComplete();
128
+ });
129
+ const result = new Promise((resolve, reject) => {
130
+ child.once('error', (error) => {
131
+ failOutput(error);
132
+ fixture.descendant.failStartup(error);
133
+ fixture.command.failStartup(error);
134
+ reject(error);
135
+ });
136
+ child.once('close', (code) => {
137
+ if (!stdout.includes('out\n') || !stderr.includes('err\n'))
138
+ failOutput(new Error('Wrapper closed before output readiness'));
139
+ if (!fixture.descendant.connected())
140
+ fixture.descendant.failStartup(new Error('Wrapper closed before descendant readiness'));
141
+ if (!fixture.command.connected())
142
+ fixture.command.failStartup(new Error('Wrapper closed before command readiness'));
143
+ resolve({ code, stdout, stderr });
144
+ });
145
+ });
146
+ const started = Promise.all([fixture.descendant.started, fixture.command.started, output]).then(() => undefined);
147
+ void result.catch(observeError);
148
+ void started.catch(observeError);
149
+ return {
150
+ result,
151
+ started,
152
+ dir,
153
+ descendantClosed: fixture.descendant.closed,
154
+ commandClosed: fixture.command.closed,
155
+ wrapperClosed: fixture.wrapperClosed,
156
+ wrapperRunning: () => child.exitCode === null,
157
+ commandOpen: fixture.command.open,
158
+ descendantOpen: fixture.descendant.open,
159
+ };
160
+ }
161
+ return { cleanup, launch };
162
+ }
@@ -0,0 +1,2 @@
1
+ export { checkAndRestoreFakeTimers, formatFakeTimerLeakDiagnostics, } from './vitest-fake-timer-guard.mts';
2
+ export type { FakeTimerController } from './vitest-fake-timer-guard.mts';
@@ -0,0 +1,6 @@
1
+ // Browser-safe entry for Storybook and Vitest browser projects. Everything re-exported here must
2
+ // stay free of `node:*` imports and Node-only globals; `browser.test.mts` checks the import graph.
3
+ // Resource, fork-leak, reporter, and network-allowlist helpers need Node, so they live only in the
4
+ // Node entry (`vouchington-tooling/vitest-diagnostics`). The effective-timeout cap is a
5
+ // config-time Vite plugin and also stays out of the browser bundle.
6
+ export { checkAndRestoreFakeTimers, formatFakeTimerLeakDiagnostics, } from "./vitest-fake-timer-guard.mjs";
@@ -3,27 +3,18 @@ export type { ForkExitSentinelOptions } from './vitest-fork-exit-sentinel.mts';
3
3
  export { clearForkExitRecords, formatForkExitSentinelSection, readForkExitRecords, summarizeForkExitRecords, } from './vitest-fork-exit-records.mts';
4
4
  export type { ForkExitSentinelRecord, ForkExitRecordSummary } from './vitest-fork-exit-records.mts';
5
5
  export { createVitestWorkerExitDiagnosticsReporter, formatWorkerExitDiagnostics, isWorkerExitError, } from './vitest-worker-exit-diagnostics-reporter.mts';
6
- export { createForkLeakDetector, formatForkLeakDiagnostics, waitForResourceCloseCallbacks, } from './vitest-fork-leak-detection.mts';
6
+ export { createForkLeakDetector, formatForkLeakDiagnostics, getForkLeakDetector, waitForResourceCloseCallbacks, } from './vitest-fork-leak-detection.mts';
7
+ export { checkAndRestoreFakeTimers, formatFakeTimerLeakDiagnostics, } from './vitest-fake-timer-guard.mts';
8
+ export type { FakeTimerController } from './vitest-fake-timer-guard.mts';
9
+ export { consumeTestNetworkAllowlistViolation, installTestNetworkAllowlist, } from './vitest-network-allowlist.mts';
10
+ export type { TestNetworkAllowlistOptions } from './vitest-network-allowlist.mts';
11
+ export { getRegisteredPoolMetrics, getRegisteredPoolSocketHandles, } from './vitest-fork-leak-diagnostics.mts';
12
+ export { FORK_LEAK_HANDSHAKE_MAX_TURNS, FORK_LEAK_HANDSHAKE_STABLE_OBSERVATIONS, formatActiveResources, formatProcessResources, formatResourceCounts, waitForForkLeakHandshakeSettle, } from './vitest-fork-leak-handshake.mts';
13
+ export { countResourcesByType } from './vitest-process-resources.mts';
14
+ export { recordForkLeakCheckpoint } from './vitest-fork-leak-handshake-samples.mts';
15
+ export type { ForkLeakHandshakeSettlement } from './vitest-fork-leak-handshake.mts';
16
+ export type { PoolMetrics, PoolSocketHandles } from './vitest-fork-leak-handshake-samples.mts';
17
+ export type { ForkLeakDiagnosticsOptions } from './vitest-fork-leak-diagnostics.mts';
7
18
  export type { ForkLeakDetector, ForkLeakDetectorOptions, ForkLeakVerdict, } from './vitest-fork-leak-detection.mts';
8
- export { MAX_DIAGNOSTIC_REPORT_BYTES } from './read-file.mts';
9
- export declare const DEFAULT_MAX_DIAGNOSTIC_REPORTS = 100;
10
- export declare const DEFAULT_MAX_FORMATTED_DIAGNOSTIC_REPORTS = 20;
11
- export declare const HARD_MAX_DIAGNOSTIC_REPORTS = 100;
12
- export { HARD_MAX_DIAGNOSTIC_DIRECTORY_ENTRIES } from './directory.mts';
13
- export interface DiagnosticReportSummary {
14
- file: string;
15
- trigger: string;
16
- event: string;
17
- threadId: number | null;
18
- heapUsedMB: string;
19
- heapTotalMB: string;
20
- heapLimitMB: string;
21
- maxRssMB: string;
22
- topNativeFrameModule: string | null;
23
- }
24
- export interface DiagnosticReportLimitOptions {
25
- maxReports?: number;
26
- }
27
- export declare function summarizeDiagnosticReport(file: string, report: unknown): DiagnosticReportSummary;
28
- export declare function readDiagnosticReportSummaries(directory: string, options?: DiagnosticReportLimitOptions): DiagnosticReportSummary[];
29
- export declare function formatDiagnosticReportSummaries(summaries: readonly unknown[], options?: DiagnosticReportLimitOptions): string;
19
+ export { DEFAULT_MAX_DIAGNOSTIC_REPORTS, DEFAULT_MAX_FORMATTED_DIAGNOSTIC_REPORTS, formatDiagnosticReportSummaries, HARD_MAX_DIAGNOSTIC_REPORTS, MAX_DIAGNOSTIC_REPORT_BYTES, HARD_MAX_DIAGNOSTIC_DIRECTORY_ENTRIES, readDiagnosticReportSummaries, summarizeDiagnosticReport, } from './report-summary.mts';
20
+ export type { DiagnosticReportLimitOptions, DiagnosticReportSummary } from './report-summary.mts';
@@ -1,127 +1,11 @@
1
- import { join, posix, win32 } from 'node:path';
2
1
  export { registerForkExitSentinel, setCurrentForkExitModule, setCurrentForkExitProject, } from "./vitest-fork-exit-sentinel.mjs";
3
2
  export { clearForkExitRecords, formatForkExitSentinelSection, readForkExitRecords, summarizeForkExitRecords, } from "./vitest-fork-exit-records.mjs";
4
3
  export { createVitestWorkerExitDiagnosticsReporter, formatWorkerExitDiagnostics, isWorkerExitError, } from "./vitest-worker-exit-diagnostics-reporter.mjs";
5
- export { createForkLeakDetector, formatForkLeakDiagnostics, waitForResourceCloseCallbacks, } from "./vitest-fork-leak-detection.mjs";
6
- import { isDiagnosticReportDirectoryCurrent, readDiagnosticReportDirectory } from "./directory.mjs";
7
- import { readBoundedRegularFile } from "./read-file.mjs";
8
- export { MAX_DIAGNOSTIC_REPORT_BYTES } from "./read-file.mjs";
9
- export const DEFAULT_MAX_DIAGNOSTIC_REPORTS = 100;
10
- export const DEFAULT_MAX_FORMATTED_DIAGNOSTIC_REPORTS = 20;
11
- export const HARD_MAX_DIAGNOSTIC_REPORTS = 100;
12
- export { HARD_MAX_DIAGNOSTIC_DIRECTORY_ENTRIES } from "./directory.mjs";
13
- const TEXT_LIMIT = 200;
14
- const PATH_LIMIT = 240;
15
- function objectValue(value) {
16
- return typeof value === 'object' && value !== null && !Array.isArray(value)
17
- ? value
18
- : {};
19
- }
20
- function boundedText(value, fallback, limit) {
21
- if (typeof value !== 'string')
22
- return fallback;
23
- const normalized = value
24
- .slice(0, limit * 4)
25
- .replace(/[\p{Cc}\p{Cf}]/gu, ' ')
26
- .replace(/\s+/g, ' ')
27
- .trim();
28
- return normalized.length === 0 ? fallback : normalized.slice(0, limit);
29
- }
30
- function formatMebibytes(value) {
31
- const bytes = typeof value === 'number' && Number.isFinite(value) && value >= 0 ? value : 0;
32
- return (bytes / 1024 / 1024).toFixed(1);
33
- }
34
- function threadId(value) {
35
- return typeof value === 'number' && Number.isSafeInteger(value) && value >= 0 ? value : null;
36
- }
37
- function nativeModulePath(value) {
38
- const module = boundedText(value, '', PATH_LIMIT);
39
- return posix.isAbsolute(module) || win32.isAbsolute(module) ? module : null;
40
- }
41
- function topNativeFrameModule(value) {
42
- if (!Array.isArray(value))
43
- return null;
44
- const symbol = objectValue(value[0]).symbol;
45
- if (typeof symbol !== 'string')
46
- return null;
47
- const tail = symbol.slice(-PATH_LIMIT * 2).trimEnd();
48
- if (!tail.endsWith(']'))
49
- return null;
50
- const opening = tail.lastIndexOf('[');
51
- if (opening < 0)
52
- return null;
53
- return nativeModulePath(tail.slice(opening + 1, -1));
54
- }
55
- function reportLimit(value, fallback) {
56
- if (value === undefined)
57
- return fallback;
58
- if (!Number.isFinite(value))
59
- return fallback;
60
- return Math.min(Math.max(Math.floor(value), 0), HARD_MAX_DIAGNOSTIC_REPORTS);
61
- }
62
- export function summarizeDiagnosticReport(file, report) {
63
- const root = objectValue(report);
64
- const header = objectValue(root.header);
65
- const heap = objectValue(root.javascriptHeap);
66
- const resourceUsage = objectValue(root.resourceUsage);
67
- return {
68
- file: boundedText(file, 'unknown', PATH_LIMIT),
69
- trigger: boundedText(header.trigger, 'unknown', TEXT_LIMIT),
70
- event: boundedText(header.event, 'unknown', TEXT_LIMIT),
71
- threadId: threadId(header.threadId),
72
- heapUsedMB: formatMebibytes(heap.usedMemory),
73
- heapTotalMB: formatMebibytes(heap.totalMemory),
74
- heapLimitMB: formatMebibytes(heap.memoryLimit),
75
- maxRssMB: formatMebibytes(resourceUsage.maxRss),
76
- topNativeFrameModule: topNativeFrameModule(root.nativeStack),
77
- };
78
- }
79
- export function readDiagnosticReportSummaries(directory, options = {}) {
80
- const maxReports = reportLimit(options.maxReports, DEFAULT_MAX_DIAGNOSTIC_REPORTS);
81
- if (maxReports === 0)
82
- return [];
83
- const reportsDirectory = readDiagnosticReportDirectory(directory);
84
- if (reportsDirectory === undefined)
85
- return [];
86
- const filenames = reportsDirectory.filenames.sort();
87
- const selected = filenames.slice(-maxReports);
88
- const summaries = [];
89
- for (const filename of selected) {
90
- try {
91
- if (!isDiagnosticReportDirectoryCurrent(directory, reportsDirectory.identity))
92
- return [];
93
- const contents = readBoundedRegularFile(join(directory, filename));
94
- if (!isDiagnosticReportDirectoryCurrent(directory, reportsDirectory.identity))
95
- return [];
96
- if (contents === undefined)
97
- continue;
98
- const report = JSON.parse(contents);
99
- summaries.push(summarizeDiagnosticReport(filename, report));
100
- }
101
- catch {
102
- // Node can leave a partial report if the process exits while writing it.
103
- }
104
- }
105
- return summaries;
106
- }
107
- export function formatDiagnosticReportSummaries(summaries, options = {}) {
108
- const maxReports = reportLimit(options.maxReports, DEFAULT_MAX_FORMATTED_DIAGNOSTIC_REPORTS);
109
- const lines = ['[vitest-diagnostics]', `reports provided: ${summaries.length}`];
110
- if (summaries.length === 0)
111
- lines.push(' (none recorded)');
112
- for (const value of summaries.slice(0, maxReports)) {
113
- const summary = objectValue(value);
114
- lines.push(` - file=${boundedText(summary.file, 'unknown', PATH_LIMIT)} ` +
115
- `trigger=${boundedText(summary.trigger, 'unknown', TEXT_LIMIT)} ` +
116
- `event=${boundedText(summary.event, 'unknown', TEXT_LIMIT)} ` +
117
- `threadId=${threadId(summary.threadId) ?? 'unknown'} ` +
118
- `heapUsedMB=${boundedText(summary.heapUsedMB, '0.0', TEXT_LIMIT)} ` +
119
- `heapTotalMB=${boundedText(summary.heapTotalMB, '0.0', TEXT_LIMIT)} ` +
120
- `heapLimitMB=${boundedText(summary.heapLimitMB, '0.0', TEXT_LIMIT)} ` +
121
- `maxRssMB=${boundedText(summary.maxRssMB, '0.0', TEXT_LIMIT)} ` +
122
- `topNativeFrameModule=${nativeModulePath(summary.topNativeFrameModule) ?? 'none'}`);
123
- }
124
- if (summaries.length > maxReports)
125
- lines.push(` ... ${summaries.length - maxReports} more`);
126
- return `${lines.join('\n')}\n`;
127
- }
4
+ export { createForkLeakDetector, formatForkLeakDiagnostics, getForkLeakDetector, waitForResourceCloseCallbacks, } from "./vitest-fork-leak-detection.mjs";
5
+ export { checkAndRestoreFakeTimers, formatFakeTimerLeakDiagnostics, } from "./vitest-fake-timer-guard.mjs";
6
+ export { consumeTestNetworkAllowlistViolation, installTestNetworkAllowlist, } from "./vitest-network-allowlist.mjs";
7
+ export { getRegisteredPoolMetrics, getRegisteredPoolSocketHandles, } from "./vitest-fork-leak-diagnostics.mjs";
8
+ export { FORK_LEAK_HANDSHAKE_MAX_TURNS, FORK_LEAK_HANDSHAKE_STABLE_OBSERVATIONS, formatActiveResources, formatProcessResources, formatResourceCounts, waitForForkLeakHandshakeSettle, } from "./vitest-fork-leak-handshake.mjs";
9
+ export { countResourcesByType } from "./vitest-process-resources.mjs";
10
+ export { recordForkLeakCheckpoint } from "./vitest-fork-leak-handshake-samples.mjs";
11
+ export { DEFAULT_MAX_DIAGNOSTIC_REPORTS, DEFAULT_MAX_FORMATTED_DIAGNOSTIC_REPORTS, formatDiagnosticReportSummaries, HARD_MAX_DIAGNOSTIC_REPORTS, MAX_DIAGNOSTIC_REPORT_BYTES, HARD_MAX_DIAGNOSTIC_DIRECTORY_ENTRIES, readDiagnosticReportSummaries, summarizeDiagnosticReport, } from "./report-summary.mjs";