generated from coulomb/repo-seed
feat: validate financial fabric graph exports
This commit is contained in:
@@ -10,6 +10,12 @@ from pathlib import Path
|
||||
from typing import Any
|
||||
|
||||
from .canon import DISPLAY_ONLY_EDGE_TYPES, edge_canon_mapping, node_canon_mapping
|
||||
from .financial import (
|
||||
financial_graph_errors,
|
||||
is_financial_graph_export,
|
||||
materialize_financial_graph_export,
|
||||
merge_financial_graph_exports,
|
||||
)
|
||||
from .loader import repo_root
|
||||
from .schema_validation import draft202012_validator
|
||||
|
||||
@@ -183,6 +189,7 @@ class RegistryStore:
|
||||
if not isinstance(graph, dict):
|
||||
raise RegistryError("snapshot payload requires object field 'graph'")
|
||||
graph = _with_source(graph, repo_slug, commit, generated_at)
|
||||
graph = materialize_financial_graph_export(graph)
|
||||
validate_graph_export(graph)
|
||||
|
||||
now = _utc_now()
|
||||
@@ -419,9 +426,15 @@ class RegistryStore:
|
||||
}
|
||||
|
||||
def combined_graph(self) -> dict[str, Any]:
|
||||
snapshots = self.latest_snapshots()
|
||||
if snapshots and all(is_financial_graph_export(snapshot["graph"]) for snapshot in snapshots):
|
||||
return merge_financial_graph_exports(
|
||||
[snapshot["graph"] for snapshot in snapshots],
|
||||
generated_at=_utc_now(),
|
||||
)
|
||||
nodes: dict[str, dict[str, Any]] = {}
|
||||
edges: list[dict[str, str]] = []
|
||||
for snapshot in self.latest_snapshots():
|
||||
for snapshot in snapshots:
|
||||
graph = snapshot["graph"]
|
||||
for node in graph.get("nodes", []):
|
||||
if isinstance(node, dict):
|
||||
@@ -913,6 +926,16 @@ class RegistryStore:
|
||||
|
||||
|
||||
def validate_graph_export(graph: dict[str, Any]) -> None:
|
||||
graph = materialize_financial_graph_export(graph)
|
||||
if is_financial_graph_export(graph):
|
||||
errors = financial_graph_errors(graph)
|
||||
if errors:
|
||||
raise RegistryError(f"invalid FinancialFabricGraphExport: {errors[0]}")
|
||||
canon_errors = _graph_canon_metadata_errors(graph)
|
||||
if canon_errors:
|
||||
raise RegistryError(f"invalid FinancialFabricGraphExport canon metadata: {canon_errors[0]}")
|
||||
return
|
||||
|
||||
schema_path = repo_root() / "schemas" / "state-hub-export.schema.yaml"
|
||||
validator = draft202012_validator(schema_path)
|
||||
errors = sorted(validator.iter_errors(graph), key=lambda error: list(error.path))
|
||||
|
||||
Reference in New Issue
Block a user