from __future__ import annotations
from pathlib import Path
import pytest
from coverage_shape_rules import (
codescene_contacts,
measuring_lanes,
publisher_faults,
unratcheted_lanes,
)
from workflow_reader import Workflow, load_workflows
REPOSITORY_ROOT = Path(__file__).resolve().parents[2]
@pytest.fixture(scope="module")
def workflows() -> list[Workflow]:
return load_workflows(REPOSITORY_ROOT)
def test_every_workflow_declares_a_trigger(workflows: list[Workflow]) -> None:
silent = [flow.path for flow in workflows if not flow.triggers]
assert not silent, f"the reader found no trigger in: {silent}"
def test_a_pull_request_lane_measures_coverage(
workflows: list[Workflow],
) -> None:
assert measuring_lanes(workflows), (
"no pull-request coverage step can run; the ratchet has nothing to compare"
)
def test_no_pull_request_lane_reaches_codescene(
workflows: list[Workflow],
) -> None:
offenders = codescene_contacts(workflows)
assert not offenders, (
f"a pull-request lane must not reach CodeScene; the service's gate "
f"configuration is not this repository's to fix: {offenders}"
)
def test_every_pull_request_coverage_step_ratchets_locally(
workflows: list[Workflow],
) -> None:
wrong = unratcheted_lanes(workflows)
assert not wrong, f"pull-request coverage steps must ratchet locally: {wrong}"
def test_one_serialized_trunk_publisher_uploads(
workflows: list[Workflow],
) -> None:
faults = publisher_faults(workflows)
assert not faults, f"the trunk publisher is not CV-005 shaped: {faults}"