mirror of
https://github.com/fabro-sh/fabro.git
synced 2026-10-07 03:00:29 +00:00
test: preserve LLVM_PROFILE_FILE across env_clear in CLI tests
Integration tests spawn the fabro binary as a subprocess and call env_clear() for isolation, which strips LLVM_PROFILE_FILE. Under cargo-llvm-cov this dropped subprocess coverage into orphaned default.profraw files in tempdirs instead of the merged profile. Add a preserve_coverage_env! macro in fabro-test and call it after each env_clear() in apply_test_isolation, LightweightCli, and the exec.rs sites. No-op when the env var is unset (normal test runs). Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
parent
e06a47f357
commit
a77c45207f
3 changed files with 23 additions and 2 deletions
|
|
@ -2,7 +2,7 @@
|
|||
|
||||
use std::process::Output;
|
||||
|
||||
use fabro_test::{fabro_snapshot, test_context};
|
||||
use fabro_test::{fabro_snapshot, preserve_coverage_env, test_context};
|
||||
use httpmock::MockServer;
|
||||
|
||||
async fn run_success_output(mut cmd: assert_cmd::Command) -> Output {
|
||||
|
|
@ -85,6 +85,7 @@ fn exec_missing_api_key_exits_with_error() {
|
|||
let mut cmd = context.exec_cmd();
|
||||
cmd.arg("test prompt");
|
||||
cmd.env_clear();
|
||||
preserve_coverage_env!(cmd);
|
||||
cmd.env("HOME", &context.home_dir);
|
||||
fabro_snapshot!(context.filters(), cmd, @"
|
||||
success: false
|
||||
|
|
@ -106,6 +107,7 @@ fn exec_uses_user_config_defaults() {
|
|||
let mut cmd = context.exec_cmd();
|
||||
cmd.arg("test prompt");
|
||||
cmd.env_clear();
|
||||
preserve_coverage_env!(cmd);
|
||||
cmd.env("HOME", &context.home_dir);
|
||||
cmd.env("FABRO_STORAGE_DIR", &context.storage_dir);
|
||||
cmd.env("FABRO_NO_UPGRADE_CHECK", "true")
|
||||
|
|
@ -133,6 +135,7 @@ fn exec_server_target_uses_remote_transport_instead_of_local_api_key_resolution(
|
|||
|
||||
let mut cmd = context.exec_cmd();
|
||||
cmd.env_clear();
|
||||
preserve_coverage_env!(cmd);
|
||||
cmd.env("HOME", &context.home_dir);
|
||||
cmd.env("FABRO_NO_UPGRADE_CHECK", "true")
|
||||
.env("FABRO_HTTP_PROXY_POLICY", "disabled");
|
||||
|
|
@ -176,6 +179,7 @@ fn exec_configured_server_target_alone_does_not_reroute_exec() {
|
|||
|
||||
let mut cmd = context.exec_cmd();
|
||||
cmd.env_clear();
|
||||
preserve_coverage_env!(cmd);
|
||||
cmd.env("HOME", &context.home_dir);
|
||||
cmd.env("FABRO_NO_UPGRADE_CHECK", "true")
|
||||
.env("FABRO_HTTP_PROXY_POLICY", "disabled");
|
||||
|
|
@ -224,6 +228,7 @@ fn exec_cli_server_target_overrides_configured_server_target() {
|
|||
|
||||
let mut cmd = context.exec_cmd();
|
||||
cmd.env_clear();
|
||||
preserve_coverage_env!(cmd);
|
||||
cmd.env("HOME", &context.home_dir);
|
||||
cmd.env("FABRO_NO_UPGRADE_CHECK", "true")
|
||||
.env("FABRO_HTTP_PROXY_POLICY", "disabled");
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
use assert_cmd::Command;
|
||||
use fabro_store::EventEnvelope;
|
||||
use fabro_test::TestContext;
|
||||
use fabro_test::{TestContext, preserve_coverage_env};
|
||||
use fabro_types::RunId;
|
||||
macro_rules! fabro_json_snapshot {
|
||||
($context:expr, $value:expr, @$snapshot:literal) => {{
|
||||
|
|
@ -85,6 +85,7 @@ impl LightweightCli {
|
|||
pub(crate) fn command(&self) -> Command {
|
||||
let mut cmd = Command::new(env!("CARGO_BIN_EXE_fabro"));
|
||||
cmd.env_clear();
|
||||
preserve_coverage_env!(cmd);
|
||||
if let Some(path) = std::env::var_os("PATH") {
|
||||
cmd.env("PATH", path);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -14,6 +14,20 @@ use serde_json::{Map, Value, json};
|
|||
use toml::Value as TomlValue;
|
||||
use toml::map::Map as TomlMap;
|
||||
|
||||
/// Re-export `LLVM_PROFILE_FILE` into a `Command` whose env was just cleared,
|
||||
/// so subprocess coverage data lands in the profile path that
|
||||
/// `cargo-llvm-cov` configured for the parent test process. Accepts both
|
||||
/// `std::process::Command` and `assert_cmd::Command` (any type with an
|
||||
/// `env(key, value)` method).
|
||||
#[macro_export]
|
||||
macro_rules! preserve_coverage_env {
|
||||
($cmd:expr) => {{
|
||||
if let Some(val) = ::std::env::var_os("LLVM_PROFILE_FILE") {
|
||||
$cmd.env("LLVM_PROFILE_FILE", val);
|
||||
}
|
||||
}};
|
||||
}
|
||||
|
||||
/// Walk up from `start` to find the repo-level `test/` fixtures directory.
|
||||
pub fn find_test_fixtures_dir(start: &Path) -> Option<PathBuf> {
|
||||
let mut dir = start;
|
||||
|
|
@ -113,6 +127,7 @@ pub fn require_env(name: &str) -> Option<String> {
|
|||
/// subsequent `.env(...)` call, which survives the clear.
|
||||
pub fn apply_test_isolation(cmd: &mut std::process::Command, home_dir: &Path) {
|
||||
cmd.env_clear();
|
||||
preserve_coverage_env!(cmd);
|
||||
if let Some(path) = std::env::var_os("PATH") {
|
||||
cmd.env("PATH", path);
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue