"""The env file at start-up: variables for other libraries reach the environment.""" from execution_engine.config import export_env_file def test_variables_for_other_libraries_are_exported(tmp_path): env_file = tmp_path / ".env" env_file.write_text( "GOOGLE_CLOUD_PROJECT=my-project\n" 'GOOGLE_CLOUD_LOCATION="global" # quoted, with a comment\n' "# COMMENTED_OUT=1\n" ) environ: dict[str, str] = {} exported = export_env_file(env_file, environ) assert environ == { "GOOGLE_CLOUD_PROJECT": "my-project", "GOOGLE_CLOUD_LOCATION": "global", } assert exported == ["GOOGLE_CLOUD_PROJECT", "GOOGLE_CLOUD_LOCATION"] def test_the_environment_wins_over_the_file(tmp_path): env_file = tmp_path / ".env" env_file.write_text("GOOGLE_CLOUD_PROJECT=from-file\n") environ = {"GOOGLE_CLOUD_PROJECT": "from-shell"} assert export_env_file(env_file, environ) == [] assert environ == {"GOOGLE_CLOUD_PROJECT": "from-shell"} def test_the_apps_own_settings_and_secrets_are_not_exported(tmp_path): env_file = tmp_path / ".env" env_file.write_text( "TYPESAFE_API_KEY=secret\nPOSTGRES_PASSWORD=secret\nLOG_LEVEL=DEBUG\n" ) environ: dict[str, str] = {} assert export_env_file(env_file, environ) == [] assert environ == {} def test_a_missing_file_exports_nothing(tmp_path): assert export_env_file(tmp_path / "absent.env", {}) == []