bee9d02f01
---ci---
project: acdl
phase: 40
milestone: v1.9
status: execute
---/ci---
Phase 40 — contract-interpolation (REQ-103, REQ-104, D-081):
Interpolation:
- core/contract_resolver.py: _expand_vars(value, context) recursively
expands ${env.<field>} + ${contract.<field>} tokens (dotted paths
supported, e.g. ${env.state_backend.bucket}). Unknown tokens raise
ValueError (fail loud). Expansion is post-schema-validation,
pre-IR-resolution.
- resolve() accepts environment_override (D-088) — overrides the
contract's environment field BEFORE schema validation so interpolation
context is consistent.
- env context loaded via _load_env (self-contained, works as script +
package import); 'environment' alias for env 'name' so
${env.environment} resolves.
Environment schema + bindings:
- schemas/environment.schema.json (draft 2020-12): name, account_id,
region, state_backend, network, runner_role_arn, autonomy, confidence_threshold.
- core/environments/qa.json, prod.json, dr.json placeholder bindings
(attested, thresholds 0.75/0.90/0.95, placeholder account_id with
stderr warning at load).
- core/environment_check.py: load(env_name) helper + placeholder warning.
Sample contracts:
- contracts/static-assets.yaml + microservice.yaml use
acdl-${env.environment}-${contract.module}-${env.account_id}-${env.region}
naming pattern (region + account id + environment).
Tests: +35 (test_environment_schema.py, test_interpolation.py,
test_sample_contracts_interpolate.py). 406 passed; run_ci.sh green;
run_platform.sh --check-only green. Existing fixture-based tests
preserved (instance.json static fixtures unaffected).
61 lines
2.4 KiB
Python
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.yaml"))
|
|
s3 = [r for r in stack["resources"] if r["type"] == "aws:s3:bucket"][0]
|
|
bucket = s3["inputs"]["bucket_name"]
|
|
# The naming pattern: acdl-<env>-<module>-<account_id>-<region>
|
|
assert bucket.startswith("acdl-dev-static-assets-")
|
|
assert "000000000000" in bucket
|
|
assert bucket.endswith("us-east-1")
|
|
assert bucket == "acdl-dev-static-assets-000000000000-us-east-1"
|
|
|
|
|
|
def test_static_assets_region_uses_env_region():
|
|
stack = resolve(str(ROOT / "contracts" / "static-assets.yaml"))
|
|
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.yaml").read_text()
|
|
assert "${env.environment}" in text
|
|
assert "${contract.module}" in text
|
|
assert "${env.account_id}" in text
|
|
assert "${env.region}" in text
|
|
|
|
|
|
def test_microservice_contract_has_interpolation_tokens():
|
|
text = (ROOT / "contracts" / "microservice.yaml").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.yaml"))
|
|
assert stack["stack"]["name"] == "microservice"
|
|
# 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.yaml"))
|
|
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 "static-assets" in bucket # module |