Files
acdl/tests/test_environment_check.py
T
Jon Chery dca35c78ec feat(P22): rename static-asset→static-assets + cloudfront/waf primitives + production stack + @v1.6 bump
---ci---
phase: 22
title: rename-and-production-static-assets-stack
status: complete
verification:
  - scripts/run_ci.sh: PASS (CI PIPELINE OK)
  - python3 -m pytest tests/ -v: 175 passed
  - scripts/run_platform.sh --check-only: PASS (PLATFORM CHECK OK)
  - grep -R "static-asset[^s]" . (excl .git/): 0 hits
  - grep -R "static-asset$" . (excl .git/): 0 hits
  - floating git tags v1.6 + v1 point at v1.6.0 (a90a756)
changed_files:
  - Task 1 (rename): contracts/static-asset.yaml→static-assets.yaml (git mv); modules/l2/static-asset→static-assets (git mv); sed replaceAll static-asset→static-assets in 22 files (README, docs, scripts/run_platform.sh, pipelines/deploy.yaml, modules/registry.json, tests/*, .ciagent/* historical narrative)
  - Task 2 (cloudfront primitive): modules/l1/cloudfront/interface.json + README.md
  - Task 3 (waf primitive): modules/l1/waf/interface.json + README.md
  - Task 4 (registry): modules/registry.json (+cloudfront, +waf, static-assets renamed)
  - Task 5 (augment static-assets): modules/l2/static-assets/composition.json (s3+cloudfront+waf, depth 1); modules/l1/s3/interface.json +instance.json (+bucket_regional_domain_name output); modules/l2/static-assets/README.md (production stack docs)
  - Task 6 (adapter): adapters/terraform/adapter.py (+TYPE_MAP/INPUT_MAP/OUTPUT_MAP for cloudfront distribution+OAC+wafv2 webacl; special handling in _emit_resource for OAC defaults, distribution origin/cache_behavior/restrictions/viewer_certificate/web_acl_id, waf scope/default_action/visibility_config/managed rules)
  - Task 7 (contract schema): no change needed (generic inputs object; new module names match ^[a-z][a-z0-9-]*$)
  - Task 8 (@v1.6 bump): contracts/static-assets.yaml, .gitea/.github/workflows/deploy.yml (ref: v1.6 + header comments), docs/consumer-guide.md, docs/contracts/index.md, docs/pipeline/versioning.md, docs/pipeline/index.md, docs/architecture.md, README.md, modules/l2/microservice/README.md, tests/test_environment_check.py, tests/test_pipeline_contract.py
  - Task 9 (floating tags): git tag -f v1.6 v1.6.0; git tag -f v1 v1.6.0
  - Task 10 (tests): tests/test_adapter.py (registry 11 entries/9 L1/2 L2; cloudfront+waf type map tests; TestS3Output bucket_regional_domain_name; TestStaticAssetsStack 4 tests); tests/test_contract_resolver.py (+s3/cloudfront/waf resource assertions)
generated:
  - terraform/spike/main.tf + terraform.tf (regenerated by run_platform.sh --check-only; reflect static-assets production stack + backend key spike/static-assets/)
notes:
  - D-048 full rewrite of .ciagent/ historical narrative (verbatim phase descriptions, REQ-25/27/50, D-036) — produces intentional tautologies (e.g. "Rename static-assets → static-assets") per the decision to override the v1.6 preservation precedent.
  - cloudfront interface.json resources array ordered distribution-first so the resolver (first-match wire resolution) routes bucket_regional_domain_name/waf_web_acl_arn/region to the distribution; the OAC gets adapter-provided defaults (name=acdl-oac, origin_type=s3, signing_behavior=always).
  - .ciagent/ @v1.4 references left as historical record (D-048 scope was static-asset rename only; @v1.4 is historical narrative of Phase 20).
  - s3 OUTPUT_MAP bucket_regional_domain_name not added (identity fallback in adapt() already handles it; OUTPUT_MAP documents non-identity mappings only).
---ci---
2026-07-22 19:56:52 +00:00

99 lines
3.5 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.yaml"), root=ROOT)
assert ok is True
assert "dev" in msg
def test_contract_with_missing_environment_fails(self, tmp_path):
contract = tmp_path / "contract.yaml"
contract.write_text(
"uses: acdl/pipelines/deploy.yaml@v1.6\n"
"module: static-assets\n"
"environment: no-such-env\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.yaml"
contract.write_text(
"uses: acdl/pipelines/deploy.yaml@v1.6\n"
"module: static-assets\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