From b6239f19c8cc79633ec290d42579598a17fbb39d Mon Sep 17 00:00:00 2001 From: Otavio Salvador Date: Wed, 19 Aug 2026 16:53:29 -0300 Subject: [PATCH] chore: keep test-env out of the default features `test-env` gates the `updatehub-setup-mock-env` binary and the `updatehub::tests` helpers the integration tests drive the agent with. It was on by default, so anyone who follows the README and runs `cargo build --release` compiles 18 crates they will never run, `mockito` and its HTTP mock server among them, and pays for them on every build. Nobody should have to remember `--no-default-features` to get the plain agent. Turn the default feature set off and let the test targets ask for what they need: `crate::tests` and `crate::firmware::tests` now answer to `cfg(test)` as well, so the unit tests keep reaching them with no feature at all. The three integration test targets gain `required-features = ["test-env"]`. They call `updatehub::tests::TestEnvironment` and `mockito`, and cargo builds the library without `cfg(test)` for an integration test, so the feature is the only way in. `cargo test` skips them and `cargo test --all-features` runs them. `async-ctrlc` and `mockito` stay optional rather than move to dev-dependencies, because `src/setup_mock_env.rs` is a binary and cargo gives dev-dependencies to tests, examples and benches only. CI needs no change; every step already passes `--all-features`. The `Check build with the default features` step now covers the feature set users really get. The stripped binary loses only 8 KiB, as the linker already dropped what the agent never called. The build graph is where this is paid. --- updatehub/Cargo.toml | 16 +++++++++++++++- updatehub/src/firmware/mod.rs | 2 +- updatehub/src/lib.rs | 2 +- 3 files changed, 17 insertions(+), 3 deletions(-) diff --git a/updatehub/Cargo.toml b/updatehub/Cargo.toml index c942e92e..8548d9a3 100644 --- a/updatehub/Cargo.toml +++ b/updatehub/Cargo.toml @@ -16,7 +16,7 @@ publish = false repository = "https://github.com/UpdateHub/updatehub.git" [features] -default = ["test-env"] +default = [] # Feature to allow deserialization from v1 Settings v1-parsing = ["serde_ini"] @@ -35,6 +35,20 @@ path = "src/setup_mock_env.rs" test = true required-features = ["test-env"] +# The integration tests drive the agent against a mock server, so they need the +# `updatehub::tests` helpers and `mockito`, both of which live behind `test-env`. +[[test]] +name = "common" +required-features = ["test-env"] + +[[test]] +name = "successful_integration_test" +required-features = ["test-env"] + +[[test]] +name = "failed_integration_test" +required-features = ["test-env"] + [dependencies] argh = "0.1.3" async-ctrlc = { version = "1", optional = true } diff --git a/updatehub/src/firmware/mod.rs b/updatehub/src/firmware/mod.rs index d30d1b54..625827df 100644 --- a/updatehub/src/firmware/mod.rs +++ b/updatehub/src/firmware/mod.rs @@ -5,7 +5,7 @@ mod hook; pub mod installation_set; -#[cfg(feature = "test-env")] +#[cfg(any(test, feature = "test-env"))] pub mod tests; use self::hook::{run_hook, run_hooks_from_dir}; diff --git a/updatehub/src/lib.rs b/updatehub/src/lib.rs index d94dfd94..420ccf3f 100644 --- a/updatehub/src/lib.rs +++ b/updatehub/src/lib.rs @@ -17,7 +17,7 @@ mod utils; #[cfg(test)] mod cloud_mock; -#[cfg(feature = "test-env")] +#[cfg(any(test, feature = "test-env"))] pub mod tests; #[cfg(test)]