Skip to content

Add a test for Ctrl+C in a pipeline of external commands - #19641

Merged
fdncred merged 2 commits into
nushell:mainfrom
mkuchuman:fix/6591-signal-pipeline-tests
Nov 23, 2026
Merged

fdncred merged 2 commits into
nushell:mainfrom
mkuchuman:fix/6591-signal-pipeline-tests

Conversation

@mkuchuman

Copy link
Copy Markdown
Contributor

Description

Adds a regression test for pipeline signal handling: pressing Ctrl+C while a pipeline of two external commands is running should interrupt both of them, and Nushell should carry on with the rest of the script.

The test starts nu -i on its own pseudo-terminal, so the externals run in a foreground process group the way they would in a real terminal. Both commands trap SIGINT and print a line when they get it. After Ctrl+C the test expects producer, consumer, and then resumed from the next statement. Output is read through a separate socket, so terminal echo can't make the test pass by accident.

To check that it catches the kind of bug described in #6542, I changed set_foreground_pid in crates/nu-system/src/foreground.rs so that every external in a pipeline got its own process group. With that change the test fails after its 15 second read timeout. With the current code it passes. I haven't tried it against the older commits mentioned in the issue.

The test is Unix only (#[cfg(unix)]) because it relies on a pty and process groups.

User-facing changes (Release notes)

n/a

Additional notes

Part of #6591. This covers Ctrl+C in a two-command external pipeline. Other cases from #6542 could follow in separate PRs.

@fdncred fdncred left a comment •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Review overview

🟡 Changes recommended

The pty setup works on macOS once one cast is added, and the test then passed 20 of 20 runs. As pushed, though, it doesn't compile there, and because every root integration test builds into the same tests target, none of them compile on a Mac either. The other two findings are small changes to the assertion and the failure message.

Findings: 0 High severity · 1 Medium severity · 2 Low severity

Open (3)

Notes from my clanker, checked on 80d51b0. Built the branch on macOS, where the root tests target fails to compile (E0308 on TIOCSCTTY). With as _ added, cargo test --test tests -- shell::pipeline::foreground passed 20 of 20 runs and clippy with CI's flags was clean, both before and after adding the two test suggestions below. Nothing ran on Linux. The Linux side comes from reading libc and a clippy check of the ioctl line for x86_64-unknown-linux-gnu.

Comment thread tests/shell/pipeline/foreground.rs Resolved
Comment thread tests/shell/pipeline/foreground.rs Resolved
Comment thread tests/shell/pipeline/foreground.rs Resolved
@mkuchuman

Copy link
Copy Markdown
Contributor Author

Thanks, applied all three in e7f9983: the as _ cast for macOS, resumed is now checked as the last line before sorting the two traps, and a timeout reports the lines read so far. On Linux the test still passes and clippy on the tests target is clean.

@fdncred fdncred added tests issues to add tests or fix tests notes:mention Noted in "Hall of Fame" section notes:ready Indicates Ready for Release notes labels Nov 23, 2026
@fdncred
fdncred merged commit 1dc849d into nushell:main Nov 23, 2026
14 checks passed
@fdncred

fdncred commented Nov 23, 2026

Copy link
Copy Markdown
Contributor

Thanks

@github-actions github-actions Bot added this to the v0.118.0 milestone Nov 23, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

notes:mention Noted in "Hall of Fame" section notes:ready Indicates Ready for Release notes tests issues to add tests or fix tests

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants