Skip to content

test(cli): add isolated real-agent provisioning coverage - #365

Open
Peyton Robertson (peytonr18) wants to merge 9 commits into
Azure:mainfrom
peytonr18:probertson-main-test-infrastrcuture
Open

Peyton Robertson (peytonr18) wants to merge 9 commits into
Azure:mainfrom
peytonr18:probertson-main-test-infrastrcuture

Conversation

@peytonr18

@peytonr18 Peyton Robertson (peytonr18) commented Nov 9, 2026 •

Copy link
Copy Markdown
Contributor

This PR adds an isolated Docker fixture for the real azure-init entrypoint, covering successful provisioning, provisioning failure, and configuration-error exits (0, 1, and 78). Stubbed commands and local Azure-service mocks let the tests validate markers, logs, and HTTP/KVP reports without provisioning the host. The goal of this is to hit 100% code coverage in main.rs, which is one of the only files left that does not hit that coverage metric.

The logic is extracted from Azure/azure-init#363, where main.rs was first flagged for not having 100% code coverage. It made more sense to make this change independently, since it doesn't depend on the health logic.

How to use

From the repository root on Ubuntu with Docker running, build the image and run the commands below. Normal cargo test skips the Docker fixture.

Build the fixture image using the same Ubuntu version as the host:

. /etc/os-release
docker build --build-arg "BASE_IMAGE=ubuntu:${VERSION_ID}" -t azure-init-main-tests:local tests/support

Run the CLI tests, then explicitly run the ignored Docker fixture:

cargo test --locked --all-features --package azure-init --test cli
cargo test --locked --all-features --package azure-init --test cli -- --ignored agent_provisioning_in_container --nocapture

The second command runs all three provisioning scenarios inside disposable containers, checking markers, logs, and HTTP/KVP reports without provisioning the host.

Test the Python runner's isolation, cleanup, and coverage-profile handling without Docker:

python3 -m unittest discover -s tests/support -p test_container_provisioning.py -v

Run the related formatting, scoped lint, and workspace checks:

cargo fmt --all --check
cargo clippy --locked --all-features --package azure-init --bin azure-init --test cli --no-deps -- -D warnings
cargo check --locked --all-features --workspace --all-targets

To reproduce the combined coverage report used by CI, first install cargo-llvm-cov and the LLVM tools if needed:

rustup component add llvm-tools-preview
cargo install cargo-llvm-cov --locked

With the fixture image already built, collect workspace coverage, explicitly add the ignored entrypoint test, and generate lcov.info:

cargo llvm-cov clean --workspace
cargo llvm-cov --locked --all-features --workspace --no-clean --no-report
cargo llvm-cov --locked --all-features --package azure-init --test cli --no-clean --no-report -- --ignored agent_provisioning_in_container
cargo llvm-cov report --package azure-init --package libazureinit --package libazureinit-kvp --lcov --output-path lcov.info

Testing done

Passed on Ubuntu 22.04 against main (26e98be), using Rust 1.89.0 and stable 1.94.1. All of the other CLI tests and local tests passed as well.

@peytonr18
Peyton Robertson (peytonr18) marked this pull request as ready for review November 9, 2026 19:15
@codecov-commenter

Codecov Comments Bot (codecov-commenter) commented Nov 9, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 99.37%. Comparing base (bb7b9ff) to head (152cb3c).

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #365      +/-   ##
==========================================
+ Coverage   98.12%   99.37%   +1.24%     
==========================================
  Files          29       29              
  Lines       10518    10522       +4     
==========================================
+ Hits        10321    10456     +135     
+ Misses        197       66     -131     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@cjp256

Copy link
Copy Markdown
Contributor

See if this can converge with: https://github.com/Azure/azure-init/tree/main/testinit

@cadejacobson

Copy link
Copy Markdown
Collaborator

Could we add a couple of sample changes to main to show that this collects those lines as expected to help hit 100%? Those could then be reverted afterwards.

@peytonr18
Peyton Robertson (peytonr18) force-pushed the probertson-main-test-infrastrcuture branch from d58eda7 to be8fb94 Compare November 10, 2026 19:43
@peytonr18

Peyton Robertson (peytonr18) commented Nov 10, 2026 •

Copy link
Copy Markdown
Contributor Author

Cade Jacobson (@cadejacobson) Added a few more tests to get the whole file to 100%, not just the patch. Here's proof!
I am working on trimming down the changes a bit if I can, so I'll comment when I think this is ready for review!
image

Restore OVF, version, and directory-cleanup implementations using
container fixtures and build variants for coverage. Retain only exit-code
classification for the otherwise-unreachable NonEmptyPassword case.
@peytonr18

Peyton Robertson (peytonr18) commented Nov 10, 2026 •

Copy link
Copy Markdown
Contributor Author

I made an effort to really trim down any changes to the logic in main.rs and had copilot help generate test coverage accordingly. It did still flag the NonEmptyPassword case as code it had to adjust to be able to reach through unit tests, so let me know what you think. As it stands, the coverage for main.rs should now be 100%, bringing the repo coverage to an overall 99.37%. I plan to followup with a separate PR once all of these merge to identify the remaining .63% and get that covered too so that we will be upholding that 100% standard throughout now.

CC: Cade Jacobson (@cadejacobson)

image

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.

4 participants