Skip to content

Commit b580ac8

Browse files
branchseerclaude
andcommitted
feat(e2e): add interactive TTY mode with expectrl for stdin testing
Add support for interactive TTY mode in e2e test runner using expectrl crate. This enables tests to simulate interactive stdin input through a PTY pseudo-terminal. Key changes: - Modified Step enum: `stdin: Str` → `interactive: bool` - Added run_interactive_step function using sync expectrl with spawn_blocking - Implemented [write-stdin:...] protocol for writing to stdin - Empty content [write-stdin:] signals EOF (sends Ctrl-D) - Updated stdin-passthrough fixture to use new protocol - Created echo-stdin.js script that verifies TTY mode Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
1 parent 348e914 commit b580ac8

9 files changed

Lines changed: 411 additions & 99 deletions

File tree

Cargo.lock

Lines changed: 120 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ derive_more = "2.0.1"
6363
diff-struct = "0.5.3"
6464
directories = "6.0.0"
6565
elf = { version = "0.8.0", default-features = false }
66+
expectrl = "0.8.0"
6667
flate2 = "1.0.35"
6768
fspy = { path = "crates/fspy" }
6869
fspy_detours_sys = { path = "crates/fspy_detours_sys" }

crates/vite_task_bin/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ which = { workspace = true }
2424
[dev-dependencies]
2525
copy_dir = { workspace = true }
2626
cow-utils = { workspace = true }
27+
expectrl = { workspace = true }
2728
insta = { workspace = true, features = ["glob", "json", "redactions", "filters", "ron"] }
2829
regex = { workspace = true }
2930
serde = { workspace = true, features = ["derive", "rc"] }
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
// Use writeSync to avoid buffering issues
2+
const fs = require('fs');
3+
4+
// First, verify we're running in a TTY (should print "true" when using expectrl PTY)
5+
fs.writeSync(1, 'TTY: ' + String(process.stdin.isTTY) + '\n');
6+
7+
// Signal the test runner to write "hello from stdin" to our stdin
8+
fs.writeSync(1, '[write-stdin:hello from stdin]');
9+
10+
// Signal that we're done with stdin commands (this triggers EOF handling)
11+
fs.writeSync(1, '[write-stdin:]');
12+
13+
// Read stdin asynchronously - the test runner will send data then EOF
14+
process.stdin.setEncoding('utf8');
15+
process.stdin.once('readable', () => {
16+
const chunk = process.stdin.read();
17+
if (chunk !== null) {
18+
fs.writeSync(1, chunk);
19+
}
20+
fs.writeSync(1, 'Done\n');
21+
process.exit(0);
22+
});
Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,3 @@
11
{
2-
"name": "stdin-passthrough",
3-
"scripts": {
4-
"echo-stdin": "node -e \"process.stdin.pipe(process.stdout)\""
5-
}
2+
"name": "stdin-passthrough"
63
}
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
# Tests that stdin is passed through to tasks
1+
# Tests that stdin is passed through to tasks with interactive TTY
22

33
[[e2e]]
44
name = "stdin passthrough to single task"
55
steps = [
6-
{ cmd = "vite run echo-stdin", stdin = "hello from stdin" },
6+
{ cmd = "vite run echo-stdin", interactive = true },
77
]
Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,16 @@
11
---
22
source: crates/vite_task_bin/tests/e2e_snapshots/main.rs
3-
assertion_line: 203
43
expression: e2e_outputs
54
input_file: crates/vite_task_bin/tests/e2e_snapshots/fixtures/stdin-passthrough
65
---
76
> vite run echo-stdin
8-
$ node -e "process.stdin.pipe(process.stdout)"
9-
hello from stdin
7+
$ node echo-stdin.js
8+
TTY: true
9+
$ node echo-stdin.js
10+
TTY: true
11+
[write-stdin:hello from stdin][write-stdin:]hello from stdin
12+
Done
13+
1014

1115
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
1216
Vite+ Task RunnerExecution Summary
@@ -17,6 +21,6 @@ Performance: 0% cache hit rate
1721

1822
Task Details:
1923
────────────────────────────────────────────────
20-
[1] stdin-passthrough#echo-stdin: $ node -e "process.stdin.pipe(process.stdout)"
24+
[1] stdin-passthrough#echo-stdin: $ node echo-stdin.js
2125
Cache miss: no previous cache entry found
2226
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"tasks": {
3+
"echo-stdin": {
4+
"command": "node echo-stdin.js"
5+
}
6+
}
7+
}

0 commit comments

Comments
 (0)