Skip to content

Commit 344fb8a

Browse files
authored
fix: pass in env vars for cli tests (#2060)
A bug was introduced in #1949 which was not injecting env vars for `baml-cli test` This PR fixes that by passing in the environment variables. Fixes #2051 <img width="880" alt="image" src="https://github.com/user-attachments/assets/6df90bcc-4ef7-4d7c-9d68-e938957ef0e3" /> <!-- ELLIPSIS_HIDDEN --> ---- > [!IMPORTANT] > Fixes bug in `baml-cli test` by passing environment variables to `BamlRuntime` and `TestExecutor`. > > - **Behavior**: > - Fixes bug in `baml-cli test` by passing environment variables to `BamlRuntime::from_directory` and `TestExecutor::cli_run_tests`. > - Collects environment variables into `HashMap` and passes them to `BamlRuntime` and `TestExecutor`. > - **Functions**: > - Updates `BamlRuntime::from_directory` in `lib.rs` to accept `env_vars`. > - Updates `TestExecutor::cli_run_tests` in `test_executor/mod.rs` to accept `env_vars`. > - **Misc**: > - Removes redundant logging of environment variables in `lib.rs`. > > <sup>This description was created by </sup>[<img alt="Ellipsis" src="https://img.shields.io/badge/Ellipsis-blue?color=175173">](https://www.ellipsis.dev?ref=BoundaryML%2Fbaml&utm_source=github&utm_medium=referral)<sup> for db380e2. You can [customize](https://app.ellipsis.dev/BoundaryML/settings/summaries) this summary. It will automatically update as commits are pushed.</sup> <!-- ELLIPSIS_HIDDEN -->
1 parent 687404f commit 344fb8a

3 files changed

Lines changed: 7 additions & 8 deletions

File tree

engine/baml-runtime/src/cli/testing.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,8 @@ impl TestArgs {
124124
}
125125
}
126126

127-
let runtime = BamlRuntime::from_directory(&from, std::env::vars().collect())?;
127+
let env_vars = std::env::vars().collect::<HashMap<String, String>>();
128+
let runtime = BamlRuntime::from_directory(&from, env_vars.clone())?;
128129
let runtime = std::sync::Arc::new(runtime);
129130

130131
let test_execution_args = TestFilter::from(
@@ -151,6 +152,7 @@ impl TestArgs {
151152
*parallel,
152153
output_format,
153154
if *junit { Some(junit_path) } else { None },
155+
&env_vars,
154156
)
155157
.await
156158
{

engine/baml-runtime/src/lib.rs

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -411,14 +411,8 @@ impl BamlRuntime {
411411
where
412412
F: Fn(FunctionResult),
413413
{
414-
log::info!("env vars1: {:#?}", env_vars.clone());
415414

416415
baml_log::set_from_env(&env_vars).unwrap();
417-
baml_log::info!("env vars: {:#?}", env_vars.clone());
418-
log::info!("env vars2: {:#?}", env_vars.clone());
419-
for (key, value) in env_vars.iter() {
420-
log::info!("env var: {} = {}", key, value);
421-
}
422416

423417
let call = self
424418
.tracer_wrapper

engine/baml-runtime/src/test_executor/mod.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ pub trait TestExecutor {
4545
max_concurrency: usize,
4646
output_format: &crate::cli::testing::OutputFormat,
4747
junit_path: Option<&String>,
48+
env_vars: &HashMap<String, String>,
4849
) -> TestRunStatus;
4950
}
5051

@@ -180,6 +181,7 @@ impl TestExecutor for BamlRuntime {
180181
max_concurrency: usize,
181182
output_format: &crate::cli::testing::OutputFormat,
182183
junit_path: Option<&String>,
184+
env_vars: &HashMap<String, String>,
183185
) -> TestRunStatus {
184186
let renderer = AggregateRenderer::new(output_format, junit_path);
185187
let selected_tests = self
@@ -219,6 +221,7 @@ impl TestExecutor for BamlRuntime {
219221
let runtime = self.clone();
220222
let function_name = fn_name.to_string();
221223
let test_name = tt_name.to_string();
224+
let env_vars = env_vars.clone();
222225
let fut = tokio::spawn(async move {
223226
let _permit = semaphore.acquire().await.unwrap();
224227
let ctx_manager = runtime.create_ctx_manager(
@@ -233,7 +236,7 @@ impl TestExecutor for BamlRuntime {
233236
TestExecutionStatus::Running,
234237
));
235238
let (result, _) = runtime
236-
.run_test(&function_name, &test_name, &ctx_manager, Some(|_| {}), None, HashMap::new())
239+
.run_test(&function_name, &test_name, &ctx_manager, Some(|_| {}), None, env_vars)
237240
.await;
238241
let duration = start_instant.elapsed();
239242
let _ = tx.send((

0 commit comments

Comments
 (0)