Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions crates/vite_task/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ async-trait = { workspace = true }
bincode = { workspace = true, features = ["derive"] }
bstr = { workspace = true }
clap = { workspace = true, features = ["derive"] }
ctrlc = { workspace = true }
derive_more = { workspace = true, features = ["from"] }
fspy = { workspace = true }
futures-util = { workspace = true }
Expand Down
7 changes: 7 additions & 0 deletions crates/vite_task/src/session/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -327,6 +327,13 @@ impl<'a> Session<'a> {
Some(self.make_summary_writer()),
self.program_name.clone(),
));
// Ignore SIGINT/CTRL_C before executing tasks. Child tasks
// receive the signal directly from the terminal driver and handle
// it themselves. This lets the runner wait for tasks to exit and
// report their actual exit status rather than being killed
// mid-flight.
let _ = ctrlc::set_handler(|| {});

self.execute_graph(graph, builder).await.map_err(SessionError::EarlyExit)
}
}
Expand Down
6 changes: 0 additions & 6 deletions crates/vite_task_bin/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,6 @@ use vite_task::{Command, ExitStatus, Session};
use vite_task_bin::OwnedSessionConfig;

fn main() -> ! {
// Ignore SIGINT/CTRL_C before the tokio runtime starts. Child tasks
// receive the signal directly from the terminal driver and handle it
// themselves. This lets the runner wait for tasks to exit and report
// their actual exit status rather than being killed mid-flight.
let _ = ctrlc::set_handler(|| {});

let exit_code: i32 =
tokio::runtime::Builder::new_multi_thread().enable_all().build().unwrap().block_on(async {
match run().await {
Expand Down
3 changes: 3 additions & 0 deletions crates/vite_task_bin/src/vtt/exit_on_ctrlc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,9 @@ pub fn run() -> Result<(), Box<dyn std::error::Error>> {
})?;

pty_terminal_test_client::mark_milestone("ready");
// Print a newline so the milestone bytes get flushed through line-buffered
// writers (labeled/grouped log modes).
println!();

loop {
std::thread::park();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,30 @@ steps = [
{ "write-key" = "ctrl-c" },
] },
]

[[e2e]]
name = "ctrl-c terminates running tasks (labeled)"
steps = [
{ argv = [
"vt",
"run",
"--log=labeled",
"dev",
], interactions = [
{ "expect-milestone" = "ready" },
{ "write-key" = "ctrl-c" },
] },
]

[[e2e]]
name = "ctrl-c terminates running tasks (cached)"
steps = [
{ argv = [
"vt",
"run",
"dev-cached",
], interactions = [
{ "expect-milestone" = "ready" },
{ "write-key" = "ctrl-c" },
] },
]
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
---
source: crates/vite_task_bin/tests/e2e_snapshots/main.rs
expression: e2e_outputs
---
> vt run dev-cached
@ expect-milestone: ready
$ vtt exit-on-ctrlc
@ write-key: ctrl-c
$ vtt exit-on-ctrlc

ctrl-c received
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
---
source: crates/vite_task_bin/tests/e2e_snapshots/main.rs
expression: e2e_outputs
---
> vt run --log=labeled dev
@ expect-milestone: ready
[ctrl-c-test#dev] $ vtt exit-on-ctrlc ⊘ cache disabled
[ctrl-c-test#dev]
@ write-key: ctrl-c
[ctrl-c-test#dev] $ vtt exit-on-ctrlc ⊘ cache disabled
[ctrl-c-test#dev]

[ctrl-c-test#dev] ctrl-c received
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,5 @@ expression: e2e_outputs
$ vtt exit-on-ctrlc ⊘ cache disabled
@ write-key: ctrl-c
$ vtt exit-on-ctrlc ⊘ cache disabled

ctrl-c received
Original file line number Diff line number Diff line change
@@ -1,8 +1,13 @@
{
"cache": false,
"cache": true,
"tasks": {
"dev": {
"command": "vtt exit-on-ctrlc"
"command": "vtt exit-on-ctrlc",
"cache": false
},
"dev-cached": {
"command": "vtt exit-on-ctrlc",
"cache": true
}
}
}
Loading