Skip to content

nvx: build the CLI's console outputs and forced stderr writes once - #2312

Merged
Pedro Henrique Penna (ppenna) merged 1 commit into
devfrom
agents/issue-2311-console-output-helpers
Nov 28, 2026
Merged

Pedro Henrique Penna (ppenna) merged 1 commit into
devfrom
agents/issue-2311-console-output-helpers

Conversation

@ppenna

Copy link
Copy Markdown
Contributor

Fixes #2311

What does this pull request change?

In nvx/src/host/cli/output.rs, ConsoleOutput::new and ConsoleOutput::stderr now 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_stderr and end_stderr_line now make their forced standard-error write with one private helper, force_stderr, which locks, writes, flushes, and ignores a failure, and documents why. Start at to_stream and force_stderr.

Behavior is unchanged: the same stream decides whether an output is a console, end_stderr_line still 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:

  • Baseline at 9f4ab27 on Windows: 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.
  • Windows: cargo clippy --locked --features cli --all-targets --manifest-path nvx\Cargo.toml -- -D warnings: clean.
  • Windows: 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 with NVX unset, so its nvx-running tests skipped).
  • Linux (WSL), from the check-nvx action on toolchain 1.97.1: 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, and python3 scripts/public_api.py: all passed. This covers the Unix path, where to_stream's stream parameter is unused and its expect(unused_variables) applies.
  • Code review subagent: no issues found.

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

  • Tests cover the new or fixed behavior, in the layout that
    python3 scripts/check_test_layout.py checks.
  • python3 scripts/check_test_changes.py --base origin/dev lists no change
    to an existing test, or a Changes to existing tests section below
    explains each one.
  • The documentation that the change affects is updated, including
    .github/copilot-instructions.md and the skills when a convention or
    workflow changes.
  • A change to the public API of nvx updates nvx/public-api/ with
    python3 scripts/public_api.py --update.
  • Snapshots, protocols, and on-disk formats stay compatible, or the
    description says how the change versions or migrates them.

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>
Copilot AI balanced review requested due to automatic review settings November 28, 2026 05:33

Copilot AI 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.

🟢 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_stream to centralize constructor logic, including Windows console detection.
  • Adds force_stderr to 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

@ppenna
Pedro Henrique Penna (ppenna) added this pull request to the merge queue Nov 28, 2026
Merged via the queue into dev with commit 97378f9 Nov 28, 2026
56 checks passed
@ppenna
Pedro Henrique Penna (ppenna) deleted the agents/issue-2311-console-output-helpers branch November 28, 2026 17:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

nvx: build the CLI's console outputs and forced standard-error writes with one helper each

2 participants