vouchington-tooling 0.53.0 → 0.54.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 (187) hide show
  1. package/README.md +76 -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/parse-forwarded-commands.d.mts +3 -0
  12. package/dist/cli/parse-forwarded-commands.mjs +2 -0
  13. package/dist/cli/parse-story-coverage-fields.d.mts +19 -0
  14. package/dist/cli/parse-story-coverage-fields.mjs +69 -0
  15. package/dist/cli/parse-story-coverage.d.mts +8 -0
  16. package/dist/cli/parse-story-coverage.mjs +34 -0
  17. package/dist/cli/parse.d.mts +5 -1
  18. package/dist/cli/parse.mjs +3 -0
  19. package/dist/cli/usage.d.mts +1 -1
  20. package/dist/cli/usage.mjs +8 -7
  21. package/dist/host-storage/check.d.mts +38 -0
  22. package/dist/host-storage/check.mjs +109 -0
  23. package/dist/host-storage/cli.d.mts +7 -0
  24. package/dist/host-storage/cli.mjs +102 -0
  25. package/dist/host-storage/host-storage.test-helpers.d.mts +26 -0
  26. package/dist/host-storage/host-storage.test-helpers.mjs +58 -0
  27. package/dist/host-storage/index.d.mts +3 -0
  28. package/dist/host-storage/index.mjs +3 -0
  29. package/dist/host-storage/preflight.d.mts +22 -0
  30. package/dist/host-storage/preflight.mjs +105 -0
  31. package/dist/index.d.mts +2 -0
  32. package/dist/index.mjs +1 -0
  33. package/dist/playwright/assertions.d.mts +1 -0
  34. package/dist/playwright/assertions.mjs +5 -0
  35. package/dist/playwright/blocked-external-network.d.mts +15 -0
  36. package/dist/playwright/blocked-external-network.mjs +73 -0
  37. package/dist/playwright/browser-dialog-issues.d.mts +12 -0
  38. package/dist/playwright/browser-dialog-issues.mjs +29 -0
  39. package/dist/playwright/browser-errors.d.mts +22 -0
  40. package/dist/playwright/browser-errors.mjs +130 -0
  41. package/dist/playwright/browser-issue-monitor.test-helpers.d.mts +31 -0
  42. package/dist/playwright/browser-issue-monitor.test-helpers.mjs +51 -0
  43. package/dist/playwright/browser-issue-records.d.mts +42 -0
  44. package/dist/playwright/browser-issue-records.mjs +148 -0
  45. package/dist/playwright/browser-test.d.mts +21 -0
  46. package/dist/playwright/browser-test.mjs +68 -0
  47. package/dist/playwright/expect-no-broken-images.d.mts +17 -0
  48. package/dist/playwright/expect-no-broken-images.mjs +39 -0
  49. package/dist/playwright/index.d.mts +30 -0
  50. package/dist/playwright/index.mjs +22 -0
  51. package/dist/playwright/mobile-assertions.d.mts +14 -0
  52. package/dist/playwright/mobile-assertions.mjs +43 -0
  53. package/dist/playwright/navigate-to.d.mts +27 -0
  54. package/dist/playwright/navigate-to.mjs +39 -0
  55. package/dist/playwright/radix-select.d.mts +18 -0
  56. package/dist/playwright/radix-select.mjs +19 -0
  57. package/dist/playwright/random-id.d.mts +34 -0
  58. package/dist/playwright/random-id.mjs +37 -0
  59. package/dist/playwright/retry-on-connection-lost.d.mts +7 -0
  60. package/dist/playwright/retry-on-connection-lost.mjs +107 -0
  61. package/dist/playwright/scroll-to-load-more.d.mts +37 -0
  62. package/dist/playwright/scroll-to-load-more.mjs +158 -0
  63. package/dist/playwright/storybook.d.mts +2 -0
  64. package/dist/playwright/storybook.mjs +13 -0
  65. package/dist/playwright/test-fixtures.d.mts +1 -0
  66. package/dist/playwright/test-fixtures.mjs +2 -0
  67. package/dist/playwright/test-lifecycle-reporter.d.mts +11 -0
  68. package/dist/playwright/test-lifecycle-reporter.mjs +35 -0
  69. package/dist/playwright/totp.d.mts +6 -0
  70. package/dist/playwright/totp.mjs +37 -0
  71. package/dist/playwright/turnstile-stub.d.mts +8 -0
  72. package/dist/playwright/turnstile-stub.mjs +61 -0
  73. package/dist/playwright/viewport-constants.d.mts +30 -0
  74. package/dist/playwright/viewport-constants.mjs +9 -0
  75. package/dist/playwright/virtual-authenticator.d.mts +5 -0
  76. package/dist/playwright/virtual-authenticator.mjs +15 -0
  77. package/dist/playwright/wait-for-hydration.d.mts +29 -0
  78. package/dist/playwright/wait-for-hydration.mjs +81 -0
  79. package/dist/shell-parse/ansi-c-string.d.mts +12 -0
  80. package/dist/shell-parse/ansi-c-string.mjs +80 -0
  81. package/dist/shell-parse/index.d.mts +20 -0
  82. package/dist/shell-parse/index.mjs +15 -0
  83. package/dist/shell-parse/shell-command-substitution-reads.d.mts +8 -0
  84. package/dist/shell-parse/shell-command-substitution-reads.mjs +53 -0
  85. package/dist/shell-parse/shell-command-substitutions.d.mts +8 -0
  86. package/dist/shell-parse/shell-command-substitutions.mjs +52 -0
  87. package/dist/shell-parse/shell-command-wrappers.d.mts +26 -0
  88. package/dist/shell-parse/shell-command-wrappers.mjs +143 -0
  89. package/dist/shell-parse/shell-commands.d.mts +24 -0
  90. package/dist/shell-parse/shell-commands.mjs +155 -0
  91. package/dist/shell-parse/shell-heredoc-delimiter.d.mts +5 -0
  92. package/dist/shell-parse/shell-heredoc-delimiter.mjs +52 -0
  93. package/dist/shell-parse/shell-heredoc-parser.d.mts +7 -0
  94. package/dist/shell-parse/shell-heredoc-parser.mjs +49 -0
  95. package/dist/shell-parse/shell-heredoc-quote-state.d.mts +19 -0
  96. package/dist/shell-parse/shell-heredoc-quote-state.mjs +40 -0
  97. package/dist/shell-parse/shell-heredoc.d.mts +10 -0
  98. package/dist/shell-parse/shell-heredoc.mjs +90 -0
  99. package/dist/shell-parse/shell-redirections.d.mts +5 -0
  100. package/dist/shell-parse/shell-redirections.mjs +34 -0
  101. package/dist/shell-parse/shell-script-operand.d.mts +13 -0
  102. package/dist/shell-parse/shell-script-operand.mjs +103 -0
  103. package/dist/shell-parse/shell-stdin-script.d.mts +6 -0
  104. package/dist/shell-parse/shell-stdin-script.mjs +61 -0
  105. package/dist/shell-parse/shell-token-utils.d.mts +9 -0
  106. package/dist/shell-parse/shell-token-utils.mjs +33 -0
  107. package/dist/shell-parse/shell-tokenizer-comments.d.mts +1 -0
  108. package/dist/shell-parse/shell-tokenizer-comments.mjs +57 -0
  109. package/dist/shell-parse/shell-tokenizer-operators.d.mts +14 -0
  110. package/dist/shell-parse/shell-tokenizer-operators.mjs +47 -0
  111. package/dist/shell-parse/shell-tokenizer.d.mts +12 -0
  112. package/dist/shell-parse/shell-tokenizer.mjs +104 -0
  113. package/dist/story-coverage/analyze.d.mts +8 -0
  114. package/dist/story-coverage/analyze.mjs +24 -0
  115. package/dist/story-coverage/check.d.mts +11 -0
  116. package/dist/story-coverage/check.mjs +42 -0
  117. package/dist/story-coverage/components.d.mts +10 -0
  118. package/dist/story-coverage/components.mjs +40 -0
  119. package/dist/story-coverage/coverage.d.mts +10 -0
  120. package/dist/story-coverage/coverage.mjs +43 -0
  121. package/dist/story-coverage/index.d.mts +13 -0
  122. package/dist/story-coverage/index.mjs +7 -0
  123. package/dist/story-coverage/messages.d.mts +10 -0
  124. package/dist/story-coverage/messages.mjs +42 -0
  125. package/dist/story-coverage/options.d.mts +27 -0
  126. package/dist/story-coverage/options.mjs +51 -0
  127. package/dist/story-coverage/workspace.d.mts +2 -0
  128. package/dist/story-coverage/workspace.mjs +27 -0
  129. package/dist/test-helpers/cancel-runs.test-helpers.d.mts +39 -0
  130. package/dist/test-helpers/cancel-runs.test-helpers.mjs +124 -0
  131. package/dist/test-helpers/run-bounded-exit-observer.test-helpers.d.mts +12 -0
  132. package/dist/test-helpers/run-bounded-exit-observer.test-helpers.mjs +68 -0
  133. package/dist/test-helpers/run-bounded-output-fixture.test-helpers.d.mts +18 -0
  134. package/dist/test-helpers/run-bounded-output-fixture.test-helpers.mjs +162 -0
  135. package/dist/vitest-diagnostics/index.d.mts +9 -1
  136. package/dist/vitest-diagnostics/index.mjs +5 -1
  137. package/dist/vitest-diagnostics/vitest-fake-timer-guard.d.mts +6 -0
  138. package/dist/vitest-diagnostics/vitest-fake-timer-guard.mjs +34 -0
  139. package/dist/vitest-diagnostics/vitest-fork-leak-detection.d.mts +1 -0
  140. package/dist/vitest-diagnostics/vitest-fork-leak-detection.mjs +8 -0
  141. package/dist/vitest-diagnostics/vitest-fork-leak-diagnostics.d.mts +10 -1
  142. package/dist/vitest-diagnostics/vitest-fork-leak-diagnostics.mjs +43 -2
  143. package/dist/vitest-diagnostics/vitest-fork-leak-handshake-samples.d.mts +50 -0
  144. package/dist/vitest-diagnostics/vitest-fork-leak-handshake-samples.mjs +69 -0
  145. package/dist/vitest-diagnostics/vitest-fork-leak-handshake.d.mts +19 -0
  146. package/dist/vitest-diagnostics/vitest-fork-leak-handshake.mjs +136 -0
  147. package/dist/vitest-diagnostics/vitest-network-allowlist-dns.d.mts +7 -0
  148. package/dist/vitest-diagnostics/vitest-network-allowlist-dns.mjs +54 -0
  149. package/dist/vitest-diagnostics/vitest-network-allowlist-host.d.mts +8 -0
  150. package/dist/vitest-diagnostics/vitest-network-allowlist-host.mjs +48 -0
  151. package/dist/vitest-diagnostics/vitest-network-allowlist-socket.d.mts +14 -0
  152. package/dist/vitest-diagnostics/vitest-network-allowlist-socket.mjs +39 -0
  153. package/dist/vitest-diagnostics/vitest-network-allowlist.d.mts +7 -0
  154. package/dist/vitest-diagnostics/vitest-network-allowlist.mjs +72 -0
  155. package/dist/vitest-diagnostics/vitest-process-resources.d.mts +6 -0
  156. package/dist/vitest-diagnostics/vitest-process-resources.mjs +51 -0
  157. package/dist/vitest-effective-timeout/cap.d.mts +9 -0
  158. package/dist/vitest-effective-timeout/cap.mjs +28 -0
  159. package/dist/vitest-effective-timeout/check-profiles.d.mts +15 -0
  160. package/dist/vitest-effective-timeout/check-profiles.mjs +52 -0
  161. package/dist/vitest-effective-timeout/config-file.d.mts +6 -0
  162. package/dist/vitest-effective-timeout/config-file.mjs +23 -0
  163. package/dist/vitest-effective-timeout/fixtures.d.mts +2 -0
  164. package/dist/vitest-effective-timeout/fixtures.mjs +18 -0
  165. package/dist/vitest-effective-timeout/index.d.mts +7 -0
  166. package/dist/vitest-effective-timeout/index.mjs +4 -0
  167. package/dist/vitest-effective-timeout/profiles.d.mts +10 -0
  168. package/dist/vitest-effective-timeout/profiles.mjs +33 -0
  169. package/dist/vitest-effective-timeout/run-profile.d.mts +31 -0
  170. package/dist/vitest-effective-timeout/run-profile.mjs +95 -0
  171. package/docs/mcp-server.md +2 -13
  172. package/package.json +32 -2
  173. package/scripts/__pycache__/run_bounded_process.cpython-312.pyc +0 -0
  174. package/scripts/chromium-launch-probe.d.mts +7 -0
  175. package/scripts/chromium-launch-probe.mjs +101 -0
  176. package/scripts/run-bounded-fixtures/run-bounded-backpressure.py +186 -0
  177. package/scripts/run-bounded-fixtures/run-bounded-merged-output.py +75 -0
  178. package/scripts/run-bounded-fixtures/run-bounded-reset-socket.py +25 -0
  179. package/scripts/run-bounded.py +199 -0
  180. package/scripts/run_bounded_process.py +129 -0
  181. package/scripts/worktree/git-index-lock.sh +16 -0
  182. package/scripts/worktree/git-worktrees.sh +23 -20
  183. package/scripts/worktree/reset-worktree-run.sh +199 -0
  184. package/scripts/worktree/reset-worktree.sh +122 -0
  185. package/skills/blackboard/SKILL.md +4 -64
  186. package/skills/stacked-prs/SKILL.md +1 -1
  187. package/skills/stacked-prs/references/drain.md +2 -2
@@ -0,0 +1,13 @@
1
+ export { analyzeStorySources } from './analyze.mts';
2
+ export type { StorySourceAnalysis } from './analyze.mts';
3
+ export { checkStoryCoverage } from './check.mts';
4
+ export type { StoryCoverageReport } from './check.mts';
5
+ export { componentExports, exportKey } from './components.mts';
6
+ export type { ComponentExport } from './components.mts';
7
+ export { coveredComponentKeys, namespaceComponentImports, reachableStoryFiles, } from './coverage.mts';
8
+ export type { NamespaceComponentImport } from './coverage.mts';
9
+ export { formatExclusionsMessage, formatMissingComponentsMessage, formatNamespaceImportsMessage, } from './messages.mts';
10
+ export type { MissingComponent } from './messages.mts';
11
+ export { storyCoverageConfig } from './options.mts';
12
+ export type { StoryCoverageConfig, StoryCoverageRequest } from './options.mts';
13
+ export { workspaceFiles } from './workspace.mts';
@@ -0,0 +1,7 @@
1
+ export { analyzeStorySources } from "./analyze.mjs";
2
+ export { checkStoryCoverage } from "./check.mjs";
3
+ export { componentExports, exportKey } from "./components.mjs";
4
+ export { coveredComponentKeys, namespaceComponentImports, reachableStoryFiles, } from "./coverage.mjs";
5
+ export { formatExclusionsMessage, formatMissingComponentsMessage, formatNamespaceImportsMessage, } from "./messages.mjs";
6
+ export { storyCoverageConfig } from "./options.mjs";
7
+ export { workspaceFiles } from "./workspace.mjs";
@@ -0,0 +1,10 @@
1
+ import type { StoryCoverageConfig } from './options.mts';
2
+ import type { NamespaceComponentImport } from './coverage.mts';
3
+ export type MissingComponent = {
4
+ component: string;
5
+ exportName: string;
6
+ file: string;
7
+ };
8
+ export declare function formatMissingComponentsMessage(missingComponents: readonly MissingComponent[], config: StoryCoverageConfig): string;
9
+ export declare function formatNamespaceImportsMessage(namespaceImports: readonly NamespaceComponentImport[], config: StoryCoverageConfig): string;
10
+ export declare function formatExclusionsMessage(excludedKeys: readonly string[]): string;
@@ -0,0 +1,42 @@
1
+ export function formatMissingComponentsMessage(missingComponents, config) {
2
+ if (missingComponents.length === 0)
3
+ return '';
4
+ const lines = [
5
+ `${missingComponents.length} component(s) matching the marker have no story coverage.`,
6
+ '',
7
+ `For each missing component, add a story under ${config.storyRoot} that imports and uses the component at runtime.`,
8
+ '',
9
+ `Use 'default' for default exports when matching the key reported below.`,
10
+ `The zero-exclusion ratchet rejects entries in ${config.exclusionsLabel}.`,
11
+ '',
12
+ 'Missing components:',
13
+ ];
14
+ for (const { component, exportName, file } of missingComponents) {
15
+ lines.push(` ${component} — ${file}#${exportName}`);
16
+ lines.push('');
17
+ }
18
+ return lines.join('\n');
19
+ }
20
+ export function formatNamespaceImportsMessage(namespaceImports, config) {
21
+ if (namespaceImports.length === 0)
22
+ return '';
23
+ const lines = [
24
+ `${namespaceImports.length} story file(s) use namespace imports (* as ...) from ${config.componentRoot} — individual component coverage cannot be tracked:`,
25
+ '',
26
+ ];
27
+ for (const { file, source, local } of namespaceImports) {
28
+ lines.push(` ${file}: import * as ${local} from '${source}'`);
29
+ }
30
+ lines.push('');
31
+ lines.push('Fix: replace namespace imports with named imports for the specific components used.');
32
+ return lines.join('\n');
33
+ }
34
+ export function formatExclusionsMessage(excludedKeys) {
35
+ if (excludedKeys.length === 0)
36
+ return '';
37
+ return [
38
+ `${excludedKeys.length} component story exclusion(s) remain after the zero-exclusion ratchet:`,
39
+ ...excludedKeys.map((key) => ` - ${key}`),
40
+ 'Add direct story coverage instead of adding exclusions.',
41
+ ].join('\n');
42
+ }
@@ -0,0 +1,27 @@
1
+ export type StoryCoverageRequest = {
2
+ root: string;
3
+ componentRoot: string;
4
+ storyRoot: string;
5
+ aliases?: Readonly<Record<string, string>>;
6
+ sourceExtensions: readonly string[];
7
+ componentExtensions: readonly string[];
8
+ marker: RegExp;
9
+ storyFilePattern: RegExp;
10
+ exclusions?: Readonly<Record<string, unknown>>;
11
+ exclusionsLabel?: string;
12
+ };
13
+ export type StoryCoverageConfig = {
14
+ root: string;
15
+ componentRoot: string;
16
+ storyRoot: string;
17
+ aliases: Readonly<Record<string, string>>;
18
+ sourceExtensions: readonly string[];
19
+ componentExtensions: readonly string[];
20
+ marker: RegExp;
21
+ storyFilePattern: RegExp;
22
+ exclusions: Readonly<Record<string, unknown>>;
23
+ exclusionsLabel: string;
24
+ };
25
+ export declare function storyCoverageConfig(request: StoryCoverageRequest): StoryCoverageConfig;
26
+ /** Resets `lastIndex` so a global or sticky pattern can match more than once. */
27
+ export declare function patternMatches(pattern: RegExp, value: string): boolean;
@@ -0,0 +1,51 @@
1
+ import { resolve } from 'node:path';
2
+ export function storyCoverageConfig(request) {
3
+ const componentRoot = directoryRoot(request.componentRoot, 'componentRoot');
4
+ const storyRoot = directoryRoot(request.storyRoot, 'storyRoot');
5
+ if (componentRoot.startsWith(storyRoot) || storyRoot.startsWith(componentRoot)) {
6
+ throw new Error('componentRoot and storyRoot must not overlap');
7
+ }
8
+ requireExtensions(request.sourceExtensions, 'sourceExtensions');
9
+ requireExtensions(request.componentExtensions, 'componentExtensions');
10
+ if (request.exclusions !== undefined && !plainRecord(request.exclusions)) {
11
+ throw new Error('exclusions must be a plain object');
12
+ }
13
+ return {
14
+ root: resolve(request.root),
15
+ componentRoot,
16
+ storyRoot,
17
+ aliases: request.aliases ?? {},
18
+ sourceExtensions: request.sourceExtensions,
19
+ componentExtensions: request.componentExtensions,
20
+ marker: request.marker,
21
+ storyFilePattern: request.storyFilePattern,
22
+ exclusions: request.exclusions ?? {},
23
+ exclusionsLabel: request.exclusionsLabel ?? 'the exclusions map',
24
+ };
25
+ }
26
+ /** Resets `lastIndex` so a global or sticky pattern can match more than once. */
27
+ export function patternMatches(pattern, value) {
28
+ pattern.lastIndex = 0;
29
+ return pattern.test(value);
30
+ }
31
+ function directoryRoot(value, label) {
32
+ const normalized = value.replaceAll('\\', '/').replace(/^\.\//, '');
33
+ if (normalized.startsWith('/') ||
34
+ normalized.split('/').includes('..') ||
35
+ normalized === '' ||
36
+ normalized === '.') {
37
+ throw new Error(`${label} must be a relative directory inside the root`);
38
+ }
39
+ return normalized.endsWith('/') ? normalized : `${normalized}/`;
40
+ }
41
+ function requireExtensions(extensions, label) {
42
+ if (extensions.length === 0)
43
+ throw new Error(`${label} must not be empty`);
44
+ for (const extension of extensions) {
45
+ if (!extension.startsWith('.'))
46
+ throw new Error(`${label} entries must start with '.'`);
47
+ }
48
+ }
49
+ function plainRecord(value) {
50
+ return typeof value === 'object' && value !== null && !Array.isArray(value);
51
+ }
@@ -0,0 +1,2 @@
1
+ import type { StoryCoverageConfig } from './options.mts';
2
+ export declare function workspaceFiles(config: StoryCoverageConfig): string[];
@@ -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
+ }
@@ -3,7 +3,15 @@ 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 type { ForkLeakHandshakeSettlement } from './vitest-fork-leak-handshake.mts';
14
+ export type { PoolMetrics, PoolSocketHandles } from './vitest-fork-leak-handshake-samples.mts';
7
15
  export type { ForkLeakDetector, ForkLeakDetectorOptions, ForkLeakVerdict, } from './vitest-fork-leak-detection.mts';
8
16
  export { MAX_DIAGNOSTIC_REPORT_BYTES } from './read-file.mts';
9
17
  export declare const DEFAULT_MAX_DIAGNOSTIC_REPORTS = 100;
@@ -2,7 +2,11 @@ import { join, posix, win32 } from 'node:path';
2
2
  export { registerForkExitSentinel, setCurrentForkExitModule, setCurrentForkExitProject, } from "./vitest-fork-exit-sentinel.mjs";
3
3
  export { clearForkExitRecords, formatForkExitSentinelSection, readForkExitRecords, summarizeForkExitRecords, } from "./vitest-fork-exit-records.mjs";
4
4
  export { createVitestWorkerExitDiagnosticsReporter, formatWorkerExitDiagnostics, isWorkerExitError, } from "./vitest-worker-exit-diagnostics-reporter.mjs";
5
- export { createForkLeakDetector, formatForkLeakDiagnostics, waitForResourceCloseCallbacks, } from "./vitest-fork-leak-detection.mjs";
5
+ export { createForkLeakDetector, formatForkLeakDiagnostics, getForkLeakDetector, waitForResourceCloseCallbacks, } from "./vitest-fork-leak-detection.mjs";
6
+ export { checkAndRestoreFakeTimers, formatFakeTimerLeakDiagnostics, } from "./vitest-fake-timer-guard.mjs";
7
+ export { consumeTestNetworkAllowlistViolation, installTestNetworkAllowlist, } from "./vitest-network-allowlist.mjs";
8
+ export { getRegisteredPoolMetrics, getRegisteredPoolSocketHandles, } from "./vitest-fork-leak-diagnostics.mjs";
9
+ export { FORK_LEAK_HANDSHAKE_MAX_TURNS, FORK_LEAK_HANDSHAKE_STABLE_OBSERVATIONS, formatActiveResources, formatProcessResources, formatResourceCounts, waitForForkLeakHandshakeSettle, } from "./vitest-fork-leak-handshake.mjs";
6
10
  import { isDiagnosticReportDirectoryCurrent, readDiagnosticReportDirectory } from "./directory.mjs";
7
11
  import { readBoundedRegularFile } from "./read-file.mjs";
8
12
  export { MAX_DIAGNOSTIC_REPORT_BYTES } from "./read-file.mjs";
@@ -0,0 +1,6 @@
1
+ export type FakeTimerController = {
2
+ isFakeTimers(): boolean;
3
+ useRealTimers(): void;
4
+ };
5
+ export declare function formatFakeTimerLeakDiagnostics(testName: string): string;
6
+ export declare function checkAndRestoreFakeTimers(controller: FakeTimerController, testName: string): string | null;