Files
acdl/tests/test_sample_contracts_interpolate.py
T
Jon Chery 031887ec56 refactor(P57): contract surface redesign + rename + .yml repo-wide
Contract surface redesign:
- New top-level fields: id (3-6 char acronym → stack.name), name (full → stack.title),
  infrastructure (map keyed by module name, replaces module:)
- Drop uses: field (dead reference; version pin lives in CI workflow uses: line)
- Drop top-level module/inputs (now nested under infrastructure map)
- Per-module optional version (defaults to latest published from registry)
- Multi-module contracts: one file deploys N modules in one pipeline run,
  resource IDs namespaced with module name to avoid collisions
- stack.schema.json: add optional title field for display name

Rename:
- pipelines/deploy.yaml → pipelines/contract.yml (declarative spec, not a pipeline)
- pipelines/ci.yaml → pipelines/ci.yml
- All 44 .yaml files → .yml repo-wide (contracts, module examples, kyverno policies)
- .acdl/contract.yaml → .acdl/contract.yml

Resolver (core/contract_resolver.py):
- Rewrite resolve() to loop infrastructure map, default version to latest,
  merge module fragments into one stack with namespaced resource IDs
- _latest_version() picks highest non-deprecated from registry
- _namespace_resources() prefixes IDs + rewrites ref: expressions for multi-module
- Single-module path: unprefixed IDs (backward compatible)

Verification:
- 494 tests pass (0 contract-shape failures)
- Local E2E passes (contract → resolver → adapter → local ECS HTTP 200 → outbox)

---ci---
project: acdl
phase: 57
milestone: v1.10.2
status: execute
---/ci---
2026-07-27 21:37:40 +00:00

61 lines
2.4 KiB
Python

"""REQ-103: sample contracts use naming patterns with interpolation."""
import sys
from pathlib import Path
import pytest
ROOT = Path(__file__).resolve().parent.parent
sys.path.insert(0, str(ROOT))
from core.contract_resolver import resolve
def test_static_assets_bucket_name_uses_naming_pattern():
stack = resolve(str(ROOT / "contracts" / "static-assets.yml"))
s3 = [r for r in stack["resources"] if r["type"] == "aws:s3:bucket"][0]
bucket = s3["inputs"]["bucket_name"]
# The naming pattern: acdl-<env>-<id>-<account_id>-<region>
assert bucket.startswith("acdl-dev-assets-")
assert "000000000000" in bucket
assert bucket.endswith("us-east-1")
assert bucket == "acdl-dev-assets-000000000000-us-east-1"
def test_static_assets_region_uses_env_region():
stack = resolve(str(ROOT / "contracts" / "static-assets.yml"))
s3 = [r for r in stack["resources"] if r["type"] == "aws:s3:bucket"][0]
assert s3["inputs"]["region"] == "us-east-1"
def test_static_assets_contract_has_interpolation_tokens_pre_resolve():
"""The contract file itself contains the raw ${env.*} tokens (pre-resolution)."""
text = (ROOT / "contracts" / "static-assets.yml").read_text()
assert "${env.environment}" in text
assert "${contract.id}" in text
assert "${env.account_id}" in text
assert "${env.region}" in text
def test_microservice_contract_has_interpolation_tokens():
text = (ROOT / "contracts" / "microservice.yml").read_text()
assert "${env.environment}" in text
assert "${env.account_id}" in text
assert "${env.region}" in text
def test_microservice_resolves_with_interpolation():
stack = resolve(str(ROOT / "contracts" / "microservice.yml"))
assert stack["stack"]["name"] == "msvc"
# Resolution succeeded — no unresolved tokens.
def test_interpolation_uses_all_naming_components():
"""The naming pattern includes region, account id, and environment (the binding requirement)."""
stack = resolve(str(ROOT / "contracts" / "static-assets.yml"))
s3 = [r for r in stack["resources"] if r["type"] == "aws:s3:bucket"][0]
bucket = s3["inputs"]["bucket_name"]
# Verify all three required components are present in the resolved name.
assert "dev" in bucket # environment
assert "000000000000" in bucket # account_id
assert "us-east-1" in bucket # region
assert "assets" in bucket # contract id