Repository navigation
nvx: build the CLI's console outputs and forced stderr writes once - #2312
Merged
Pedro Henrique Penna (ppenna) merged 1 commit intoNov 28, 2026
Merged
Conversation
ConsoleOutput::new and ConsoleOutput::stderr built the same structure with its Windows console fields for two streams, and print_stderr and end_stderr_line each locked standard error, wrote, flushed, and ignored the failure. Build both outputs with ConsoleOutput::to_stream, and make both forced writes with force_stderr, so that the Windows console fields and the reason for ignoring a failure each live in one place. Behavior is unchanged: the same stream decides whether the output is a console, and the forced writes lock, write, flush, and ignore a failure as before. A new test checks that output to a stream that is not a terminal passes its bytes, invalid UTF-8 included, unchanged. Base: 9f4ab27. On Windows, cargo test --locked --features cli --lib -- host::cli::output host::cli::run::tests host::cli::session::tests::windows passed 18 with 2 ignored before, and 19 with 2 ignored after; clippy --all-targets -D warnings is clean. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Contributor
There was a problem hiding this comment.
🟢 Approval recommended
No active review issues are reported for the CLI output refactor.
No open issues 🎉
What changed in this PR
Addresses #2311 by removing duplicated setup and write logic in NVX’s CLI output module while preserving output behavior and the public API.
Changes:
- Adds
ConsoleOutput::to_streamto centralize constructor logic, including Windows console detection. - Adds
force_stderrto share locking, writing, flushing, and ignored-error handling. - Adds a regression test verifying that non-terminal output preserves raw bytes, including invalid UTF-8.
| File | Description |
|---|---|
nvx/src/host/cli/output/tests.rs |
Adds byte-preservation coverage for the shared constructor. |
nvx/src/host/cli/output.rs |
Extracts shared construction and forced-stderr helpers and documents their behavior. |
Review effort: Balanced
Pedro Henrique Penna (ppenna)
deleted the
agents/issue-2311-console-output-helpers
branch
November 28, 2026 17:06
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.
Fixes #2311
What does this pull request change?
In
nvx/src/host/cli/output.rs,ConsoleOutput::newandConsoleOutput::stderrnow build their output with one private constructor,ConsoleOutput::to_stream(write, stream), which sets the write function and, on Windows, whether the stream is a console.print_stderrandend_stderr_linenow make their forced standard-error write with one private helper,force_stderr, which locks, writes, flushes, and ignores a failure, and documents why. Start atto_streamandforce_stderr.Behavior is unchanged: the same stream decides whether an output is a console,
end_stderr_linestill writes nothing after a line that is already ended, and the forced writes keep their lock, flush, and ignored result. The public API, protocol bytes, and existing tests are unchanged. A new test checks that an output to a stream that is not a terminal passes its bytes, invalid UTF-8 included, unchanged.Why is this change needed?
The two constructors repeated the structure with its three Windows-only console fields, and the two stderr functions repeated the lock, write, flush, and ignored failure, with the reason for ignoring it stated in one place only. One helper each keeps the Windows console fields and the failure policy in a single place, so a future change to either cannot miss a copy.
How was this change validated?
Checks and results:
cargo test --locked --features cli --manifest-path nvx\Cargo.toml --lib -- host::cli::output host::cli::run::tests host::cli::session::tests::windows: 18 passed, 2 ignored. After: 19 passed, 2 ignored.cargo clippy --locked --features cli --all-targets --manifest-path nvx\Cargo.toml -- -D warnings: clean.python scripts\local_gates.py --base origin/dev --run: test-changes, markdown-links, test-layout, nvx-format, nvx-lint, nvx-test, nvx-doc, nvx-msrv, and nvx-cli passed (nvx-cli withNVXunset, so its nvx-running tests skipped).cargo fmt --all --check,cargo clippy --locked --all-targets --all-features -- -D warnings,cargo clippy --locked --lib --bins --features cli -- -D warnings,cargo test --locked --all-features --lib -- host::cli(271 passed, 5 ignored),cargo +1.89 check --locked --all-targets --all-features,cargo check --locked --all-targets --all-features --target aarch64-apple-darwin, andpython3 scripts/public_api.py: all passed. This covers the Unix path, whereto_stream'sstreamparameter is unused and itsexpect(unused_variables)applies.Backend, host OS, host type, and guest: none; the change touches CLI output code only and runs no microVM.
Left to CI: the WHP, KVM, and MSHV microVM scenarios, the full Linux check-nvx run (including the guest binaries), and benchmarks.
Checklist
python3 scripts/check_test_layout.pychecks.python3 scripts/check_test_changes.py --base origin/devlists no changeto an existing test, or a Changes to existing tests section below
explains each one.
.github/copilot-instructions.mdand the skills when a convention orworkflow changes.
nvxupdatesnvx/public-api/withpython3 scripts/public_api.py --update.description says how the change versions or migrates them.