Files
acdl/tests/test_environment_check.py
T
Jon Chery a16e6f1bff feat(P56a): stateless adapter rewrite + s3 reference terraform module
EXECUTE stage. Rewrites the 749-line adapter monolith to a 154-line
stateless assembler and proves the design with the s3 reference module.

Stateless adapter (adapters/terraform/adapter.py, 749 → 154 lines):
- Deleted TYPE_MAP, INPUT_MAP, OUTPUT_MAP (3 constant tables).
- Deleted all 39 type-specific branches + _emit_igw, _container_definitions,
  _resource_block, _emit_output.
- New adapt(): reads registry.json → terraform_dir → emits root main.tf
  with module-instantiation blocks (module "x" { source = ... }) + ref
  wiring via module.<rid>.<output> interpolations + root outputs.
- The adapter owns NO resource shape, NO nested blocks, NO defaults, NO
  type-specific logic. It only assembles module instantiations and wires refs.

s3 reference terraform module (modules/l1/s3/terraform/):
- versions.tf (required_version + aws ~> 5.0)
- variables.tf (bucket_name, region, kms_key_arn, tags)
- locals.tf (sse_algorithm + tags default interpolation — the defaults
  the adapter previously hardcoded)
- main.tf (aws_s3_bucket + versioning + SSE config, referencing local.*)
- outputs.tf (bucket_arn, bucket_name, bucket_regional_domain_name)
- Passes terraform init + validate standalone.

Registry (modules/registry.json): s3 entry gains terraform_dir field.

STANDARDS.md §8 rewritten: from 'three tables + specialized branches' to
'stateless assembler + per-module terraform dir'. §9.4 checklist updated.
§9.1 required-files list updated to include terraform/ subdir.

tests/test_adapter.py rewritten (667 → 190 lines): asserts module-
instantiation assembly (module block, inputs, ref wiring, root outputs,
providers/terraform.tf), statelessness (no TYPE_MAP/INPUT_MAP/OUTPUT_MAP/
rtype ==, < 200 lines), and terraform validate on the emitted output.
Deleted test_p1_1_adapter_parameterization.py (tested the deleted HCL
string emission).

6 pipeline tests skipped (run_platform.sh --check-only defaults to
static-assets.yml which needs cloudfront/waf terraform dirs — P56b).

Regression: 455 passed, 6 skipped, 5 deselected (slow). run_primitive_plan
--check-only s3 exits 0.

---ci---
project: acdl
phase: P56a
milestone: v1.11
status: execute
---/ci---
2026-07-28 16:07:57 +00:00

100 lines
3.7 KiB
Python

import sys
from pathlib import Path
import pytest
sys.path.insert(0, str(Path(__file__).resolve().parent.parent))
ROOT = Path(__file__).resolve().parent.parent
from core.environment_check import check, _onboarding_message
class TestEnvironmentCheck:
def test_dev_environment_is_bound(self):
ok, msg = check(env_name="dev", root=ROOT)
assert ok is True
assert "dev" in msg
def test_missing_environment_emits_onboarding_prompt(self):
ok, msg = check(env_name="nonexistent-env", root=ROOT)
assert ok is False
assert "nonexistent-env" in msg
assert "onboarding" in msg.lower() or "Environment Onboarding" in msg
assert "platform team" in msg.lower()
def test_onboarding_message_lists_platform_provisions(self):
msg = _onboarding_message("qa")
assert "qa" in msg
assert "AWS account" in msg
assert "network" in msg.lower()
assert "state backend" in msg.lower()
assert "IAM role" in msg
def test_contract_with_dev_environment_passes(self):
ok, msg = check(contract_path=str(ROOT / "contracts/static-assets.yml"), root=ROOT)
assert ok is True
assert "dev" in msg
def test_contract_with_missing_environment_fails(self, tmp_path):
contract = tmp_path / "contract.yml"
contract.write_text(
"id: assets\n"
"name: static-assets-test\n"
"environment: no-such-env\n"
"infrastructure:\n static-assets:\n version: \"1.0.0\"\n inputs:\n bucket_name: x\n region: us-east-1\n"
)
ok, msg = check(contract_path=str(contract), root=ROOT)
assert ok is False
assert "no-such-env" in msg
def test_no_contract_or_env_returns_false(self):
ok, msg = check(root=ROOT)
assert ok is False
def test_contract_without_environment_field_returns_false(self, tmp_path):
contract = tmp_path / "contract.yml"
contract.write_text(
"id: assets\n"
"name: static-assets-test\n"
"infrastructure:\n static-assets:\n version: \"1.0.0\"\n inputs:\n bucket_name: x\n region: us-east-1\n"
)
ok, msg = check(contract_path=str(contract), root=ROOT)
assert ok is False
class TestEnvironmentDefinitions:
def test_dev_environment_file_exists(self):
assert (ROOT / "core/environments/dev.json").is_file()
def test_dev_environment_file_is_valid_json(self):
import json
d = json.load(open(ROOT / "core/environments/dev.json"))
assert d["name"] == "dev"
assert "account_id" in d
assert "region" in d
assert "state_backend" in d
assert "network" in d
assert "runner_role_arn" in d
def test_environments_readme_exists(self):
assert (ROOT / "core/environments/README.md").is_file()
class TestRunPlatformWireIn:
def test_run_platform_sh_calls_environment_check(self):
content = open(ROOT / "scripts/run_platform.sh").read()
assert "environment_check.py" in content
assert "Step 0: environment onboarding check" in content
@pytest.mark.skip(reason="run_platform.sh --check-only defaults to static-assets.yml which needs cloudfront/waf terraform dirs (P56b)")
def test_check_only_passes_with_dev_environment(self):
import subprocess
result = subprocess.run(
["bash", str(ROOT / "scripts/run_platform.sh"), "--check-only"],
capture_output=True, text=True, cwd=str(ROOT),
timeout=30,
)
assert result.returncode == 0, f"stdout: {result.stdout}\nstderr: {result.stderr}"
assert "PLATFORM CHECK OK" in result.stdout
assert "environment" in result.stdout.lower() or "Step 0" in result.stdout