fix runtime_startup_env_vars not being used (#4250)

This commit is contained in:
Xingyao Wang 2024-10-07 14:33:12 -05:00 committed by GitHub
parent bfdd7fd620
commit 9c07370559
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 24 additions and 0 deletions

View File

@ -202,6 +202,9 @@ class RemoteRuntime(Runtime):
), 'Runtime URL is not set. This should never happen.'
self.send_status_message(' ')
self._wait_until_alive()
self.setup_initial_env()
@retry(
stop=stop_after_attempt(10) | stop_if_should_exit(),
wait=wait_exponential(multiplier=1, min=4, max=60),

View File

@ -77,6 +77,8 @@ class Runtime:
def setup_initial_env(self) -> None:
logger.debug(f'Adding env vars: {self.initial_env_vars}')
self.add_env_vars(self.initial_env_vars)
if self.config.sandbox.runtime_startup_env_vars:
self.add_env_vars(self.config.sandbox.runtime_startup_env_vars)
def close(self) -> None:
pass

View File

@ -209,6 +209,7 @@ def _load_runtime(
browsergym_eval_env: str | None = None,
use_workspace: bool | None = None,
force_rebuild_runtime: bool = False,
runtime_startup_env_vars: dict[str, str] | None = None,
) -> Runtime:
sid = 'rt_' + str(random.randint(100000, 999999))
@ -241,6 +242,8 @@ def _load_runtime(
config.sandbox.browsergym_eval_env = browsergym_eval_env
config.sandbox.enable_auto_lint = enable_auto_lint
if runtime_startup_env_vars is not None:
config.sandbox.runtime_startup_env_vars = runtime_startup_env_vars
if base_container_image is not None:
config.sandbox.base_container_image = base_container_image

View File

@ -65,3 +65,19 @@ def test_env_vars_runtime_operations(temp_dir, box_class):
)
_close_test_runtime(runtime)
def test_env_vars_added_by_config(temp_dir, box_class):
runtime = _load_runtime(
temp_dir,
box_class,
runtime_startup_env_vars={'ADDED_ENV_VAR': 'added_value'},
)
# Test adding single env var
obs = runtime.run_action(CmdRunAction(command='echo $ADDED_ENV_VAR'))
assert (
obs.exit_code == 0
and obs.content.strip().split('\r\n')[0].strip() == 'added_value'
)
_close_test_runtime(runtime)