Skip to content

fix(go): model and resolve embedded type relationships - #835

Open
merlincat11 wants to merge 3 commits into
tirth8205:mainfrom
merlincat11:agent/fix-834-go-embeddings
Open

fix(go): model and resolve embedded type relationships#835
merlincat11 wants to merge 3 commits into
tirth8205:mainfrom
merlincat11:agent/fix-834-go-embeddings

Conversation

@merlincat11

@merlincat11 merlincat11 commented Aug 8, 2026

Copy link
Copy Markdown

Closes #834

Summary

  • model each Go type_spec or alias as its own graph node, including grouped declarations
  • extract struct and interface embedding candidates from the actual tree-sitter Go AST
  • resolve same-package and imported embedding targets to canonical graph nodes using package/import and go.mod evidence
  • exclude _test.go declarations from imported-package resolution so external test packages cannot shadow production types
  • keep interface type_elem relationships as INHERITS only when they resolve to interfaces; represent concrete or unresolved constraint terms as REFERENCES
  • scope import-edge loading to files with embedding candidates and batch edge reconciliation
  • remove unused file-level Go package metadata and document the expanded REFERENCES semantics
  • force a one-time full rebuild for graphs created with the legacy Go type model

Root cause

The parser treated a whole type_declaration as one type and expected embedded identifiers at the wrong AST depth. Its raw relationship targets also lacked enough package evidence for graph queries, while a single interface type_elem is syntactically ambiguous between interface composition and a concrete type-set term. Imported resolution additionally treated declarations from external _test.go packages as normal package exports, creating false ambiguity when production and test packages defined the same type name.

Impact

Go embedding and composition now participate in canonical graph traversal without making false inheritance claims for resolved concrete constraints. Grouped declarations and aliases are no longer silently omitted. Qualified imports resolve to production declarations even when a same-directory external test package shadows the type name.

On Terraform main at da3a115efef0de2e817a8c3ef57c5df9297c99ce:

  • parsed all 1,993 Go files
  • inheritors_of Vertex returns all 12 embedding sites, including the nine formerly disconnected dag.Vertex relationships
  • inheritors_of GraphNodeConfigResource returns all five embedding sites
  • all remaining raw qualified embedding targets belong to standard-library or third-party packages absent from the repository graph

Validation

  • uv run pytest -q — 2,402 passed, 5 skipped, 2 xpassed
  • focused Go parser/resolver tests — 11 passed
  • uv run ruff check code_review_graph/ tests/test_multilang.py
  • uv run mypy code_review_graph/ --ignore-missing-imports --no-strict-optional
  • full Terraform graph build with minimal post-processing — 4,314 files, 28,918 parsed nodes, 314,844 parsed edges
  • Terraform queries after rebuild — 12 Vertex inheritors and 5 GraphNodeConfigResource inheritors

@github-actions

github-actions Bot commented Aug 8, 2026

Copy link
Copy Markdown

code-review-graph review

Overall risk: 0.40 (MEDIUM) — 23 changed function(s)/class(es), 0 affected flow(s), 13 test gap(s)

Risk-scored changes

Risk Level Symbol Location Tested
0.40 medium code_review_graph/graph.py::GraphStore.load_extra code_review_graph/graph.py:764 no
0.40 medium code_review_graph/graph.py::GraphStore.resolve_type code_review_graph/graph.py:869 no
0.40 medium code_review_graph/graph.py::GraphStore.interface_status code_review_graph/graph.py:912 no
0.35 low code_review_graph/graph.py::GraphStore.import_directory code_review_graph/graph.py:814 no
0.35 low code_review_graph/postprocessing.py::_resolve_bare_endpoints code_review_graph/postprocessing.py:73 no
0.30 low code_review_graph/parser.py::CodeParser._collect_file_scope code_review_graph/parser.py:12914 no
0.30 low code_review_graph/parser.py::CodeParser._collect_import_names code_review_graph/parser.py:13377 no
0.30 low code_review_graph/parser.py::CodeParser._get_name code_review_graph/parser.py:14496 no
0.30 low code_review_graph/parser.py::CodeParser._go_named_type code_review_graph/parser.py:15126 no
0.30 low code_review_graph/parser.py::CodeParser._get_bases code_review_graph/parser.py:15134 no

Test gaps

  • code_review_graph/graph.py::GraphStore.load_extra (code_review_graph/graph.py:764)
  • code_review_graph/graph.py::GraphStore.import_directory (code_review_graph/graph.py:814)
  • code_review_graph/graph.py::GraphStore.resolve_type (code_review_graph/graph.py:869)
  • code_review_graph/graph.py::GraphStore.interface_status (code_review_graph/graph.py:912)
  • code_review_graph/parser.py::CodeParser._preceding_doc_comment (code_review_graph/parser.py:10067)
  • ...and 8 more without direct tests

Token savings: this graph-backed report used ~255,556 fewer tokens (~98%) than reading every changed file in full (estimated, chars/4 approximation).


Powered by code-review-graph — local-first analysis; no code leaves the CI runner.

@merlincat11
merlincat11 marked this pull request as ready for review August 8, 2026 03:54
@merlincat11 merlincat11 changed the title fix(go): extract embedded type relationships fix(go): model and resolve embedded type relationships Aug 8, 2026
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.

[Bug]: Go struct and interface embeddings never emit INHERITS edges

2 participants