testingterm 0.0.2 → 0.0.4
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/AGENT-DOCS.md +1 -0
- package/dist/chunks/{chunk-YFGNBX2I.js → chunk-FQASQ43D.js} +12 -7
- package/dist/chunks/{chunk-YHQYNBAN.js → chunk-XCWXGUFI.js} +27 -2
- package/dist/chunks/{commands-IWTFRW33.js → commands-QVHQORTJ.js} +1 -1
- package/dist/chunks/{help-I5WIJHZM.js → help-LZQLUFX7.js} +1 -1
- package/dist/chunks/{run-RNFQMMXD.js → run-6BMSCVGT.js} +2 -2
- package/dist/chunks/{verify-55DFXJOY.js → verify-7WDJYYPZ.js} +1 -1
- package/dist/cli/main.js +4 -4
- package/dist/engine.d.ts +1 -1
- package/dist/index.js +2 -2
- package/dist/terminal.d.ts +4 -2
- package/dist/types.d.ts +25 -0
- package/package.json +5 -5
- package/skill/testingterm/SKILL.md +4 -2
package/AGENT-DOCS.md
CHANGED
|
@@ -43,6 +43,7 @@ terminal.getByText(text | RegExp, { exact }) -> Locator: first() last() nth(i) a
|
|
|
43
43
|
terminal.find(text | RegExp) -> Box[]
|
|
44
44
|
terminal.waitForText / waitForGone / waitForIdle(ms) / waitForStable(ms) / waitForTitle / waitForExit
|
|
45
45
|
terminal.screenshot({ path, name, cursor }) -> { path, width, height }
|
|
46
|
+
terminal.pixels({ region: { x, y, w, h }, cursor }) -> { x, y, width, height, rgba, at(x, y) -> [r, g, b, a] }
|
|
46
47
|
terminal.startRecording({ path, fps }) / stopRecording()
|
|
47
48
|
terminal.startProfile({ path }) / stopProfile()
|
|
48
49
|
terminal.resize(cols, rows) / signal(name) / focus(bool) / scroll(lines)
|
|
@@ -20,7 +20,7 @@ import net from "node:net";
|
|
|
20
20
|
var Connection = class {
|
|
21
21
|
next = 1;
|
|
22
22
|
pending = /* @__PURE__ */ new Map();
|
|
23
|
-
|
|
23
|
+
partial = [];
|
|
24
24
|
closed = null;
|
|
25
25
|
exit = null;
|
|
26
26
|
onExit = null;
|
|
@@ -32,12 +32,16 @@ var Connection = class {
|
|
|
32
32
|
this.end = end;
|
|
33
33
|
}
|
|
34
34
|
data(chunk) {
|
|
35
|
-
|
|
36
|
-
let newline =
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
35
|
+
let start = 0;
|
|
36
|
+
let newline = chunk.indexOf("\n");
|
|
37
|
+
if (newline === -1) {
|
|
38
|
+
this.partial.push(chunk);
|
|
39
|
+
return;
|
|
40
|
+
}
|
|
41
|
+
for (; newline !== -1; start = newline + 1, newline = chunk.indexOf("\n", start)) {
|
|
42
|
+
this.partial.push(chunk.slice(start, newline));
|
|
43
|
+
const line = this.partial.join("");
|
|
44
|
+
this.partial = [];
|
|
41
45
|
if (!line) continue;
|
|
42
46
|
let message;
|
|
43
47
|
try {
|
|
@@ -58,6 +62,7 @@ var Connection = class {
|
|
|
58
62
|
if (message.ok === false) waiter.reject(new EngineError(String(message.error), message.screen));
|
|
59
63
|
else waiter.resolve(message);
|
|
60
64
|
}
|
|
65
|
+
if (start < chunk.length) this.partial.push(chunk.slice(start));
|
|
61
66
|
}
|
|
62
67
|
fail(error) {
|
|
63
68
|
this.closed = error;
|
|
@@ -9,7 +9,7 @@ import {
|
|
|
9
9
|
socketPath,
|
|
10
10
|
startEngine,
|
|
11
11
|
writeInstance
|
|
12
|
-
} from "./chunk-
|
|
12
|
+
} from "./chunk-FQASQ43D.js";
|
|
13
13
|
import {
|
|
14
14
|
currentScope,
|
|
15
15
|
rootScope,
|
|
@@ -446,7 +446,7 @@ var Terminal = class _Terminal {
|
|
|
446
446
|
await this.wait({ idle: ms }, options, `wait for ${ms}ms of quiet`);
|
|
447
447
|
}
|
|
448
448
|
// fixme: placeholder copy
|
|
449
|
-
/** Wait until the screen has not changed for `ms` milliseconds. Useful after animations and spinners. */
|
|
449
|
+
/** Wait until the screen (text, colors, cursor and kitty graphics) has not changed for `ms` milliseconds. Useful after animations and spinners. */
|
|
450
450
|
async waitForStable(ms = 150, options = {}) {
|
|
451
451
|
await this.wait({ stable: ms }, options, `wait for the screen to settle for ${ms}ms`);
|
|
452
452
|
}
|
|
@@ -471,6 +471,31 @@ var Terminal = class _Terminal {
|
|
|
471
471
|
return { path: reply.path, width: reply.width, height: reply.height };
|
|
472
472
|
}
|
|
473
473
|
// fixme: placeholder copy
|
|
474
|
+
/** Read the rendered frame as raw RGBA pixels, exactly what {@link screenshot} would save, without writing a file. */
|
|
475
|
+
async pixels(options = {}) {
|
|
476
|
+
const region = options.region && { x: options.region.x, y: options.region.y, w: options.region.w, h: options.region.h };
|
|
477
|
+
const reply = await this.connection.request("pixels", { region, cursor: options.cursor });
|
|
478
|
+
const bytes = Buffer.from(reply.rgba, "base64");
|
|
479
|
+
const rgba = new Uint8Array(bytes.buffer, bytes.byteOffset, bytes.byteLength);
|
|
480
|
+
const { x, y, width, height } = reply;
|
|
481
|
+
return {
|
|
482
|
+
x,
|
|
483
|
+
y,
|
|
484
|
+
width,
|
|
485
|
+
height,
|
|
486
|
+
rgba,
|
|
487
|
+
at(px, py) {
|
|
488
|
+
const col = Math.floor(px) - x;
|
|
489
|
+
const row = Math.floor(py) - y;
|
|
490
|
+
if (col < 0 || row < 0 || col >= width || row >= height) {
|
|
491
|
+
throw new RangeError(`pixel ${px},${py} is outside these pixels (${x},${y} ${width}x${height})`);
|
|
492
|
+
}
|
|
493
|
+
const i = (row * width + col) * 4;
|
|
494
|
+
return [rgba[i], rgba[i + 1], rgba[i + 2], rgba[i + 3]];
|
|
495
|
+
}
|
|
496
|
+
};
|
|
497
|
+
}
|
|
498
|
+
// fixme: placeholder copy
|
|
474
499
|
/** Start recording a video. Stop it with {@link stopRecording}. */
|
|
475
500
|
async startRecording(options = {}) {
|
|
476
501
|
const file = options.path ? path.resolve(options.path) : this.file("mp4", `${this.name}-${this.id}-${Date.now()}`);
|
|
@@ -186,7 +186,7 @@ Conditions:
|
|
|
186
186
|
--regex <pattern> A regex matches the screen
|
|
187
187
|
--gone <text> The text is no longer on screen
|
|
188
188
|
--idle <ms> The program printed nothing for this long
|
|
189
|
-
--stable <ms> The screen did not change for this long
|
|
189
|
+
--stable <ms> The screen, including images, did not change for this long
|
|
190
190
|
--title <text> The title contains the text
|
|
191
191
|
--exit The program exited (prints the exit code)
|
|
192
192
|
--scrollback Search the whole history, not just the screen
|
|
@@ -2,9 +2,9 @@ import {
|
|
|
2
2
|
defaultWorkers,
|
|
3
3
|
evalFile,
|
|
4
4
|
runFiles
|
|
5
|
-
} from "./chunk-
|
|
5
|
+
} from "./chunk-XCWXGUFI.js";
|
|
6
6
|
import "./chunk-INTJPVJZ.js";
|
|
7
|
-
import "./chunk-
|
|
7
|
+
import "./chunk-FQASQ43D.js";
|
|
8
8
|
import {
|
|
9
9
|
settings
|
|
10
10
|
} from "./chunk-IJ5VA4HN.js";
|
package/dist/cli/main.js
CHANGED
|
@@ -6,7 +6,7 @@ module.enableCompileCache?.();
|
|
|
6
6
|
var argv = process.argv.slice(2);
|
|
7
7
|
var command = argv[0];
|
|
8
8
|
async function main() {
|
|
9
|
-
const { commandHelp, rootHelp } = await import("../chunks/help-
|
|
9
|
+
const { commandHelp, rootHelp } = await import("../chunks/help-LZQLUFX7.js");
|
|
10
10
|
if (!command || command === "help" || command === "--help" || command === "-h") {
|
|
11
11
|
const topic = command === "help" ? argv[1] : void 0;
|
|
12
12
|
process.stdout.write(topic && commandHelp(topic) || rootHelp());
|
|
@@ -36,15 +36,15 @@ async function main() {
|
|
|
36
36
|
const args = new Args(rest);
|
|
37
37
|
switch (command) {
|
|
38
38
|
case "run":
|
|
39
|
-
return await (await import("../chunks/run-
|
|
39
|
+
return await (await import("../chunks/run-6BMSCVGT.js")).runCommand(args);
|
|
40
40
|
case "setup":
|
|
41
41
|
return await (await import("../chunks/setup-WIZULKES.js")).setupCommand(args);
|
|
42
42
|
case "upgrade":
|
|
43
43
|
return await (await import("../chunks/upgrade-43JWCQ63.js")).upgradeCommand(args);
|
|
44
44
|
case "verify":
|
|
45
|
-
return await (await import("../chunks/verify-
|
|
45
|
+
return await (await import("../chunks/verify-7WDJYYPZ.js")).verifyCommand(args);
|
|
46
46
|
default: {
|
|
47
|
-
const commands = await import("../chunks/commands-
|
|
47
|
+
const commands = await import("../chunks/commands-QVHQORTJ.js");
|
|
48
48
|
const handler = commands.COMMANDS[command];
|
|
49
49
|
if (!handler) {
|
|
50
50
|
process.stderr.write(`testingterm: unknown command ${command}
|
package/dist/engine.d.ts
CHANGED
package/dist/index.js
CHANGED
|
@@ -4,13 +4,13 @@ import {
|
|
|
4
4
|
Terminal,
|
|
5
5
|
normalizeLaunch,
|
|
6
6
|
test
|
|
7
|
-
} from "./chunks/chunk-
|
|
7
|
+
} from "./chunks/chunk-XCWXGUFI.js";
|
|
8
8
|
import {
|
|
9
9
|
CAPABILITY_PRESETS
|
|
10
10
|
} from "./chunks/chunk-INTJPVJZ.js";
|
|
11
11
|
import {
|
|
12
12
|
EngineError
|
|
13
|
-
} from "./chunks/chunk-
|
|
13
|
+
} from "./chunks/chunk-FQASQ43D.js";
|
|
14
14
|
import "./chunks/chunk-IJ5VA4HN.js";
|
|
15
15
|
import "./chunks/chunk-PA67Y4XN.js";
|
|
16
16
|
import {
|
package/dist/terminal.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { resolveCapabilities } from "./capabilities.ts";
|
|
2
2
|
import { Locator, type TextQuery } from "./locator.ts";
|
|
3
|
-
import type { Box, ClickOptions, ExitStatus, LaunchOptions, Point, Screen, Shot, StyledSpan, Theme, VerifyOptions, VerifyResult, WaitOptions } from "./types.ts";
|
|
3
|
+
import type { Box, ClickOptions, ExitStatus, LaunchOptions, Pixels, PixelsOptions, Point, Screen, Shot, StyledSpan, Theme, VerifyOptions, VerifyResult, WaitOptions } from "./types.ts";
|
|
4
4
|
export declare class Terminal {
|
|
5
5
|
readonly id: string;
|
|
6
6
|
readonly name: string;
|
|
@@ -87,7 +87,7 @@ export declare class Terminal {
|
|
|
87
87
|
waitForGone(text: string, options?: WaitOptions): Promise<void>;
|
|
88
88
|
/** Wait until the program has printed nothing for `ms` milliseconds. */
|
|
89
89
|
waitForIdle(ms?: number, options?: WaitOptions): Promise<void>;
|
|
90
|
-
/** Wait until the screen has not changed for `ms` milliseconds. Useful after animations and spinners. */
|
|
90
|
+
/** Wait until the screen (text, colors, cursor and kitty graphics) has not changed for `ms` milliseconds. Useful after animations and spinners. */
|
|
91
91
|
waitForStable(ms?: number, options?: WaitOptions): Promise<void>;
|
|
92
92
|
/** Wait until the window title contains `title`. */
|
|
93
93
|
waitForTitle(title: string, options?: WaitOptions): Promise<void>;
|
|
@@ -99,6 +99,8 @@ export declare class Terminal {
|
|
|
99
99
|
name?: string;
|
|
100
100
|
cursor?: boolean;
|
|
101
101
|
}): Promise<Shot>;
|
|
102
|
+
/** Read the rendered frame as raw RGBA pixels, exactly what {@link screenshot} would save, without writing a file. */
|
|
103
|
+
pixels(options?: PixelsOptions): Promise<Pixels>;
|
|
102
104
|
/** Start recording a video. Stop it with {@link stopRecording}. */
|
|
103
105
|
startRecording(options?: {
|
|
104
106
|
path?: string;
|
package/dist/types.d.ts
CHANGED
|
@@ -178,6 +178,31 @@ export type Point = {
|
|
|
178
178
|
col: number;
|
|
179
179
|
row: number;
|
|
180
180
|
};
|
|
181
|
+
/** A rectangle in screenshot pixels. A {@link Box} from `find()` or `box()` fits. */
|
|
182
|
+
export interface Region {
|
|
183
|
+
x: number;
|
|
184
|
+
y: number;
|
|
185
|
+
w: number;
|
|
186
|
+
h: number;
|
|
187
|
+
}
|
|
188
|
+
export interface PixelsOptions {
|
|
189
|
+
/** Only return this rectangle of the frame, in screenshot pixels. Default: the whole frame. */
|
|
190
|
+
region?: Region;
|
|
191
|
+
/** Draw the cursor. Default: the terminal's `cursor` option. */
|
|
192
|
+
cursor?: boolean;
|
|
193
|
+
}
|
|
194
|
+
export interface Pixels {
|
|
195
|
+
/** Left edge in screenshot pixels: the region's `x`, or 0 for the whole frame. */
|
|
196
|
+
x: number;
|
|
197
|
+
/** Top edge in screenshot pixels: the region's `y`, or 0 for the whole frame. */
|
|
198
|
+
y: number;
|
|
199
|
+
width: number;
|
|
200
|
+
height: number;
|
|
201
|
+
/** Row by row, 4 bytes (r, g, b, a) per pixel, starting at the top left of this rectangle. */
|
|
202
|
+
rgba: Uint8Array;
|
|
203
|
+
/** The `[r, g, b, a]` of a pixel, by screenshot coordinates (the same ones `click()` takes). */
|
|
204
|
+
at(x: number, y: number): [r: number, g: number, b: number, a: number];
|
|
205
|
+
}
|
|
181
206
|
export interface WaitOptions {
|
|
182
207
|
/** Milliseconds before giving up. Default: the terminal's timeout. */
|
|
183
208
|
timeout?: number;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "testingterm",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.4",
|
|
4
4
|
"description": "Test terminal apps: drive a real terminal, read its state, and capture screenshots, videos and profiles",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"type": "module",
|
|
@@ -35,9 +35,9 @@
|
|
|
35
35
|
"zod": "^4.6.7"
|
|
36
36
|
},
|
|
37
37
|
"optionalDependencies": {
|
|
38
|
-
"@zenbu-labs/testingterm-darwin-arm64": "0.0.
|
|
39
|
-
"@zenbu-labs/testingterm-darwin-x64": "0.0.
|
|
40
|
-
"@zenbu-labs/testingterm-linux-x64": "0.0.
|
|
41
|
-
"@zenbu-labs/testingterm-linux-arm64": "0.0.
|
|
38
|
+
"@zenbu-labs/testingterm-darwin-arm64": "0.0.4",
|
|
39
|
+
"@zenbu-labs/testingterm-darwin-x64": "0.0.4",
|
|
40
|
+
"@zenbu-labs/testingterm-linux-x64": "0.0.4",
|
|
41
|
+
"@zenbu-labs/testingterm-linux-arm64": "0.0.4"
|
|
42
42
|
}
|
|
43
43
|
}
|
|
@@ -82,8 +82,8 @@ With one terminal running, commands use it; with several, pass `--id <id>`
|
|
|
82
82
|
## Rules that keep tests reliable
|
|
83
83
|
|
|
84
84
|
- Never sleep. Wait for what you expect: `waitForText` / `--text`, `--gone`,
|
|
85
|
-
`waitForStable(ms)` / `--stable` after animations and spinners
|
|
86
|
-
output to stop, `waitForExit` / `--exit`.
|
|
85
|
+
`waitForStable(ms)` / `--stable` after animations and spinners (kitty graphics
|
|
86
|
+
changes count too), `--idle` for output to stop, `waitForExit` / `--exit`.
|
|
87
87
|
- `expect(term)` assertions retry until they pass or time out (default 5s), so
|
|
88
88
|
they never race the program.
|
|
89
89
|
- `getByText()` is strict: if the text appears more than once it errors; pick
|
|
@@ -116,6 +116,8 @@ With one terminal running, commands use it; with several, pass `--id <id>`
|
|
|
116
116
|
## Evidence for the human
|
|
117
117
|
|
|
118
118
|
- Screenshots: `term.screenshot()` / `testingterm screenshot`.
|
|
119
|
+
- Pixels in a test: `term.pixels({ region })` returns raw RGBA (`at(x, y)` ->
|
|
120
|
+
`[r, g, b, a]`), so you can assert colors and images without decoding PNGs.
|
|
119
121
|
- Videos: `launch(cmd, { record: true })`, `--video on` on `run`, or `testingterm
|
|
120
122
|
record start|stop`. Videos show the pointer, clicks and keys pressed.
|
|
121
123
|
- Let the human watch live: `--headed` on `run` or `new` opens a window, and
|