Files
acdl/tests/test_contract_resolver.py
T
Jon Chery f68f85c9fd
acdl-ci / Lint (push) Successful in 7s
acdl-ci / Test (push) Successful in 15s
acdl-ci / Platform check-only (offline) (push) Successful in 9s
review(v1.5): READY TO SHIP — multi-persona code review
---ci---
project: acdl
phase: 20
milestone: v1.5
status: review
verdict: READY TO SHIP
p0: 1 (fixed — contract path resolution in deploy workflow)
p1: 6 (flagged post-hoc)
---/ci---

Multi-persona review of v1.5 phase 20 (docs + reusable deploy workflow).

P0 (blocking) — AUTO-FIXED:
- C1: scripts/run_platform.sh contract path resolution broken in deploy
  workflow. The reusable workflow invokes run_platform.sh from the consumer
  workspace root with a relative contract path (.acdl/contract.yaml), but
  run_platform.sh does `cd "$ROOT"` (platform repo) early, so the relative
  path resolved against the platform repo and the pipeline could never run.
  Fix (commit 75c2274): capture CALLER_CWD before cd "$ROOT"; resolve
  caller-supplied relative paths against CALLER_CWD; default no-arg contract
  stays relative to ROOT (preserves platform-local CI). Reproduced pre-fix;
  verified post-fix.

P1 (important) — FLAGGED FOR POST-HOC REVIEW (do not block ship):
- C2: ref: v1.4 in the deploy workflow platform checkout — no v1.4 tag exists
  (only v1.4.0 / v1.4.1). Operator must create a floating v1.4 tag or change
  the ref to v1.4.1.
- C3: modules/l2/{static-asset,microservice}/README.md still use @v1 in their
  Usage examples; missed by the v1.4 bump.
- S1: static-key override is not wired. ACDL_AWS_* env vars on the OIDC step
  are not read by aws-actions/configure-aws-credentials@v4 (it reads AWS_*
  or its own access-key/secret-key inputs). The README/CONSUMER_GUIDE claim
  a working override that doesn't function as written. Needs a conditional
  step or renamed env vars + input wiring.
- S2: README overstates ABAC repo:org/repo:ref:... scoping. The workflow
  constructs a numeric role name (github.repository_id); the actual claim
  enforcement lives in the IAM trust policy, not in this workflow.
- T1: no deploy-workflow triggers conformance test (CI workflow has one;
  deploy doesn't). Minor — reusable workflows use workflow_call, not push
  triggers, but the contract's triggers field is then unenforced.
- A1: terraform/spike/terraform.tf uploaded as artifact leaks the AWS account
  ID via the state-backend bucket name. Recommend excluding terraform.tf or
  gating artifact upload to non-public repos.

P2 (nits) — listed for awareness: floating-tag terminology imprecision (M1),
  header comment "Gitea Actions" in the GitHub copy (M2, intentional byte-
  identical), pip install split (P1-perf), comment drift in pipelines/deploy.yaml
  header (C4), module README internal inconsistency (C5).

Verdict: READY TO SHIP. The one P0 is fixed. The 6 P1s are post-hoc items —
the deploy workflow is a scaffold whose first real consumer run requires
operator setup (tag, IAM role, secrets) that gates go-live. The P1s should
be addressed before any consumer invokes uses: acdl/.gitea/workflows/
deploy.yml@v1.4 in earnest.

Tests: 154 pass (19 new). run_ci.sh green.
2026-07-22 17:24:28 +00:00

154 lines
6.0 KiB
Python

import json
import os
import sys
from pathlib import Path
import jsonschema
import pytest
import yaml
sys.path.insert(0, str(Path(__file__).resolve().parent.parent))
ROOT = Path(__file__).resolve().parent.parent
class TestContractSchema:
def test_schema_is_valid_json_schema(self):
schema = json.load(open(ROOT / "schemas/contract.schema.json"))
jsonschema.Draft202012Validator.check_schema(schema)
def test_schema_requires_uses_module_environment_inputs(self):
schema = json.load(open(ROOT / "schemas/contract.schema.json"))
for field in ["uses", "module", "environment", "inputs"]:
assert field in schema["required"]
class TestResolveStaticAsset:
def test_resolve_static_asset_contract(self, tmp_path):
from acdl_platform.contract_resolver import resolve
stack = resolve(str(ROOT / "contracts/static-asset.yaml"), str(ROOT))
assert stack["stack"]["name"] == "static-asset"
assert stack["stack"]["kind"] == "l2"
assert stack["stack"]["depth"] == 1
assert len(stack["resources"]) >= 1
def test_resolve_static_asset_has_s3_resource(self):
from acdl_platform.contract_resolver import resolve
stack = resolve(str(ROOT / "contracts/static-asset.yaml"), 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-spike-bucket"
assert s3_res[0]["inputs"]["region"] == "us-east-1"
def test_resolve_static_asset_validates_against_stack_schema(self):
from acdl_platform.contract_resolver import resolve
stack = resolve(str(ROOT / "contracts/static-asset.yaml"), str(ROOT))
schema = json.load(open(ROOT / "schemas/stack.schema.json"))
jsonschema.validate(stack, schema)
class TestResolveMicroservice:
def test_resolve_microservice_contract(self):
contract = {
"uses": "acdl/pipelines/deploy.yaml@v1",
"module": "microservice",
"environment": "dev",
"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"
with open(contract_path, "w") as fh:
yaml.dump(contract, fh)
try:
from acdl_platform.contract_resolver import resolve
stack = resolve(str(contract_path), str(ROOT))
assert stack["stack"]["name"] == "microservice"
assert stack["stack"]["kind"] == "l2"
assert len(stack["resources"]) >= 6
finally:
os.remove(contract_path)
class TestResolveL1Direct:
def test_resolve_s3_direct(self, tmp_path):
contract = {
"uses": "acdl/pipelines/deploy.yaml@v1",
"module": "s3",
"environment": "dev",
"inputs": {
"bucket_name": "my-test-bucket",
"region": "us-east-1",
},
}
contract_path = tmp_path / "test-s3.yaml"
with open(contract_path, "w") as fh:
yaml.dump(contract, fh)
from acdl_platform.contract_resolver import resolve
stack = resolve(str(contract_path), str(ROOT))
assert stack["stack"]["name"] == "s3"
assert stack["stack"]["kind"] == "l1"
assert len(stack["resources"]) == 1
assert stack["resources"][0]["type"] == "aws:s3:bucket"
assert stack["resources"][0]["inputs"]["bucket_name"] == "my-test-bucket"
def test_resolve_s3_validates_against_stack_schema(self, tmp_path):
contract = {
"uses": "acdl/pipelines/deploy.yaml@v1",
"module": "s3",
"environment": "dev",
"inputs": {"bucket_name": "test", "region": "us-east-1"},
}
contract_path = tmp_path / "test-s3-schema.yaml"
with open(contract_path, "w") as fh:
yaml.dump(contract, fh)
from acdl_platform.contract_resolver import resolve
stack = resolve(str(contract_path), str(ROOT))
schema = json.load(open(ROOT / "schemas/stack.schema.json"))
jsonschema.validate(stack, schema)
class TestResolveErrors:
def test_unknown_module_raises(self, tmp_path):
contract = {
"uses": "acdl/pipelines/deploy.yaml@v1",
"module": "nonexistent",
"environment": "dev",
"inputs": {},
}
contract_path = tmp_path / "bad.yaml"
with open(contract_path, "w") as fh:
yaml.dump(contract, fh)
from acdl_platform.contract_resolver import resolve
with pytest.raises(ValueError, match="not found in registry"):
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"
with open(contract_path, "w") as fh:
yaml.dump(contract, fh)
from acdl_platform.contract_resolver import resolve
with pytest.raises(jsonschema.ValidationError):
resolve(str(contract_path), str(ROOT))
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:
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:
contract = yaml.safe_load(fh)
stage_names = [s["name"] for s in contract["stages"]]
assert "validate-contract" in stage_names
assert "resolve-stack" in stage_names
assert "terraform-plan" in stage_names
assert "checkov" in stage_names
assert "confidence" in stage_names
assert "apply" in stage_names