vouchington-tooling 0.54.0 → 0.56.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 +23 -0
- package/dist/cli/index.mjs +2 -2
- package/dist/cli/optional-peer.d.mts +5 -0
- package/dist/cli/optional-peer.mjs +17 -0
- package/dist/cli/story-coverage-lazy.d.mts +3 -0
- package/dist/cli/story-coverage-lazy.mjs +6 -0
- package/dist/gh-api-shell-quoting/logical-line.mjs +14 -74
- package/dist/mcp-server/policy-run.d.mts +2 -0
- package/dist/mcp-server/policy-run.mjs +6 -2
- package/dist/mcp-server/policy-spawn.d.mts +1 -0
- package/dist/mcp-server/policy-spawn.mjs +10 -2
- package/dist/playwright/browser-errors.d.mts +3 -2
- package/dist/playwright/browser-test.d.mts +4 -3
- package/dist/playwright/index.d.mts +2 -0
- package/dist/playwright/monitored-test-info.d.mts +14 -0
- package/dist/playwright/monitored-test-info.mjs +1 -0
- package/dist/playwright/test-lifecycle-reporter.d.mts +17 -1
- package/dist/playwright/test-lifecycle-reporter.mjs +23 -1
- package/dist/retrospective-transcript/codex-records.mjs +4 -0
- package/dist/retrospective-transcript/command-prefix.d.mts +1 -0
- package/dist/retrospective-transcript/command-prefix.mjs +1 -1
- package/dist/retrospective-transcript/command-segments.d.mts +1 -1
- package/dist/retrospective-transcript/command-segments.mjs +3 -48
- package/dist/retrospective-transcript/escalations.d.mts +6 -0
- package/dist/retrospective-transcript/escalations.mjs +34 -0
- package/dist/retrospective-transcript/format.mjs +13 -0
- package/dist/retrospective-transcript/index.mjs +2 -1
- package/dist/retrospective-transcript/malformed-record.d.mts +1 -0
- package/dist/retrospective-transcript/malformed-record.mjs +13 -0
- package/dist/retrospective-transcript/shared.d.mts +2 -1
- package/dist/retrospective-transcript/shared.mjs +1 -12
- package/dist/shell-parse/index.d.mts +2 -0
- package/dist/shell-parse/index.mjs +2 -0
- package/dist/shell-parse/shell-command-segments.d.mts +6 -0
- package/dist/shell-parse/shell-command-segments.mjs +26 -0
- package/dist/shell-parse/shell-tokenizer-operators.d.mts +2 -4
- package/dist/shell-parse/shell-tokenizer-operators.mjs +14 -4
- package/dist/shell-parse/shell-tokenizer.d.mts +9 -5
- package/dist/shell-parse/shell-tokenizer.mjs +5 -1
- package/dist/shell-parse/shell-walk.d.mts +8 -0
- package/dist/shell-parse/shell-walk.mjs +62 -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 +5 -22
- package/dist/vitest-diagnostics/index.mjs +3 -123
- package/dist/vitest-diagnostics/report-summary.d.mts +22 -0
- package/dist/vitest-diagnostics/report-summary.mjs +123 -0
- package/dist/vitest-diagnostics/vitest-fork-leak-diagnostics.d.mts +9 -2
- package/dist/vitest-diagnostics/vitest-fork-leak-diagnostics.mjs +3 -2
- package/dist/vitest-diagnostics/vitest-fork-leak-handshake-samples.d.mts +5 -0
- package/dist/vitest-diagnostics/vitest-fork-leak-handshake-samples.mjs +5 -0
- package/dist/vitest-diagnostics/vitest-process-resources.d.mts +4 -0
- package/dist/vitest-diagnostics/vitest-process-resources.mjs +4 -1
- package/package.json +6 -1
- package/scripts/__pycache__/run_bounded_process.cpython-312.pyc +0 -0
|
@@ -16,6 +16,7 @@ export const emptyFacts = () => ({
|
|
|
16
16
|
tokens: emptyTokens(),
|
|
17
17
|
subagentToolCalls: 0,
|
|
18
18
|
subagentTokens: emptyTokens(),
|
|
19
|
+
escalations: [],
|
|
19
20
|
});
|
|
20
21
|
export function asRecord(value) {
|
|
21
22
|
return value !== null && typeof value === 'object' && !Array.isArray(value)
|
|
@@ -39,18 +40,6 @@ export function parseLines(lines) {
|
|
|
39
40
|
}
|
|
40
41
|
return records;
|
|
41
42
|
}
|
|
42
|
-
export function hasMalformedInteriorRecord(lines) {
|
|
43
|
-
const nonblank = lines.filter((line) => line.trim());
|
|
44
|
-
const complete = lines.at(-1)?.trim() ? nonblank.slice(0, -1) : nonblank;
|
|
45
|
-
return complete.some((line) => {
|
|
46
|
-
try {
|
|
47
|
-
return !asRecord(JSON.parse(line));
|
|
48
|
-
}
|
|
49
|
-
catch {
|
|
50
|
-
return true;
|
|
51
|
-
}
|
|
52
|
-
});
|
|
53
|
-
}
|
|
54
43
|
function hereDocs(tokens) {
|
|
55
44
|
return tokens.flatMap((token, index) => {
|
|
56
45
|
if (token.startsWith('<<<'))
|
|
@@ -18,3 +18,5 @@ export { stripUnquotedShellComments } from './shell-tokenizer-comments.mts';
|
|
|
18
18
|
export { consumeShellSeparator } from './shell-tokenizer-operators.mts';
|
|
19
19
|
export { tokenizeShellWords, tokenizeShellWordsDetailed } from './shell-tokenizer.mts';
|
|
20
20
|
export type { ShellWord } from './shell-tokenizer.mts';
|
|
21
|
+
export { walkUnquotedShell } from './shell-walk.mts';
|
|
22
|
+
export { splitCommandSegments } from './shell-command-segments.mts';
|
|
@@ -13,3 +13,5 @@ export { commandSegmentStart, isShellAssignment, isShellCommandSeparator, nextSh
|
|
|
13
13
|
export { stripUnquotedShellComments } from "./shell-tokenizer-comments.mjs";
|
|
14
14
|
export { consumeShellSeparator } from "./shell-tokenizer-operators.mjs";
|
|
15
15
|
export { tokenizeShellWords, tokenizeShellWordsDetailed } from "./shell-tokenizer.mjs";
|
|
16
|
+
export { walkUnquotedShell } from "./shell-walk.mjs";
|
|
17
|
+
export { splitCommandSegments } from "./shell-command-segments.mjs";
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Splits a command into segments on unquoted `;`, `&`, `&&`, `|`, `||`, and newlines, each segment
|
|
3
|
+
* being its already-unquoted words. Parentheses stay inside words (`$(git status)` is one word
|
|
4
|
+
* run, not a nested command), so only top-level command position is exposed.
|
|
5
|
+
*/
|
|
6
|
+
export declare function splitCommandSegments(command: string): string[][];
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { tokenizeShellWordsDetailed } from "./shell-tokenizer.mjs";
|
|
2
|
+
/**
|
|
3
|
+
* Splits a command into segments on unquoted `;`, `&`, `&&`, `|`, `||`, and newlines, each segment
|
|
4
|
+
* being its already-unquoted words. Parentheses stay inside words (`$(git status)` is one word
|
|
5
|
+
* run, not a nested command), so only top-level command position is exposed.
|
|
6
|
+
*/
|
|
7
|
+
export function splitCommandSegments(command) {
|
|
8
|
+
const segments = [];
|
|
9
|
+
let current = [];
|
|
10
|
+
for (const word of tokenizeShellWordsDetailed(command, {
|
|
11
|
+
keepParentheses: true,
|
|
12
|
+
markOperators: true,
|
|
13
|
+
})) {
|
|
14
|
+
if (word.operator === true) {
|
|
15
|
+
if (current.length > 0)
|
|
16
|
+
segments.push(current);
|
|
17
|
+
current = [];
|
|
18
|
+
}
|
|
19
|
+
else {
|
|
20
|
+
current.push(word.value);
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
if (current.length > 0)
|
|
24
|
+
segments.push(current);
|
|
25
|
+
return segments;
|
|
26
|
+
}
|
|
@@ -1,12 +1,10 @@
|
|
|
1
|
-
import type { ShellWord } from './shell-tokenizer.mts';
|
|
1
|
+
import type { ShellTokenizeOptions, ShellWord } from './shell-tokenizer.mts';
|
|
2
2
|
type SeparatorState = {
|
|
3
3
|
char: string;
|
|
4
4
|
command: string;
|
|
5
5
|
expandable: boolean;
|
|
6
6
|
index: number;
|
|
7
|
-
options:
|
|
8
|
-
splitRedirections?: boolean;
|
|
9
|
-
};
|
|
7
|
+
options: ShellTokenizeOptions;
|
|
10
8
|
token: string;
|
|
11
9
|
tokens: ShellWord[];
|
|
12
10
|
};
|
|
@@ -29,17 +29,27 @@ export function consumeShellSeparator(state) {
|
|
|
29
29
|
return state.index + redirectionOperator.length - 1;
|
|
30
30
|
}
|
|
31
31
|
const { char } = state;
|
|
32
|
-
|
|
32
|
+
const isParenthesis = char === '(' || char === ')';
|
|
33
|
+
if (char === '&' ||
|
|
34
|
+
char === '|' ||
|
|
35
|
+
char === ';' ||
|
|
36
|
+
(isParenthesis && !state.options.keepParentheses)) {
|
|
33
37
|
pushStateToken(state);
|
|
34
|
-
const
|
|
35
|
-
|
|
38
|
+
const operator = state.options.markOperators ? { operator: true } : {};
|
|
39
|
+
const previous = state.tokens.at(-1);
|
|
40
|
+
const previousToken = previous?.value;
|
|
41
|
+
// With `markOperators` a quoted `"|"` argument is not an operator, so only operators merge.
|
|
42
|
+
const mergeable = state.options.markOperators !== true || previous?.operator === true;
|
|
43
|
+
if (mergeable &&
|
|
44
|
+
((char === '&' && previousToken === '&') || (char === '|' && previousToken === '|'))) {
|
|
36
45
|
state.tokens[state.tokens.length - 1] = {
|
|
37
46
|
expandable: false,
|
|
47
|
+
...operator,
|
|
38
48
|
value: `${previousToken}${char}`,
|
|
39
49
|
};
|
|
40
50
|
}
|
|
41
51
|
else {
|
|
42
|
-
state.tokens.push({ expandable: false, value: char });
|
|
52
|
+
state.tokens.push({ expandable: false, ...operator, value: char });
|
|
43
53
|
}
|
|
44
54
|
return state.index;
|
|
45
55
|
}
|
|
@@ -1,12 +1,16 @@
|
|
|
1
1
|
import { stripUnquotedShellComments } from './shell-tokenizer-comments.mts';
|
|
2
2
|
export type ShellWord = {
|
|
3
3
|
expandable: boolean;
|
|
4
|
+
operator?: true;
|
|
4
5
|
value: string;
|
|
5
6
|
};
|
|
6
|
-
export
|
|
7
|
+
export type ShellTokenizeOptions = {
|
|
8
|
+
/** Keep `(` and `)` inside words instead of emitting them as operator tokens. */
|
|
9
|
+
keepParentheses?: boolean;
|
|
10
|
+
/** Tag command-separator tokens (`;`, `&`, `&&`, `|`, `||`, `(`, `)`, newline) with `operator`. */
|
|
11
|
+
markOperators?: boolean;
|
|
7
12
|
splitRedirections?: boolean;
|
|
8
|
-
}
|
|
9
|
-
export declare function
|
|
10
|
-
|
|
11
|
-
}): string[];
|
|
13
|
+
};
|
|
14
|
+
export declare function tokenizeShellWordsDetailed(command: string, options?: ShellTokenizeOptions): ShellWord[];
|
|
15
|
+
export declare function tokenizeShellWords(command: string, options?: ShellTokenizeOptions): string[];
|
|
12
16
|
export { stripUnquotedShellComments };
|
|
@@ -64,7 +64,11 @@ export function tokenizeShellWordsDetailed(command, options = {}) {
|
|
|
64
64
|
}
|
|
65
65
|
if (char === '\n') {
|
|
66
66
|
pushToken();
|
|
67
|
-
tokens.push({
|
|
67
|
+
tokens.push({
|
|
68
|
+
expandable: false,
|
|
69
|
+
value: '\n',
|
|
70
|
+
...(options.markOperators ? { operator: true } : {}),
|
|
71
|
+
});
|
|
68
72
|
continue;
|
|
69
73
|
}
|
|
70
74
|
if (/\s/.test(char)) {
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Calls `visit(index, state)` for every character outside quotes, escapes, comments, and the
|
|
3
|
+
* structural `$(` / `(` / `)` of a substitution. `state` belongs to the current `$(...)` level. The
|
|
4
|
+
* visitor returns the next index to consume from, or `undefined` to advance by one. Backslash
|
|
5
|
+
* escapes consume the following character, even inside double quotes, and a `#` at the start or
|
|
6
|
+
* after whitespace ends the text.
|
|
7
|
+
*/
|
|
8
|
+
export declare function walkUnquotedShell<State>(text: string, createState: () => State, visit: (index: number, state: State) => number | undefined): void;
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
// A quote-aware walk over shell text for callers that need per-character positions rather than
|
|
2
|
+
// tokens (for example to report offsets). It tracks single and double quotes, backslash escapes,
|
|
3
|
+
// unquoted `#` comments, and `$(...)` nesting, giving each nesting level its own caller-defined
|
|
4
|
+
// state. Unlike `tokenizeShellWordsDetailed` it never classifies expansion or glob characters, so a
|
|
5
|
+
// quoted `"...${VAR}...?x=1"` yields no unquoted `?` to the visitor.
|
|
6
|
+
function newFrame(state, parenDepth) {
|
|
7
|
+
return { inSingleQuote: false, inDoubleQuote: false, parenDepth, state };
|
|
8
|
+
}
|
|
9
|
+
/**
|
|
10
|
+
* Calls `visit(index, state)` for every character outside quotes, escapes, comments, and the
|
|
11
|
+
* structural `$(` / `(` / `)` of a substitution. `state` belongs to the current `$(...)` level. The
|
|
12
|
+
* visitor returns the next index to consume from, or `undefined` to advance by one. Backslash
|
|
13
|
+
* escapes consume the following character, even inside double quotes, and a `#` at the start or
|
|
14
|
+
* after whitespace ends the text.
|
|
15
|
+
*/
|
|
16
|
+
export function walkUnquotedShell(text, createState, visit) {
|
|
17
|
+
const stack = [newFrame(createState(), 0)];
|
|
18
|
+
let i = 0;
|
|
19
|
+
while (i < text.length) {
|
|
20
|
+
const frame = stack[stack.length - 1];
|
|
21
|
+
const char = text[i];
|
|
22
|
+
if (frame.inSingleQuote) {
|
|
23
|
+
if (char === "'")
|
|
24
|
+
frame.inSingleQuote = false;
|
|
25
|
+
i += 1;
|
|
26
|
+
continue;
|
|
27
|
+
}
|
|
28
|
+
if (char === '\\') {
|
|
29
|
+
i += 2;
|
|
30
|
+
continue;
|
|
31
|
+
}
|
|
32
|
+
if (char === '$' && text[i + 1] === '(') {
|
|
33
|
+
stack.push(newFrame(createState(), 1));
|
|
34
|
+
i += 2;
|
|
35
|
+
continue;
|
|
36
|
+
}
|
|
37
|
+
if (frame.inDoubleQuote) {
|
|
38
|
+
if (char === '"')
|
|
39
|
+
frame.inDoubleQuote = false;
|
|
40
|
+
i += 1;
|
|
41
|
+
continue;
|
|
42
|
+
}
|
|
43
|
+
if (char === '#' && (i === 0 || /\s/.test(text[i - 1])))
|
|
44
|
+
break;
|
|
45
|
+
if (char === "'" || char === '"') {
|
|
46
|
+
if (char === "'")
|
|
47
|
+
frame.inSingleQuote = true;
|
|
48
|
+
else
|
|
49
|
+
frame.inDoubleQuote = true;
|
|
50
|
+
i += 1;
|
|
51
|
+
continue;
|
|
52
|
+
}
|
|
53
|
+
if (stack.length > 1 && (char === '(' || char === ')')) {
|
|
54
|
+
frame.parenDepth += char === '(' ? 1 : -1;
|
|
55
|
+
i += 1;
|
|
56
|
+
if (frame.parenDepth === 0)
|
|
57
|
+
stack.pop();
|
|
58
|
+
continue;
|
|
59
|
+
}
|
|
60
|
+
i = visit(i, frame.state) ?? i + 1;
|
|
61
|
+
}
|
|
62
|
+
}
|
|
@@ -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";
|
|
@@ -10,28 +10,11 @@ export { consumeTestNetworkAllowlistViolation, installTestNetworkAllowlist, } fr
|
|
|
10
10
|
export type { TestNetworkAllowlistOptions } from './vitest-network-allowlist.mts';
|
|
11
11
|
export { getRegisteredPoolMetrics, getRegisteredPoolSocketHandles, } from './vitest-fork-leak-diagnostics.mts';
|
|
12
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';
|
|
13
15
|
export type { ForkLeakHandshakeSettlement } from './vitest-fork-leak-handshake.mts';
|
|
14
16
|
export type { PoolMetrics, PoolSocketHandles } from './vitest-fork-leak-handshake-samples.mts';
|
|
17
|
+
export type { ForkLeakDiagnosticsOptions } from './vitest-fork-leak-diagnostics.mts';
|
|
15
18
|
export type { ForkLeakDetector, ForkLeakDetectorOptions, ForkLeakVerdict, } from './vitest-fork-leak-detection.mts';
|
|
16
|
-
export { MAX_DIAGNOSTIC_REPORT_BYTES } from './
|
|
17
|
-
export
|
|
18
|
-
export declare const DEFAULT_MAX_FORMATTED_DIAGNOSTIC_REPORTS = 20;
|
|
19
|
-
export declare const HARD_MAX_DIAGNOSTIC_REPORTS = 100;
|
|
20
|
-
export { HARD_MAX_DIAGNOSTIC_DIRECTORY_ENTRIES } from './directory.mts';
|
|
21
|
-
export interface DiagnosticReportSummary {
|
|
22
|
-
file: string;
|
|
23
|
-
trigger: string;
|
|
24
|
-
event: string;
|
|
25
|
-
threadId: number | null;
|
|
26
|
-
heapUsedMB: string;
|
|
27
|
-
heapTotalMB: string;
|
|
28
|
-
heapLimitMB: string;
|
|
29
|
-
maxRssMB: string;
|
|
30
|
-
topNativeFrameModule: string | null;
|
|
31
|
-
}
|
|
32
|
-
export interface DiagnosticReportLimitOptions {
|
|
33
|
-
maxReports?: number;
|
|
34
|
-
}
|
|
35
|
-
export declare function summarizeDiagnosticReport(file: string, report: unknown): DiagnosticReportSummary;
|
|
36
|
-
export declare function readDiagnosticReportSummaries(directory: string, options?: DiagnosticReportLimitOptions): DiagnosticReportSummary[];
|
|
37
|
-
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,4 +1,3 @@
|
|
|
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";
|
|
@@ -7,125 +6,6 @@ export { checkAndRestoreFakeTimers, formatFakeTimerLeakDiagnostics, } from "./vi
|
|
|
7
6
|
export { consumeTestNetworkAllowlistViolation, installTestNetworkAllowlist, } from "./vitest-network-allowlist.mjs";
|
|
8
7
|
export { getRegisteredPoolMetrics, getRegisteredPoolSocketHandles, } from "./vitest-fork-leak-diagnostics.mjs";
|
|
9
8
|
export { FORK_LEAK_HANDSHAKE_MAX_TURNS, FORK_LEAK_HANDSHAKE_STABLE_OBSERVATIONS, formatActiveResources, formatProcessResources, formatResourceCounts, waitForForkLeakHandshakeSettle, } from "./vitest-fork-leak-handshake.mjs";
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
export { MAX_DIAGNOSTIC_REPORT_BYTES } from "./
|
|
13
|
-
export const DEFAULT_MAX_DIAGNOSTIC_REPORTS = 100;
|
|
14
|
-
export const DEFAULT_MAX_FORMATTED_DIAGNOSTIC_REPORTS = 20;
|
|
15
|
-
export const HARD_MAX_DIAGNOSTIC_REPORTS = 100;
|
|
16
|
-
export { HARD_MAX_DIAGNOSTIC_DIRECTORY_ENTRIES } from "./directory.mjs";
|
|
17
|
-
const TEXT_LIMIT = 200;
|
|
18
|
-
const PATH_LIMIT = 240;
|
|
19
|
-
function objectValue(value) {
|
|
20
|
-
return typeof value === 'object' && value !== null && !Array.isArray(value)
|
|
21
|
-
? value
|
|
22
|
-
: {};
|
|
23
|
-
}
|
|
24
|
-
function boundedText(value, fallback, limit) {
|
|
25
|
-
if (typeof value !== 'string')
|
|
26
|
-
return fallback;
|
|
27
|
-
const normalized = value
|
|
28
|
-
.slice(0, limit * 4)
|
|
29
|
-
.replace(/[\p{Cc}\p{Cf}]/gu, ' ')
|
|
30
|
-
.replace(/\s+/g, ' ')
|
|
31
|
-
.trim();
|
|
32
|
-
return normalized.length === 0 ? fallback : normalized.slice(0, limit);
|
|
33
|
-
}
|
|
34
|
-
function formatMebibytes(value) {
|
|
35
|
-
const bytes = typeof value === 'number' && Number.isFinite(value) && value >= 0 ? value : 0;
|
|
36
|
-
return (bytes / 1024 / 1024).toFixed(1);
|
|
37
|
-
}
|
|
38
|
-
function threadId(value) {
|
|
39
|
-
return typeof value === 'number' && Number.isSafeInteger(value) && value >= 0 ? value : null;
|
|
40
|
-
}
|
|
41
|
-
function nativeModulePath(value) {
|
|
42
|
-
const module = boundedText(value, '', PATH_LIMIT);
|
|
43
|
-
return posix.isAbsolute(module) || win32.isAbsolute(module) ? module : null;
|
|
44
|
-
}
|
|
45
|
-
function topNativeFrameModule(value) {
|
|
46
|
-
if (!Array.isArray(value))
|
|
47
|
-
return null;
|
|
48
|
-
const symbol = objectValue(value[0]).symbol;
|
|
49
|
-
if (typeof symbol !== 'string')
|
|
50
|
-
return null;
|
|
51
|
-
const tail = symbol.slice(-PATH_LIMIT * 2).trimEnd();
|
|
52
|
-
if (!tail.endsWith(']'))
|
|
53
|
-
return null;
|
|
54
|
-
const opening = tail.lastIndexOf('[');
|
|
55
|
-
if (opening < 0)
|
|
56
|
-
return null;
|
|
57
|
-
return nativeModulePath(tail.slice(opening + 1, -1));
|
|
58
|
-
}
|
|
59
|
-
function reportLimit(value, fallback) {
|
|
60
|
-
if (value === undefined)
|
|
61
|
-
return fallback;
|
|
62
|
-
if (!Number.isFinite(value))
|
|
63
|
-
return fallback;
|
|
64
|
-
return Math.min(Math.max(Math.floor(value), 0), HARD_MAX_DIAGNOSTIC_REPORTS);
|
|
65
|
-
}
|
|
66
|
-
export function summarizeDiagnosticReport(file, report) {
|
|
67
|
-
const root = objectValue(report);
|
|
68
|
-
const header = objectValue(root.header);
|
|
69
|
-
const heap = objectValue(root.javascriptHeap);
|
|
70
|
-
const resourceUsage = objectValue(root.resourceUsage);
|
|
71
|
-
return {
|
|
72
|
-
file: boundedText(file, 'unknown', PATH_LIMIT),
|
|
73
|
-
trigger: boundedText(header.trigger, 'unknown', TEXT_LIMIT),
|
|
74
|
-
event: boundedText(header.event, 'unknown', TEXT_LIMIT),
|
|
75
|
-
threadId: threadId(header.threadId),
|
|
76
|
-
heapUsedMB: formatMebibytes(heap.usedMemory),
|
|
77
|
-
heapTotalMB: formatMebibytes(heap.totalMemory),
|
|
78
|
-
heapLimitMB: formatMebibytes(heap.memoryLimit),
|
|
79
|
-
maxRssMB: formatMebibytes(resourceUsage.maxRss),
|
|
80
|
-
topNativeFrameModule: topNativeFrameModule(root.nativeStack),
|
|
81
|
-
};
|
|
82
|
-
}
|
|
83
|
-
export function readDiagnosticReportSummaries(directory, options = {}) {
|
|
84
|
-
const maxReports = reportLimit(options.maxReports, DEFAULT_MAX_DIAGNOSTIC_REPORTS);
|
|
85
|
-
if (maxReports === 0)
|
|
86
|
-
return [];
|
|
87
|
-
const reportsDirectory = readDiagnosticReportDirectory(directory);
|
|
88
|
-
if (reportsDirectory === undefined)
|
|
89
|
-
return [];
|
|
90
|
-
const filenames = reportsDirectory.filenames.sort();
|
|
91
|
-
const selected = filenames.slice(-maxReports);
|
|
92
|
-
const summaries = [];
|
|
93
|
-
for (const filename of selected) {
|
|
94
|
-
try {
|
|
95
|
-
if (!isDiagnosticReportDirectoryCurrent(directory, reportsDirectory.identity))
|
|
96
|
-
return [];
|
|
97
|
-
const contents = readBoundedRegularFile(join(directory, filename));
|
|
98
|
-
if (!isDiagnosticReportDirectoryCurrent(directory, reportsDirectory.identity))
|
|
99
|
-
return [];
|
|
100
|
-
if (contents === undefined)
|
|
101
|
-
continue;
|
|
102
|
-
const report = JSON.parse(contents);
|
|
103
|
-
summaries.push(summarizeDiagnosticReport(filename, report));
|
|
104
|
-
}
|
|
105
|
-
catch {
|
|
106
|
-
// Node can leave a partial report if the process exits while writing it.
|
|
107
|
-
}
|
|
108
|
-
}
|
|
109
|
-
return summaries;
|
|
110
|
-
}
|
|
111
|
-
export function formatDiagnosticReportSummaries(summaries, options = {}) {
|
|
112
|
-
const maxReports = reportLimit(options.maxReports, DEFAULT_MAX_FORMATTED_DIAGNOSTIC_REPORTS);
|
|
113
|
-
const lines = ['[vitest-diagnostics]', `reports provided: ${summaries.length}`];
|
|
114
|
-
if (summaries.length === 0)
|
|
115
|
-
lines.push(' (none recorded)');
|
|
116
|
-
for (const value of summaries.slice(0, maxReports)) {
|
|
117
|
-
const summary = objectValue(value);
|
|
118
|
-
lines.push(` - file=${boundedText(summary.file, 'unknown', PATH_LIMIT)} ` +
|
|
119
|
-
`trigger=${boundedText(summary.trigger, 'unknown', TEXT_LIMIT)} ` +
|
|
120
|
-
`event=${boundedText(summary.event, 'unknown', TEXT_LIMIT)} ` +
|
|
121
|
-
`threadId=${threadId(summary.threadId) ?? 'unknown'} ` +
|
|
122
|
-
`heapUsedMB=${boundedText(summary.heapUsedMB, '0.0', TEXT_LIMIT)} ` +
|
|
123
|
-
`heapTotalMB=${boundedText(summary.heapTotalMB, '0.0', TEXT_LIMIT)} ` +
|
|
124
|
-
`heapLimitMB=${boundedText(summary.heapLimitMB, '0.0', TEXT_LIMIT)} ` +
|
|
125
|
-
`maxRssMB=${boundedText(summary.maxRssMB, '0.0', TEXT_LIMIT)} ` +
|
|
126
|
-
`topNativeFrameModule=${nativeModulePath(summary.topNativeFrameModule) ?? 'none'}`);
|
|
127
|
-
}
|
|
128
|
-
if (summaries.length > maxReports)
|
|
129
|
-
lines.push(` ... ${summaries.length - maxReports} more`);
|
|
130
|
-
return `${lines.join('\n')}\n`;
|
|
131
|
-
}
|
|
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";
|
|
@@ -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
|
+
}
|
|
@@ -6,7 +6,14 @@ type PoolSocketHandles = {
|
|
|
6
6
|
};
|
|
7
7
|
export declare function getRegisteredPoolMetrics(): PoolMetrics | null;
|
|
8
8
|
export declare function getRegisteredPoolSocketHandles(): PoolSocketHandles | null;
|
|
9
|
-
|
|
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
|
+
*/
|
|
10
17
|
export declare function formatForkLeakDiagnostics(verdict: ForkLeakVerdict): string;
|
|
11
|
-
export declare function formatForkLeakDiagnostics(verdict: ForkLeakVerdict, counts: ReadonlyMap<string, number>, poolMetrics?: PoolMetrics | null): string;
|
|
18
|
+
export declare function formatForkLeakDiagnostics(verdict: ForkLeakVerdict, counts: ReadonlyMap<string, number>, poolMetrics?: PoolMetrics | null, options?: ForkLeakDiagnosticsOptions): string;
|
|
12
19
|
export {};
|
|
@@ -9,7 +9,8 @@ export function getRegisteredPoolSocketHandles() {
|
|
|
9
9
|
const provider = globalThis[POOL_SOCKETS_KEY];
|
|
10
10
|
return provider?.() ?? null;
|
|
11
11
|
}
|
|
12
|
-
|
|
12
|
+
const DEFAULT_POOL_METRICS_LABEL = 'pool metrics:';
|
|
13
|
+
export function formatForkLeakDiagnostics(verdict, counts, poolMetrics, options = {}) {
|
|
13
14
|
if (counts === undefined)
|
|
14
15
|
return formatForkLeakSummary(verdict);
|
|
15
16
|
return [
|
|
@@ -23,7 +24,7 @@ export function formatForkLeakDiagnostics(verdict, counts, poolMetrics) {
|
|
|
23
24
|
`suspected growth file: ${verdict.suspectedGrowth?.testFile ?? 'unknown'}`,
|
|
24
25
|
`largest growth step: ${formatGrowthStep(verdict.suspectedGrowth)}`,
|
|
25
26
|
`tracked resource counts: ${formatResourceCounts(counts)}`,
|
|
26
|
-
|
|
27
|
+
`${options.poolMetricsLabel ?? DEFAULT_POOL_METRICS_LABEL} ${formatPoolMetrics(poolMetrics ?? null)}`,
|
|
27
28
|
].join('\n');
|
|
28
29
|
}
|
|
29
30
|
function formatForkLeakSummary(verdict) {
|
|
@@ -28,6 +28,11 @@ export type ForkLeakHandshakeSnapshot = {
|
|
|
28
28
|
tcpSocketHandles: ReadonlySet<object>;
|
|
29
29
|
poolMetrics: PoolMetrics | null;
|
|
30
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
|
+
*/
|
|
31
36
|
export declare function recordForkLeakCheckpoint<T>(record: (counts: ReadonlyMap<string, number>, testFile: string) => T[], settlement: {
|
|
32
37
|
snapshot: ForkLeakHandshakeSnapshot;
|
|
33
38
|
detectorSnapshot: ForkLeakHandshakeSnapshot;
|
|
@@ -30,6 +30,11 @@ export function pendingPoolSocketEpisode(options) {
|
|
|
30
30
|
!options.ownedHandlesObserved.has(handle),
|
|
31
31
|
};
|
|
32
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
|
+
*/
|
|
33
38
|
export function recordForkLeakCheckpoint(record, settlement, testFile) {
|
|
34
39
|
const checkpoint = settlement.coalesced ? settlement.snapshot : settlement.detectorSnapshot;
|
|
35
40
|
return record(countResourcesByType(checkpoint.resources), testFile);
|
|
@@ -1,5 +1,9 @@
|
|
|
1
1
|
export declare function formatProcessResources(): string;
|
|
2
2
|
export declare function formatActiveResources(): string;
|
|
3
|
+
/**
|
|
4
|
+
* Counts how many times each resource type appears, such as the names returned by
|
|
5
|
+
* `process.getActiveResourcesInfo()`. Pass the result to a fork leak detector's `record`.
|
|
6
|
+
*/
|
|
3
7
|
export declare function countResourcesByType(resources: readonly string[]): Map<string, number>;
|
|
4
8
|
export declare function formatResourceCounts(counts: ReadonlyMap<string, number>): string;
|
|
5
9
|
export declare function formatBytes(bytes: number): string;
|
|
@@ -24,7 +24,10 @@ export function formatActiveResources() {
|
|
|
24
24
|
return '(none)';
|
|
25
25
|
return resources.slice(0, 20).join(', ');
|
|
26
26
|
}
|
|
27
|
-
|
|
27
|
+
/**
|
|
28
|
+
* Counts how many times each resource type appears, such as the names returned by
|
|
29
|
+
* `process.getActiveResourcesInfo()`. Pass the result to a fork leak detector's `record`.
|
|
30
|
+
*/
|
|
28
31
|
export function countResourcesByType(resources) {
|
|
29
32
|
const counts = new Map();
|
|
30
33
|
for (const resource of resources) {
|