c80060878a
EXECUTE stage. Authors the remaining 11 L1 module terraform subdirs with the full versions/variables/locals/main/outputs split. Defaults previously hardcoded in the adapter move into locals.tf. Simple single-resource modules (7): - kms-key: aws_kms_key + alias (enable_key_rotation, deletion_window defaults) - ecr: aws_ecr_repository (encryption_configuration from kms_key_arn, image_scanning) - ecs-cluster: aws_ecs_cluster (name default) - iam-role: aws_iam_role + inline_policy (assume_role_policy fallback, ECR/logs policy in locals.tf) - rds: aws_db_instance (storage_encrypted, multi_az, kms_key_arn defaults) - waf: aws_wafv2_web_acl (default_action, visibility_config, dynamic rules) - uptime: aws_ecs_task_definition + aws_ecs_service (Fargate compat, container_definitions in locals.tf) Multi-resource modules with intra-refs (4): - vpc: aws_vpc + aws_subnet + aws_internet_gateway + aws_route_table (CIDR derivation in locals.tf) - ecs-service: aws_ecs_task_definition + aws_ecs_service (Fargate compat, container_definitions, network_config in locals.tf) - alb: aws_lb + aws_lb_target_group + aws_lb_listener (subnet/security_group list derivation in locals.tf) - cloudfront: aws_cloudfront_distribution + aws_cloudfront_origin_access_control (OAC defaults in locals.tf) Registry: terraform_dir added to all 11 remaining entries. Adapter fix: stack output format uses separate 'from' + 'output' fields (not 'from': 'rid.output'). Fixed _emit_root_output to read both fields. 6 previously-skipped tests unblocked (run_platform.sh --check-only now resolves static-assets.yml through the new module-assembled adapter). Removed skip markers. Fixed test assertion (aws_s3_bucket → module). Regression: 461 passed, 0 skipped, 5 deselected (slow). All 12 modules pass run_primitive_plan.sh --check-only. All 12 terraform/ subdirs pass terraform init + validate standalone. ---ci--- project: acdl phase: P56b milestone: v1.11 status: execute ---/ci---
99 lines
3.6 KiB
Python
99 lines
3.6 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
|
|
|
|
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 |