@elench/testkit 0.1.112 → 0.1.114
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/lib/bundler/index.mjs +95 -1
- package/lib/cli/components/blocks/run-tree.mjs +28 -63
- package/lib/cli/renderers/run/inline-detail.mjs +64 -0
- package/lib/cli/state/run/model.mjs +24 -95
- package/lib/cli/state/run/state.mjs +0 -22
- package/lib/playwright/index.d.ts +1 -0
- package/lib/playwright/index.mjs +1 -0
- package/lib/runner/default-runtime-runner.mjs +8 -29
- package/lib/runner/failure-details.mjs +22 -0
- package/lib/runner/lifecycle.mjs +2 -51
- package/lib/runner/managed-processes.mjs +2 -1
- package/lib/runner/playwright-config.mjs +13 -1
- package/lib/runner/playwright-runner.mjs +85 -15
- package/lib/runner/processes.mjs +59 -3
- package/lib/runner/results.mjs +31 -0
- package/lib/runner/subprocess.mjs +155 -0
- package/lib/shared/file-timeout.mjs +1 -1
- package/lib/ui/index.d.ts +2 -0
- package/lib/ui/index.mjs +1 -0
- package/node_modules/@elench/next-analysis/package.json +1 -1
- package/node_modules/@elench/testkit-bridge/package.json +2 -2
- package/node_modules/@elench/testkit-protocol/package.json +1 -1
- package/node_modules/@elench/ts-analysis/package.json +1 -1
- package/package.json +5 -5
- package/lib/cli/components/primitives/filter-bar.mjs +0 -12
- package/lib/cli/state/tree/fuzzy-match.mjs +0 -106
|
@@ -0,0 +1,155 @@
|
|
|
1
|
+
import { execa } from "execa";
|
|
2
|
+
import { killProcessTree, sleep } from "./processes.mjs";
|
|
3
|
+
|
|
4
|
+
const DEFAULT_TERMINATION_GRACE_MS = 5_000;
|
|
5
|
+
|
|
6
|
+
export function startManagedSubprocess(command, args = [], options = {}) {
|
|
7
|
+
const detached = options.detached ?? process.platform !== "win32";
|
|
8
|
+
return execa(command, args, {
|
|
9
|
+
...options,
|
|
10
|
+
detached,
|
|
11
|
+
reject: false,
|
|
12
|
+
forceKillAfterDelay: options.forceKillAfterDelay ?? DEFAULT_TERMINATION_GRACE_MS,
|
|
13
|
+
});
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export async function settleManagedSubprocess(
|
|
17
|
+
subprocess,
|
|
18
|
+
{
|
|
19
|
+
timeoutMs,
|
|
20
|
+
gracefulSignal = "SIGTERM",
|
|
21
|
+
forceSignal = "SIGKILL",
|
|
22
|
+
terminationGraceMs = DEFAULT_TERMINATION_GRACE_MS,
|
|
23
|
+
} = {}
|
|
24
|
+
) {
|
|
25
|
+
const normalizedTimeoutMs = normalizePositiveInteger(timeoutMs, "timeoutMs");
|
|
26
|
+
const normalizedGraceMs = normalizePositiveInteger(terminationGraceMs, "terminationGraceMs");
|
|
27
|
+
const startedAt = Date.now();
|
|
28
|
+
let timeoutHandle = null;
|
|
29
|
+
let timeoutStarted = false;
|
|
30
|
+
let terminationPromise = null;
|
|
31
|
+
|
|
32
|
+
try {
|
|
33
|
+
const completed = await Promise.race([
|
|
34
|
+
subprocess.then(
|
|
35
|
+
async (result) => {
|
|
36
|
+
if (!timeoutStarted) return { result, timedOut: false, termination: null };
|
|
37
|
+
const termination = terminationPromise ? await terminationPromise : null;
|
|
38
|
+
return { result, timedOut: true, termination };
|
|
39
|
+
},
|
|
40
|
+
async (error) => {
|
|
41
|
+
const result = normalizeSubprocessError(error);
|
|
42
|
+
if (!timeoutStarted) return { result, timedOut: false, termination: null };
|
|
43
|
+
const termination = terminationPromise ? await terminationPromise : null;
|
|
44
|
+
return { result, timedOut: true, termination };
|
|
45
|
+
}
|
|
46
|
+
),
|
|
47
|
+
new Promise((resolve) => {
|
|
48
|
+
timeoutHandle = setTimeout(async () => {
|
|
49
|
+
timeoutStarted = true;
|
|
50
|
+
terminationPromise = terminateSubprocess(subprocess, {
|
|
51
|
+
gracefulSignal,
|
|
52
|
+
forceSignal,
|
|
53
|
+
terminationGraceMs: normalizedGraceMs,
|
|
54
|
+
});
|
|
55
|
+
const termination = await terminationPromise;
|
|
56
|
+
resolve({
|
|
57
|
+
result: termination.result,
|
|
58
|
+
timedOut: true,
|
|
59
|
+
termination,
|
|
60
|
+
});
|
|
61
|
+
}, normalizedTimeoutMs);
|
|
62
|
+
}),
|
|
63
|
+
]);
|
|
64
|
+
|
|
65
|
+
return {
|
|
66
|
+
...completed,
|
|
67
|
+
durationMs: Date.now() - startedAt,
|
|
68
|
+
};
|
|
69
|
+
} finally {
|
|
70
|
+
if (timeoutHandle) clearTimeout(timeoutHandle);
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
export async function terminateSubprocess(
|
|
75
|
+
subprocess,
|
|
76
|
+
{
|
|
77
|
+
gracefulSignal = "SIGTERM",
|
|
78
|
+
forceSignal = "SIGKILL",
|
|
79
|
+
terminationGraceMs = DEFAULT_TERMINATION_GRACE_MS,
|
|
80
|
+
} = {}
|
|
81
|
+
) {
|
|
82
|
+
const normalizedGraceMs = normalizePositiveInteger(terminationGraceMs, "terminationGraceMs");
|
|
83
|
+
const gracefulAt = Date.now();
|
|
84
|
+
killProcessTree(subprocess?.pid, gracefulSignal);
|
|
85
|
+
|
|
86
|
+
const gracefulResult = await waitForSubprocess(subprocess, normalizedGraceMs);
|
|
87
|
+
if (gracefulResult.settled) {
|
|
88
|
+
return {
|
|
89
|
+
gracefulSignal,
|
|
90
|
+
forceSignal: null,
|
|
91
|
+
forced: false,
|
|
92
|
+
durationMs: Date.now() - gracefulAt,
|
|
93
|
+
result: gracefulResult.result,
|
|
94
|
+
};
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
killProcessTree(subprocess?.pid, forceSignal);
|
|
98
|
+
const forcedResult = await waitForSubprocess(subprocess, normalizedGraceMs);
|
|
99
|
+
return {
|
|
100
|
+
gracefulSignal,
|
|
101
|
+
forceSignal,
|
|
102
|
+
forced: true,
|
|
103
|
+
durationMs: Date.now() - gracefulAt,
|
|
104
|
+
result: forcedResult.settled
|
|
105
|
+
? forcedResult.result
|
|
106
|
+
: syntheticKilledResult(subprocess, forceSignal),
|
|
107
|
+
};
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
async function waitForSubprocess(subprocess, timeoutMs) {
|
|
111
|
+
if (!subprocess) {
|
|
112
|
+
return { settled: true, result: syntheticKilledResult(null, "SIGKILL") };
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
const result = await Promise.race([
|
|
116
|
+
subprocess.then(
|
|
117
|
+
(value) => ({ settled: true, result: value }),
|
|
118
|
+
(error) => ({ settled: true, result: normalizeSubprocessError(error) })
|
|
119
|
+
),
|
|
120
|
+
sleep(timeoutMs).then(() => ({ settled: false, result: null })),
|
|
121
|
+
]);
|
|
122
|
+
return result;
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
function syntheticKilledResult(subprocess, signal) {
|
|
126
|
+
return {
|
|
127
|
+
command: subprocess?.command || null,
|
|
128
|
+
escapedCommand: subprocess?.escapedCommand || null,
|
|
129
|
+
exitCode: null,
|
|
130
|
+
signal,
|
|
131
|
+
stdout: "",
|
|
132
|
+
stderr: "",
|
|
133
|
+
timedOut: true,
|
|
134
|
+
failed: true,
|
|
135
|
+
killed: true,
|
|
136
|
+
};
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
function normalizeSubprocessError(error) {
|
|
140
|
+
return {
|
|
141
|
+
...error,
|
|
142
|
+
exitCode: error?.exitCode ?? null,
|
|
143
|
+
signal: error?.signal ?? null,
|
|
144
|
+
stdout: error?.stdout || "",
|
|
145
|
+
stderr: error?.stderr || error?.message || "",
|
|
146
|
+
};
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
function normalizePositiveInteger(value, label) {
|
|
150
|
+
const normalized = Number(value);
|
|
151
|
+
if (!Number.isInteger(normalized) || normalized <= 0) {
|
|
152
|
+
throw new Error(`${label} must be a positive integer.`);
|
|
153
|
+
}
|
|
154
|
+
return normalized;
|
|
155
|
+
}
|
|
@@ -79,7 +79,7 @@ export function formatFileTimeoutBudgetError(fileTimeoutSeconds) {
|
|
|
79
79
|
fileTimeoutSeconds,
|
|
80
80
|
"fileTimeoutSeconds"
|
|
81
81
|
);
|
|
82
|
-
return `
|
|
82
|
+
return `Test file exceeded the ${normalizedFileTimeoutSeconds}s wall-clock timeout`;
|
|
83
83
|
}
|
|
84
84
|
|
|
85
85
|
function parsePositiveInteger(value, label) {
|
package/lib/ui/index.d.ts
CHANGED
package/lib/ui/index.mjs
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@elench/testkit-bridge",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.114",
|
|
4
4
|
"description": "Browser bridge helpers for testkit",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.js",
|
|
@@ -22,7 +22,7 @@
|
|
|
22
22
|
"typecheck": "tsc -p tsconfig.json --noEmit"
|
|
23
23
|
},
|
|
24
24
|
"dependencies": {
|
|
25
|
-
"@elench/testkit-protocol": "0.1.
|
|
25
|
+
"@elench/testkit-protocol": "0.1.114"
|
|
26
26
|
},
|
|
27
27
|
"private": false
|
|
28
28
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@elench/testkit",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.114",
|
|
4
4
|
"description": "Assistant-first CLI for running, inspecting, and debugging local testkit suites",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"workspaces": [
|
|
@@ -90,10 +90,10 @@
|
|
|
90
90
|
},
|
|
91
91
|
"dependencies": {
|
|
92
92
|
"@babel/code-frame": "^7.29.0",
|
|
93
|
-
"@elench/next-analysis": "0.1.
|
|
94
|
-
"@elench/testkit-bridge": "0.1.
|
|
95
|
-
"@elench/testkit-protocol": "0.1.
|
|
96
|
-
"@elench/ts-analysis": "0.1.
|
|
93
|
+
"@elench/next-analysis": "0.1.114",
|
|
94
|
+
"@elench/testkit-bridge": "0.1.114",
|
|
95
|
+
"@elench/testkit-protocol": "0.1.114",
|
|
96
|
+
"@elench/ts-analysis": "0.1.114",
|
|
97
97
|
"@oclif/core": "^4.10.6",
|
|
98
98
|
"@playwright/test": "^1.52.0",
|
|
99
99
|
"esbuild": "^0.25.11",
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
import React, { createElement } from "react";
|
|
2
|
-
import { Text } from "ink";
|
|
3
|
-
import { bold, dim } from "../../terminal/colors.mjs";
|
|
4
|
-
|
|
5
|
-
export function FilterBar({ filter } = {}) {
|
|
6
|
-
if (!filter?.active) return null;
|
|
7
|
-
return createElement(
|
|
8
|
-
Text,
|
|
9
|
-
null,
|
|
10
|
-
`${bold("/")}${filter.query}${dim(` ${filter.count} ${filter.count === 1 ? "match" : "matches"}`)}`
|
|
11
|
-
);
|
|
12
|
-
}
|
|
@@ -1,106 +0,0 @@
|
|
|
1
|
-
const FIELD_WEIGHTS = {
|
|
2
|
-
path: 140,
|
|
3
|
-
label: 120,
|
|
4
|
-
suite: 90,
|
|
5
|
-
service: 70,
|
|
6
|
-
type: 60,
|
|
7
|
-
status: 30,
|
|
8
|
-
error: 20,
|
|
9
|
-
};
|
|
10
|
-
|
|
11
|
-
export function fuzzyMatch(query, candidate) {
|
|
12
|
-
const normalizedQuery = normalizeValue(query);
|
|
13
|
-
const normalizedCandidate = normalizeValue(candidate);
|
|
14
|
-
if (!normalizedQuery) {
|
|
15
|
-
return { matched: true, score: 0, positions: [] };
|
|
16
|
-
}
|
|
17
|
-
if (!normalizedCandidate) {
|
|
18
|
-
return { matched: false, score: Number.NEGATIVE_INFINITY, positions: [] };
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
const positions = [];
|
|
22
|
-
let queryIndex = 0;
|
|
23
|
-
let lastPosition = -1;
|
|
24
|
-
let score = 0;
|
|
25
|
-
|
|
26
|
-
for (let candidateIndex = 0; candidateIndex < normalizedCandidate.length; candidateIndex += 1) {
|
|
27
|
-
if (normalizedCandidate[candidateIndex] !== normalizedQuery[queryIndex]) continue;
|
|
28
|
-
positions.push(candidateIndex);
|
|
29
|
-
score += 1;
|
|
30
|
-
if (candidateIndex === 0) score += 3;
|
|
31
|
-
if (isBoundary(candidate, candidateIndex)) score += 10;
|
|
32
|
-
if (lastPosition >= 0) {
|
|
33
|
-
const gap = candidateIndex - lastPosition - 1;
|
|
34
|
-
score -= gap;
|
|
35
|
-
if (gap === 0) score += 5;
|
|
36
|
-
}
|
|
37
|
-
lastPosition = candidateIndex;
|
|
38
|
-
queryIndex += 1;
|
|
39
|
-
if (queryIndex >= normalizedQuery.length) {
|
|
40
|
-
return { matched: true, score, positions };
|
|
41
|
-
}
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
return { matched: false, score: Number.NEGATIVE_INFINITY, positions: [] };
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
export function matchRunTreeEntry(query, entry) {
|
|
48
|
-
const fields = buildEntryMatchFields(entry);
|
|
49
|
-
let best = null;
|
|
50
|
-
|
|
51
|
-
for (const field of fields) {
|
|
52
|
-
if (!field.value) continue;
|
|
53
|
-
const result = fuzzyMatch(query, field.value);
|
|
54
|
-
if (!result.matched) continue;
|
|
55
|
-
const weightedScore = result.score + (FIELD_WEIGHTS[field.name] || 0);
|
|
56
|
-
if (!best || weightedScore > best.score) {
|
|
57
|
-
best = {
|
|
58
|
-
matched: true,
|
|
59
|
-
score: weightedScore,
|
|
60
|
-
field: field.name,
|
|
61
|
-
positions: result.positions,
|
|
62
|
-
};
|
|
63
|
-
}
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
if (!best) {
|
|
67
|
-
return { matched: false, score: Number.NEGATIVE_INFINITY, field: null, positions: [] };
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
return best;
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
export function applyHighlight(text, positions, highlightFn) {
|
|
74
|
-
const source = String(text || "");
|
|
75
|
-
if (!Array.isArray(positions) || positions.length === 0) return source;
|
|
76
|
-
const positionSet = new Set(positions);
|
|
77
|
-
let output = "";
|
|
78
|
-
for (let index = 0; index < source.length; index += 1) {
|
|
79
|
-
output += positionSet.has(index) ? highlightFn(source[index]) : source[index];
|
|
80
|
-
}
|
|
81
|
-
return output;
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
function buildEntryMatchFields(entry) {
|
|
85
|
-
return [
|
|
86
|
-
{ name: "label", value: entry.label || "" },
|
|
87
|
-
{ name: "path", value: entry.filePath || "" },
|
|
88
|
-
{ name: "suite", value: entry.suiteName || "" },
|
|
89
|
-
{ name: "service", value: entry.serviceName || "" },
|
|
90
|
-
{ name: "type", value: entry.type || "" },
|
|
91
|
-
{ name: "status", value: entry.status || "" },
|
|
92
|
-
{ name: "error", value: entry.error || "" },
|
|
93
|
-
];
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
function normalizeValue(value) {
|
|
97
|
-
return String(value || "").toLowerCase();
|
|
98
|
-
}
|
|
99
|
-
|
|
100
|
-
function isBoundary(source, index) {
|
|
101
|
-
if (index <= 0) return true;
|
|
102
|
-
const current = source[index];
|
|
103
|
-
const previous = source[index - 1];
|
|
104
|
-
if (/[/_.\-\s]/.test(previous)) return true;
|
|
105
|
-
return previous.toLowerCase() === previous && current.toUpperCase() === current && current.toLowerCase() !== current;
|
|
106
|
-
}
|