Pass environment to docker container for local-test#409
Pass environment to docker container for local-test#409
local-test#409Conversation
…iable loading into local test command. Introduced functions to find and retrieve values from .env files, enhancing configuration management for Docker tests.
| dotenv_vars = get_dotenv_values(project_root) | ||
| for key, value in dotenv_vars.items(): | ||
| if value is not None: | ||
| cmd += ["-e", f"{key}={value}"] |
There was a problem hiding this comment.
Dotenv variables may override critical container settings
Medium Severity
Environment variables from the .env file are added after the hardcoded HOME and EVAL_PROTOCOL_DIR settings. In Docker, when the same -e flag is specified multiple times, the last value wins. If a user's .env file contains HOME or EVAL_PROTOCOL_DIR, these values would override the container's critical configuration (HOME=/container_home, EVAL_PROTOCOL_DIR=/container_home/.eval_protocol), potentially breaking the container's ability to write logs and artifacts to the mounted volume.
| env_path = find_dotenv(filename=".env", raise_error_if_not_found=False, usecwd=True) | ||
| if env_path: | ||
| return env_path | ||
| return None |
There was a problem hiding this comment.
Inconsistent dotenv search behavior between host and Docker
Medium Severity
The find_dotenv_path function behaves differently depending on whether search_path is provided. Without an argument, it searches up the directory tree using find_dotenv(). With a path, it only looks in that exact directory. The module-level load uses the former (finding parent .env files), while get_dotenv_values(project_root) uses the latter. This means environment variables from a parent directory's .env file are loaded into the host but not forwarded to Docker, causing tests to pass locally but fail in the container.
Note
Introduces .env support and forwards env vars to Docker for local-test.
.env.dev/.envinto thedocker runenvironment inlocal_test.pyfind_dotenv_pathandget_dotenv_valuesinauth.py; auto-load.env.devthen.envon import (without overriding existing env)Written by Cursor Bugbot for commit 838c7a5. This will update automatically on new commits. Configure here.