Files
gcp_solution_architecture_a…/tests/test_env_file.py
Jonathan Boniface f1f6f1b83a feat: load the env file at start-up, trim schema lookups, remove legacy samples
Start-up
- Export the env file's variables for other libraries (the Cloud provider's
  client) into the process environment; the app's own settings and secrets
  are never exported, and a value already in the environment wins.
- Use GOOGLE_GENAI_USE_ENTERPRISE in place of the deprecated
  GOOGLE_GENAI_USE_VERTEXAI.

Target architect
- Look each distinct resource type up once instead of once per setting: in
  the run of 2026-10-07 it made 39 lookups for 8 types and exhausted its
  budget. terraform_schema's find takes several names; budget 30 to 45.
- A cut-off schema outline says so.

Removed, as leftovers of the original pipeline that nothing read
- terraform/ (no longer passed terraform validate), scripts/validate.sh,
  tests/test_package.py and the CI steps that ran on them.
- The sample outputs under docs/ and requirements.yaml.
- CI now pins Terraform 1.14.3, as the container image does.

Plans record the case 01 run: completed at 100% in 18 minutes with no
Revision, against 60 minutes and warnings before.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-07 20:06:58 +01:00

46 lines
1.4 KiB
Python

"""The env file at start-up: variables for other libraries reach the environment."""
from app.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", {}) == []