|
| 1 | +"""YAG- Phase Y accountability gate schema. |
| 2 | +
|
| 3 | +Top-level gate asserting all four Phase Y accountability components are |
| 4 | +present: CBR + FIA + SDA + PMC. |
| 5 | +
|
| 6 | +No external pilot claim is credible without passing this gate. |
| 7 | +Verdict: accountability_verified / accountability_partial / accountability_not_established. |
| 8 | +""" |
| 9 | + |
| 10 | +from __future__ import annotations |
| 11 | + |
| 12 | +from dataclasses import dataclass |
| 13 | + |
| 14 | +REQUIRED_Y_COMPONENTS: tuple[str, ...] = ("CBR", "FIA", "SDA", "PMC") |
| 15 | + |
| 16 | +VALID_YAG_VERDICTS: frozenset[str] = frozenset({ |
| 17 | + "accountability_verified", |
| 18 | + "accountability_partial", |
| 19 | + "accountability_not_established", |
| 20 | +}) |
| 21 | + |
| 22 | +ACCOUNTABILITY_VERIFIED_REQUIRED_PRESENT: int = 4 |
| 23 | +ACCOUNTABILITY_PARTIAL_MIN_PRESENT: int = 2 |
| 24 | + |
| 25 | + |
| 26 | +@dataclass |
| 27 | +class YComponentCheck: |
| 28 | + component_type: str |
| 29 | + artifact_id: str |
| 30 | + present: bool |
| 31 | + |
| 32 | + |
| 33 | +@dataclass |
| 34 | +class PhaseYAccountabilityGate: |
| 35 | + yag_id: str |
| 36 | + pipeline_version: str |
| 37 | + component_checks: list[YComponentCheck] |
| 38 | + n_components_present: int |
| 39 | + yag_verdict: str |
| 40 | + dry_lab_only: bool |
| 41 | + limitations: list[str] |
| 42 | + created_at: str |
| 43 | + |
| 44 | + |
| 45 | +def validate_phase_y_accountability_gate(yag: PhaseYAccountabilityGate) -> None: |
| 46 | + if not yag.yag_id.startswith("YAG-"): |
| 47 | + raise ValueError(f"yag_id must start with 'YAG-': {yag.yag_id!r}") |
| 48 | + if not yag.pipeline_version: |
| 49 | + raise ValueError("pipeline_version must be non-empty") |
| 50 | + if len(yag.component_checks) != len(REQUIRED_Y_COMPONENTS): |
| 51 | + raise ValueError( |
| 52 | + f"component_checks must have exactly {len(REQUIRED_Y_COMPONENTS)} entries" |
| 53 | + ) |
| 54 | + for check in yag.component_checks: |
| 55 | + if check.component_type not in REQUIRED_Y_COMPONENTS: |
| 56 | + raise ValueError( |
| 57 | + f"component_type {check.component_type!r} not in REQUIRED_Y_COMPONENTS" |
| 58 | + ) |
| 59 | + expected_prefix = f"{check.component_type}-" |
| 60 | + if check.artifact_id and not check.artifact_id.startswith(expected_prefix): |
| 61 | + raise ValueError( |
| 62 | + f"artifact_id {check.artifact_id!r} must start with {expected_prefix!r}" |
| 63 | + ) |
| 64 | + n_present = sum(1 for c in yag.component_checks if c.present) |
| 65 | + if yag.n_components_present != n_present: |
| 66 | + raise ValueError("n_components_present mismatch") |
| 67 | + if yag.yag_verdict not in VALID_YAG_VERDICTS: |
| 68 | + raise ValueError( |
| 69 | + f"yag_verdict {yag.yag_verdict!r} not in VALID_YAG_VERDICTS" |
| 70 | + ) |
| 71 | + if not yag.dry_lab_only: |
| 72 | + raise ValueError("dry_lab_only must be True") |
| 73 | + if not yag.limitations: |
| 74 | + raise ValueError("limitations must be non-empty") |
| 75 | + if not yag.created_at: |
| 76 | + raise ValueError("created_at must be non-empty") |
| 77 | + |
| 78 | + |
| 79 | +def _compute_verdict(n_present: int) -> str: |
| 80 | + if n_present >= ACCOUNTABILITY_VERIFIED_REQUIRED_PRESENT: |
| 81 | + return "accountability_verified" |
| 82 | + if n_present >= ACCOUNTABILITY_PARTIAL_MIN_PRESENT: |
| 83 | + return "accountability_partial" |
| 84 | + return "accountability_not_established" |
| 85 | + |
| 86 | + |
| 87 | +def build_phase_y_accountability_gate( |
| 88 | + *, |
| 89 | + yag_id: str, |
| 90 | + pipeline_version: str, |
| 91 | + cbr_artifact_id: str = "", |
| 92 | + fia_artifact_id: str = "", |
| 93 | + sda_artifact_id: str = "", |
| 94 | + pmc_artifact_id: str = "", |
| 95 | + limitations: list[str], |
| 96 | + created_at: str, |
| 97 | +) -> PhaseYAccountabilityGate: |
| 98 | + """Build a PhaseYAccountabilityGate. |
| 99 | +
|
| 100 | + Pass non-empty artifact_id for each component that is present. |
| 101 | + Empty artifact_id means the component is absent (present=False). |
| 102 | + """ |
| 103 | + checks = [ |
| 104 | + YComponentCheck( |
| 105 | + component_type="CBR", |
| 106 | + artifact_id=cbr_artifact_id, |
| 107 | + present=bool(cbr_artifact_id), |
| 108 | + ), |
| 109 | + YComponentCheck( |
| 110 | + component_type="FIA", |
| 111 | + artifact_id=fia_artifact_id, |
| 112 | + present=bool(fia_artifact_id), |
| 113 | + ), |
| 114 | + YComponentCheck( |
| 115 | + component_type="SDA", |
| 116 | + artifact_id=sda_artifact_id, |
| 117 | + present=bool(sda_artifact_id), |
| 118 | + ), |
| 119 | + YComponentCheck( |
| 120 | + component_type="PMC", |
| 121 | + artifact_id=pmc_artifact_id, |
| 122 | + present=bool(pmc_artifact_id), |
| 123 | + ), |
| 124 | + ] |
| 125 | + n_present = sum(1 for c in checks if c.present) |
| 126 | + verdict = _compute_verdict(n_present) |
| 127 | + yag = PhaseYAccountabilityGate( |
| 128 | + yag_id=yag_id, |
| 129 | + pipeline_version=pipeline_version, |
| 130 | + component_checks=checks, |
| 131 | + n_components_present=n_present, |
| 132 | + yag_verdict=verdict, |
| 133 | + dry_lab_only=True, |
| 134 | + limitations=limitations, |
| 135 | + created_at=created_at, |
| 136 | + ) |
| 137 | + validate_phase_y_accountability_gate(yag) |
| 138 | + return yag |
| 139 | + |
| 140 | + |
| 141 | +def format_phase_y_accountability_gate(yag: PhaseYAccountabilityGate) -> str: |
| 142 | + lines = [ |
| 143 | + f"Phase Y Accountability Gate — {yag.yag_id}", |
| 144 | + f"Pipeline: {yag.pipeline_version}", |
| 145 | + f"Verdict: {yag.yag_verdict}", |
| 146 | + f"Components present: {yag.n_components_present}/{len(REQUIRED_Y_COMPONENTS)}", |
| 147 | + ] |
| 148 | + lines.append("Component checks:") |
| 149 | + for check in yag.component_checks: |
| 150 | + status = "PRESENT" if check.present else "ABSENT" |
| 151 | + artifact = f" [{check.artifact_id}]" if check.artifact_id else "" |
| 152 | + lines.append(f" {check.component_type}: {status}{artifact}") |
| 153 | + lines.append(f"Created: {yag.created_at}") |
| 154 | + lines.append(f"Limitations: {'; '.join(yag.limitations)}") |
| 155 | + lines.append(f"dry_lab_only: {yag.dry_lab_only}") |
| 156 | + return "\n".join(lines) |
0 commit comments