|
@@ -1193,112 +1193,6 @@ class DataRuleRepository:
|
|
|
"plan_hash": plan_hash,
|
|
"plan_hash": plan_hash,
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- def record_bound_plan_test(
|
|
|
|
|
- self,
|
|
|
|
|
- *,
|
|
|
|
|
- plan_id: str,
|
|
|
|
|
- evidence: dict[str, Any],
|
|
|
|
|
- test_kind: str = "integration_preflight",
|
|
|
|
|
- ) -> dict[str, Any]:
|
|
|
|
|
- """Attest integration evidence and transition compiled to tested."""
|
|
|
|
|
-
|
|
|
|
|
- execution_plan_id = _uid(plan_id, "plan_id")
|
|
|
|
|
- kind = _text(test_kind, "test_kind", 40)
|
|
|
|
|
- if not isinstance(evidence, dict):
|
|
|
|
|
- raise ValueError("test evidence must be an object")
|
|
|
|
|
- rows_in = evidence.get("rows_in")
|
|
|
|
|
- rows_out = evidence.get("rows_out")
|
|
|
|
|
- rows_rejected = evidence.get("rows_rejected")
|
|
|
|
|
- counts = (rows_in, rows_out, rows_rejected)
|
|
|
|
|
- if (
|
|
|
|
|
- evidence.get("commit_outcome") != "committed"
|
|
|
|
|
- or any(
|
|
|
|
|
- isinstance(value, bool)
|
|
|
|
|
- or not isinstance(value, int)
|
|
|
|
|
- or value < 0
|
|
|
|
|
- for value in counts
|
|
|
|
|
- )
|
|
|
|
|
- or rows_out > rows_in
|
|
|
|
|
- or rows_rejected != rows_in - rows_out
|
|
|
|
|
- ):
|
|
|
|
|
- raise ValueError("successful integration preflight evidence is required")
|
|
|
|
|
- evidence_hash = _canonical_hash(evidence)
|
|
|
|
|
- row = (
|
|
|
|
|
- self.session.execute(
|
|
|
|
|
- text(
|
|
|
|
|
- "WITH eligible AS ("
|
|
|
|
|
- "SELECT id FROM public.rule_execution_plans "
|
|
|
|
|
- "WHERE id = CAST(:plan_id AS uuid) "
|
|
|
|
|
- "AND backend = 'sql_pushdown' AND status = 'compiled' "
|
|
|
|
|
- "FOR UPDATE"
|
|
|
|
|
- "), inserted AS ("
|
|
|
|
|
- "INSERT INTO public.rule_test_evidence "
|
|
|
|
|
- "(id, rule_execution_plan_id, test_kind, evidence_hash, "
|
|
|
|
|
- "status, evidence) "
|
|
|
|
|
- "SELECT CAST(:evidence_id AS uuid), id, :test_kind, "
|
|
|
|
|
- ":evidence_hash, 'success', CAST(:evidence AS jsonb) "
|
|
|
|
|
- "FROM eligible RETURNING rule_execution_plan_id"
|
|
|
|
|
- ") "
|
|
|
|
|
- "UPDATE public.rule_execution_plans p SET status = 'tested' "
|
|
|
|
|
- "FROM inserted i WHERE p.id = i.rule_execution_plan_id "
|
|
|
|
|
- "RETURNING p.id::text AS id, p.status"
|
|
|
|
|
- ),
|
|
|
|
|
- {
|
|
|
|
|
- "plan_id": execution_plan_id,
|
|
|
|
|
- "evidence_id": new_governance_uid(),
|
|
|
|
|
- "test_kind": kind,
|
|
|
|
|
- "evidence_hash": evidence_hash,
|
|
|
|
|
- "evidence": _json(evidence),
|
|
|
|
|
- },
|
|
|
|
|
- )
|
|
|
|
|
- .mappings()
|
|
|
|
|
- .one_or_none()
|
|
|
|
|
- )
|
|
|
|
|
- if row is None:
|
|
|
|
|
- raise ValueError("only a compiled SQL plan may be tested")
|
|
|
|
|
- return {
|
|
|
|
|
- "id": str(row["id"]),
|
|
|
|
|
- "status": str(row["status"]),
|
|
|
|
|
- "evidence_hash": evidence_hash,
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- def publish_tested_bound_plan(self, *, plan_id: str) -> dict[str, Any]:
|
|
|
|
|
- """Publish only a tested plan with canonical successful evidence."""
|
|
|
|
|
-
|
|
|
|
|
- execution_plan_id = _uid(plan_id, "plan_id")
|
|
|
|
|
- row = (
|
|
|
|
|
- self.session.execute(
|
|
|
|
|
- text(
|
|
|
|
|
- "UPDATE public.rule_execution_plans p "
|
|
|
|
|
- "SET status = 'published' "
|
|
|
|
|
- "FROM public.dataflow_component_bindings cb, "
|
|
|
|
|
- "public.data_rule_versions rv "
|
|
|
|
|
- "WHERE p.id = CAST(:plan_id AS uuid) "
|
|
|
|
|
- "AND p.status = 'tested' "
|
|
|
|
|
- "AND cb.id = p.component_binding_id "
|
|
|
|
|
- "AND rv.id = cb.rule_version_id "
|
|
|
|
|
- "AND rv.status = 'published' "
|
|
|
|
|
- "AND EXISTS (SELECT 1 FROM public.rule_test_evidence e "
|
|
|
|
|
- "WHERE e.rule_execution_plan_id = p.id "
|
|
|
|
|
- "AND e.test_kind = 'integration_preflight' "
|
|
|
|
|
- "AND e.status = 'success') "
|
|
|
|
|
- "RETURNING p.id::text AS id, p.status, p.plan_hash"
|
|
|
|
|
- ),
|
|
|
|
|
- {"plan_id": execution_plan_id},
|
|
|
|
|
- )
|
|
|
|
|
- .mappings()
|
|
|
|
|
- .one_or_none()
|
|
|
|
|
- )
|
|
|
|
|
- if row is None:
|
|
|
|
|
- raise ValueError(
|
|
|
|
|
- "only a successfully tested canonical plan may be published"
|
|
|
|
|
- )
|
|
|
|
|
- return {
|
|
|
|
|
- "id": str(row["id"]),
|
|
|
|
|
- "status": str(row["status"]),
|
|
|
|
|
- "plan_hash": str(row["plan_hash"]),
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
def complete_dataflow_release(
|
|
def complete_dataflow_release(
|
|
|
self,
|
|
self,
|
|
|
*,
|
|
*,
|