Skip to content

fix: render inter-domain relationships in graph2md#7

Open
jonathanpopham wants to merge 2 commits intomainfrom
fix/inter-domain-relationships
Open

fix: render inter-domain relationships in graph2md#7
jonathanpopham wants to merge 2 commits intomainfrom
fix/inter-domain-relationships

Conversation

@jonathanpopham
Copy link

@jonathanpopham jonathanpopham commented Feb 17, 2026

Summary

  • Domain entity pages on repos.supermodeltools.com showed no connections between domains because graph2md silently dropped domain-to-domain relationships
  • Added domainEdge struct and domainRelatesOut/domainRelatesIn index maps that capture any relationship connecting two Domain nodes
  • Updated writeGraphData(), writeMermaidDiagram(), and writeDomainBody() to render outgoing and incoming domain relationships
  • Created first test suite for graph2md (graph2md_test.go) with 7 tests including end-to-end

Test plan

  • go test ./... — all 7 tests pass
  • go vet ./... — clean
  • CI passes (CodeRabbit, build)
  • Verify on a live repo that domain pages now show related domains in the body, Mermaid diagram, and graph_data frontmatter

Closes #6

Summary by CodeRabbit

  • New Features

    • Domains now show a "Related Domains" section listing outgoing and incoming connections with relationship types
    • Diagrams and graph data now include domain-to-domain edges with direction and labels
  • Improvements

    • Relationship data is consistently included in rendering output and diagrams
    • Input validation improved and output directory creation moved earlier
  • Tests

    • Added comprehensive tests covering domain relationships, diagram/graph output, and end-to-end rendering

Note

Medium Risk
Changes markdown/frontmatter generation for Domain pages by indexing previously-ignored relationships and emitting new edges/sections, which can affect site output and any consumers of graph_data/Mermaid diagrams. Test coverage is added, but behavior changes may surface formatting or size-limit edge cases on large graphs.

Overview
graph2md now indexes any relationship between two Domain nodes (captured as domainRelatesOut/domainRelatesIn) instead of silently dropping them.

Domain pages render these connections in three places: a new Related Domains section in the body (with relationship type and incoming/outgoing labeling), additional relatesTo edges in graph_data frontmatter, and labeled arrows in the Mermaid domain diagram.

Adds a new graph2md_test.go suite with unit and end-to-end tests asserting relationship indexing and the new rendered outputs.

Written by Cursor Bugbot for commit 33ef5a4. This will update automatically on new commits. Configure here.

Domain entity pages were missing connections between domains because
the relationship switch block silently dropped domain-to-domain edges.

Add domainEdge struct and domainRelatesOut/domainRelatesIn index maps,
populate them via a default case for any relationship connecting two
Domain nodes, and render them in writeGraphData, writeMermaidDiagram,
and writeDomainBody.

Closes #6
@coderabbitai
Copy link

coderabbitai bot commented Feb 17, 2026

Walkthrough

Adds capture and rendering of domain-to-domain relationships: parses inter-domain edges into new indexes, threads them through renderContext.Run, and includes related-domain info in domain body text, graph_data frontmatter, and Mermaid diagrams.

Changes

Cohort / File(s) Summary
Core parsing & rendering logic
internal/graph2md/graph2md.go
Introduces domainEdge and domainRelatesOut/domainRelatesIn maps; detects domain→domain relationships during graph parsing; passes these maps through renderContext; updates graph_data, Mermaid generation, and domain body rendering to include Related Domains (outgoing/incoming) with labels. Also adds input validation for Run and ensures output dir creation early.
Tests
internal/graph2md/graph2md_test.go
Adds comprehensive tests and helpers: constructs nodes/rels, verifies domain relationship indexing (including filtering), graph_data includes relatesTo edges, Mermaid/markdown rendering shows Related Domains and edges, and an end-to-end check for generated markdown content.

Sequence Diagram(s)

sequenceDiagram
  participant Parser as Graph Parser
  participant Indexer as Domain Indexer
  participant Renderer as Render Engine
  participant Writer as File Writer

  Parser->>Indexer: parse nodes & relationships
  Indexer-->>Indexer: build domainRelatesOut/in maps
  Indexer->>Renderer: pass nodes, relationships, domainRelates maps
  Renderer->>Renderer: generate domain body, graph_data, mermaid (including relatesTo edges)
  Renderer->>Writer: emit markdown files with frontmatter and diagrams
  Writer-->>Renderer: write success
Loading

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~45 minutes

Possibly related issues

  • supermodeltools/graph2md#1: Direct match — this PR implements domain-to-domain edge indexing and rendering (adds domainEdge and related maps, threads through render flow).
  • Domain entity pages missing inter-domain relationships #5: Related — implements the same changes described there for including domain relates-to edges in graph_data and diagrams.

Poem

🔗 Domains once quiet, now speak in queues,
Arrows and labels revealing their views.
Indexes built, diagrams sing,
Markdown pages show everything.
Connections found — a small victory for clues!

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 35.71% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately describes the main change: adding rendering of inter-domain relationships in graph2md, which directly matches the core objective of fixing missing domain-to-domain connections.
Linked Issues check ✅ Passed All objectives from issue #6 are implemented: domainEdge struct and index maps added, domain-to-domain relationships captured, Related Domains section added to domain body, graph_data JSON updated, and Mermaid diagrams enhanced with related domain visualization.
Out of Scope Changes check ✅ Passed All changes align with issue #6 scope: domain relationship handling, rendering updates, and test coverage. Input validation and output directory creation are minor supporting improvements directly enabling the core functionality.
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch fix/inter-domain-relationships

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🧹 Nitpick comments (1)
internal/graph2md/graph2md_test.go (1)

56-101: Consider populating domainNodeByName for completeness.

Right now the helper sets up nodeLookup and slugLookup, but domainNodeByName stays empty (line 93). This is fine for the current tests, but if you later add a test that exercises domainLink() (which looks up domains by name), it'll return plain text instead of a link.

Quick fix if you ever need it:

♻️ Suggested enhancement
 	for i := range allNodes {
 		n := &allNodes[i]
 		nodeLookup[n.ID] = n
 		slugLookup[n.ID] = toSlug(getStr(n.Properties, "name"))
+		if hasLabel(n, "Domain") {
+			// Populate domainNodeByName so domainLink() works
+			domainNodeByName[getStr(n.Properties, "name")] = n.ID
+		}
 	}
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@internal/graph2md/graph2md_test.go` around lines 56 - 101, The helper
domainRenderCtx builds nodeLookup and slugLookup but leaves domainNodeByName
empty; update domainRenderCtx to populate domainNodeByName by iterating allNodes
(and center) and mapping each node's name (getStr(node.Properties,"name")) or
slug to the node ID using the same toSlug logic so domainNodeByName[nameOrSlug]
= node.ID; ensure you handle center the same way as other nodes and use the
existing toSlug/getStr helpers so domainLink() can resolve names to links.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@internal/graph2md/graph2md_test.go`:
- Around line 407-424: The extractGraphDataJSON test helper can panic when the
closing quote pattern isn't found; change the logic in extractGraphDataJSON to
compute endIdx := strings.Index(rest, "\"\n") and if endIdx == -1 call t.Fatalf
with a clear message (including the offending frontmatter or rest) instead of
slicing with -1, then build full using rest[:endIdx] as before and proceed with
json.Unmarshal; this prevents a slice bounds panic and gives a helpful test
failure message.

---

Nitpick comments:
In `@internal/graph2md/graph2md_test.go`:
- Around line 56-101: The helper domainRenderCtx builds nodeLookup and
slugLookup but leaves domainNodeByName empty; update domainRenderCtx to populate
domainNodeByName by iterating allNodes (and center) and mapping each node's name
(getStr(node.Properties,"name")) or slug to the node ID using the same toSlug
logic so domainNodeByName[nameOrSlug] = node.ID; ensure you handle center the
same way as other nodes and use the existing toSlug/getStr helpers so
domainLink() can resolve names to links.

- Guard against panic in extractGraphDataJSON when closing quote not found
- Populate domainNodeByName in test helper so domainLink() resolves correctly
Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹 Nitpick comments (1)
internal/graph2md/graph2md_test.go (1)

23-31: Unused helper function makeSubdomainNode.

Hey, heads up — this helper is defined but never actually called anywhere in the test file. It's like buying ingredients for a recipe you never cooked.

If you're planning to add subdomain tests later, totally fine to keep it around. Otherwise, consider removing it to keep things tidy.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@internal/graph2md/graph2md_test.go` around lines 23 - 31, The helper function
makeSubdomainNode is defined but never used; either remove the unused function
to tidy the test file or, if you intend to test subdomains, add tests that call
makeSubdomainNode (referencing the makeSubdomainNode function and the Node type)
so it is exercised; pick one and apply the change consistently in
graph2md_test.go.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Nitpick comments:
In `@internal/graph2md/graph2md_test.go`:
- Around line 23-31: The helper function makeSubdomainNode is defined but never
used; either remove the unused function to tidy the test file or, if you intend
to test subdomains, add tests that call makeSubdomainNode (referencing the
makeSubdomainNode function and the Node type) so it is exercised; pick one and
apply the change consistently in graph2md_test.go.

@jonathanpopham jonathanpopham self-assigned this Feb 18, 2026
@jonathanpopham jonathanpopham marked this pull request as ready for review February 18, 2026 20:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Domain entity pages show no inter-domain relationships

1 participant

Comments