@nokout/big-dill-core 0.0.1
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/LICENSE +21 -0
- package/README.md +202 -0
- package/dist/completion/complete.d.ts +40 -0
- package/dist/completion/complete.d.ts.map +1 -0
- package/dist/completion/complete.js +134 -0
- package/dist/completion/complete.js.map +1 -0
- package/dist/format/tables.d.ts +7 -0
- package/dist/format/tables.d.ts.map +1 -0
- package/dist/format/tables.js +87 -0
- package/dist/format/tables.js.map +1 -0
- package/dist/gherkin/parser.d.ts +28 -0
- package/dist/gherkin/parser.d.ts.map +1 -0
- package/dist/gherkin/parser.js +44 -0
- package/dist/gherkin/parser.js.map +1 -0
- package/dist/index.d.ts +25 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +92 -0
- package/dist/index.js.map +1 -0
- package/dist/ipc/server.d.ts +13 -0
- package/dist/ipc/server.d.ts.map +1 -0
- package/dist/ipc/server.js +106 -0
- package/dist/ipc/server.js.map +1 -0
- package/dist/lint/rules.d.ts +46 -0
- package/dist/lint/rules.d.ts.map +1 -0
- package/dist/lint/rules.js +387 -0
- package/dist/lint/rules.js.map +1 -0
- package/dist/protocol/types.d.ts +97 -0
- package/dist/protocol/types.d.ts.map +1 -0
- package/dist/protocol/types.js +5 -0
- package/dist/protocol/types.js.map +1 -0
- package/dist/pytest/runner.d.ts +29 -0
- package/dist/pytest/runner.d.ts.map +1 -0
- package/dist/pytest/runner.js +225 -0
- package/dist/pytest/runner.js.map +1 -0
- package/dist/results/outcomes.d.ts +36 -0
- package/dist/results/outcomes.d.ts.map +1 -0
- package/dist/results/outcomes.js +69 -0
- package/dist/results/outcomes.js.map +1 -0
- package/dist/steps/browser.d.ts +42 -0
- package/dist/steps/browser.d.ts.map +1 -0
- package/dist/steps/browser.js +110 -0
- package/dist/steps/browser.js.map +1 -0
- package/dist/steps/documentation.d.ts +10 -0
- package/dist/steps/documentation.d.ts.map +1 -0
- package/dist/steps/documentation.js +39 -0
- package/dist/steps/documentation.js.map +1 -0
- package/dist/steps/references.d.ts +10 -0
- package/dist/steps/references.d.ts.map +1 -0
- package/dist/steps/references.js +34 -0
- package/dist/steps/references.js.map +1 -0
- package/dist/steps/stepCache.d.ts +50 -0
- package/dist/steps/stepCache.d.ts.map +1 -0
- package/dist/steps/stepCache.js +149 -0
- package/dist/steps/stepCache.js.map +1 -0
- package/dist/steps/stubs.d.ts +10 -0
- package/dist/steps/stubs.d.ts.map +1 -0
- package/dist/steps/stubs.js +46 -0
- package/dist/steps/stubs.js.map +1 -0
- package/dist/steps/unimplemented.d.ts +10 -0
- package/dist/steps/unimplemented.d.ts.map +1 -0
- package/dist/steps/unimplemented.js +26 -0
- package/dist/steps/unimplemented.js.map +1 -0
- package/dist/symbols/outline.d.ts +13 -0
- package/dist/symbols/outline.d.ts.map +1 -0
- package/dist/symbols/outline.js +38 -0
- package/dist/symbols/outline.js.map +1 -0
- package/dist/tokens/semanticTokens.d.ts +13 -0
- package/dist/tokens/semanticTokens.d.ts.map +1 -0
- package/dist/tokens/semanticTokens.js +77 -0
- package/dist/tokens/semanticTokens.js.map +1 -0
- package/dist/tree/builder.d.ts +40 -0
- package/dist/tree/builder.d.ts.map +1 -0
- package/dist/tree/builder.js +178 -0
- package/dist/tree/builder.js.map +1 -0
- package/package.json +58 -0
- package/src/completion/complete.ts +165 -0
- package/src/format/tables.ts +108 -0
- package/src/gherkin/parser.ts +69 -0
- package/src/index.ts +136 -0
- package/src/ipc/server.ts +84 -0
- package/src/lint/rules.ts +425 -0
- package/src/protocol/types.ts +114 -0
- package/src/pytest/runner.ts +249 -0
- package/src/results/outcomes.ts +102 -0
- package/src/steps/browser.ts +105 -0
- package/src/steps/documentation.ts +43 -0
- package/src/steps/references.ts +33 -0
- package/src/steps/stepCache.ts +168 -0
- package/src/steps/stubs.ts +48 -0
- package/src/steps/unimplemented.ts +31 -0
- package/src/symbols/outline.ts +52 -0
- package/src/tokens/semanticTokens.ts +98 -0
- package/src/tree/builder.ts +187 -0
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
// Copyright (c) 2026 Nigel O'Keefe. All rights reserved.
|
|
2
|
+
// Licensed under the MIT License.
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* The wire contract between the pytest side and any host.
|
|
6
|
+
*
|
|
7
|
+
* Everything here is plain data by construction — it crosses a pipe as JSON, so
|
|
8
|
+
* it cannot reference editor types even in principle. Both ends must agree on
|
|
9
|
+
* these shapes.
|
|
10
|
+
*
|
|
11
|
+
* These shapes began as ms-python's payload types, back when the Python half was
|
|
12
|
+
* a vendored copy of its bridge. pytest-big-dill now produces them itself, so the
|
|
13
|
+
* contract is ours to define and change.
|
|
14
|
+
*/
|
|
15
|
+
|
|
16
|
+
export type DiscoveredTestType = 'folder' | 'file' | 'class' | 'function' | 'test';
|
|
17
|
+
|
|
18
|
+
export type DiscoveredTestCommon = {
|
|
19
|
+
path: string;
|
|
20
|
+
name: string;
|
|
21
|
+
type_: DiscoveredTestType;
|
|
22
|
+
id_: string;
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
export type DiscoveredTestItem = DiscoveredTestCommon & {
|
|
26
|
+
lineno: number | string;
|
|
27
|
+
runID: string;
|
|
28
|
+
/** Relative path to the .feature file (e.g. "features/states/basic_states.feature") */
|
|
29
|
+
feature_path?: string;
|
|
30
|
+
/** Display name for the scenario (may differ from name for outlines) */
|
|
31
|
+
scenario_name?: string;
|
|
32
|
+
/** Scenario tags from the .feature file (without the @ prefix) */
|
|
33
|
+
scenario_tags?: string[];
|
|
34
|
+
/** Feature-level tags from the Feature: declaration (without the @ prefix) */
|
|
35
|
+
feature_tags?: string[];
|
|
36
|
+
/** Feature display name from the Feature: declaration */
|
|
37
|
+
feature_name?: string;
|
|
38
|
+
};
|
|
39
|
+
|
|
40
|
+
export type DiscoveredTestNode = DiscoveredTestCommon & {
|
|
41
|
+
children: (DiscoveredTestNode | DiscoveredTestItem)[];
|
|
42
|
+
lineno?: number | string;
|
|
43
|
+
};
|
|
44
|
+
|
|
45
|
+
export type DiscoveredTestPayload = {
|
|
46
|
+
cwd: string;
|
|
47
|
+
tests?: DiscoveredTestNode;
|
|
48
|
+
status: 'success' | 'error';
|
|
49
|
+
error?: string[];
|
|
50
|
+
};
|
|
51
|
+
|
|
52
|
+
export type ExecutionTestPayload = {
|
|
53
|
+
cwd: string;
|
|
54
|
+
status: 'success' | 'error';
|
|
55
|
+
result?: {
|
|
56
|
+
[testRunID: string]: {
|
|
57
|
+
test?: string;
|
|
58
|
+
outcome?: string;
|
|
59
|
+
message?: string;
|
|
60
|
+
traceback?: string;
|
|
61
|
+
subtest?: string;
|
|
62
|
+
/** Custom status string from pytest_report_customstatus */
|
|
63
|
+
custom_status?: string;
|
|
64
|
+
};
|
|
65
|
+
};
|
|
66
|
+
notFound?: string[];
|
|
67
|
+
error: string;
|
|
68
|
+
};
|
|
69
|
+
|
|
70
|
+
// ── Step definition types (for completions and validation) ─────────────────
|
|
71
|
+
|
|
72
|
+
export type StepParameter = {
|
|
73
|
+
name: string;
|
|
74
|
+
type_name: string;
|
|
75
|
+
suggested_values: string[];
|
|
76
|
+
has_validator: boolean;
|
|
77
|
+
};
|
|
78
|
+
|
|
79
|
+
export type StepDefinition = {
|
|
80
|
+
keyword: 'given' | 'when' | 'then' | 'step';
|
|
81
|
+
pattern: string;
|
|
82
|
+
parameters: StepParameter[];
|
|
83
|
+
/** Absolute path to the Python file where this step is defined. */
|
|
84
|
+
file?: string;
|
|
85
|
+
/** 1-indexed line number in the Python file. */
|
|
86
|
+
line?: number;
|
|
87
|
+
/** First line of the function docstring. */
|
|
88
|
+
summary?: string;
|
|
89
|
+
/** Tags from the Tags: docstring section. */
|
|
90
|
+
tags?: string[];
|
|
91
|
+
/** StepType/StepEnum class names used as parameter types. */
|
|
92
|
+
param_types?: string[];
|
|
93
|
+
/** Times this step pattern appears across workspace .feature files. Tracked by StepCache. */
|
|
94
|
+
usage_count?: number;
|
|
95
|
+
};
|
|
96
|
+
|
|
97
|
+
export type StepDefinitionPayload = {
|
|
98
|
+
type: 'stepDefinitions';
|
|
99
|
+
stepDefinitions: StepDefinition[];
|
|
100
|
+
};
|
|
101
|
+
|
|
102
|
+
// ── Lint diagnostic types ───────────────────────────────────────────────────
|
|
103
|
+
|
|
104
|
+
export type LintDiagnosticEntry = {
|
|
105
|
+
path: string;
|
|
106
|
+
message: string;
|
|
107
|
+
severity: 'error' | 'warning' | 'info';
|
|
108
|
+
line: number | null;
|
|
109
|
+
};
|
|
110
|
+
|
|
111
|
+
export type LintDiagnosticPayload = {
|
|
112
|
+
type: 'lintDiagnostics';
|
|
113
|
+
diagnostics: LintDiagnosticEntry[];
|
|
114
|
+
};
|
|
@@ -0,0 +1,249 @@
|
|
|
1
|
+
// Copyright (c) 2026 Nigel O'Keefe. All rights reserved.
|
|
2
|
+
// Licensed under the MIT License.
|
|
3
|
+
//
|
|
4
|
+
// Spawns pytest and collects discovery, execution, and lint payloads over the
|
|
5
|
+
// named-pipe IPC channel.
|
|
6
|
+
//
|
|
7
|
+
// Nothing here knows about an editor. Everything a host would otherwise read
|
|
8
|
+
// from editor state — the working directory, the interpreter, extra arguments,
|
|
9
|
+
// where the Python bridge lives, where log output goes, and how cancellation is
|
|
10
|
+
// signalled — arrives as plain options.
|
|
11
|
+
|
|
12
|
+
import * as cp from 'child_process';
|
|
13
|
+
import * as fs from 'fs';
|
|
14
|
+
import * as os from 'os';
|
|
15
|
+
import * as path from 'path';
|
|
16
|
+
import { createIpcServer } from '../ipc/server';
|
|
17
|
+
import type {
|
|
18
|
+
DiscoveredTestPayload,
|
|
19
|
+
ExecutionTestPayload,
|
|
20
|
+
LintDiagnosticEntry,
|
|
21
|
+
LintDiagnosticPayload,
|
|
22
|
+
StepDefinition,
|
|
23
|
+
StepDefinitionPayload,
|
|
24
|
+
} from '../protocol/types';
|
|
25
|
+
|
|
26
|
+
export interface PytestOptions {
|
|
27
|
+
/**
|
|
28
|
+
* Working directory for the pytest process, already resolved. Hosts that
|
|
29
|
+
* layer their own settings over this (an editor reading `cwd` from
|
|
30
|
+
* configuration, say) resolve them before calling.
|
|
31
|
+
*/
|
|
32
|
+
cwd: string;
|
|
33
|
+
/** Interpreter used to run pytest. */
|
|
34
|
+
interpreterPath: string;
|
|
35
|
+
/** Extra arguments appended to every pytest invocation. */
|
|
36
|
+
pytestArgs?: string[];
|
|
37
|
+
/** Receives subprocess stderr as it arrives. */
|
|
38
|
+
log?: (text: string) => void;
|
|
39
|
+
/** Aborts the run. Hosts with their own cancellation bridge to this. */
|
|
40
|
+
signal?: AbortSignal;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
export type DiscoveryResult = {
|
|
44
|
+
discovery: DiscoveredTestPayload;
|
|
45
|
+
stepDefinitions: StepDefinition[];
|
|
46
|
+
};
|
|
47
|
+
|
|
48
|
+
/**
|
|
49
|
+
* Test ids are passed to the runner in a file rather than on the command line:
|
|
50
|
+
* Windows caps a command line at roughly 32,000 characters, and a few hundred
|
|
51
|
+
* scenarios exceeds it with an opaque OS error.
|
|
52
|
+
*/
|
|
53
|
+
const TEST_IDS_ENV = 'BIG_DILL_TEST_IDS';
|
|
54
|
+
|
|
55
|
+
/**
|
|
56
|
+
* Wire an AbortSignal to a running subprocess.
|
|
57
|
+
*
|
|
58
|
+
* Handles the already-aborted case too: a signal that fired before the process
|
|
59
|
+
* started would otherwise never deliver an 'abort' event, leaving the run
|
|
60
|
+
* unkillable.
|
|
61
|
+
*/
|
|
62
|
+
function onAbort(signal: AbortSignal | undefined, handler: () => void): void {
|
|
63
|
+
if (!signal) return;
|
|
64
|
+
if (signal.aborted) {
|
|
65
|
+
handler();
|
|
66
|
+
return;
|
|
67
|
+
}
|
|
68
|
+
signal.addEventListener('abort', handler, { once: true });
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
export async function discoverTests(opts: PytestOptions): Promise<DiscoveryResult> {
|
|
72
|
+
const { cwd, interpreterPath, pytestArgs = [], log, signal } = opts;
|
|
73
|
+
const ipc = await createIpcServer();
|
|
74
|
+
|
|
75
|
+
const env: NodeJS.ProcessEnv = {
|
|
76
|
+
...process.env,
|
|
77
|
+
TEST_RUN_PIPE: ipc.pipeName,
|
|
78
|
+
};
|
|
79
|
+
|
|
80
|
+
const args = [
|
|
81
|
+
'-m', 'pytest',
|
|
82
|
+
'--collect-only',
|
|
83
|
+
'-q',
|
|
84
|
+
'--rootdir', cwd,
|
|
85
|
+
'--import-mode=importlib',
|
|
86
|
+
...pytestArgs,
|
|
87
|
+
];
|
|
88
|
+
|
|
89
|
+
let discoveryPayload: DiscoveredTestPayload | null = null;
|
|
90
|
+
const stepDefinitions: StepDefinition[] = [];
|
|
91
|
+
|
|
92
|
+
return new Promise<DiscoveryResult>((resolve, reject) => {
|
|
93
|
+
ipc.onMessage((data) => {
|
|
94
|
+
const payload = data as Record<string, unknown>;
|
|
95
|
+
if (payload['type'] === 'stepDefinitions') {
|
|
96
|
+
const p = payload as unknown as StepDefinitionPayload;
|
|
97
|
+
stepDefinitions.push(...p.stepDefinitions);
|
|
98
|
+
} else if ('cwd' in payload) {
|
|
99
|
+
discoveryPayload = payload as unknown as DiscoveredTestPayload;
|
|
100
|
+
}
|
|
101
|
+
});
|
|
102
|
+
|
|
103
|
+
const proc = cp.spawn(interpreterPath, args, { cwd, env });
|
|
104
|
+
|
|
105
|
+
const stderr: string[] = [];
|
|
106
|
+
proc.stderr.on('data', (chunk) => {
|
|
107
|
+
const text = chunk.toString();
|
|
108
|
+
stderr.push(text);
|
|
109
|
+
log?.(text);
|
|
110
|
+
});
|
|
111
|
+
|
|
112
|
+
onAbort(signal, () => {
|
|
113
|
+
proc.kill();
|
|
114
|
+
ipc.dispose();
|
|
115
|
+
reject(new Error('Discovery cancelled'));
|
|
116
|
+
});
|
|
117
|
+
|
|
118
|
+
proc.on('close', (code) => {
|
|
119
|
+
ipc.dispose();
|
|
120
|
+
const discovery = discoveryPayload ?? {
|
|
121
|
+
cwd,
|
|
122
|
+
status: 'error' as const,
|
|
123
|
+
error: code !== 0 ? stderr : [],
|
|
124
|
+
};
|
|
125
|
+
resolve({ discovery, stepDefinitions });
|
|
126
|
+
});
|
|
127
|
+
|
|
128
|
+
proc.on('error', (err) => {
|
|
129
|
+
ipc.dispose();
|
|
130
|
+
reject(err);
|
|
131
|
+
});
|
|
132
|
+
});
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
export async function runTests(
|
|
136
|
+
opts: PytestOptions & { testIds: string[] },
|
|
137
|
+
): Promise<ExecutionTestPayload[]> {
|
|
138
|
+
const { cwd, interpreterPath, pytestArgs = [], log, signal, testIds } = opts;
|
|
139
|
+
const ipc = await createIpcServer();
|
|
140
|
+
|
|
141
|
+
// mkdtempSync atomically creates a directory with a random suffix and 0700
|
|
142
|
+
// permissions, so the path cannot be predicted or pre-created by another user
|
|
143
|
+
// on a shared machine — unlike a name derived from a timestamp, where a
|
|
144
|
+
// symlink planted at the predicted path turns this into an arbitrary write.
|
|
145
|
+
const tmpDir = fs.mkdtempSync(path.join(os.tmpdir(), 'big-dill-'));
|
|
146
|
+
const testIdsFile = path.join(tmpDir, 'test-ids.txt');
|
|
147
|
+
fs.writeFileSync(testIdsFile, testIds.join('\n'), 'utf-8');
|
|
148
|
+
|
|
149
|
+
// Remove the whole directory, from every exit path including cancellation.
|
|
150
|
+
const cleanup = (): void => {
|
|
151
|
+
try { fs.rmSync(tmpDir, { recursive: true, force: true }); } catch { /* ignore */ }
|
|
152
|
+
};
|
|
153
|
+
|
|
154
|
+
const env: NodeJS.ProcessEnv = {
|
|
155
|
+
...process.env,
|
|
156
|
+
TEST_RUN_PIPE: ipc.pipeName,
|
|
157
|
+
[TEST_IDS_ENV]: testIdsFile,
|
|
158
|
+
};
|
|
159
|
+
|
|
160
|
+
// Deliberately no --import-mode here: discovery passes importlib and execution
|
|
161
|
+
// never has. Node ids must match between the two or results attach to nothing,
|
|
162
|
+
// and import mode is exactly what shifts them.
|
|
163
|
+
const args = ['-m', 'pytest_big_dill', '--rootdir', cwd, ...pytestArgs];
|
|
164
|
+
const payloads: ExecutionTestPayload[] = [];
|
|
165
|
+
|
|
166
|
+
return new Promise<ExecutionTestPayload[]>((resolve, reject) => {
|
|
167
|
+
ipc.onMessage((data) => {
|
|
168
|
+
// Coverage payloads carry a 'coverage' key; they are not results.
|
|
169
|
+
if (!('coverage' in data)) {
|
|
170
|
+
payloads.push(data as unknown as ExecutionTestPayload);
|
|
171
|
+
}
|
|
172
|
+
});
|
|
173
|
+
|
|
174
|
+
const proc = cp.spawn(interpreterPath, args, { cwd, env });
|
|
175
|
+
|
|
176
|
+
proc.stderr.on('data', (chunk) => log?.(chunk.toString()));
|
|
177
|
+
|
|
178
|
+
onAbort(signal, () => {
|
|
179
|
+
proc.kill();
|
|
180
|
+
ipc.dispose();
|
|
181
|
+
cleanup();
|
|
182
|
+
reject(new Error('Test run cancelled'));
|
|
183
|
+
});
|
|
184
|
+
|
|
185
|
+
proc.on('close', () => {
|
|
186
|
+
ipc.dispose();
|
|
187
|
+
cleanup();
|
|
188
|
+
resolve(payloads);
|
|
189
|
+
});
|
|
190
|
+
|
|
191
|
+
proc.on('error', (err) => {
|
|
192
|
+
ipc.dispose();
|
|
193
|
+
cleanup();
|
|
194
|
+
reject(err);
|
|
195
|
+
});
|
|
196
|
+
});
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
export async function runBddLint(
|
|
200
|
+
opts: PytestOptions & { featureFilePath: string },
|
|
201
|
+
): Promise<LintDiagnosticEntry[]> {
|
|
202
|
+
const { cwd, interpreterPath, pytestArgs = [], log, signal, featureFilePath } = opts;
|
|
203
|
+
const ipc = await createIpcServer();
|
|
204
|
+
|
|
205
|
+
const env: NodeJS.ProcessEnv = {
|
|
206
|
+
...process.env,
|
|
207
|
+
TEST_RUN_PIPE: ipc.pipeName,
|
|
208
|
+
};
|
|
209
|
+
|
|
210
|
+
const args = [
|
|
211
|
+
'-m', 'pytest',
|
|
212
|
+
'--bdd-lint', featureFilePath,
|
|
213
|
+
'--rootdir', cwd,
|
|
214
|
+
'--import-mode=importlib',
|
|
215
|
+
...pytestArgs,
|
|
216
|
+
];
|
|
217
|
+
|
|
218
|
+
const entries: LintDiagnosticEntry[] = [];
|
|
219
|
+
|
|
220
|
+
return new Promise<LintDiagnosticEntry[]>((resolve, reject) => {
|
|
221
|
+
ipc.onMessage((data) => {
|
|
222
|
+
const payload = data as Record<string, unknown>;
|
|
223
|
+
if (payload['type'] === 'lintDiagnostics') {
|
|
224
|
+
const p = payload as unknown as LintDiagnosticPayload;
|
|
225
|
+
entries.push(...p.diagnostics);
|
|
226
|
+
}
|
|
227
|
+
});
|
|
228
|
+
|
|
229
|
+
const proc = cp.spawn(interpreterPath, args, { cwd, env });
|
|
230
|
+
|
|
231
|
+
proc.stderr.on('data', (chunk) => log?.(chunk.toString()));
|
|
232
|
+
|
|
233
|
+
onAbort(signal, () => {
|
|
234
|
+
proc.kill();
|
|
235
|
+
ipc.dispose();
|
|
236
|
+
reject(new Error('Lint cancelled'));
|
|
237
|
+
});
|
|
238
|
+
|
|
239
|
+
proc.on('close', () => {
|
|
240
|
+
ipc.dispose();
|
|
241
|
+
resolve(entries);
|
|
242
|
+
});
|
|
243
|
+
|
|
244
|
+
proc.on('error', (err) => {
|
|
245
|
+
ipc.dispose();
|
|
246
|
+
reject(err);
|
|
247
|
+
});
|
|
248
|
+
});
|
|
249
|
+
}
|
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
// Copyright (c) 2026 Nigel O'Keefe. All rights reserved.
|
|
2
|
+
// Licensed under the MIT License.
|
|
3
|
+
//
|
|
4
|
+
// Decides what an execution payload means, without applying it.
|
|
5
|
+
//
|
|
6
|
+
// Hosts turn these decisions into whatever their UI needs — TestRun calls, for a
|
|
7
|
+
// VS Code host. Keeping the decision separate is what makes the mapping rules
|
|
8
|
+
// testable without an editor.
|
|
9
|
+
|
|
10
|
+
import type { ExecutionTestPayload } from '../protocol/types';
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* 'passed', 'failed', 'errored' and 'skipped' are terminal. 'enqueued' is
|
|
14
|
+
* transient: it shows a pending indicator during a run, but is not stored as a
|
|
15
|
+
* result, so afterwards the item reads as "not run" — visually the same as
|
|
16
|
+
* skipped. Use 'skipped' to mean "deliberately did not run this time".
|
|
17
|
+
*/
|
|
18
|
+
export type RunState = 'passed' | 'failed' | 'errored' | 'skipped' | 'enqueued';
|
|
19
|
+
|
|
20
|
+
const VALID_STATES = new Set<string>(['passed', 'failed', 'errored', 'skipped', 'enqueued']);
|
|
21
|
+
|
|
22
|
+
/** Marker a host may prepend to an item awaiting a result. */
|
|
23
|
+
export const WAITING_PREFIX = '⏳ ';
|
|
24
|
+
|
|
25
|
+
export interface OutcomeDecision {
|
|
26
|
+
/** pytest run id; the host maps this to its own item. */
|
|
27
|
+
runId: string;
|
|
28
|
+
state: RunState;
|
|
29
|
+
/** Attached by the host for failed/errored states. */
|
|
30
|
+
message?: string;
|
|
31
|
+
/**
|
|
32
|
+
* What to do with the waiting marker on the item's label.
|
|
33
|
+
*
|
|
34
|
+
* Only the custom-status path touches labels. A plain 'success' leaves the
|
|
35
|
+
* label alone, so an item previously marked waiting keeps its marker — odd,
|
|
36
|
+
* but existing behaviour, and encoded here rather than quietly changed.
|
|
37
|
+
*/
|
|
38
|
+
label: 'strip' | 'prefix' | 'none';
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
/**
|
|
42
|
+
* Resolve an execution payload into per-test decisions.
|
|
43
|
+
*
|
|
44
|
+
* `outcomeMapping` maps a pytest custom status string onto a run state; unknown
|
|
45
|
+
* or invalid values fall back to 'errored'.
|
|
46
|
+
*
|
|
47
|
+
* Decisions are produced for every run id in the payload. Hosts skip the ones
|
|
48
|
+
* they do not recognise — a run may include tests outside this tree.
|
|
49
|
+
*/
|
|
50
|
+
export function resolveExecutionOutcomes(
|
|
51
|
+
payload: ExecutionTestPayload,
|
|
52
|
+
outcomeMapping: Record<string, string> = {},
|
|
53
|
+
): OutcomeDecision[] {
|
|
54
|
+
const decisions: OutcomeDecision[] = [];
|
|
55
|
+
|
|
56
|
+
for (const [runId, result] of Object.entries(payload.result ?? {})) {
|
|
57
|
+
const outcome = result.outcome ?? 'error';
|
|
58
|
+
const customStatus = result.custom_status;
|
|
59
|
+
|
|
60
|
+
switch (outcome) {
|
|
61
|
+
case 'success':
|
|
62
|
+
decisions.push({ runId, state: 'passed', label: 'none' });
|
|
63
|
+
break;
|
|
64
|
+
|
|
65
|
+
case 'skipped':
|
|
66
|
+
decisions.push({ runId, state: 'skipped', label: 'none' });
|
|
67
|
+
break;
|
|
68
|
+
|
|
69
|
+
case 'failure':
|
|
70
|
+
case 'error':
|
|
71
|
+
if (customStatus) {
|
|
72
|
+
const raw = outcomeMapping[customStatus];
|
|
73
|
+
const state: RunState = VALID_STATES.has(raw) ? (raw as RunState) : 'errored';
|
|
74
|
+
decisions.push({
|
|
75
|
+
runId,
|
|
76
|
+
state,
|
|
77
|
+
message: customStatus,
|
|
78
|
+
label: state === 'enqueued' ? 'prefix' : 'strip',
|
|
79
|
+
});
|
|
80
|
+
} else {
|
|
81
|
+
decisions.push({
|
|
82
|
+
runId,
|
|
83
|
+
state: 'failed',
|
|
84
|
+
message: result.message ?? result.traceback ?? outcome,
|
|
85
|
+
label: 'none',
|
|
86
|
+
});
|
|
87
|
+
}
|
|
88
|
+
break;
|
|
89
|
+
|
|
90
|
+
default:
|
|
91
|
+
decisions.push({ runId, state: 'errored', message: outcome, label: 'none' });
|
|
92
|
+
break;
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
// Anything the run never reported on — a crash during collection, say.
|
|
97
|
+
for (const runId of payload.notFound ?? []) {
|
|
98
|
+
decisions.push({ runId, state: 'errored', message: 'Test not found', label: 'none' });
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
return decisions;
|
|
102
|
+
}
|
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
// Copyright (c) 2026 Nigel O'Keefe. All rights reserved.
|
|
2
|
+
// Licensed under the MIT License.
|
|
3
|
+
//
|
|
4
|
+
// The step browser's model: what rows to show for a given grouping, filter and
|
|
5
|
+
// expanded group.
|
|
6
|
+
//
|
|
7
|
+
// Returns plain nodes. Rendering them — as a tree view, a list, or anything
|
|
8
|
+
// else — and wiring navigation is the host's job.
|
|
9
|
+
|
|
10
|
+
import * as path from 'path';
|
|
11
|
+
import type { StepDefinition } from '../protocol/types';
|
|
12
|
+
|
|
13
|
+
export type GroupingMode = 'file' | 'stepType' | 'tag';
|
|
14
|
+
|
|
15
|
+
export const UNKNOWN_FILE = '(unknown file)';
|
|
16
|
+
export const NO_TYPE = '(no type)';
|
|
17
|
+
export const UNTAGGED = '(untagged)';
|
|
18
|
+
|
|
19
|
+
export type StepBrowserNode =
|
|
20
|
+
/** An expandable group heading. */
|
|
21
|
+
| { kind: 'group'; label: string }
|
|
22
|
+
/** A step, carrying its definition so the host can offer navigation. */
|
|
23
|
+
| { kind: 'step'; label: string; step: StepDefinition }
|
|
24
|
+
/** A non-selectable placeholder — nothing discovered, or nothing matched. */
|
|
25
|
+
| { kind: 'message'; label: string };
|
|
26
|
+
|
|
27
|
+
export interface BrowseOptions {
|
|
28
|
+
mode: GroupingMode;
|
|
29
|
+
/** Case-insensitive substring match against the step pattern. */
|
|
30
|
+
filter?: string;
|
|
31
|
+
/** Label of the group being expanded. Omitted for the root level. */
|
|
32
|
+
group?: string;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
/** The group labels a step belongs under, for a given grouping. */
|
|
36
|
+
function keysFor(step: StepDefinition, mode: GroupingMode): string[] {
|
|
37
|
+
switch (mode) {
|
|
38
|
+
case 'file':
|
|
39
|
+
return [step.file ? path.basename(step.file) : UNKNOWN_FILE];
|
|
40
|
+
case 'stepType':
|
|
41
|
+
return step.param_types?.length ? [...step.param_types] : [NO_TYPE];
|
|
42
|
+
case 'tag':
|
|
43
|
+
return step.tags?.length ? step.tags.map((t) => `@${t}`) : [UNTAGGED];
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
export function filterSteps(steps: StepDefinition[], filter?: string): StepDefinition[] {
|
|
48
|
+
const needle = (filter ?? '').toLowerCase().trim();
|
|
49
|
+
if (!needle) return steps;
|
|
50
|
+
return steps.filter((s) => s.pattern.toLowerCase().includes(needle));
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
/** Distinct group labels, sorted. A step may appear under several. */
|
|
54
|
+
export function groupLabels(steps: StepDefinition[], mode: GroupingMode): string[] {
|
|
55
|
+
const labels = new Set<string>();
|
|
56
|
+
for (const step of steps) {
|
|
57
|
+
for (const key of keysFor(step, mode)) {
|
|
58
|
+
labels.add(key);
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
return [...labels].sort();
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
/** Steps belonging to *groupLabel*, sorted by pattern. */
|
|
65
|
+
export function stepsInGroup(
|
|
66
|
+
steps: StepDefinition[],
|
|
67
|
+
mode: GroupingMode,
|
|
68
|
+
groupLabel: string,
|
|
69
|
+
): StepDefinition[] {
|
|
70
|
+
return steps
|
|
71
|
+
.filter((s) => keysFor(s, mode).includes(groupLabel))
|
|
72
|
+
.sort((a, b) => a.pattern.localeCompare(b.pattern));
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
/**
|
|
76
|
+
* Rows to display.
|
|
77
|
+
*
|
|
78
|
+
* With no `group`, returns the root level: group headings, or a single message
|
|
79
|
+
* when there is nothing to show. With a `group`, returns that group's steps.
|
|
80
|
+
*/
|
|
81
|
+
export function browseSteps(
|
|
82
|
+
allSteps: StepDefinition[],
|
|
83
|
+
options: BrowseOptions,
|
|
84
|
+
): StepBrowserNode[] {
|
|
85
|
+
const { mode, filter, group } = options;
|
|
86
|
+
|
|
87
|
+
if (allSteps.length === 0) {
|
|
88
|
+
return group ? [] : [{ kind: 'message', label: 'Awaiting discovery...' }];
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
const visible = filterSteps(allSteps, filter);
|
|
92
|
+
if (visible.length === 0) {
|
|
93
|
+
return group ? [] : [{ kind: 'message', label: `No steps match "${(filter ?? '').toLowerCase().trim()}"` }];
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
if (group === undefined) {
|
|
97
|
+
return groupLabels(visible, mode).map((label) => ({ kind: 'group' as const, label }));
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
return stepsInGroup(visible, mode, group).map((step) => ({
|
|
101
|
+
kind: 'step' as const,
|
|
102
|
+
label: step.pattern,
|
|
103
|
+
step,
|
|
104
|
+
}));
|
|
105
|
+
}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
// Copyright (c) 2026 Nigel O'Keefe. All rights reserved.
|
|
2
|
+
// Licensed under the MIT License.
|
|
3
|
+
//
|
|
4
|
+
// Renders a step definition as Markdown, for hover documentation or anywhere
|
|
5
|
+
// else a human-readable description of a step is wanted.
|
|
6
|
+
|
|
7
|
+
import type { StepDefinition } from '../protocol/types';
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* Markdown describing *step*: its pattern, docstring summary, parameters with
|
|
11
|
+
* their suggested values, tags, and where it is defined.
|
|
12
|
+
*
|
|
13
|
+
* Sections are omitted entirely when empty rather than rendered as headings with
|
|
14
|
+
* nothing under them.
|
|
15
|
+
*/
|
|
16
|
+
export function renderStepMarkdown(step: StepDefinition): string {
|
|
17
|
+
const parts: string[] = [`**\`${step.pattern}\`**`];
|
|
18
|
+
|
|
19
|
+
if (step.summary) {
|
|
20
|
+
parts.push(step.summary);
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
if (step.parameters.length > 0) {
|
|
24
|
+
const rows = step.parameters.map((p) => {
|
|
25
|
+
const values = p.suggested_values.length > 0
|
|
26
|
+
? p.suggested_values.join(', ')
|
|
27
|
+
: '_(no suggested values)_';
|
|
28
|
+
return `- \`{${p.name}}\` — **${p.type_name}**: ${values}`;
|
|
29
|
+
});
|
|
30
|
+
parts.push(`**Parameters:**\n\n${rows.join('\n')}`);
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
if (step.tags?.length) {
|
|
34
|
+
parts.push(`**Tags:** ${step.tags.map((t) => `\`@${t}\``).join(' ')}`);
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
if (step.file) {
|
|
38
|
+
const location = step.line ? `${step.file}:${step.line}` : step.file;
|
|
39
|
+
parts.push(`_Defined in \`${location}\`_`);
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
return parts.join('\n\n');
|
|
43
|
+
}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
// Copyright (c) 2026 Nigel O'Keefe. All rights reserved.
|
|
2
|
+
// Licensed under the MIT License.
|
|
3
|
+
//
|
|
4
|
+
// Finds the lines in a feature file where a given step definition is used.
|
|
5
|
+
|
|
6
|
+
import type { StepDefinition } from '../protocol/types';
|
|
7
|
+
import { patternToRegex } from './stepCache';
|
|
8
|
+
|
|
9
|
+
const COMMENT_RE = /^\s*#/;
|
|
10
|
+
const KEYWORD_RE = /^\s*(?:Given|When|Then|And|But|\*)\s+/i;
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* Zero-indexed lines within *lines* whose step text matches *step*'s pattern.
|
|
14
|
+
*
|
|
15
|
+
* Comments are skipped, and the keyword is stripped before matching so that
|
|
16
|
+
* Given/When/Then/And/But all match the same definition — which is how pytest-bdd
|
|
17
|
+
* resolves them.
|
|
18
|
+
*/
|
|
19
|
+
export function findReferencesInLines(lines: string[], step: StepDefinition): number[] {
|
|
20
|
+
const rx = patternToRegex(step.pattern);
|
|
21
|
+
|
|
22
|
+
const results: number[] = [];
|
|
23
|
+
for (let i = 0; i < lines.length; i++) {
|
|
24
|
+
const line = lines[i];
|
|
25
|
+
if (COMMENT_RE.test(line)) continue;
|
|
26
|
+
const m = KEYWORD_RE.exec(line);
|
|
27
|
+
if (!m) continue;
|
|
28
|
+
if (rx.test(line.slice(m[0].length).trim())) {
|
|
29
|
+
results.push(i);
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
return results;
|
|
33
|
+
}
|