Skip to content

Commit c5aa545

Browse files
branchseerclaude
andauthored
test(e2e): add ctrl-c tests for labeled mode and cached tasks (#307)
## Summary - Add ctrl-c e2e tests for `--log=labeled` mode and cache-enabled tasks - Move SIGINT ignore handler from program startup to right before plan execution, so interactive task selection (`vp run`) remains cancellable with Ctrl+C - Add `println!()` after milestone in `exit-on-ctrlc` tool so milestone bytes flush through line-buffered writers in labeled mode ## Test plan - [x] All e2e snapshot tests pass on macOS - [x] ctrl-c tests pass on Windows VM - [ ] CI passes 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent 8da83e9 commit c5aa545

File tree

10 files changed

+71
-8
lines changed

10 files changed

+71
-8
lines changed

Cargo.lock

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

crates/vite_task/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ async-trait = { workspace = true }
1717
bincode = { workspace = true, features = ["derive"] }
1818
bstr = { workspace = true }
1919
clap = { workspace = true, features = ["derive"] }
20+
ctrlc = { workspace = true }
2021
derive_more = { workspace = true, features = ["from"] }
2122
fspy = { workspace = true }
2223
futures-util = { workspace = true }

crates/vite_task/src/session/mod.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -327,6 +327,13 @@ impl<'a> Session<'a> {
327327
Some(self.make_summary_writer()),
328328
self.program_name.clone(),
329329
));
330+
// Ignore SIGINT/CTRL_C before executing tasks. Child tasks
331+
// receive the signal directly from the terminal driver and handle
332+
// it themselves. This lets the runner wait for tasks to exit and
333+
// report their actual exit status rather than being killed
334+
// mid-flight.
335+
let _ = ctrlc::set_handler(|| {});
336+
330337
self.execute_graph(graph, builder).await.map_err(SessionError::EarlyExit)
331338
}
332339
}

crates/vite_task_bin/src/main.rs

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,6 @@ use vite_task::{Command, ExitStatus, Session};
33
use vite_task_bin::OwnedSessionConfig;
44

55
fn main() -> ! {
6-
// Ignore SIGINT/CTRL_C before the tokio runtime starts. Child tasks
7-
// receive the signal directly from the terminal driver and handle it
8-
// themselves. This lets the runner wait for tasks to exit and report
9-
// their actual exit status rather than being killed mid-flight.
10-
let _ = ctrlc::set_handler(|| {});
11-
126
let exit_code: i32 =
137
tokio::runtime::Builder::new_multi_thread().enable_all().build().unwrap().block_on(async {
148
match run().await {

crates/vite_task_bin/src/vtt/exit_on_ctrlc.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,9 @@ pub fn run() -> Result<(), Box<dyn std::error::Error>> {
3333
})?;
3434

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

3740
loop {
3841
std::thread::park();

crates/vite_task_bin/tests/e2e_snapshots/fixtures/ctrl-c/snapshots.toml

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,3 +12,30 @@ steps = [
1212
{ "write-key" = "ctrl-c" },
1313
] },
1414
]
15+
16+
[[e2e]]
17+
name = "ctrl-c terminates running tasks (labeled)"
18+
steps = [
19+
{ argv = [
20+
"vt",
21+
"run",
22+
"--log=labeled",
23+
"dev",
24+
], interactions = [
25+
{ "expect-milestone" = "ready" },
26+
{ "write-key" = "ctrl-c" },
27+
] },
28+
]
29+
30+
[[e2e]]
31+
name = "ctrl-c terminates running tasks (cached)"
32+
steps = [
33+
{ argv = [
34+
"vt",
35+
"run",
36+
"dev-cached",
37+
], interactions = [
38+
{ "expect-milestone" = "ready" },
39+
{ "write-key" = "ctrl-c" },
40+
] },
41+
]
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
---
2+
source: crates/vite_task_bin/tests/e2e_snapshots/main.rs
3+
expression: e2e_outputs
4+
---
5+
> vt run dev-cached
6+
@ expect-milestone: ready
7+
$ vtt exit-on-ctrlc
8+
@ write-key: ctrl-c
9+
$ vtt exit-on-ctrlc
10+
11+
ctrl-c received
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
---
2+
source: crates/vite_task_bin/tests/e2e_snapshots/main.rs
3+
expression: e2e_outputs
4+
---
5+
> vt run --log=labeled dev
6+
@ expect-milestone: ready
7+
[ctrl-c-test#dev] $ vtt exit-on-ctrlccache disabled
8+
[ctrl-c-test#dev]
9+
@ write-key: ctrl-c
10+
[ctrl-c-test#dev] $ vtt exit-on-ctrlccache disabled
11+
[ctrl-c-test#dev]
12+
13+
[ctrl-c-test#dev] ctrl-c received

crates/vite_task_bin/tests/e2e_snapshots/fixtures/ctrl-c/snapshots/ctrl-c terminates running tasks.snap

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,5 @@ expression: e2e_outputs
77
$ vtt exit-on-ctrlccache disabled
88
@ write-key: ctrl-c
99
$ vtt exit-on-ctrlccache disabled
10+
1011
ctrl-c received
Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,13 @@
11
{
2-
"cache": false,
2+
"cache": true,
33
"tasks": {
44
"dev": {
5-
"command": "vtt exit-on-ctrlc"
5+
"command": "vtt exit-on-ctrlc",
6+
"cache": false
7+
},
8+
"dev-cached": {
9+
"command": "vtt exit-on-ctrlc",
10+
"cache": true
611
}
712
}
813
}

0 commit comments

Comments
 (0)