GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — test(snapshots): bound the PTY spawn with the per-step timeout by fengmk2 · Pull Request #2102 · voidzero-dev/vite-plus

test(snapshots): bound the PTY spawn with the per-step timeout #2102

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

Sign up for GitHub

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
fengmk2 merged 4 commits into main from fix/pty-spawn-timeout
Jul 9, 2026

Uh oh!

There was an error while loading. Please reload this page.

Merged

test(snapshots): bound the PTY spawn with the per-step timeout #2102

Changes from all commits
Commits
Show all changes
4 commits
Select commit Hold shift + click to select a range
d8a5b97
test(snapshots): bound the PTY spawn with the per-step timeout
fengmk2 Jul 9, 2026
504379f
test(snapshots): kill a spawn that completes after the timeout
fengmk2 Jul 9, 2026
281437a
Merge branch 'main' into fix/pty-spawn-timeout
fengmk2 Jul 9, 2026
0789c79
Merge branch 'main' into fix/pty-spawn-timeout
fengmk2 Jul 9, 2026
File filter
Filter by extension

Clear filters
Conversations
Failed to load comments.
Loading

Uh oh!

There was an error while loading. Please reload this page.

Jump to
Jump to file
Failed to load files.
Loading

Uh oh!

There was an error while loading. Please reload this page.

Diff view
Diff view

There are no files selected for viewing

199 changes: 118 additions & 81 deletions 199 crates/vite_cli_snapshots/tests/cli_snapshots/main.rs
Show comments
View file
Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -907,93 +907,130 @@ fn run_case(
let timeout = step.timeout(step_default_timeout);

let (termination_state, raw_output) = if step.tty {
let mut cmd = CommandBuilder::new(&program);
for arg in &argv[1..] {
cmd.arg(arg);
}
cmd.env_clear();
for (k, v) in step_env {
cmd.env(k, v);
}
cmd.cwd(&step_cwd);

let terminal = TestTerminal::spawn(SCREEN_SIZE, cmd).unwrap();
let mut killer = terminal.child_handle.clone();
let interactions = step.interactions.clone();
let formatted_snapshot = step.formatted_snapshot;
let output = Arc::new(Mutex::new(String::new()));
let output_for_thread = Arc::clone(&output);
let (tx, rx) = mpsc::channel();
std::thread::spawn(move || {
let mut terminal = terminal;

for interaction in interactions {
match interaction {
Interaction::ExpectMilestone(expect) => {
output_for_thread.lock().unwrap().push_str(&format!(
"**→ expect-milestone:** `{}`\n\n",
expect.expect_milestone
));
let milestone_screen =
terminal.reader.expect_milestone(&expect.expect_milestone);
let mut output = output_for_thread.lock().unwrap();
push_fenced_block(&mut output, &milestone_screen);
output.push('\n');
}
Interaction::Write(write) => {
output_for_thread
.lock()
.unwrap()
.push_str(&format!("**← write:** `{}`\n\n", write.write));
terminal.writer.write_all(write.write.as_bytes()).unwrap();
terminal.writer.flush().unwrap();
}
Interaction::WriteLine(write_line) => {
output_for_thread.lock().unwrap().push_str(&format!(
"**← write-line:** `{}`\n\n",
write_line.write_line
));
terminal.writer.write_line(write_line.write_line.as_bytes()).unwrap();
}
Interaction::WriteKey(write_key) => {
let key_name = write_key.write_key.as_str();
output_for_thread
.lock()
.unwrap()
.push_str(&format!("**← write-key:** `{key_name}`\n\n"));
terminal.writer.write_all(write_key.write_key.bytes()).unwrap();
terminal.writer.flush().unwrap();
'tty: {
let mut cmd = CommandBuilder::new(&program);
for arg in &argv[1..] {
cmd.arg(arg);
}
cmd.env_clear();
for (k, v) in step_env {
cmd.env(k, v);
}
cmd.cwd(&step_cwd);

// Bound the PTY spawn itself. `TestTerminal::spawn` (openpty plus
// fork/exec of the child into the PTY) can block indefinitely on
// some CI runners, and it runs before the interaction-phase
// `recv_timeout` below could catch it. Run it on a helper thread so
// a wedged spawn becomes a per-step timeout, not a suite-wide hang:
// the helper thread is abandoned, this case fails, and the rest of
// the suite proceeds.
let (spawn_tx, spawn_rx) = mpsc::channel();
std::thread::spawn(move || {
// If the main thread already timed out and dropped the
// receiver, the spawn may still complete afterwards: kill
// the child so a slow-but-live command can't keep running
// (holding a port, mutating the staged workspace) after the
// case has already failed.
if let Err(mpsc::SendError(Ok(terminal))) =
spawn_tx.send(TestTerminal::spawn(SCREEN_SIZE, cmd))
{
let _ = terminal.child_handle.clone().kill();
}
});
let terminal = match spawn_rx.recv_timeout(timeout) {
Ok(Ok(terminal)) => terminal,
Ok(Err(err)) => panic!("failed to spawn PTY terminal: {err}"),
Err(mpsc::RecvTimeoutError::Timeout) => {
break 'tty (
TerminationState::TimedOut,
"(PTY spawn did not complete)".to_string(),
);
}
Err(mpsc::RecvTimeoutError::Disconnected) => {
panic!("PTY spawn thread panicked");
}
};
let mut killer = terminal.child_handle.clone();
let interactions = step.interactions.clone();
let formatted_snapshot = step.formatted_snapshot;
let output = Arc::new(Mutex::new(String::new()));
let output_for_thread = Arc::clone(&output);
let (tx, rx) = mpsc::channel();
std::thread::spawn(move || {
let mut terminal = terminal;

for interaction in interactions {
match interaction {
Interaction::ExpectMilestone(expect) => {
output_for_thread.lock().unwrap().push_str(&format!(
"**→ expect-milestone:** `{}`\n\n",
expect.expect_milestone
));
let milestone_screen =
terminal.reader.expect_milestone(&expect.expect_milestone);
let mut output = output_for_thread.lock().unwrap();
push_fenced_block(&mut output, &milestone_screen);
output.push('\n');
}
Interaction::Write(write) => {
output_for_thread
.lock()
.unwrap()
.push_str(&format!("**← write:** `{}`\n\n", write.write));
terminal.writer.write_all(write.write.as_bytes()).unwrap();
terminal.writer.flush().unwrap();
}
Interaction::WriteLine(write_line) => {
output_for_thread.lock().unwrap().push_str(&format!(
"**← write-line:** `{}`\n\n",
write_line.write_line
));
terminal
.writer
.write_line(write_line.write_line.as_bytes())
.unwrap();
}
Interaction::WriteKey(write_key) => {
let key_name = write_key.write_key.as_str();
output_for_thread
.lock()
.unwrap()
.push_str(&format!("**← write-key:** `{key_name}`\n\n"));
terminal.writer.write_all(write_key.write_key.bytes()).unwrap();
terminal.writer.flush().unwrap();
}
}
}
}

let status = terminal.reader.wait_for_exit().unwrap();
let screen = if formatted_snapshot {
render_formatted_screen(&terminal.reader.screen_contents_formatted())
} else {
terminal.reader.screen_contents()
};
let status = terminal.reader.wait_for_exit().unwrap();
let screen = if formatted_snapshot {
render_formatted_screen(&terminal.reader.screen_contents_formatted())
} else {
terminal.reader.screen_contents()
};

{
let mut output = output_for_thread.lock().unwrap();
push_fenced_block(&mut output, &screen);
}
{
let mut output = output_for_thread.lock().unwrap();
push_fenced_block(&mut output, &screen);
}

let _ = tx.send(i64::from(status.exit_code()));
});
let _ = tx.send(i64::from(status.exit_code()));
});

match rx.recv_timeout(timeout) {
Ok(exit_code) => {
let output = output.lock().unwrap().clone();
(TerminationState::Exited(exit_code), output)
}
Err(mpsc::RecvTimeoutError::Timeout) => {
let _ = killer.kill();
let output = output.lock().unwrap().clone();
(TerminationState::TimedOut, output)
}
Err(mpsc::RecvTimeoutError::Disconnected) => {
panic!("terminal thread panicked");
match rx.recv_timeout(timeout) {
Ok(exit_code) => {
let output = output.lock().unwrap().clone();
(TerminationState::Exited(exit_code), output)
}
Err(mpsc::RecvTimeoutError::Timeout) => {
let _ = killer.kill();
let output = output.lock().unwrap().clone();
(TerminationState::TimedOut, output)
}
Err(mpsc::RecvTimeoutError::Disconnected) => {
panic!("terminal thread panicked");
}
}
}
} else {
Expand Down
Loading
Oops, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

Add this suggestion to a batch that can be applied as a single commit. This suggestion is invalid because no changes were made to the code. Suggestions cannot be applied while the pull request is closed. Suggestions cannot be applied while viewing a subset of changes. Only one suggestion per line can be applied in a batch. Add this suggestion to a batch that can be applied as a single commit. Applying suggestions on deleted lines is not supported. You must change the existing code in this line in order to create a valid suggestion. Outdated suggestions cannot be applied. This suggestion has been applied or marked resolved. Suggestions cannot be applied from pending reviews. Suggestions cannot be applied on multi-line comments. Suggestions cannot be applied while the pull request is queued to merge. Suggestion cannot be applied right now. Please check back later.
You are visitor 01402775 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.