Skip to content

nvx: keep the declarations that only their own file uses private - #1775

Merged
Pedro Henrique Penna (ppenna) merged 1 commit into
devfrom
agents/issue-1772-private-declarations
Nov 20, 2026
Merged

Pedro Henrique Penna (ppenna) merged 1 commit into
devfrom
agents/issue-1772-private-declarations

Conversation

@ppenna

Copy link
Copy Markdown
Contributor

Fixes #1772

What does this pull request change?

Narrows five declarations in the nvx crate to the visibility that their
only users need. Each is a one-keyword change, so the diff is 5 lines added
and 5 removed across 4 files:

Item File Before After
ENDPOINT_CLOSED nvx/src/host/cli/mod.rs pub(crate) const const
check_exit nvx/src/host/snapshot/capture.rs pub(in crate::host) fn fn
safe_path nvx/src/guest/managed_agent/launch.rs pub(crate) fn fn
PreparationFailure nvx/src/guest/snapshot.rs pub(crate) type type
preparation_failure nvx/src/guest/snapshot.rs pub(super) fn fn

Each item's only non-test user is in its own file, and safe_path is also
used by the file's tests child module, which sees its parent's private items
through use super::*. No item appears in the signature of a more visible
item, so the private_interfaces lint stays quiet. The change alters no
behavior, public API, error message, protocol byte, or guest binary, and it
adds or changes no test.

Left out on purpose: the helpers of host/cli/mod.rs that its submodules
use (temporary_path, random_bytes, io_message, check_interrupt,
from_stop, from_os_error). Their pub(crate) could narrow in principle,
but doing so spreads the change across files, which the issue lists as a
follow-up.

Why is this change needed?

A declaration that is more visible than its users need makes the reader check
the whole crate before changing it, and lets another module start depending on
it by accident. Closed issues #1683, #1696, #1700, #1706, #1710, #1713, #1755,
and #1767 narrowed other declarations the same way. This pull request covers
the over-visible declarations that a scan of the crate found and whose every
use I checked. ENDPOINT_CLOSED was an unconfirmed candidate of #1683.

I rejected narrowing items that appear in the signature of a pub(crate) or
pub(super) item (PolicyPath, RestoreOptions, LockedSnapshot,
CompiledEgressPolicy, UnmountFailure, AppliedTeardownError,
DataFailure): the compiler rejects them under private_interfaces.

How was this change validated?

Checks and results (Windows, in nvx/ unless noted):

  • cargo fmt --all --check: passed.
  • cargo clippy --locked with -- -D warnings, over --all-targets --all-features, --lib, --lib --no-default-features, --lib --no-default-features --features serde, --lib --bins --features cli, and --lib --bins --no-default-features --features testing: all passed.
  • RUSTDOCFLAGS="-D warnings" cargo doc --locked --no-deps --all-features: passed.
  • cargo check --locked --all-targets --all-features --target aarch64-apple-darwin: passed. One warning, in host/snapshot/tests.rs, was already present before the change.
  • cargo clippy --locked --all-targets --all-features --target x86_64-unknown-linux-gnu -- -D warnings and cargo clippy --locked --lib --bins --no-default-features --features guest --target x86_64-unknown-linux-musl -- -D warnings: passed. These compile the Linux-only guest module that the Windows build skips.
  • cargo test --locked --all-features --lib -- host::cli host::snapshot: 345 passed, 0 failed, 6 ignored, the same as at the base commit.
  • python scripts\check_test_layout.py: passed. python scripts\check_test_changes.py --base origin/dev: 0 changes to existing tests.

Backend, host OS, host type, and guest: no microVM ran, since the change touches no runtime behavior. The Linux checks ran on a KVM host (Azure Linux 3.0, x86_64) in a temporary worktree at 2bcc739a9:

  • cargo test --locked --all-features --lib -- guest::managed_agent::launch guest::snapshot host::cli host::snapshot: 394 passed, 0 failed, 7 ignored, the same as at the base commit.
  • cargo fmt --all --check, the six clippy runs above with -D warnings, cargo test --locked --all-features, cargo test --locked, cargo build --locked --lib --no-default-features, cargo test --locked --lib --no-default-features, cargo doc --locked --no-deps --all-features with -D warnings, and the minimum supported Rust version check (cargo +1.89 check --locked --all-targets --all-features): all passed.
  • python3 scripts/public_api.py: passed, with no snapshot change.
  • python3 scripts/nvx.py check-guest-binaries --toolchain 1.97.1: passed.

Left to CI: the microVM and hypervisor scenarios, build-guest-binaries and test-guest-binaries, and the other repository gates, none of which this change reaches.

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-rs/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.

ENDPOINT_CLOSED of host/cli/mod.rs, check_exit of
host/snapshot/capture.rs, safe_path of guest/managed_agent/launch.rs,
and preparation_failure and its PreparationFailure alias of
guest/snapshot.rs were pub(crate), pub(super), or pub(in crate::host),
although each is used only in the file that declares it and in that
file's own tests child module, which sees a private item.

Make each private, the least visibility that its uses require, so the
compiler enforces that the rest of the crate cannot call or depend on
them. Only visibility changes; function bodies, messages, protocol
bytes, and the public API stay as they were.

Part of #1772

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot AI balanced review requested due to automatic review settings November 20, 2026 00:07

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 recorded for this change restricting the visibility of internal declarations.

No open issues 🎉

What changed in this PR

Addresses #1772 by making five internal declarations private within the nvx crate, preventing unrelated modules from depending on implementation details.

Changes:

  • Removes broader visibility from host CLI and snapshot helpers.
  • Makes guest path validation and snapshot preparation helpers private.
  • Leaves function bodies, callers, tests, and public API unchanged.
File Description
nvx/​src/​host/​snapshot/​capture.rs Makes check_exit private.
nvx/​src/​host/​cli/​mod.rs Makes ENDPOINT_CLOSED private.
nvx/​src/​guest/​snapshot.rs Makes PreparationFailure and preparation_failure private.
nvx/​src/​guest/​managed_agent/​launch.rs Makes safe_path private, retaining child-test access.

Review effort: Balanced

@ppenna
Pedro Henrique Penna (ppenna) added this pull request to the merge queue Nov 20, 2026
Merged via the queue into dev with commit a16e73f Nov 20, 2026
52 checks passed
@ppenna
Pedro Henrique Penna (ppenna) deleted the agents/issue-1772-private-declarations branch November 20, 2026 00:58
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: keep the declarations that only their own file uses private

2 participants