ptywright 0.3.0 → 0.5.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.
@@ -0,0 +1,80 @@
1
+ # Script Runner
2
+
3
+ Use scripts for deterministic CLI/TUI tests that do not need a browser terminal renderer.
4
+
5
+ ## JSON Script
6
+
7
+ ```json
8
+ {
9
+ "$schema": "../schemas/ptywright-script.schema.json",
10
+ "name": "tui_smoke",
11
+ "command": ["bun", "tests/fixtures/tui_demo.ts"],
12
+ "cols": 80,
13
+ "rows": 24,
14
+ "env": { "TERM": "xterm-256color" },
15
+ "steps": [
16
+ { "type": "waitForText", "text": "Ready", "scope": "buffer" },
17
+ { "type": "snapshot", "kind": "text", "saveAs": "ready" },
18
+ { "type": "expectGolden", "name": "ready" }
19
+ ]
20
+ }
21
+ ```
22
+
23
+ Run it:
24
+
25
+ ```bash
26
+ ptywright run scripts/tui_smoke.json
27
+ ptywright run scripts/tui_smoke.json --update-goldens
28
+ ```
29
+
30
+ Run a suite:
31
+
32
+ ```bash
33
+ ptywright run-all --dir scripts
34
+ ptywright run-all --dir scripts --update-goldens
35
+ ```
36
+
37
+ ## TypeScript Scripts
38
+
39
+ Use TS scripts when the test needs custom data, helper functions, or custom steps. Keep business logic small. If the script gets complex, move deterministic behavior into a fixture program and keep the ptywright script declarative.
40
+
41
+ ## MCP Recording To Script
42
+
43
+ When driving a TUI through MCP tools:
44
+
45
+ 1. `start_script_recording(name=...)`
46
+ 2. Use normal tools such as `launch_session`, `send_text`, `press_key`, `wait_for_text`, and `snapshot_text`.
47
+ 3. Add checkpoints with `mark(label=...)`.
48
+ 4. `stop_script_recording(recordingId=..., writeFiles=true)`.
49
+
50
+ The exported script can be committed and replayed without the original agent interaction.
51
+
52
+ ## Reports And Artifacts
53
+
54
+ Look for:
55
+
56
+ - `index.html` or `*.report.html`: Timeline report.
57
+ - `*.cast`: Playback stream.
58
+ - `run.summary.json`: Suite/run summary.
59
+ - `failure.last.view.txt`: Last visible terminal state.
60
+ - `failure.last.txt`: Plain last screen.
61
+ - `failure.error.txt`: Error details.
62
+
63
+ ## Snapshot Rules
64
+
65
+ - Use `snapshot_text` or text snapshots for stable regression.
66
+ - Use ANSI snapshots only when style information matters.
67
+ - Use masks for random tokens, timestamps, ids, progress counters, and spinner glyphs.
68
+ - Use `scope="buffer"` when content may scroll out of the viewport.
69
+ - Use explicit waits before snapshots. Prefer `waitForText` or stable-screen waits over fixed sleeps.
70
+
71
+ ## CI Pattern
72
+
73
+ ```bash
74
+ ptywright run-all --dir scripts
75
+ ptywright script validate .tmp/run-all
76
+ ptywright script commands .tmp/run-all --json
77
+ ptywright script exec .tmp/run-all --command updateGoldens
78
+ ```
79
+
80
+ Use update commands only for intentional baseline changes.
@@ -1,6 +1,6 @@
1
- import { z } from "zod";
2
- import { dirname } from "node:path";
3
1
  import { mkdirSync, readFileSync, writeFileSync } from "node:fs";
2
+ import { dirname } from "node:path";
3
+ import { z } from "zod";
4
4
  import { Buffer } from "node:buffer";
5
5
  //#region src/pty-cassette/data.ts
6
6
  function dataToBytes(data) {