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>
This commit is contained in:
2026-10-07 20:06:58 +01:00
parent 5bb22d984e
commit f1f6f1b83a
34 changed files with 161 additions and 402 deletions

View File

@@ -1 +1,5 @@
# Env var setup that must run before app.config is imported.
import os
# The suite must not pick up credentials from a developer's .env.
os.environ["ENV_FILE_EXPORT"] = "false"

45
tests/test_env_file.py Normal file
View File

@@ -0,0 +1,45 @@
"""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", {}) == []

View File

@@ -1,10 +0,0 @@
from pathlib import Path
ROOT = Path(__file__).parents[1]
def test_no_secret_values():
assert (
"replace-with-project-id"
in (ROOT / "terraform/terraform.tfvars.example").read_text()
)

View File

@@ -228,6 +228,16 @@ async def test_schema_says_where_a_setting_sits_or_that_it_cannot_be_set(monkeyp
assert "It cannot be set on this resource type." in absent.message
async def test_schema_answers_for_several_settings_in_one_call(monkeypatch):
runner, _ = schema_runner(monkeypatch)
result = await runner.schema("cloud_service", find="cpu_boost, labels,ingress")
assert "template.cpu_boost (bool, optional)" in result.message
assert " labels (map of string, optional)" in result.message
assert "no argument or block named like 'ingress'" in result.message
async def test_schema_suggests_close_resource_types_and_is_loaded_once(monkeypatch):
runner, commands = schema_runner(monkeypatch)