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.
- package/README.md +99 -12
- package/dist/agent-blackboard/index.d.mts +0 -1
- package/dist/agent-blackboard/index.mjs +0 -23
- package/dist/cli/commands/agent-blackboard-flags.d.mts +0 -1
- package/dist/cli/commands/agent-blackboard-flags.mjs +0 -9
- package/dist/cli/commands/agent-blackboard.d.mts +0 -2
- package/dist/cli/commands/agent-blackboard.mjs +7 -121
- package/dist/cli/commands/story-coverage.d.mts +2 -0
- package/dist/cli/commands/story-coverage.mjs +56 -0
- package/dist/cli/index.mjs +6 -0
- package/dist/cli/optional-peer.d.mts +5 -0
- package/dist/cli/optional-peer.mjs +17 -0
- package/dist/cli/parse-forwarded-commands.d.mts +3 -0
- package/dist/cli/parse-forwarded-commands.mjs +2 -0
- package/dist/cli/parse-story-coverage-fields.d.mts +19 -0
- package/dist/cli/parse-story-coverage-fields.mjs +69 -0
- package/dist/cli/parse-story-coverage.d.mts +8 -0
- package/dist/cli/parse-story-coverage.mjs +34 -0
- package/dist/cli/parse.d.mts +5 -1
- package/dist/cli/parse.mjs +3 -0
- package/dist/cli/story-coverage-lazy.d.mts +3 -0
- package/dist/cli/story-coverage-lazy.mjs +6 -0
- package/dist/cli/usage.d.mts +1 -1
- package/dist/cli/usage.mjs +8 -7
- package/dist/host-storage/check.d.mts +38 -0
- package/dist/host-storage/check.mjs +109 -0
- package/dist/host-storage/cli.d.mts +7 -0
- package/dist/host-storage/cli.mjs +102 -0
- package/dist/host-storage/host-storage.test-helpers.d.mts +26 -0
- package/dist/host-storage/host-storage.test-helpers.mjs +58 -0
- package/dist/host-storage/index.d.mts +3 -0
- package/dist/host-storage/index.mjs +3 -0
- package/dist/host-storage/preflight.d.mts +22 -0
- package/dist/host-storage/preflight.mjs +105 -0
- package/dist/index.d.mts +2 -0
- package/dist/index.mjs +1 -0
- package/dist/playwright/assertions.d.mts +1 -0
- package/dist/playwright/assertions.mjs +5 -0
- package/dist/playwright/blocked-external-network.d.mts +15 -0
- package/dist/playwright/blocked-external-network.mjs +73 -0
- package/dist/playwright/browser-dialog-issues.d.mts +12 -0
- package/dist/playwright/browser-dialog-issues.mjs +29 -0
- package/dist/playwright/browser-errors.d.mts +23 -0
- package/dist/playwright/browser-errors.mjs +130 -0
- package/dist/playwright/browser-issue-monitor.test-helpers.d.mts +31 -0
- package/dist/playwright/browser-issue-monitor.test-helpers.mjs +51 -0
- package/dist/playwright/browser-issue-records.d.mts +42 -0
- package/dist/playwright/browser-issue-records.mjs +148 -0
- package/dist/playwright/browser-test.d.mts +22 -0
- package/dist/playwright/browser-test.mjs +68 -0
- package/dist/playwright/expect-no-broken-images.d.mts +17 -0
- package/dist/playwright/expect-no-broken-images.mjs +39 -0
- package/dist/playwright/index.d.mts +32 -0
- package/dist/playwright/index.mjs +22 -0
- package/dist/playwright/mobile-assertions.d.mts +14 -0
- package/dist/playwright/mobile-assertions.mjs +43 -0
- package/dist/playwright/monitored-test-info.d.mts +14 -0
- package/dist/playwright/monitored-test-info.mjs +1 -0
- package/dist/playwright/navigate-to.d.mts +27 -0
- package/dist/playwright/navigate-to.mjs +39 -0
- package/dist/playwright/radix-select.d.mts +18 -0
- package/dist/playwright/radix-select.mjs +19 -0
- package/dist/playwright/random-id.d.mts +34 -0
- package/dist/playwright/random-id.mjs +37 -0
- package/dist/playwright/retry-on-connection-lost.d.mts +7 -0
- package/dist/playwright/retry-on-connection-lost.mjs +107 -0
- package/dist/playwright/scroll-to-load-more.d.mts +37 -0
- package/dist/playwright/scroll-to-load-more.mjs +158 -0
- package/dist/playwright/storybook.d.mts +2 -0
- package/dist/playwright/storybook.mjs +13 -0
- package/dist/playwright/test-fixtures.d.mts +1 -0
- package/dist/playwright/test-fixtures.mjs +2 -0
- package/dist/playwright/test-lifecycle-reporter.d.mts +27 -0
- package/dist/playwright/test-lifecycle-reporter.mjs +57 -0
- package/dist/playwright/totp.d.mts +6 -0
- package/dist/playwright/totp.mjs +37 -0
- package/dist/playwright/turnstile-stub.d.mts +8 -0
- package/dist/playwright/turnstile-stub.mjs +61 -0
- package/dist/playwright/viewport-constants.d.mts +30 -0
- package/dist/playwright/viewport-constants.mjs +9 -0
- package/dist/playwright/virtual-authenticator.d.mts +5 -0
- package/dist/playwright/virtual-authenticator.mjs +15 -0
- package/dist/playwright/wait-for-hydration.d.mts +29 -0
- package/dist/playwright/wait-for-hydration.mjs +81 -0
- package/dist/shell-parse/ansi-c-string.d.mts +12 -0
- package/dist/shell-parse/ansi-c-string.mjs +80 -0
- package/dist/shell-parse/index.d.mts +20 -0
- package/dist/shell-parse/index.mjs +15 -0
- package/dist/shell-parse/shell-command-substitution-reads.d.mts +8 -0
- package/dist/shell-parse/shell-command-substitution-reads.mjs +53 -0
- package/dist/shell-parse/shell-command-substitutions.d.mts +8 -0
- package/dist/shell-parse/shell-command-substitutions.mjs +52 -0
- package/dist/shell-parse/shell-command-wrappers.d.mts +26 -0
- package/dist/shell-parse/shell-command-wrappers.mjs +143 -0
- package/dist/shell-parse/shell-commands.d.mts +24 -0
- package/dist/shell-parse/shell-commands.mjs +155 -0
- package/dist/shell-parse/shell-heredoc-delimiter.d.mts +5 -0
- package/dist/shell-parse/shell-heredoc-delimiter.mjs +52 -0
- package/dist/shell-parse/shell-heredoc-parser.d.mts +7 -0
- package/dist/shell-parse/shell-heredoc-parser.mjs +49 -0
- package/dist/shell-parse/shell-heredoc-quote-state.d.mts +19 -0
- package/dist/shell-parse/shell-heredoc-quote-state.mjs +40 -0
- package/dist/shell-parse/shell-heredoc.d.mts +10 -0
- package/dist/shell-parse/shell-heredoc.mjs +90 -0
- package/dist/shell-parse/shell-redirections.d.mts +5 -0
- package/dist/shell-parse/shell-redirections.mjs +34 -0
- package/dist/shell-parse/shell-script-operand.d.mts +13 -0
- package/dist/shell-parse/shell-script-operand.mjs +103 -0
- package/dist/shell-parse/shell-stdin-script.d.mts +6 -0
- package/dist/shell-parse/shell-stdin-script.mjs +61 -0
- package/dist/shell-parse/shell-token-utils.d.mts +9 -0
- package/dist/shell-parse/shell-token-utils.mjs +33 -0
- package/dist/shell-parse/shell-tokenizer-comments.d.mts +1 -0
- package/dist/shell-parse/shell-tokenizer-comments.mjs +57 -0
- package/dist/shell-parse/shell-tokenizer-operators.d.mts +14 -0
- package/dist/shell-parse/shell-tokenizer-operators.mjs +47 -0
- package/dist/shell-parse/shell-tokenizer.d.mts +12 -0
- package/dist/shell-parse/shell-tokenizer.mjs +104 -0
- package/dist/story-coverage/analyze.d.mts +8 -0
- package/dist/story-coverage/analyze.mjs +24 -0
- package/dist/story-coverage/check.d.mts +11 -0
- package/dist/story-coverage/check.mjs +42 -0
- package/dist/story-coverage/components.d.mts +10 -0
- package/dist/story-coverage/components.mjs +40 -0
- package/dist/story-coverage/coverage.d.mts +10 -0
- package/dist/story-coverage/coverage.mjs +43 -0
- package/dist/story-coverage/index.d.mts +13 -0
- package/dist/story-coverage/index.mjs +7 -0
- package/dist/story-coverage/messages.d.mts +10 -0
- package/dist/story-coverage/messages.mjs +42 -0
- package/dist/story-coverage/options.d.mts +27 -0
- package/dist/story-coverage/options.mjs +51 -0
- package/dist/story-coverage/workspace.d.mts +2 -0
- package/dist/story-coverage/workspace.mjs +27 -0
- package/dist/test-helpers/cancel-runs.test-helpers.d.mts +39 -0
- package/dist/test-helpers/cancel-runs.test-helpers.mjs +124 -0
- package/dist/test-helpers/run-bounded-exit-observer.test-helpers.d.mts +12 -0
- package/dist/test-helpers/run-bounded-exit-observer.test-helpers.mjs +68 -0
- package/dist/test-helpers/run-bounded-output-fixture.test-helpers.d.mts +18 -0
- package/dist/test-helpers/run-bounded-output-fixture.test-helpers.mjs +162 -0
- package/dist/vitest-diagnostics/browser.d.mts +2 -0
- package/dist/vitest-diagnostics/browser.mjs +6 -0
- package/dist/vitest-diagnostics/index.d.mts +14 -23
- package/dist/vitest-diagnostics/index.mjs +8 -124
- package/dist/vitest-diagnostics/report-summary.d.mts +22 -0
- package/dist/vitest-diagnostics/report-summary.mjs +123 -0
- package/dist/vitest-diagnostics/vitest-fake-timer-guard.d.mts +6 -0
- package/dist/vitest-diagnostics/vitest-fake-timer-guard.mjs +34 -0
- package/dist/vitest-diagnostics/vitest-fork-leak-detection.d.mts +1 -0
- package/dist/vitest-diagnostics/vitest-fork-leak-detection.mjs +8 -0
- package/dist/vitest-diagnostics/vitest-fork-leak-diagnostics.d.mts +17 -1
- package/dist/vitest-diagnostics/vitest-fork-leak-diagnostics.mjs +44 -2
- package/dist/vitest-diagnostics/vitest-fork-leak-handshake-samples.d.mts +55 -0
- package/dist/vitest-diagnostics/vitest-fork-leak-handshake-samples.mjs +74 -0
- package/dist/vitest-diagnostics/vitest-fork-leak-handshake.d.mts +19 -0
- package/dist/vitest-diagnostics/vitest-fork-leak-handshake.mjs +136 -0
- package/dist/vitest-diagnostics/vitest-network-allowlist-dns.d.mts +7 -0
- package/dist/vitest-diagnostics/vitest-network-allowlist-dns.mjs +54 -0
- package/dist/vitest-diagnostics/vitest-network-allowlist-host.d.mts +8 -0
- package/dist/vitest-diagnostics/vitest-network-allowlist-host.mjs +48 -0
- package/dist/vitest-diagnostics/vitest-network-allowlist-socket.d.mts +14 -0
- package/dist/vitest-diagnostics/vitest-network-allowlist-socket.mjs +39 -0
- package/dist/vitest-diagnostics/vitest-network-allowlist.d.mts +7 -0
- package/dist/vitest-diagnostics/vitest-network-allowlist.mjs +72 -0
- package/dist/vitest-diagnostics/vitest-process-resources.d.mts +10 -0
- package/dist/vitest-diagnostics/vitest-process-resources.mjs +54 -0
- package/dist/vitest-effective-timeout/cap.d.mts +9 -0
- package/dist/vitest-effective-timeout/cap.mjs +28 -0
- package/dist/vitest-effective-timeout/check-profiles.d.mts +15 -0
- package/dist/vitest-effective-timeout/check-profiles.mjs +52 -0
- package/dist/vitest-effective-timeout/config-file.d.mts +6 -0
- package/dist/vitest-effective-timeout/config-file.mjs +23 -0
- package/dist/vitest-effective-timeout/fixtures.d.mts +2 -0
- package/dist/vitest-effective-timeout/fixtures.mjs +18 -0
- package/dist/vitest-effective-timeout/index.d.mts +7 -0
- package/dist/vitest-effective-timeout/index.mjs +4 -0
- package/dist/vitest-effective-timeout/profiles.d.mts +10 -0
- package/dist/vitest-effective-timeout/profiles.mjs +33 -0
- package/dist/vitest-effective-timeout/run-profile.d.mts +31 -0
- package/dist/vitest-effective-timeout/run-profile.mjs +95 -0
- package/docs/mcp-server.md +2 -13
- package/package.json +37 -2
- package/scripts/__pycache__/run_bounded_process.cpython-312.pyc +0 -0
- package/scripts/chromium-launch-probe.d.mts +7 -0
- package/scripts/chromium-launch-probe.mjs +101 -0
- package/scripts/run-bounded-fixtures/run-bounded-backpressure.py +186 -0
- package/scripts/run-bounded-fixtures/run-bounded-merged-output.py +75 -0
- package/scripts/run-bounded-fixtures/run-bounded-reset-socket.py +25 -0
- package/scripts/run-bounded.py +199 -0
- package/scripts/run_bounded_process.py +129 -0
- package/scripts/worktree/git-index-lock.sh +16 -0
- package/scripts/worktree/git-worktrees.sh +23 -20
- package/scripts/worktree/reset-worktree-run.sh +199 -0
- package/scripts/worktree/reset-worktree.sh +122 -0
- package/skills/blackboard/SKILL.md +4 -64
- package/skills/stacked-prs/SKILL.md +1 -1
- package/skills/stacked-prs/references/drain.md +2 -2
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
export { MAX_DIAGNOSTIC_REPORT_BYTES } from './read-file.mts';
|
|
2
|
+
export declare const DEFAULT_MAX_DIAGNOSTIC_REPORTS = 100;
|
|
3
|
+
export declare const DEFAULT_MAX_FORMATTED_DIAGNOSTIC_REPORTS = 20;
|
|
4
|
+
export declare const HARD_MAX_DIAGNOSTIC_REPORTS = 100;
|
|
5
|
+
export { HARD_MAX_DIAGNOSTIC_DIRECTORY_ENTRIES } from './directory.mts';
|
|
6
|
+
export interface DiagnosticReportSummary {
|
|
7
|
+
file: string;
|
|
8
|
+
trigger: string;
|
|
9
|
+
event: string;
|
|
10
|
+
threadId: number | null;
|
|
11
|
+
heapUsedMB: string;
|
|
12
|
+
heapTotalMB: string;
|
|
13
|
+
heapLimitMB: string;
|
|
14
|
+
maxRssMB: string;
|
|
15
|
+
topNativeFrameModule: string | null;
|
|
16
|
+
}
|
|
17
|
+
export interface DiagnosticReportLimitOptions {
|
|
18
|
+
maxReports?: number;
|
|
19
|
+
}
|
|
20
|
+
export declare function summarizeDiagnosticReport(file: string, report: unknown): DiagnosticReportSummary;
|
|
21
|
+
export declare function readDiagnosticReportSummaries(directory: string, options?: DiagnosticReportLimitOptions): DiagnosticReportSummary[];
|
|
22
|
+
export declare function formatDiagnosticReportSummaries(summaries: readonly unknown[], options?: DiagnosticReportLimitOptions): string;
|
|
@@ -0,0 +1,123 @@
|
|
|
1
|
+
import { join, posix, win32 } from 'node:path';
|
|
2
|
+
import { isDiagnosticReportDirectoryCurrent, readDiagnosticReportDirectory } from "./directory.mjs";
|
|
3
|
+
import { readBoundedRegularFile } from "./read-file.mjs";
|
|
4
|
+
export { MAX_DIAGNOSTIC_REPORT_BYTES } from "./read-file.mjs";
|
|
5
|
+
export const DEFAULT_MAX_DIAGNOSTIC_REPORTS = 100;
|
|
6
|
+
export const DEFAULT_MAX_FORMATTED_DIAGNOSTIC_REPORTS = 20;
|
|
7
|
+
export const HARD_MAX_DIAGNOSTIC_REPORTS = 100;
|
|
8
|
+
export { HARD_MAX_DIAGNOSTIC_DIRECTORY_ENTRIES } from "./directory.mjs";
|
|
9
|
+
const TEXT_LIMIT = 200;
|
|
10
|
+
const PATH_LIMIT = 240;
|
|
11
|
+
function objectValue(value) {
|
|
12
|
+
return typeof value === 'object' && value !== null && !Array.isArray(value)
|
|
13
|
+
? value
|
|
14
|
+
: {};
|
|
15
|
+
}
|
|
16
|
+
function boundedText(value, fallback, limit) {
|
|
17
|
+
if (typeof value !== 'string')
|
|
18
|
+
return fallback;
|
|
19
|
+
const normalized = value
|
|
20
|
+
.slice(0, limit * 4)
|
|
21
|
+
.replace(/[\p{Cc}\p{Cf}]/gu, ' ')
|
|
22
|
+
.replace(/\s+/g, ' ')
|
|
23
|
+
.trim();
|
|
24
|
+
return normalized.length === 0 ? fallback : normalized.slice(0, limit);
|
|
25
|
+
}
|
|
26
|
+
function formatMebibytes(value) {
|
|
27
|
+
const bytes = typeof value === 'number' && Number.isFinite(value) && value >= 0 ? value : 0;
|
|
28
|
+
return (bytes / 1024 / 1024).toFixed(1);
|
|
29
|
+
}
|
|
30
|
+
function threadId(value) {
|
|
31
|
+
return typeof value === 'number' && Number.isSafeInteger(value) && value >= 0 ? value : null;
|
|
32
|
+
}
|
|
33
|
+
function nativeModulePath(value) {
|
|
34
|
+
const module = boundedText(value, '', PATH_LIMIT);
|
|
35
|
+
return posix.isAbsolute(module) || win32.isAbsolute(module) ? module : null;
|
|
36
|
+
}
|
|
37
|
+
function topNativeFrameModule(value) {
|
|
38
|
+
if (!Array.isArray(value))
|
|
39
|
+
return null;
|
|
40
|
+
const symbol = objectValue(value[0]).symbol;
|
|
41
|
+
if (typeof symbol !== 'string')
|
|
42
|
+
return null;
|
|
43
|
+
const tail = symbol.slice(-PATH_LIMIT * 2).trimEnd();
|
|
44
|
+
if (!tail.endsWith(']'))
|
|
45
|
+
return null;
|
|
46
|
+
const opening = tail.lastIndexOf('[');
|
|
47
|
+
if (opening < 0)
|
|
48
|
+
return null;
|
|
49
|
+
return nativeModulePath(tail.slice(opening + 1, -1));
|
|
50
|
+
}
|
|
51
|
+
function reportLimit(value, fallback) {
|
|
52
|
+
if (value === undefined)
|
|
53
|
+
return fallback;
|
|
54
|
+
if (!Number.isFinite(value))
|
|
55
|
+
return fallback;
|
|
56
|
+
return Math.min(Math.max(Math.floor(value), 0), HARD_MAX_DIAGNOSTIC_REPORTS);
|
|
57
|
+
}
|
|
58
|
+
export function summarizeDiagnosticReport(file, report) {
|
|
59
|
+
const root = objectValue(report);
|
|
60
|
+
const header = objectValue(root.header);
|
|
61
|
+
const heap = objectValue(root.javascriptHeap);
|
|
62
|
+
const resourceUsage = objectValue(root.resourceUsage);
|
|
63
|
+
return {
|
|
64
|
+
file: boundedText(file, 'unknown', PATH_LIMIT),
|
|
65
|
+
trigger: boundedText(header.trigger, 'unknown', TEXT_LIMIT),
|
|
66
|
+
event: boundedText(header.event, 'unknown', TEXT_LIMIT),
|
|
67
|
+
threadId: threadId(header.threadId),
|
|
68
|
+
heapUsedMB: formatMebibytes(heap.usedMemory),
|
|
69
|
+
heapTotalMB: formatMebibytes(heap.totalMemory),
|
|
70
|
+
heapLimitMB: formatMebibytes(heap.memoryLimit),
|
|
71
|
+
maxRssMB: formatMebibytes(resourceUsage.maxRss),
|
|
72
|
+
topNativeFrameModule: topNativeFrameModule(root.nativeStack),
|
|
73
|
+
};
|
|
74
|
+
}
|
|
75
|
+
export function readDiagnosticReportSummaries(directory, options = {}) {
|
|
76
|
+
const maxReports = reportLimit(options.maxReports, DEFAULT_MAX_DIAGNOSTIC_REPORTS);
|
|
77
|
+
if (maxReports === 0)
|
|
78
|
+
return [];
|
|
79
|
+
const reportsDirectory = readDiagnosticReportDirectory(directory);
|
|
80
|
+
if (reportsDirectory === undefined)
|
|
81
|
+
return [];
|
|
82
|
+
const filenames = reportsDirectory.filenames.sort();
|
|
83
|
+
const selected = filenames.slice(-maxReports);
|
|
84
|
+
const summaries = [];
|
|
85
|
+
for (const filename of selected) {
|
|
86
|
+
try {
|
|
87
|
+
if (!isDiagnosticReportDirectoryCurrent(directory, reportsDirectory.identity))
|
|
88
|
+
return [];
|
|
89
|
+
const contents = readBoundedRegularFile(join(directory, filename));
|
|
90
|
+
if (!isDiagnosticReportDirectoryCurrent(directory, reportsDirectory.identity))
|
|
91
|
+
return [];
|
|
92
|
+
if (contents === undefined)
|
|
93
|
+
continue;
|
|
94
|
+
const report = JSON.parse(contents);
|
|
95
|
+
summaries.push(summarizeDiagnosticReport(filename, report));
|
|
96
|
+
}
|
|
97
|
+
catch {
|
|
98
|
+
// Node can leave a partial report if the process exits while writing it.
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
return summaries;
|
|
102
|
+
}
|
|
103
|
+
export function formatDiagnosticReportSummaries(summaries, options = {}) {
|
|
104
|
+
const maxReports = reportLimit(options.maxReports, DEFAULT_MAX_FORMATTED_DIAGNOSTIC_REPORTS);
|
|
105
|
+
const lines = ['[vitest-diagnostics]', `reports provided: ${summaries.length}`];
|
|
106
|
+
if (summaries.length === 0)
|
|
107
|
+
lines.push(' (none recorded)');
|
|
108
|
+
for (const value of summaries.slice(0, maxReports)) {
|
|
109
|
+
const summary = objectValue(value);
|
|
110
|
+
lines.push(` - file=${boundedText(summary.file, 'unknown', PATH_LIMIT)} ` +
|
|
111
|
+
`trigger=${boundedText(summary.trigger, 'unknown', TEXT_LIMIT)} ` +
|
|
112
|
+
`event=${boundedText(summary.event, 'unknown', TEXT_LIMIT)} ` +
|
|
113
|
+
`threadId=${threadId(summary.threadId) ?? 'unknown'} ` +
|
|
114
|
+
`heapUsedMB=${boundedText(summary.heapUsedMB, '0.0', TEXT_LIMIT)} ` +
|
|
115
|
+
`heapTotalMB=${boundedText(summary.heapTotalMB, '0.0', TEXT_LIMIT)} ` +
|
|
116
|
+
`heapLimitMB=${boundedText(summary.heapLimitMB, '0.0', TEXT_LIMIT)} ` +
|
|
117
|
+
`maxRssMB=${boundedText(summary.maxRssMB, '0.0', TEXT_LIMIT)} ` +
|
|
118
|
+
`topNativeFrameModule=${nativeModulePath(summary.topNativeFrameModule) ?? 'none'}`);
|
|
119
|
+
}
|
|
120
|
+
if (summaries.length > maxReports)
|
|
121
|
+
lines.push(` ... ${summaries.length - maxReports} more`);
|
|
122
|
+
return `${lines.join('\n')}\n`;
|
|
123
|
+
}
|
|
@@ -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;
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
// Fake-timer-leak guard: a test that leaves vi.useFakeTimers() installed corrupts every later
|
|
2
|
+
// test sharing the same fork (isolate: false) or file (isolate: true). This asserts the
|
|
3
|
+
// invariant after every test — a source-level lint rule can't help because a correct
|
|
4
|
+
// beforeEach/afterEach pair looks identical to a stray call at the AST level.
|
|
5
|
+
//
|
|
6
|
+
// Kept dependency-free (no import from 'vitest' at module scope) so the check function is
|
|
7
|
+
// unit-testable with a fake vi-shaped object, mirroring vitest-fork-leak-detection.mts.
|
|
8
|
+
//
|
|
9
|
+
// `.ts`, not `.mts`: the root-level setupFiles chain imports this inside the
|
|
10
|
+
// browser project whose transform hardcodes TypeScript detection to
|
|
11
|
+
// `.ts`/`.tsx` and silently misparses `.mts` as plain JS.
|
|
12
|
+
export function formatFakeTimerLeakDiagnostics(testName) {
|
|
13
|
+
return [
|
|
14
|
+
'[vitest-fake-timer-leak]',
|
|
15
|
+
`test: ${testName}`,
|
|
16
|
+
'vi.useFakeTimers() was still installed when this test finished.',
|
|
17
|
+
"Fake timers are process-global state: under pool: 'forks', isolate: false they leak into",
|
|
18
|
+
'every later test file sharing this fork (not just later tests in this file); under',
|
|
19
|
+
'isolate: true they still leak into later tests in this same file. Either way, real',
|
|
20
|
+
'timer-driven code in a later test can hang or silently behave differently.',
|
|
21
|
+
'Fix: call vi.useRealTimers() in an afterEach for this file (or wrap the test body in',
|
|
22
|
+
'try/finally) so real timers are restored even when the test throws or returns early.',
|
|
23
|
+
].join('\n');
|
|
24
|
+
}
|
|
25
|
+
// Restores real timers defensively before returning, so a single offending test cannot corrupt
|
|
26
|
+
// every test that runs after it even when this guard's own failure aborts the current file.
|
|
27
|
+
// Returns a diagnostic string when the invariant was violated, or null when the test left
|
|
28
|
+
// real timers in place (the expected, clean state).
|
|
29
|
+
export function checkAndRestoreFakeTimers(controller, testName) {
|
|
30
|
+
if (!controller.isFakeTimers())
|
|
31
|
+
return null;
|
|
32
|
+
controller.useRealTimers();
|
|
33
|
+
return formatFakeTimerLeakDiagnostics(testName);
|
|
34
|
+
}
|
|
@@ -22,5 +22,6 @@ export type ForkLeakDetectorOptions = {
|
|
|
22
22
|
export type ForkLeakDetector = {
|
|
23
23
|
record(counts: ReadonlyMap<string, number>, testFile?: string | null): ForkLeakVerdict[];
|
|
24
24
|
};
|
|
25
|
+
export declare function getForkLeakDetector(options?: ForkLeakDetectorOptions): ForkLeakDetector;
|
|
25
26
|
export declare function waitForResourceCloseCallbacks(): Promise<void>;
|
|
26
27
|
export declare function createForkLeakDetector(options?: ForkLeakDetectorOptions): ForkLeakDetector;
|
|
@@ -18,6 +18,14 @@ const PERSISTENT_HANDLE_TYPES = new Set([
|
|
|
18
18
|
export const WARMUP_CHECKPOINTS = 5;
|
|
19
19
|
export const LEAK_THRESHOLD = 4;
|
|
20
20
|
export const SUSTAINED_CHECKPOINTS = 5;
|
|
21
|
+
const FORK_LEAK_DETECTOR_KEY = Symbol.for('vitest-fork-leak-detector');
|
|
22
|
+
// Vitest re-evaluates a fork's setup files on every file while reusing the process.
|
|
23
|
+
// A module-scope detector would reset every file and never leave the warmup window.
|
|
24
|
+
// Only the first call's options apply; later calls return the existing detector unchanged.
|
|
25
|
+
export function getForkLeakDetector(options = {}) {
|
|
26
|
+
return (globalThis[FORK_LEAK_DETECTOR_KEY] ??=
|
|
27
|
+
createForkLeakDetector(options));
|
|
28
|
+
}
|
|
21
29
|
export function waitForResourceCloseCallbacks() {
|
|
22
30
|
return new Promise((resolve) => realSetTimeout(resolve, 0));
|
|
23
31
|
}
|
|
@@ -1,3 +1,19 @@
|
|
|
1
1
|
import type { ForkLeakVerdict } from './vitest-fork-leak-detection.mts';
|
|
2
|
-
|
|
2
|
+
import type { PoolMetrics } from './vitest-fork-leak-handshake-samples.mts';
|
|
3
|
+
type PoolSocketHandles = {
|
|
4
|
+
active: ReadonlySet<object>;
|
|
5
|
+
owned: ReadonlySet<object>;
|
|
6
|
+
};
|
|
7
|
+
export declare function getRegisteredPoolMetrics(): PoolMetrics | null;
|
|
8
|
+
export declare function getRegisteredPoolSocketHandles(): PoolSocketHandles | null;
|
|
9
|
+
export type ForkLeakDiagnosticsOptions = {
|
|
10
|
+
/** Text printed before the pool metrics line. Defaults to `pool metrics:`. */
|
|
11
|
+
poolMetricsLabel?: string;
|
|
12
|
+
};
|
|
13
|
+
/**
|
|
14
|
+
* One-line summary, or a multi-line report when resource counts are supplied. The multi-line
|
|
15
|
+
* report ends with a pool metrics line whose label comes from `options.poolMetricsLabel`.
|
|
16
|
+
*/
|
|
3
17
|
export declare function formatForkLeakDiagnostics(verdict: ForkLeakVerdict): string;
|
|
18
|
+
export declare function formatForkLeakDiagnostics(verdict: ForkLeakVerdict, counts: ReadonlyMap<string, number>, poolMetrics?: PoolMetrics | null, options?: ForkLeakDiagnosticsOptions): string;
|
|
19
|
+
export {};
|
|
@@ -1,5 +1,33 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
import { formatResourceCounts } from "./vitest-process-resources.mjs";
|
|
2
|
+
const POOL_METRICS_KEY = Symbol.for('vitest-fork-leak-pool-metrics');
|
|
3
|
+
const POOL_SOCKETS_KEY = Symbol.for('vitest-fork-leak-pool-socket-handles');
|
|
4
|
+
export function getRegisteredPoolMetrics() {
|
|
5
|
+
const provider = globalThis[POOL_METRICS_KEY];
|
|
6
|
+
return provider?.() ?? null;
|
|
7
|
+
}
|
|
8
|
+
export function getRegisteredPoolSocketHandles() {
|
|
9
|
+
const provider = globalThis[POOL_SOCKETS_KEY];
|
|
10
|
+
return provider?.() ?? null;
|
|
11
|
+
}
|
|
12
|
+
const DEFAULT_POOL_METRICS_LABEL = 'pool metrics:';
|
|
13
|
+
export function formatForkLeakDiagnostics(verdict, counts, poolMetrics, options = {}) {
|
|
14
|
+
if (counts === undefined)
|
|
15
|
+
return formatForkLeakSummary(verdict);
|
|
16
|
+
return [
|
|
17
|
+
'[vitest-fork-leak]',
|
|
18
|
+
`type: ${verdict.type}`,
|
|
19
|
+
`baseline: ${verdict.baseline}`,
|
|
20
|
+
`current: ${verdict.current} (+${verdict.current - verdict.baseline})`,
|
|
21
|
+
`candidate evidence span: ${verdict.streak}`,
|
|
22
|
+
`candidate growth evidence: ${verdict.growthCheckpoints} (required: ${verdict.requiredGrowthCheckpoints})`,
|
|
23
|
+
`confirmed by continuation in file: ${verdict.detectedInFile ?? 'unknown'}`,
|
|
24
|
+
`suspected growth file: ${verdict.suspectedGrowth?.testFile ?? 'unknown'}`,
|
|
25
|
+
`largest growth step: ${formatGrowthStep(verdict.suspectedGrowth)}`,
|
|
26
|
+
`tracked resource counts: ${formatResourceCounts(counts)}`,
|
|
27
|
+
`${options.poolMetricsLabel ?? DEFAULT_POOL_METRICS_LABEL} ${formatPoolMetrics(poolMetrics ?? null)}`,
|
|
28
|
+
].join('\n');
|
|
29
|
+
}
|
|
30
|
+
function formatForkLeakSummary(verdict) {
|
|
3
31
|
const growth = verdict.suspectedGrowth;
|
|
4
32
|
const file = growth?.testFile ?? verdict.detectedInFile ?? 'unknown';
|
|
5
33
|
return [
|
|
@@ -12,3 +40,17 @@ export function formatForkLeakDiagnostics(verdict) {
|
|
|
12
40
|
`delta=${growth?.delta ?? 0}`,
|
|
13
41
|
].join(' ');
|
|
14
42
|
}
|
|
43
|
+
function formatPoolMetrics(metrics) {
|
|
44
|
+
if (!metrics)
|
|
45
|
+
return 'unavailable (pools not initialized)';
|
|
46
|
+
return Object.entries(metrics)
|
|
47
|
+
.toSorted(([left], [right]) => left.localeCompare(right))
|
|
48
|
+
.map(([label, pool]) => formatPool(label, pool))
|
|
49
|
+
.join(' ');
|
|
50
|
+
}
|
|
51
|
+
function formatPool(label, pool) {
|
|
52
|
+
return `${label}(total=${pool.total},idle=${pool.idle},non-idle-or-connecting=${pool.nonIdleOrConnecting},waiting=${pool.waiting})`;
|
|
53
|
+
}
|
|
54
|
+
function formatGrowthStep(step) {
|
|
55
|
+
return step ? `${step.previous} -> ${step.current} (+${step.delta})` : 'unknown';
|
|
56
|
+
}
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
export type PoolConnectionMetrics = {
|
|
2
|
+
total: number;
|
|
3
|
+
idle: number;
|
|
4
|
+
nonIdleOrConnecting: number;
|
|
5
|
+
waiting: number;
|
|
6
|
+
};
|
|
7
|
+
export type PoolMetrics = Readonly<Record<string, PoolConnectionMetrics>>;
|
|
8
|
+
export type PoolSocketHandles = {
|
|
9
|
+
active: ReadonlySet<object>;
|
|
10
|
+
owned: ReadonlySet<object>;
|
|
11
|
+
};
|
|
12
|
+
export declare function pendingPoolSocketEpisode(options: {
|
|
13
|
+
initial: ForkLeakHandshakeSnapshot;
|
|
14
|
+
probe: ForkLeakHandshakeSnapshot;
|
|
15
|
+
current: ForkLeakHandshakeSnapshot;
|
|
16
|
+
initialPool: PoolConnectionCounts;
|
|
17
|
+
currentPool: PoolConnectionCounts;
|
|
18
|
+
ownedHandlesObserved: ReadonlySet<object>;
|
|
19
|
+
previousHandle: object | null;
|
|
20
|
+
}): {
|
|
21
|
+
handle: object | null;
|
|
22
|
+
inFlight: boolean;
|
|
23
|
+
};
|
|
24
|
+
export type ForkLeakHandshakeSnapshot = {
|
|
25
|
+
connectWraps: number;
|
|
26
|
+
tcpSockets: number;
|
|
27
|
+
resources: readonly string[];
|
|
28
|
+
tcpSocketHandles: ReadonlySet<object>;
|
|
29
|
+
poolMetrics: PoolMetrics | null;
|
|
30
|
+
};
|
|
31
|
+
/**
|
|
32
|
+
* Records one fork-leak checkpoint from a handshake settlement. It counts the resources of the
|
|
33
|
+
* coalesced snapshot, or of the detector snapshot otherwise, and passes them to `record` (for
|
|
34
|
+
* example a fork leak detector's `record`) with the test file name. Returns what `record` returns.
|
|
35
|
+
*/
|
|
36
|
+
export declare function recordForkLeakCheckpoint<T>(record: (counts: ReadonlyMap<string, number>, testFile: string) => T[], settlement: {
|
|
37
|
+
snapshot: ForkLeakHandshakeSnapshot;
|
|
38
|
+
detectorSnapshot: ForkLeakHandshakeSnapshot;
|
|
39
|
+
coalesced: boolean;
|
|
40
|
+
}, testFile: string): T[];
|
|
41
|
+
export type PoolConnectionCounts = {
|
|
42
|
+
total: number;
|
|
43
|
+
idle: number;
|
|
44
|
+
nonIdleOrConnecting: number;
|
|
45
|
+
waiting: number;
|
|
46
|
+
};
|
|
47
|
+
export declare function handshakeSnapshot(resources: readonly string[], tcpSocketHandles: ReadonlySet<object>, poolMetrics: PoolMetrics | null): ForkLeakHandshakeSnapshot;
|
|
48
|
+
export declare function poolConnectionCounts(metrics: PoolMetrics): PoolConnectionCounts;
|
|
49
|
+
export declare function samePoolCounts(previous: PoolConnectionCounts, current: PoolConnectionCounts): boolean;
|
|
50
|
+
export declare function handshakeSettled(previous: ForkLeakHandshakeSnapshot, current: ForkLeakHandshakeSnapshot): boolean;
|
|
51
|
+
export declare function rawDetectorCheckpoint(options: {
|
|
52
|
+
current: ForkLeakHandshakeSnapshot;
|
|
53
|
+
ownedHandlesObserved: ReadonlySet<object>;
|
|
54
|
+
unownedGrowthSnapshots: ReadonlyMap<object, ForkLeakHandshakeSnapshot>;
|
|
55
|
+
}): ForkLeakHandshakeSnapshot;
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
import { countResourcesByType } from "./vitest-process-resources.mjs";
|
|
2
|
+
const pendingEpisodeKey = Symbol.for('vitest-fork-leak-pending-pool-socket-episodes');
|
|
3
|
+
function pendingPoolSocketEpisodes() {
|
|
4
|
+
return (globalThis[pendingEpisodeKey] ??= new WeakSet());
|
|
5
|
+
}
|
|
6
|
+
function startPendingPoolSocketEpisode(growthHandles, ownedHandles) {
|
|
7
|
+
const candidate = growthHandles.find((handle) => !ownedHandles.has(handle) && !pendingPoolSocketEpisodes().has(handle));
|
|
8
|
+
if (candidate)
|
|
9
|
+
pendingPoolSocketEpisodes().add(candidate);
|
|
10
|
+
return candidate ?? null;
|
|
11
|
+
}
|
|
12
|
+
export function pendingPoolSocketEpisode(options) {
|
|
13
|
+
const growthHandles = [...options.current.tcpSocketHandles].filter((handle) => !options.initial.tcpSocketHandles.has(handle));
|
|
14
|
+
const capacity = Math.max(0, options.currentPool.total - options.initialPool.total);
|
|
15
|
+
const newlyOwned = growthHandles.filter((handle) => options.ownedHandlesObserved.has(handle)).length;
|
|
16
|
+
const initialUnowned = [...options.initial.tcpSocketHandles].filter((handle) => !options.ownedHandlesObserved.has(handle));
|
|
17
|
+
const initialPending = options.currentPool.nonIdleOrConnecting > 0 && initialUnowned.length > 0;
|
|
18
|
+
const newPending = options.currentPool.nonIdleOrConnecting > 0 && newlyOwned < capacity;
|
|
19
|
+
const candidates = newPending
|
|
20
|
+
? growthHandles
|
|
21
|
+
: initialPending
|
|
22
|
+
? [...options.current.tcpSocketHandles].filter((handle) => options.initial.tcpSocketHandles.has(handle))
|
|
23
|
+
: [];
|
|
24
|
+
const handle = startPendingPoolSocketEpisode(candidates, options.ownedHandlesObserved) ??
|
|
25
|
+
options.previousHandle;
|
|
26
|
+
return {
|
|
27
|
+
handle,
|
|
28
|
+
inFlight: handle !== null &&
|
|
29
|
+
options.current.tcpSocketHandles.has(handle) &&
|
|
30
|
+
!options.ownedHandlesObserved.has(handle),
|
|
31
|
+
};
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* Records one fork-leak checkpoint from a handshake settlement. It counts the resources of the
|
|
35
|
+
* coalesced snapshot, or of the detector snapshot otherwise, and passes them to `record` (for
|
|
36
|
+
* example a fork leak detector's `record`) with the test file name. Returns what `record` returns.
|
|
37
|
+
*/
|
|
38
|
+
export function recordForkLeakCheckpoint(record, settlement, testFile) {
|
|
39
|
+
const checkpoint = settlement.coalesced ? settlement.snapshot : settlement.detectorSnapshot;
|
|
40
|
+
return record(countResourcesByType(checkpoint.resources), testFile);
|
|
41
|
+
}
|
|
42
|
+
export function handshakeSnapshot(resources, tcpSocketHandles, poolMetrics) {
|
|
43
|
+
const counts = countResourcesByType(resources);
|
|
44
|
+
return {
|
|
45
|
+
connectWraps: counts.get('ConnectWrap') ?? 0,
|
|
46
|
+
tcpSockets: counts.get('TCPSocketWrap') ?? 0,
|
|
47
|
+
resources,
|
|
48
|
+
tcpSocketHandles,
|
|
49
|
+
poolMetrics,
|
|
50
|
+
};
|
|
51
|
+
}
|
|
52
|
+
export function poolConnectionCounts(metrics) {
|
|
53
|
+
const counts = { total: 0, idle: 0, nonIdleOrConnecting: 0, waiting: 0 };
|
|
54
|
+
for (const pool of Object.values(metrics)) {
|
|
55
|
+
counts.total += pool.total;
|
|
56
|
+
counts.idle += pool.idle;
|
|
57
|
+
counts.nonIdleOrConnecting += pool.nonIdleOrConnecting;
|
|
58
|
+
counts.waiting += pool.waiting;
|
|
59
|
+
}
|
|
60
|
+
return counts;
|
|
61
|
+
}
|
|
62
|
+
export function samePoolCounts(previous, current) {
|
|
63
|
+
return (previous.total === current.total &&
|
|
64
|
+
previous.idle === current.idle &&
|
|
65
|
+
previous.nonIdleOrConnecting === current.nonIdleOrConnecting &&
|
|
66
|
+
previous.waiting === current.waiting);
|
|
67
|
+
}
|
|
68
|
+
export function handshakeSettled(previous, current) {
|
|
69
|
+
return (previous.connectWraps === current.connectWraps && previous.tcpSockets === current.tcpSockets);
|
|
70
|
+
}
|
|
71
|
+
export function rawDetectorCheckpoint(options) {
|
|
72
|
+
const firstUnresolvedSample = [...options.unownedGrowthSnapshots].find(([handle]) => !options.ownedHandlesObserved.has(handle))?.[1];
|
|
73
|
+
return firstUnresolvedSample ?? options.current;
|
|
74
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
export { formatActiveResources, formatProcessResources, formatResourceCounts, } from './vitest-process-resources.mts';
|
|
2
|
+
import { type ForkLeakHandshakeSnapshot, type PoolMetrics, type PoolSocketHandles } from './vitest-fork-leak-handshake-samples.mts';
|
|
3
|
+
export { recordForkLeakCheckpoint, type ForkLeakHandshakeSnapshot, } from './vitest-fork-leak-handshake-samples.mts';
|
|
4
|
+
export declare const FORK_LEAK_HANDSHAKE_STABLE_OBSERVATIONS = 2;
|
|
5
|
+
export declare const FORK_LEAK_HANDSHAKE_MAX_TURNS = 100;
|
|
6
|
+
export type ForkLeakHandshakeSettlement = {
|
|
7
|
+
snapshot: ForkLeakHandshakeSnapshot;
|
|
8
|
+
detectorSnapshot: ForkLeakHandshakeSnapshot;
|
|
9
|
+
observations: readonly ForkLeakHandshakeSnapshot[];
|
|
10
|
+
coalesced: boolean;
|
|
11
|
+
};
|
|
12
|
+
export declare function waitForForkLeakHandshakeSettle(options: {
|
|
13
|
+
readResources: () => readonly string[];
|
|
14
|
+
readPoolMetrics: () => PoolMetrics | null;
|
|
15
|
+
readPoolSocketHandles: () => PoolSocketHandles | null;
|
|
16
|
+
waitForTurn: () => Promise<void>;
|
|
17
|
+
stableObservations?: number;
|
|
18
|
+
maxTurns?: number;
|
|
19
|
+
}): Promise<ForkLeakHandshakeSettlement>;
|
|
@@ -0,0 +1,136 @@
|
|
|
1
|
+
export { formatActiveResources, formatProcessResources, formatResourceCounts, } from "./vitest-process-resources.mjs";
|
|
2
|
+
import { handshakeSettled, handshakeSnapshot, pendingPoolSocketEpisode, poolConnectionCounts, rawDetectorCheckpoint, samePoolCounts, } from "./vitest-fork-leak-handshake-samples.mjs";
|
|
3
|
+
export { recordForkLeakCheckpoint, } from "./vitest-fork-leak-handshake-samples.mjs";
|
|
4
|
+
// Two quiet event-loop turns settle a completed pool transition. The hard cap
|
|
5
|
+
// bounds slow handshakes; unresolved sockets retain their sampled history.
|
|
6
|
+
export const FORK_LEAK_HANDSHAKE_STABLE_OBSERVATIONS = 2;
|
|
7
|
+
export const FORK_LEAK_HANDSHAKE_MAX_TURNS = 100;
|
|
8
|
+
// A finite pool ramp is coalesced only when the async resource
|
|
9
|
+
// identities show that every new TCP socket belongs to a registered pool.
|
|
10
|
+
// Unowned or unresolved growth keeps its complete sample history for error
|
|
11
|
+
// diagnostics, while the detector receives only one real snapshot per test.
|
|
12
|
+
export async function waitForForkLeakHandshakeSettle(options) {
|
|
13
|
+
const waitForTurn = options.waitForTurn;
|
|
14
|
+
const stableObservations = options.stableObservations ?? FORK_LEAK_HANDSHAKE_STABLE_OBSERVATIONS;
|
|
15
|
+
const maxTurns = options.maxTurns ?? FORK_LEAK_HANDSHAKE_MAX_TURNS;
|
|
16
|
+
const initial = handshakeSnapshot(options.readResources(), options.readPoolSocketHandles()?.active ?? new Set(), options.readPoolMetrics());
|
|
17
|
+
if (initial.poolMetrics === null) {
|
|
18
|
+
return {
|
|
19
|
+
snapshot: initial,
|
|
20
|
+
detectorSnapshot: initial,
|
|
21
|
+
observations: [initial],
|
|
22
|
+
coalesced: false,
|
|
23
|
+
};
|
|
24
|
+
}
|
|
25
|
+
const initialPool = poolConnectionCounts(initial.poolMetrics);
|
|
26
|
+
const initialHandles = options.readPoolSocketHandles();
|
|
27
|
+
const probeMetrics = options.readPoolMetrics();
|
|
28
|
+
const probeHandles = options.readPoolSocketHandles();
|
|
29
|
+
const probe = handshakeSnapshot(options.readResources(), probeHandles?.active ?? new Set(), probeMetrics);
|
|
30
|
+
if (probeMetrics === null || probeHandles === null || initialHandles === null) {
|
|
31
|
+
return {
|
|
32
|
+
snapshot: probe,
|
|
33
|
+
detectorSnapshot: probe,
|
|
34
|
+
observations: [initial, probe],
|
|
35
|
+
coalesced: false,
|
|
36
|
+
};
|
|
37
|
+
}
|
|
38
|
+
const probePool = poolConnectionCounts(probeMetrics);
|
|
39
|
+
const poolTransitionPending = initialPool.nonIdleOrConnecting > 0 || probePool.total > initialPool.total;
|
|
40
|
+
if (!poolTransitionPending) {
|
|
41
|
+
return { snapshot: probe, detectorSnapshot: probe, observations: [probe], coalesced: false };
|
|
42
|
+
}
|
|
43
|
+
let previous = probe;
|
|
44
|
+
let previousPool = probePool;
|
|
45
|
+
let stable = 0;
|
|
46
|
+
const observations = [initial, probe];
|
|
47
|
+
const ownedHandlesObserved = new Set(probeHandles.owned);
|
|
48
|
+
const unownedGrowthSnapshots = new Map();
|
|
49
|
+
for (const handle of probe.tcpSocketHandles) {
|
|
50
|
+
if (!initial.tcpSocketHandles.has(handle) && !probeHandles.owned.has(handle)) {
|
|
51
|
+
unownedGrowthSnapshots.set(handle, probe);
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
let pendingEpisodeHandle = null;
|
|
55
|
+
for (let turn = 0; turn < maxTurns && stable < stableObservations; turn += 1) {
|
|
56
|
+
await waitForTurn();
|
|
57
|
+
const currentHandles = options.readPoolSocketHandles();
|
|
58
|
+
const currentMetrics = options.readPoolMetrics();
|
|
59
|
+
const current = handshakeSnapshot(options.readResources(), currentHandles?.active ?? new Set(), currentMetrics);
|
|
60
|
+
observations.push(current);
|
|
61
|
+
if (currentMetrics === null || currentHandles === null) {
|
|
62
|
+
return {
|
|
63
|
+
snapshot: current,
|
|
64
|
+
detectorSnapshot: rawDetectorCheckpoint({
|
|
65
|
+
current,
|
|
66
|
+
ownedHandlesObserved,
|
|
67
|
+
unownedGrowthSnapshots,
|
|
68
|
+
}),
|
|
69
|
+
observations,
|
|
70
|
+
coalesced: false,
|
|
71
|
+
};
|
|
72
|
+
}
|
|
73
|
+
for (const handle of currentHandles.owned)
|
|
74
|
+
ownedHandlesObserved.add(handle);
|
|
75
|
+
for (const handle of current.tcpSocketHandles) {
|
|
76
|
+
if (!initial.tcpSocketHandles.has(handle) &&
|
|
77
|
+
!currentHandles.owned.has(handle) &&
|
|
78
|
+
!unownedGrowthSnapshots.has(handle)) {
|
|
79
|
+
unownedGrowthSnapshots.set(handle, current);
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
const currentPool = poolConnectionCounts(currentMetrics);
|
|
83
|
+
stable =
|
|
84
|
+
handshakeSettled(previous, current) && samePoolCounts(previousPool, currentPool)
|
|
85
|
+
? stable + 1
|
|
86
|
+
: 0;
|
|
87
|
+
const pendingEpisode = pendingPoolSocketEpisode({
|
|
88
|
+
initial,
|
|
89
|
+
probe,
|
|
90
|
+
current,
|
|
91
|
+
initialPool,
|
|
92
|
+
currentPool,
|
|
93
|
+
ownedHandlesObserved,
|
|
94
|
+
previousHandle: pendingEpisodeHandle,
|
|
95
|
+
});
|
|
96
|
+
pendingEpisodeHandle = pendingEpisode.handle;
|
|
97
|
+
const pendingEpisodeInFlight = pendingEpisode.inFlight;
|
|
98
|
+
if (stable >= stableObservations && pendingEpisodeInFlight)
|
|
99
|
+
stable = 0;
|
|
100
|
+
previous = current;
|
|
101
|
+
previousPool = currentPool;
|
|
102
|
+
if (stable >= stableObservations) {
|
|
103
|
+
const initialTcpHandles = initial.tcpSocketHandles;
|
|
104
|
+
const observedGrowthHandles = new Set([...current.tcpSocketHandles].filter((handle) => !initialTcpHandles.has(handle)));
|
|
105
|
+
const tcpCountGrowth = current.tcpSockets - initial.tcpSockets;
|
|
106
|
+
const identitiesAccountForAllGrowth = observedGrowthHandles.size === tcpCountGrowth;
|
|
107
|
+
const unresolvedGrowthWasObserved = [...unownedGrowthSnapshots.keys()].some((handle) => !ownedHandlesObserved.has(handle));
|
|
108
|
+
const allGrowthIsPoolOwned = identitiesAccountForAllGrowth &&
|
|
109
|
+
!unresolvedGrowthWasObserved &&
|
|
110
|
+
[...observedGrowthHandles].every((handle) => currentHandles.owned.has(handle) || ownedHandlesObserved.has(handle));
|
|
111
|
+
const detectorSnapshot = rawDetectorCheckpoint({
|
|
112
|
+
current,
|
|
113
|
+
ownedHandlesObserved,
|
|
114
|
+
unownedGrowthSnapshots,
|
|
115
|
+
});
|
|
116
|
+
// A stable nonzero ConnectWrap may be a slow pool handshake under runner
|
|
117
|
+
// contention. Preserve it as raw evidence instead of treating it as done.
|
|
118
|
+
return {
|
|
119
|
+
snapshot: current,
|
|
120
|
+
detectorSnapshot,
|
|
121
|
+
observations,
|
|
122
|
+
coalesced: allGrowthIsPoolOwned && current.connectWraps === 0,
|
|
123
|
+
};
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
return {
|
|
127
|
+
snapshot: previous,
|
|
128
|
+
detectorSnapshot: rawDetectorCheckpoint({
|
|
129
|
+
current: previous,
|
|
130
|
+
ownedHandlesObserved,
|
|
131
|
+
unownedGrowthSnapshots,
|
|
132
|
+
}),
|
|
133
|
+
observations,
|
|
134
|
+
coalesced: false,
|
|
135
|
+
};
|
|
136
|
+
}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
export type DnsFn = (this: unknown, ...args: unknown[]) => unknown;
|
|
2
|
+
export type DnsAllowlistHooks = {
|
|
3
|
+
isAllowedHost: (host: string) => boolean;
|
|
4
|
+
blockDns: (host: string) => Error;
|
|
5
|
+
rememberAddresses: (value: unknown) => void;
|
|
6
|
+
};
|
|
7
|
+
export declare function patchDnsSurface(target: object | undefined, promises: boolean, hooks: DnsAllowlistHooks): void;
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
function isDnsQuery(name) {
|
|
2
|
+
return /^(lookup|lookupService|reverse|resolve)/.test(name);
|
|
3
|
+
}
|
|
4
|
+
function call(fn, ...args) {
|
|
5
|
+
;
|
|
6
|
+
fn(...args);
|
|
7
|
+
}
|
|
8
|
+
function wrapDns(original, promises, hooks) {
|
|
9
|
+
return function wrapped(...args) {
|
|
10
|
+
const host = typeof args[0] === 'string' ? args[0] : null;
|
|
11
|
+
const callback = args.at(-1);
|
|
12
|
+
if (host !== null && !hooks.isAllowedHost(host)) {
|
|
13
|
+
const error = hooks.blockDns(host);
|
|
14
|
+
if (!promises && typeof callback === 'function') {
|
|
15
|
+
queueMicrotask(() => call(callback, error));
|
|
16
|
+
return undefined;
|
|
17
|
+
}
|
|
18
|
+
if (promises)
|
|
19
|
+
return Promise.reject(error);
|
|
20
|
+
throw error;
|
|
21
|
+
}
|
|
22
|
+
if (!promises && typeof callback === 'function') {
|
|
23
|
+
const next = args.slice();
|
|
24
|
+
next[next.length - 1] = (err, value, ...rest) => {
|
|
25
|
+
if (!err)
|
|
26
|
+
hooks.rememberAddresses(value);
|
|
27
|
+
call(callback, err, value, ...rest);
|
|
28
|
+
};
|
|
29
|
+
return Reflect.apply(original, this, next);
|
|
30
|
+
}
|
|
31
|
+
const result = Reflect.apply(original, this, args);
|
|
32
|
+
if (!promises || result === null || typeof result !== 'object' || !('then' in result))
|
|
33
|
+
return result;
|
|
34
|
+
return result.then((value) => {
|
|
35
|
+
hooks.rememberAddresses(value);
|
|
36
|
+
return value;
|
|
37
|
+
});
|
|
38
|
+
};
|
|
39
|
+
}
|
|
40
|
+
export function patchDnsSurface(target, promises, hooks) {
|
|
41
|
+
if (!target)
|
|
42
|
+
return;
|
|
43
|
+
for (const key of Object.getOwnPropertyNames(target)) {
|
|
44
|
+
if (!isDnsQuery(key))
|
|
45
|
+
continue;
|
|
46
|
+
const descriptor = Object.getOwnPropertyDescriptor(target, key);
|
|
47
|
+
if (!descriptor || typeof descriptor.value !== 'function')
|
|
48
|
+
continue;
|
|
49
|
+
Object.defineProperty(target, key, {
|
|
50
|
+
...descriptor,
|
|
51
|
+
value: wrapDns(descriptor.value, promises, hooks),
|
|
52
|
+
});
|
|
53
|
+
}
|
|
54
|
+
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
export declare function normalizeHost(host: string): string;
|
|
2
|
+
export type HostAllowlist = {
|
|
3
|
+
isExempt: () => boolean;
|
|
4
|
+
allowedHosts: ReadonlySet<string>;
|
|
5
|
+
allowedIps: ReadonlySet<string>;
|
|
6
|
+
};
|
|
7
|
+
export declare function isAllowedHost(host: string, current: HostAllowlist): boolean;
|
|
8
|
+
export declare function rememberAddresses(value: unknown, ips: Set<string>): void;
|