Collapse duplicate repository graph nodes

This commit is contained in:
2026-05-21 01:04:22 +02:00
parent a8e67db9e9
commit 072fa8f7a7
3 changed files with 103 additions and 2 deletions

View File

@@ -72,6 +72,57 @@ def test_graph_explorer_manifest_and_payload_validate() -> None:
assert "removed nodes are removed" in payload["filter"]["connected_edge_behavior"]
def test_graph_explorer_collapses_discovered_repository_nodes() -> None:
graph = {
"apiVersion": "railiance.fabric/v1alpha1",
"kind": "FabricGraphExport",
"generated_at": "2026-05-21T00:00:00Z",
"source": {"repo": "fixture-repo", "commit": "abc123"},
"nodes": [
{
"id": "discovery:fixture-repo:repository:fixture-repo",
"kind": "Repository",
"name": "Fixture Repo",
"repo": "fixture-repo",
"domain": "testing",
"lifecycle": "active",
"attributes": {"discovery_origin": "deterministic"},
},
{
"id": "discovery:fixture-repo:library:fixture-service",
"kind": "Library",
"name": "fixture-service",
"repo": "fixture-repo",
"domain": "testing",
"lifecycle": "active",
"attributes": {"language": "python"},
},
],
"edges": [
{
"from": "discovery:fixture-repo:repository:fixture-repo",
"to": "discovery:fixture-repo:library:fixture-service",
"type": "declares_package",
}
],
}
payload = fabric_graph_explorer_payload(
graph,
[{"slug": "fixture-repo", "name": "Fixture Repo"}],
{"fixture-repo"},
)
nodes = [element for element in payload["elements"] if "source" not in element["data"]]
edges = [element for element in payload["elements"] if "source" in element["data"]]
repository_nodes = [node for node in nodes if node["data"]["kind"] == "Repository"]
declares_package = next(edge for edge in edges if edge["data"]["edgeType"] == "declares_package")
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"
def test_cli_exports_graph_explorer_payload(capsys) -> None:
assert cli_main(["export", "--format", "graph-explorer"]) == 0
payload = json.loads(capsys.readouterr().out)