ptywright 0.1.1 → 0.3.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 +318 -1
- package/dist/agent.mjs +2 -0
- package/dist/bin/ptywright.mjs +6 -0
- package/dist/cli-CfvlbRoZ.mjs +3585 -0
- package/dist/cli.mjs +2 -0
- package/{src/index.ts → dist/index.mjs} +7 -9
- package/dist/mcp.mjs +2 -0
- package/dist/pty-cassette.mjs +24 -0
- package/dist/pty_like-Cpkh_O9B.mjs +404 -0
- package/dist/runner-zApMYWZx.mjs +3257 -0
- package/dist/runner-zi0nItvB.mjs +1874 -0
- package/dist/script.mjs +2 -0
- package/dist/server-BC3yo-dq.mjs +3068 -0
- package/dist/session.mjs +2 -0
- package/dist/terminal_session-DopC7Xg6.mjs +893 -0
- package/package.json +28 -21
- package/schemas/ptywright-agent-cassette.schema.json +57 -0
- package/schemas/ptywright-agent-check.schema.json +122 -0
- package/schemas/ptywright-agent-manifest.schema.json +107 -0
- package/schemas/ptywright-agent-promote.schema.json +146 -0
- package/schemas/ptywright-agent-replay-summary.schema.json +140 -0
- package/schemas/ptywright-agent-run.schema.json +126 -0
- package/schemas/ptywright-agent.schema.json +166 -0
- package/schemas/ptywright-pty-cassette.schema.json +86 -0
- package/schemas/ptywright-script-manifest.schema.json +75 -0
- package/schemas/ptywright-script-run-summary.schema.json +114 -0
- package/schemas/ptywright-script.schema.json +55 -3
- package/bin/ptywright +0 -4
- package/src/cli.ts +0 -414
- package/src/generator/doc_parser.ts +0 -341
- package/src/generator/generate.ts +0 -161
- package/src/generator/index.ts +0 -10
- package/src/generator/script_generator.ts +0 -209
- package/src/generator/step_extractor.ts +0 -397
- package/src/mcp/http_server.ts +0 -174
- package/src/mcp/script_recording.ts +0 -238
- package/src/mcp/server.ts +0 -1348
- package/src/pty/bun_pty_adapter.ts +0 -34
- package/src/pty/bun_terminal_adapter.ts +0 -149
- package/src/pty/pty_adapter.ts +0 -31
- package/src/script/dsl.ts +0 -188
- package/src/script/module.ts +0 -43
- package/src/script/path.ts +0 -151
- package/src/script/run.ts +0 -108
- package/src/script/run_all.ts +0 -229
- package/src/script/runner.ts +0 -983
- package/src/script/schema.ts +0 -237
- package/src/script/steps/assert_snapshot_equals.ts +0 -21
- package/src/script/steps/index.ts +0 -2
- package/src/script/suite_report.ts +0 -626
- package/src/session/session_manager.ts +0 -145
- package/src/session/terminal_session.ts +0 -473
- package/src/terminal/ansi.ts +0 -142
- package/src/terminal/keys.ts +0 -180
- package/src/terminal/mask.ts +0 -70
- package/src/terminal/mouse.ts +0 -75
- package/src/terminal/snapshot.ts +0 -196
- package/src/terminal/style.ts +0 -121
- package/src/terminal/view.ts +0 -49
- package/src/trace/asciicast.ts +0 -20
- package/src/trace/asciinema_player_assets.ts +0 -44
- package/src/trace/cast_to_txt.ts +0 -116
- package/src/trace/recorder.ts +0 -110
- package/src/trace/report.ts +0 -2092
- package/src/types.ts +0 -86
- package/src/util/hash.ts +0 -8
- package/src/util/sleep.ts +0 -5
package/src/script/run_all.ts
DELETED
|
@@ -1,229 +0,0 @@
|
|
|
1
|
-
import { readdirSync, readFileSync, statSync } from "node:fs";
|
|
2
|
-
import { join, relative, resolve } from "node:path";
|
|
3
|
-
|
|
4
|
-
import { runScriptPath } from "./path";
|
|
5
|
-
import type { RunScriptPathResult } from "./path";
|
|
6
|
-
import { writeSuiteReportArtifacts } from "./suite_report";
|
|
7
|
-
|
|
8
|
-
export type RunAllScriptsOptions = {
|
|
9
|
-
dir?: string;
|
|
10
|
-
artifactsRoot?: string;
|
|
11
|
-
stepsPath?: string;
|
|
12
|
-
updateGoldens?: boolean;
|
|
13
|
-
};
|
|
14
|
-
|
|
15
|
-
export type RunAllScriptsEntry = {
|
|
16
|
-
filePath: string;
|
|
17
|
-
durationMs: number;
|
|
18
|
-
result: RunScriptPathResult;
|
|
19
|
-
};
|
|
20
|
-
|
|
21
|
-
export type RunAllScriptsResult = {
|
|
22
|
-
ok: boolean;
|
|
23
|
-
dir: string;
|
|
24
|
-
suiteDir: string;
|
|
25
|
-
durationMs: number;
|
|
26
|
-
reportPath: string;
|
|
27
|
-
summaryPath: string;
|
|
28
|
-
entries: RunAllScriptsEntry[];
|
|
29
|
-
};
|
|
30
|
-
|
|
31
|
-
export async function runAllScripts(options?: RunAllScriptsOptions): Promise<RunAllScriptsResult> {
|
|
32
|
-
const dir = resolve(options?.dir?.trim() ? options.dir.trim() : "scripts");
|
|
33
|
-
const artifactsRoot = options?.artifactsRoot?.trim()
|
|
34
|
-
? resolve(options.artifactsRoot.trim())
|
|
35
|
-
: null;
|
|
36
|
-
const stepsPath = options?.stepsPath?.trim() ? options.stepsPath.trim() : undefined;
|
|
37
|
-
|
|
38
|
-
const suiteDir = artifactsRoot ?? resolve(".tmp", "run-all");
|
|
39
|
-
|
|
40
|
-
const filePaths = listScriptFiles(dir);
|
|
41
|
-
const entries: RunAllScriptsEntry[] = [];
|
|
42
|
-
|
|
43
|
-
const startedAt = Date.now();
|
|
44
|
-
|
|
45
|
-
for (const filePath of filePaths) {
|
|
46
|
-
const artifactsDirName = safeArtifactsDirName(relative(dir, filePath));
|
|
47
|
-
const artifactsDir = join(suiteDir, "tests", artifactsDirName);
|
|
48
|
-
|
|
49
|
-
const entryStartedAt = Date.now();
|
|
50
|
-
const result = await runScriptPath(filePath, {
|
|
51
|
-
artifactsDir,
|
|
52
|
-
stepsPath,
|
|
53
|
-
updateGoldens: options?.updateGoldens,
|
|
54
|
-
});
|
|
55
|
-
const durationMs = Date.now() - entryStartedAt;
|
|
56
|
-
|
|
57
|
-
entries.push({ filePath, durationMs, result });
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
const durationMs = Date.now() - startedAt;
|
|
61
|
-
|
|
62
|
-
const { reportPath, summaryPath } = writeSuiteReportArtifacts({
|
|
63
|
-
dir,
|
|
64
|
-
suiteDir,
|
|
65
|
-
durationMs,
|
|
66
|
-
entries,
|
|
67
|
-
});
|
|
68
|
-
|
|
69
|
-
return {
|
|
70
|
-
ok: entries.every((e) => e.result.ok),
|
|
71
|
-
dir,
|
|
72
|
-
suiteDir,
|
|
73
|
-
durationMs,
|
|
74
|
-
reportPath,
|
|
75
|
-
summaryPath,
|
|
76
|
-
entries,
|
|
77
|
-
};
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
function safeArtifactsDirName(relPath: string): string {
|
|
81
|
-
return relPath.replace(/[/\\]/g, "__");
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
function shouldIncludeJsonScript(filePath: string): boolean {
|
|
85
|
-
try {
|
|
86
|
-
const raw = readFileSync(filePath, "utf8");
|
|
87
|
-
const parsed = JSON.parse(raw) as unknown;
|
|
88
|
-
|
|
89
|
-
if (!parsed || typeof parsed !== "object" || Array.isArray(parsed)) return false;
|
|
90
|
-
|
|
91
|
-
const obj = parsed as { launch?: unknown; steps?: unknown };
|
|
92
|
-
if (!obj.launch || typeof obj.launch !== "object" || Array.isArray(obj.launch)) return false;
|
|
93
|
-
|
|
94
|
-
const launch = obj.launch as { command?: unknown };
|
|
95
|
-
if (typeof launch.command !== "string" || !launch.command.trim()) return false;
|
|
96
|
-
|
|
97
|
-
return Array.isArray(obj.steps) && obj.steps.length > 0;
|
|
98
|
-
} catch {
|
|
99
|
-
// If a .json file is invalid JSON, keep legacy behavior: let it fail as a script.
|
|
100
|
-
return true;
|
|
101
|
-
}
|
|
102
|
-
}
|
|
103
|
-
|
|
104
|
-
function listScriptFiles(dir: string): string[] {
|
|
105
|
-
const out: string[] = [];
|
|
106
|
-
|
|
107
|
-
for (const entry of readdirSync(dir)) {
|
|
108
|
-
const abs = join(dir, entry);
|
|
109
|
-
const stat = statSync(abs);
|
|
110
|
-
if (stat.isDirectory()) {
|
|
111
|
-
out.push(...listScriptFiles(abs));
|
|
112
|
-
continue;
|
|
113
|
-
}
|
|
114
|
-
|
|
115
|
-
if (entry.endsWith(".json")) {
|
|
116
|
-
if (shouldIncludeJsonScript(abs)) out.push(abs);
|
|
117
|
-
continue;
|
|
118
|
-
}
|
|
119
|
-
|
|
120
|
-
if (!entry.endsWith(".ts")) continue;
|
|
121
|
-
if (entry.endsWith(".d.ts")) continue;
|
|
122
|
-
if (entry.endsWith("_steps.ts") || entry.endsWith(".steps.ts")) continue;
|
|
123
|
-
|
|
124
|
-
out.push(abs);
|
|
125
|
-
}
|
|
126
|
-
|
|
127
|
-
return out.sort((a, b) => a.localeCompare(b));
|
|
128
|
-
}
|
|
129
|
-
|
|
130
|
-
function parseArgs(argv: string[]): {
|
|
131
|
-
dir?: string;
|
|
132
|
-
artifactsRoot?: string;
|
|
133
|
-
stepsPath?: string;
|
|
134
|
-
updateGoldens: boolean;
|
|
135
|
-
} {
|
|
136
|
-
const out: {
|
|
137
|
-
dir?: string;
|
|
138
|
-
artifactsRoot?: string;
|
|
139
|
-
stepsPath?: string;
|
|
140
|
-
updateGoldens: boolean;
|
|
141
|
-
} = { updateGoldens: false };
|
|
142
|
-
|
|
143
|
-
for (let i = 0; i < argv.length; i += 1) {
|
|
144
|
-
const arg = argv[i];
|
|
145
|
-
const next = argv[i + 1];
|
|
146
|
-
|
|
147
|
-
if (!out.dir && arg && !arg.startsWith("-")) {
|
|
148
|
-
out.dir = arg;
|
|
149
|
-
continue;
|
|
150
|
-
}
|
|
151
|
-
|
|
152
|
-
if (arg === "--dir" && next) {
|
|
153
|
-
out.dir = next;
|
|
154
|
-
i += 1;
|
|
155
|
-
continue;
|
|
156
|
-
}
|
|
157
|
-
|
|
158
|
-
if (arg === "--artifacts-root" && next) {
|
|
159
|
-
out.artifactsRoot = next;
|
|
160
|
-
i += 1;
|
|
161
|
-
continue;
|
|
162
|
-
}
|
|
163
|
-
|
|
164
|
-
if (arg === "--steps" && next) {
|
|
165
|
-
out.stepsPath = next;
|
|
166
|
-
i += 1;
|
|
167
|
-
continue;
|
|
168
|
-
}
|
|
169
|
-
|
|
170
|
-
if (arg === "--update-goldens") {
|
|
171
|
-
out.updateGoldens = true;
|
|
172
|
-
continue;
|
|
173
|
-
}
|
|
174
|
-
|
|
175
|
-
throw new Error(`unknown arg: ${arg ?? ""}`);
|
|
176
|
-
}
|
|
177
|
-
|
|
178
|
-
return out as {
|
|
179
|
-
dir?: string;
|
|
180
|
-
artifactsRoot?: string;
|
|
181
|
-
stepsPath?: string;
|
|
182
|
-
updateGoldens: boolean;
|
|
183
|
-
};
|
|
184
|
-
}
|
|
185
|
-
|
|
186
|
-
if (import.meta.main) {
|
|
187
|
-
try {
|
|
188
|
-
const args = parseArgs(process.argv.slice(2));
|
|
189
|
-
const result = await runAllScripts({
|
|
190
|
-
dir: args.dir,
|
|
191
|
-
artifactsRoot: args.artifactsRoot,
|
|
192
|
-
stepsPath: args.stepsPath,
|
|
193
|
-
updateGoldens: args.updateGoldens,
|
|
194
|
-
});
|
|
195
|
-
|
|
196
|
-
const failures = result.entries.filter((e) => !e.result.ok);
|
|
197
|
-
|
|
198
|
-
if (failures.length === 0) {
|
|
199
|
-
// eslint-disable-next-line no-console
|
|
200
|
-
console.log(
|
|
201
|
-
`ok count=${result.entries.length} dir=${result.dir}\nreport=${result.reportPath}\nsummary=${result.summaryPath}`,
|
|
202
|
-
);
|
|
203
|
-
process.exitCode = 0;
|
|
204
|
-
} else {
|
|
205
|
-
// eslint-disable-next-line no-console
|
|
206
|
-
console.error(
|
|
207
|
-
`failed count=${failures.length}/${result.entries.length} dir=${result.dir}\nreport=${result.reportPath}\nsummary=${result.summaryPath}`,
|
|
208
|
-
);
|
|
209
|
-
for (const f of failures) {
|
|
210
|
-
if (f.result.ok) continue;
|
|
211
|
-
// eslint-disable-next-line no-console
|
|
212
|
-
console.error(`- ${f.filePath}: ${f.result.error}`);
|
|
213
|
-
if (f.result.failureArtifacts) {
|
|
214
|
-
// eslint-disable-next-line no-console
|
|
215
|
-
console.error(` artifacts=${f.result.artifactsDir ?? ""}`);
|
|
216
|
-
// eslint-disable-next-line no-console
|
|
217
|
-
console.error(` last=${f.result.failureArtifacts.lastViewPath}`);
|
|
218
|
-
// eslint-disable-next-line no-console
|
|
219
|
-
console.error(` error=${f.result.failureArtifacts.errorPath}`);
|
|
220
|
-
}
|
|
221
|
-
}
|
|
222
|
-
process.exitCode = 1;
|
|
223
|
-
}
|
|
224
|
-
} catch (error) {
|
|
225
|
-
// eslint-disable-next-line no-console
|
|
226
|
-
console.error((error as Error).message);
|
|
227
|
-
process.exitCode = 1;
|
|
228
|
-
}
|
|
229
|
-
}
|