generated from coulomb/repo-seed
refactoring for canon conformity
This commit is contained in:
68
tests/test_canon.py
Normal file
68
tests/test_canon.py
Normal file
@@ -0,0 +1,68 @@
|
||||
from railiance_fabric.canon import (
|
||||
CANONICAL_EDGE_TYPES,
|
||||
CANONICAL_NODE_CATEGORIES,
|
||||
DISPLAY_ONLY_EDGE_TYPES,
|
||||
edge_canon_mapping,
|
||||
evidence_state_for,
|
||||
node_canon_mapping,
|
||||
)
|
||||
|
||||
|
||||
def test_wp0016_target_taxonomy_is_registered() -> None:
|
||||
assert set(CANONICAL_NODE_CATEGORIES) >= {
|
||||
"source-repository",
|
||||
"software-system",
|
||||
"service",
|
||||
"endpoint",
|
||||
"deployment",
|
||||
"runtime-resource",
|
||||
"datastore",
|
||||
"flow",
|
||||
"policy",
|
||||
"control",
|
||||
"evidence",
|
||||
"task",
|
||||
"consumer-purpose",
|
||||
"telemetry-signal",
|
||||
}
|
||||
assert set(CANONICAL_EDGE_TYPES) >= {
|
||||
"built_from",
|
||||
"implements",
|
||||
"exposes",
|
||||
"depends_on",
|
||||
"deploys",
|
||||
"flows_to",
|
||||
"governed_by",
|
||||
"evidenced_by",
|
||||
"observed_by",
|
||||
"part_of",
|
||||
"reads_or_writes",
|
||||
"creates_task",
|
||||
}
|
||||
assert set(DISPLAY_ONLY_EDGE_TYPES) >= {
|
||||
"collapsed_into",
|
||||
"grouped_with",
|
||||
"highlight_path",
|
||||
"near",
|
||||
"same_color_group",
|
||||
}
|
||||
|
||||
|
||||
def test_legacy_fabric_terms_map_without_becoming_display_edges() -> None:
|
||||
assert node_canon_mapping("Repository").category == "source-repository"
|
||||
assert node_canon_mapping("KubernetesDeployment").category == "runtime-resource"
|
||||
assert node_canon_mapping("DependencyDeclaration").fit == "gap"
|
||||
|
||||
assert edge_canon_mapping("exposes").canonical_type == "exposes"
|
||||
assert edge_canon_mapping("provides").canonical_type == "implements"
|
||||
assert edge_canon_mapping("binds:exact").canonical_type == "depends_on"
|
||||
assert edge_canon_mapping("resolves_to").canonical_type == "flows_to"
|
||||
assert edge_canon_mapping("declares").display_only is True
|
||||
|
||||
|
||||
def test_evidence_state_separates_origin_from_review_state() -> None:
|
||||
assert evidence_state_for(origin="repo_declaration", source_kind="declaration") == "declared"
|
||||
assert evidence_state_for(origin="llm", source_kind="llm") == "proposed"
|
||||
assert evidence_state_for(origin="deterministic", source_kind="", confidence=0.4) == "inferred"
|
||||
assert evidence_state_for(origin="deterministic", source_kind="package_registry") == "observed"
|
||||
assert evidence_state_for(review_state="rejected") == "gap"
|
||||
@@ -64,6 +64,7 @@ def test_graph_explorer_manifest_and_payload_validate() -> None:
|
||||
network_port = next(element for element in nodes if element["data"]["kind"] == "NetworkPort")
|
||||
same_repo_edge = next(edge for edge in edges if edge["data"].get("sameRepo") is True)
|
||||
cross_repo_edge = next(edge for edge in edges if edge["data"].get("layoutAffinity") == "cross-repo")
|
||||
declares_edge = next(edge for edge in edges if edge["data"]["edgeType"] == "declares")
|
||||
|
||||
assert registered_only["data"]["reviewState"] == "candidate"
|
||||
assert registered_only["data"]["unresolved"] is True
|
||||
@@ -86,8 +87,10 @@ def test_graph_explorer_manifest_and_payload_validate() -> None:
|
||||
)
|
||||
assert runs_on["data"]["layoutIdealLength"] < cross_repo_edge["data"]["layoutIdealLength"]
|
||||
assert runs_on["data"]["layoutElasticity"] > cross_repo_edge["data"]["layoutElasticity"]
|
||||
assert runs_on["data"]["displayOnly"] is True
|
||||
assert runs_on["data"]["canonicalType"] == "deploys"
|
||||
assert same_repo_edge["data"]["layoutIdealLength"] < cross_repo_edge["data"]["layoutIdealLength"]
|
||||
assert any(edge["data"]["edgeType"] == "declares" for edge in edges)
|
||||
assert declares_edge["data"]["displayOnly"] is True
|
||||
assert any(node["data"]["sourceReferences"] for node in nodes if node["data"]["kind"] != "Repository")
|
||||
assert payload["metrics"]["deployment_node_count"] >= 1
|
||||
assert payload["metrics"]["server_node_count"] >= 1
|
||||
@@ -145,6 +148,8 @@ def test_graph_explorer_collapses_discovered_repository_nodes() -> None:
|
||||
assert [node["data"]["id"] for node in repository_nodes] == ["repo:fixture-repo"]
|
||||
assert declares_package["data"]["source"] == "repo:fixture-repo"
|
||||
assert declares_package["data"]["target"] == "discovery:fixture-repo:library:fixture-service"
|
||||
assert declares_package["data"]["canonicalType"] == "built_from"
|
||||
assert declares_package["data"]["displayOnly"] is False
|
||||
|
||||
|
||||
def test_graph_explorer_presents_legacy_server_nodes_as_runtime_entities() -> None:
|
||||
|
||||
@@ -30,7 +30,10 @@ def test_scan_repo_emits_schema_valid_deterministic_snapshot(tmp_path: Path) ->
|
||||
candidates = snapshot["candidates"]
|
||||
nodes_by_label = {(node["kind"], node["label"]): node for node in candidates["nodes"]}
|
||||
assert nodes_by_label[("Repository", "Fixture Repo")]["review_state"] == "candidate"
|
||||
assert nodes_by_label[("Repository", "Fixture Repo")]["canon_category"] == "source-repository"
|
||||
assert nodes_by_label[("Repository", "Fixture Repo")]["evidence_state"] == "declared"
|
||||
assert nodes_by_label[("ServiceDeclaration", "Fixture API")]["review_state"] == "accepted"
|
||||
assert nodes_by_label[("ServiceDeclaration", "Fixture API")]["canon_category"] == "service"
|
||||
assert nodes_by_label[("Library", "fixture-service")]["attributes"]["language"] == "python"
|
||||
assert nodes_by_label[("ExternalLibrary", "PyYAML")]["attributes"]["ecosystem"] == "python"
|
||||
assert nodes_by_label[("DeploymentService", "api")]["attributes"]["orchestrator"] == "docker-compose"
|
||||
@@ -45,10 +48,15 @@ def test_scan_repo_emits_schema_valid_deterministic_snapshot(tmp_path: Path) ->
|
||||
nodes_by_label[("RuntimeService", "fixture-api.testing.svc.cluster.local")]["attributes"]["runtime_target_type"]
|
||||
== "kubernetes-service-dns"
|
||||
)
|
||||
assert (
|
||||
nodes_by_label[("RuntimeService", "fixture-api.testing.svc.cluster.local")]["canon_category"]
|
||||
== "runtime-resource"
|
||||
)
|
||||
assert (
|
||||
nodes_by_label[("ApplicationEndpoint", "declared.fixture.test")]["attributes"]["runtime_target_type"]
|
||||
== "declared-endpoint"
|
||||
)
|
||||
assert nodes_by_label[("ApplicationEndpoint", "declared.fixture.test")]["canon_category"] == "endpoint"
|
||||
assert nodes_by_label[("NetworkPort", "127.0.0.1:8080/tcp")]["attributes"]["target_port"] == 8080
|
||||
assert nodes_by_label[("NetworkPort", "fixture-api.testing.svc.cluster.local:8080/tcp")]["attributes"]["service_port"] == 8080
|
||||
assert nodes_by_label[("NetworkPort", "declared.fixture.test:9443/tcp")]["attributes"]["scheme"] == "https"
|
||||
@@ -76,6 +84,14 @@ def test_scan_repo_emits_schema_valid_deterministic_snapshot(tmp_path: Path) ->
|
||||
"routes_to_service",
|
||||
"resolves_to",
|
||||
}
|
||||
edges_by_type = {edge["edge_type"]: edge for edge in candidates["edges"]}
|
||||
assert edges_by_type["exposes"]["canonical_type"] == "exposes"
|
||||
assert edges_by_type["provides"]["canonical_type"] == "implements"
|
||||
assert edges_by_type["provides"]["mapping_fit"] == "partial"
|
||||
assert edges_by_type["opens_port"]["canonical_type"] == "exposes"
|
||||
assert edges_by_type["resolves_to"]["canonical_type"] == "flows_to"
|
||||
assert all(edge["display_only"] is False for edge in candidates["edges"])
|
||||
assert all(edge["evidence_state"] in {"declared", "observed", "inferred", "proposed", "gap"} for edge in candidates["edges"])
|
||||
assert {attribute["name"] for attribute in candidates["attributes"]} >= {
|
||||
"readme_title",
|
||||
"intent_present",
|
||||
|
||||
Reference in New Issue
Block a user