Fixes #4804 - Disable all real driver input/output in unit tests, both locally and GH actions#4811
Merged
tig merged 16 commits intov2_developfrom Mar 9, 2026
Merged
Conversation
Refactor terminal attachment checks into Driver.IsAttachedToTerminal, which now handles platform-specific logic and honors the DisableRealDriverIO environment variable for test environments. Updated all drivers to use this unified method, and simplified AnsiTerminalHelper to delegate to it. Moved relevant P/Invoke code to Driver. Added comprehensive unit tests for all drivers and the environment variable gating. Introduced test.runsettings and Directory.Build.props changes to ensure DisableRealDriverIO is set during test runs, improving testability and consistency of degraded mode detection.
- Reformat method calls and declarations for readability - Use C# pattern matching and switch expressions - Refactor OutputBase properties to auto-properties - Convert trivial methods to expression-bodied members - Fix logic in OutputBase.Write, UnixInput init, and WindowsOutput error handling - Remove AnsiTerminalHelper.IsAttachedToTerminal and related test - Use explicit types for clarity - Reformat and clarify P/Invoke signatures - Update .DotSettings and documentation comments - Improve maintainability and correctness throughout drivers
Add IsAttachedToTerminal to OutputBase and update all output drivers (AnsiOutput, NetOutput, UnixOutput, WindowsOutput) to check this property before performing terminal I/O. When not attached to a real terminal, output methods now return early, perform no-ops, or return default values. Constructors log lifecycle messages if no terminal is attached. Tests updated to verify no escape sequences or state changes occur in these scenarios. This prevents errors and unwanted output in redirected or non-interactive environments.
Move IsAttachedToTerminal checks after base logic in Output classes to ensure base behavior is always executed. Streamline and centralize terminal checks, reduce code duplication, and improve consistency across AnsiOutput, NetOutput, UnixOutput, and WindowsOutput. Adjust platform-specific logic and early returns for better maintainability and correct output buffer handling.
Centralize IsAttachedToTerminal logic in InputImpl<T> and update all input classes (AnsiInput, NetInput, UnixInput, WindowsInput) to use it for degraded mode detection and logging. Simplify AnsiOutput by removing redundant terminal checks and updating Kitty keyboard methods. Refactor MainLoopCoordinatorTests for modern C# syntax, restoring and improving Kitty protocol and error handling tests. Improves clarity, maintainability, and test reliability.
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Moved and duplicated tests for DisableRealDriverIO env var and Driver.IsAttachedToTerminal from DriverTests to IntegrationTests. Also refactored test output usage to use the output parameter directly. This ensures environment variable handling is verified in both test contexts.
Contributor
There was a problem hiding this comment.
Pull request overview
This PR enforces “degraded mode” behavior during test runs by centralizing terminal-attachment detection in Driver.IsAttachedToTerminal and using an environment-variable switch (DisableRealDriverIO=1) to disable real driver I/O in CI and unit tests, preventing hangs in test harnesses without a real terminal.
Changes:
- Added
Driver.IsAttachedToTerminal(out in, out out)withDisableRealDriverIOgating to force degraded mode during tests/CI. - Updated multiple input/output drivers to no-op (or avoid terminal operations) when no real terminal is attached.
- Added runsettings/MSBuild wiring + GitHub Actions env to propagate
DisableRealDriverIO=1, plus tests to assert expected degraded-mode behavior.
Reviewed changes
Copilot reviewed 28 out of 28 changed files in this pull request and generated 9 comments.
Show a summary per file
| File | Description |
|---|---|
| Tests/test.runsettings | Sets DisableRealDriverIO=1 for test runs via runsettings. |
| Tests/Directory.Build.props | Plumbs RunSettingsFilePath for test projects under Tests/. |
| Tests/UnitTestsParallelizable/Drivers/Windows/WindowsInputOutputTests.cs | Adds assertion that Driver.IsAttachedToTerminal returns false in the test harness. |
| Tests/UnitTestsParallelizable/Drivers/Unix/UnixInputOutputTests.cs | Adds assertion that Driver.IsAttachedToTerminal returns false in the test harness. |
| Tests/UnitTestsParallelizable/Drivers/Dotnet/NetInputOutputTests.cs | Adds assertion that Driver.IsAttachedToTerminal returns false in the test harness. |
| Tests/UnitTestsParallelizable/Drivers/Ansi/AnsiTerminalHelperTests.cs | New tests validating env-var propagation and IsAttachedToTerminal gating. |
| Tests/UnitTestsParallelizable/Drivers/Ansi/AnsiInputOutputTests.cs | Adds assertion that Driver.IsAttachedToTerminal returns false in the test harness. |
| Tests/UnitTestsParallelizable/Application/MainLoopCoordinatorTests.cs | Modernizes syntax and moves/extends the “input crash surfaces” test into the parallelizable suite. |
| Tests/UnitTests/Application/MainLoopCoordinatorTests.cs | Removes the non-parallel test file (logic moved to parallelizable tests). |
| Tests/IntegrationTests/FluentTests/TestContextTests.cs | Adds env-var + IsAttachedToTerminal gating tests to integration suite. |
| Terminal.sln.DotSettings | Adds csbi to the ReSharper user dictionary. |
| Terminal.Gui/Drivers/Driver.cs | Adds centralized IsAttachedToTerminal implementation and env-var gating. |
| Terminal.Gui/Drivers/Output/OutputBase.cs | Caches terminal-attachment state and refactors output writing logic; adds doc comments. |
| Terminal.Gui/Drivers/Input/InputImpl.cs | Caches terminal-attachment state for input implementations. |
| Terminal.Gui/Drivers/AnsiDriver/AnsiTerminalHelper.cs | Removes per-helper terminal detection (now centralized in Driver). |
| Terminal.Gui/Drivers/AnsiDriver/AnsiOutput.cs | Uses shared terminal-attachment detection and refactors write buffering. |
| Terminal.Gui/Drivers/AnsiDriver/AnsiInput.cs | Uses shared terminal-attachment detection and refactors lifecycle logging. |
| Terminal.Gui/Drivers/UnixDriver/UnixTerminalHelper.cs | Switches to shared Driver.IsAttachedToTerminal check. |
| Terminal.Gui/Drivers/UnixDriver/UnixOutput.cs | Adds terminal-attachment guards to output operations and size reporting. |
| Terminal.Gui/Drivers/UnixDriver/UnixInput.cs | Adds terminal-attachment guard + minor refactors for degraded mode behavior. |
| Terminal.Gui/Drivers/UnixDriver/UnixIOHelper.cs | Formatting/interop signature tweaks + minor pattern matching cleanup. |
| Terminal.Gui/Drivers/WindowsDriver/WindowsOutput.cs | Adds terminal-attachment guards throughout; refactors and improves no-terminal behavior. |
| Terminal.Gui/Drivers/WindowsDriver/WindowsInput.cs | Adds terminal-attachment guard and lifecycle trace on init. |
| Terminal.Gui/Drivers/DotNetDriver/NetOutput.cs | Adds terminal-attachment guards and lifecycle trace; minor modern C# refactors. |
| Terminal.Gui/Drivers/DotNetDriver/NetInput.cs | Adds terminal-attachment guard and lifecycle trace; minor doc/formatting changes. |
| .github/workflows/unit-tests.yml | Sets DisableRealDriverIO=1 for unit-test jobs. |
| .github/workflows/stress-tests.yml | Sets DisableRealDriverIO=1 for stress-test jobs. |
| .github/workflows/integration-tests.yml | Sets DisableRealDriverIO=1 for integration-test jobs. |
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
…l Logger - Use ITestOutputHelper primary constructor for test output - Replace manual Logging.Logger swap with TestLogging.BindTo scope - Remove mock logger verification (exception propagation is the key assertion) - Safe for parallel test execution Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This was referenced May 1, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Summary
Driver.IsAttachedToTerminalso drivers correctly detect when no terminal is attachedDisableRealDriverIOenvironment variable support for CI test jobs to force degraded modeIsAttachedToTerminalchecks and cleans up driver code with modern C# patternsFixes #4804
Test plan
DisableRealDriverIOto prevent hangs in test runners🤖 Generated with Claude Code