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---
This commit is contained in:
@@ -17,24 +17,25 @@ class TestContractSchema:
|
||||
schema = json.load(open(ROOT / "schemas/contract.schema.json"))
|
||||
jsonschema.Draft202012Validator.check_schema(schema)
|
||||
|
||||
def test_schema_requires_uses_module_environment_inputs(self):
|
||||
def test_schema_requires_id_name_environment_infrastructure(self):
|
||||
schema = json.load(open(ROOT / "schemas/contract.schema.json"))
|
||||
for field in ["uses", "module", "environment", "inputs"]:
|
||||
for field in ["id", "name", "environment", "infrastructure"]:
|
||||
assert field in schema["required"]
|
||||
|
||||
|
||||
class TestResolveStaticAsset:
|
||||
def test_resolve_static_asset_contract(self, tmp_path):
|
||||
from core.contract_resolver import resolve
|
||||
stack = resolve(str(ROOT / "contracts/static-assets.yaml"), str(ROOT))
|
||||
assert stack["stack"]["name"] == "static-assets"
|
||||
stack = resolve(str(ROOT / "contracts/static-assets.yml"), str(ROOT))
|
||||
assert stack["stack"]["name"] == "assets"
|
||||
assert stack["stack"]["title"] == "static-assets"
|
||||
assert stack["stack"]["kind"] == "l2"
|
||||
assert stack["stack"]["depth"] == 1
|
||||
assert len(stack["resources"]) >= 1
|
||||
|
||||
def test_resolve_static_asset_has_s3_cloudfront_waf_resources(self):
|
||||
from core.contract_resolver import resolve
|
||||
stack = resolve(str(ROOT / "contracts/static-assets.yaml"), str(ROOT))
|
||||
stack = resolve(str(ROOT / "contracts/static-assets.yml"), str(ROOT))
|
||||
types = [r["type"] for r in stack["resources"]]
|
||||
assert "aws:s3:bucket" in types
|
||||
assert "aws:cloudfront:distribution" in types
|
||||
@@ -43,15 +44,15 @@ class TestResolveStaticAsset:
|
||||
|
||||
def test_resolve_static_asset_has_s3_resource(self):
|
||||
from core.contract_resolver import resolve
|
||||
stack = resolve(str(ROOT / "contracts/static-assets.yaml"), str(ROOT))
|
||||
stack = resolve(str(ROOT / "contracts/static-assets.yml"), str(ROOT))
|
||||
s3_res = [r for r in stack["resources"] if r["type"] == "aws:s3:bucket"]
|
||||
assert len(s3_res) == 1
|
||||
assert s3_res[0]["inputs"]["bucket_name"] == "acdl-dev-static-assets-000000000000-us-east-1"
|
||||
assert s3_res[0]["inputs"]["bucket_name"] == "acdl-dev-assets-000000000000-us-east-1"
|
||||
assert s3_res[0]["inputs"]["region"] == "us-east-1"
|
||||
|
||||
def test_resolve_static_asset_validates_against_stack_schema(self):
|
||||
from core.contract_resolver import resolve
|
||||
stack = resolve(str(ROOT / "contracts/static-assets.yaml"), str(ROOT))
|
||||
stack = resolve(str(ROOT / "contracts/static-assets.yml"), str(ROOT))
|
||||
schema = json.load(open(ROOT / "schemas/stack.schema.json"))
|
||||
jsonschema.validate(stack, schema)
|
||||
|
||||
@@ -59,22 +60,28 @@ class TestResolveStaticAsset:
|
||||
class TestResolveMicroservice:
|
||||
def test_resolve_microservice_contract(self):
|
||||
contract = {
|
||||
"uses": "acdl/pipelines/deploy.yaml@v1",
|
||||
"module": "microservice",
|
||||
"id": "msvc",
|
||||
"name": "microservice-test",
|
||||
"environment": "dev",
|
||||
"inputs": {
|
||||
"image": "581513795199.dkr.ecr.us-east-1.amazonaws.com/acdl-microservice:latest",
|
||||
"port": 8080,
|
||||
"region": "us-east-1",
|
||||
"infrastructure": {
|
||||
"microservice": {
|
||||
"version": "1.0.0",
|
||||
"inputs": {
|
||||
"image": "581513795199.dkr.ecr.us-east-1.amazonaws.com/acdl-microservice:latest",
|
||||
"port": 8080,
|
||||
"region": "us-east-1",
|
||||
},
|
||||
}
|
||||
},
|
||||
}
|
||||
contract_path = ROOT / "contracts" / "test-microservice.yaml"
|
||||
contract_path = ROOT / "contracts" / "test-microservice.yml"
|
||||
with open(contract_path, "w") as fh:
|
||||
yaml.dump(contract, fh)
|
||||
try:
|
||||
from core.contract_resolver import resolve
|
||||
stack = resolve(str(contract_path), str(ROOT))
|
||||
assert stack["stack"]["name"] == "microservice"
|
||||
assert stack["stack"]["name"] == "msvc"
|
||||
assert stack["stack"]["title"] == "microservice-test"
|
||||
assert stack["stack"]["kind"] == "l2"
|
||||
assert len(stack["resources"]) >= 6
|
||||
finally:
|
||||
@@ -84,20 +91,25 @@ class TestResolveMicroservice:
|
||||
class TestResolveL1Direct:
|
||||
def test_resolve_s3_direct(self, tmp_path):
|
||||
contract = {
|
||||
"uses": "acdl/pipelines/deploy.yaml@v1",
|
||||
"module": "s3",
|
||||
"id": "s3a",
|
||||
"name": "s3-direct-test",
|
||||
"environment": "dev",
|
||||
"inputs": {
|
||||
"bucket_name": "my-test-bucket",
|
||||
"region": "us-east-1",
|
||||
"infrastructure": {
|
||||
"s3": {
|
||||
"version": "1.0.0",
|
||||
"inputs": {
|
||||
"bucket_name": "my-test-bucket",
|
||||
"region": "us-east-1",
|
||||
},
|
||||
}
|
||||
},
|
||||
}
|
||||
contract_path = tmp_path / "test-s3.yaml"
|
||||
contract_path = tmp_path / "test-s3.yml"
|
||||
with open(contract_path, "w") as fh:
|
||||
yaml.dump(contract, fh)
|
||||
from core.contract_resolver import resolve
|
||||
stack = resolve(str(contract_path), str(ROOT))
|
||||
assert stack["stack"]["name"] == "s3"
|
||||
assert stack["stack"]["name"] == "s3a"
|
||||
assert stack["stack"]["kind"] == "l1"
|
||||
assert len(stack["resources"]) == 1
|
||||
assert stack["resources"][0]["type"] == "aws:s3:bucket"
|
||||
@@ -105,12 +117,17 @@ class TestResolveL1Direct:
|
||||
|
||||
def test_resolve_s3_validates_against_stack_schema(self, tmp_path):
|
||||
contract = {
|
||||
"uses": "acdl/pipelines/deploy.yaml@v1",
|
||||
"module": "s3",
|
||||
"id": "s3a",
|
||||
"name": "s3-schema-test",
|
||||
"environment": "dev",
|
||||
"inputs": {"bucket_name": "test", "region": "us-east-1"},
|
||||
"infrastructure": {
|
||||
"s3": {
|
||||
"version": "1.0.0",
|
||||
"inputs": {"bucket_name": "test", "region": "us-east-1"},
|
||||
}
|
||||
},
|
||||
}
|
||||
contract_path = tmp_path / "test-s3-schema.yaml"
|
||||
contract_path = tmp_path / "test-s3-schema.yml"
|
||||
with open(contract_path, "w") as fh:
|
||||
yaml.dump(contract, fh)
|
||||
from core.contract_resolver import resolve
|
||||
@@ -122,12 +139,17 @@ class TestResolveL1Direct:
|
||||
class TestResolveErrors:
|
||||
def test_unknown_module_raises(self, tmp_path):
|
||||
contract = {
|
||||
"uses": "acdl/pipelines/deploy.yaml@v1",
|
||||
"module": "nonexistent",
|
||||
"id": "bad1",
|
||||
"name": "unknown-module-test",
|
||||
"environment": "dev",
|
||||
"inputs": {},
|
||||
"infrastructure": {
|
||||
"nonexistent": {
|
||||
"version": "1.0.0",
|
||||
"inputs": {},
|
||||
}
|
||||
},
|
||||
}
|
||||
contract_path = tmp_path / "bad.yaml"
|
||||
contract_path = tmp_path / "bad.yml"
|
||||
with open(contract_path, "w") as fh:
|
||||
yaml.dump(contract, fh)
|
||||
from core.contract_resolver import resolve
|
||||
@@ -135,8 +157,8 @@ class TestResolveErrors:
|
||||
resolve(str(contract_path), str(ROOT))
|
||||
|
||||
def test_missing_required_field_fails_validation(self, tmp_path):
|
||||
contract = {"uses": "acdl/pipelines/deploy.yaml@v1", "module": "s3"}
|
||||
contract_path = tmp_path / "incomplete.yaml"
|
||||
contract = {"id": "bad2", "name": "incomplete", "environment": "dev"}
|
||||
contract_path = tmp_path / "incomplete.yml"
|
||||
with open(contract_path, "w") as fh:
|
||||
yaml.dump(contract, fh)
|
||||
from core.contract_resolver import resolve
|
||||
@@ -147,12 +169,12 @@ class TestResolveErrors:
|
||||
class TestDeployPipelineContract:
|
||||
def test_deploy_pipeline_validates_against_schema(self):
|
||||
schema = json.load(open(ROOT / "schemas/deploy-pipeline.schema.json"))
|
||||
with open(ROOT / "pipelines/deploy.yaml") as fh:
|
||||
with open(ROOT / "pipelines/contract.yml") as fh:
|
||||
contract = yaml.safe_load(fh)
|
||||
jsonschema.validate(contract, schema)
|
||||
|
||||
def test_deploy_pipeline_has_six_stages(self):
|
||||
with open(ROOT / "pipelines/deploy.yaml") as fh:
|
||||
with open(ROOT / "pipelines/contract.yml") as fh:
|
||||
contract = yaml.safe_load(fh)
|
||||
stage_names = [s["name"] for s in contract["stages"]]
|
||||
assert "validate-contract" in stage_names
|
||||
@@ -168,7 +190,7 @@ class TestL2OutputsResolution:
|
||||
|
||||
def test_static_assets_outputs_present(self):
|
||||
from core.contract_resolver import resolve
|
||||
stack = resolve(str(ROOT / "contracts/static-assets.yaml"), str(ROOT))
|
||||
stack = resolve(str(ROOT / "contracts/static-assets.yml"), str(ROOT))
|
||||
assert "outputs" in stack, "stack.outputs must be present for L2 modules (P1-7)"
|
||||
assert "distribution_domain_name" in stack["outputs"]
|
||||
assert "bucket_arn" in stack["outputs"]
|
||||
@@ -176,7 +198,7 @@ class TestL2OutputsResolution:
|
||||
|
||||
def test_static_assets_output_from_field_resolves_to_resource_id(self):
|
||||
from core.contract_resolver import resolve
|
||||
stack = resolve(str(ROOT / "contracts/static-assets.yaml"), str(ROOT))
|
||||
stack = resolve(str(ROOT / "contracts/static-assets.yml"), str(ROOT))
|
||||
dist = stack["outputs"]["distribution_domain_name"]
|
||||
assert "from" in dist
|
||||
assert "output" in dist
|
||||
@@ -184,7 +206,7 @@ class TestL2OutputsResolution:
|
||||
|
||||
def test_microservice_outputs_present(self):
|
||||
from core.contract_resolver import resolve
|
||||
stack = resolve(str(ROOT / "contracts/microservice.yaml"), str(ROOT))
|
||||
stack = resolve(str(ROOT / "contracts/microservice.yml"), str(ROOT))
|
||||
assert "outputs" in stack, "stack.outputs must be present for L2 modules (P1-7)"
|
||||
assert "lb_arn" in stack["outputs"]
|
||||
assert "service_arn" in stack["outputs"]
|
||||
Reference in New Issue
Block a user