Skip to content

feat(go): Add Phase 2 type tracking integration and MCP support (PR-16) - #539

Merged
shivasurya merged 5 commits into
mainfrom
shiva/golang-pr16-integration-mcp
Feb 16, 2026
Merged

shivasurya merged 5 commits into
mainfrom
shiva/golang-pr16-integration-mcp

Conversation

@shivasurya

Copy link
Copy Markdown
Owner

Summary

This PR integrates Go Phase 2 type tracking (PR-14 and PR-15) into the call graph builder and exposes type information through MCP tools. The Go call graph builder now uses a 5-pass algorithm with full type inference support.

Changes

1. CallGraph Core Enhancement

  • Added GoTypeEngine field to CallGraph struct for storing Go type information
  • Added GoTypeProvider interface to avoid import cycles
  • Added GetGoTypeEngine() getter method

2. Builder Signature Update

  • Updated BuildGoCallGraph() to accept typeEngine parameter
  • Updated all callers: serve.go, scan.go, ci.go
  • Initialize GoTypeInferenceEngine before building call graph

3. 5-Pass Algorithm Implementation

Pass 1: Index functions from CodeGraph → populate CallGraph.Functions
Pass 2a: Extract return types from all indexed Go functions

  • Operates on callGraph.Functions (already indexed)
  • Stores return types in typeEngine

Pass 2b: Extract variable assignments (parallel)

  • Parallel extraction using worker pool pattern
  • Thread-safe via typeEngine mutex
  • Processes all .go source files

Pass 3: Extract call sites from call_expression nodes
Pass 4: Resolve call targets to FQNs → add edges to CallGraph

4. MCP Tool Enhancements

  • Added getReturnType() helper function:
    • Checks node.ReturnType first (annotations)
    • Falls back to callGraph.GoTypeEngine for Go inferred types
  • Updated GetCallees: add return_type to source object
  • Updated GetCallers: add return_type to target and caller objects
  • Return types now exposed for both Python and Go functions in MCP

5. Integration Test

  • Added TestBuildGoCallGraph_WithTypeTracking
  • Verifies all 5 passes execute without errors
  • Tests return type extraction and GoTypeEngine attachment

Testing

  • ✅ All existing tests pass
  • ✅ New integration test passes
  • ✅ Lint clean (0 issues)
  • ✅ Python and Go type information properly exposed through MCP

Dependencies

Migration Notes

No breaking changes. The typeEngine parameter is optional - if nil, Passes 2a and 2b are skipped and the builder falls back to the previous 3-pass algorithm.

🤖 Generated with Claude Code

@shivasurya shivasurya added the enhancement New feature or request label Feb 16, 2026
@shivasurya shivasurya self-assigned this Feb 16, 2026
@safedep

safedep Bot commented Feb 16, 2026 •

Copy link
Copy Markdown

SafeDep Report Summary

Green Malicious Packages Badge Green Vulnerable Packages Badge Green Risky License Badge

No dependency changes detected. Nothing to scan.

This report is generated by SafeDep Github App

@codecov

codecov Bot commented Feb 16, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 77.04918% with 14 lines in your changes missing coverage. Please review.
✅ Project coverage is 82.90%. Comparing base (a194700) to head (d393b83).
⚠️ Report is 1 commits behind head on main.

Files with missing lines Patch % Lines
sast-engine/mcp/tools.go 76.92% 4 Missing and 2 partials ⚠️
sast-engine/cmd/ci.go 0.00% 2 Missing ⚠️
sast-engine/cmd/scan.go 0.00% 2 Missing ⚠️
sast-engine/cmd/serve.go 0.00% 2 Missing ⚠️
sast-engine/graph/callgraph/core/types.go 0.00% 2 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #539      +/-   ##
==========================================
- Coverage   82.92%   82.90%   -0.02%     
==========================================
  Files         139      139              
  Lines       16847    16892      +45     
==========================================
+ Hits        13971    14005      +34     
- Misses       2349     2356       +7     
- Partials      527      531       +4     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@shivasurya shivasurya changed the title PR-16: Go Type Tracking - Integration & MCP feat(go): Add Phase 2 type tracking integration and MCP support (PR-16) Feb 16, 2026
@shivasurya shivasurya added the go Pull requests that update go code label Feb 16, 2026

shivasurya commented Feb 16, 2026 •

Copy link
Copy Markdown
Owner Author

Merge activity

  • Feb 16, 9:08 PM UTC: A user started a stack merge that includes this pull request via Graphite.
  • Feb 16, 9:14 PM UTC: Graphite rebased this pull request as part of a merge.
  • Feb 16, 9:14 PM UTC: @shivasurya merged this pull request with Graphite.

@shivasurya
shivasurya changed the base branch from shiva/golang-pr15-variable-tracking to graphite-base/539 February 16, 2026 21:11
@shivasurya
shivasurya changed the base branch from graphite-base/539 to main February 16, 2026 21:12
- Add GoTypeEngine field to CallGraph struct for Phase 2 type tracking
- Add GoTypeProvider interface to avoid import cycles
- Add GetGoTypeEngine() getter method
- Field can be nil initially, will be populated during builder Pass 2a
- Add typeEngine parameter to BuildGoCallGraph function
- Update comment to reflect 5-pass algorithm (was 3-pass)
- Store typeEngine in CallGraph.GoTypeEngine for MCP access
- Update all callers: serve.go, scan.go, ci.go
- Initialize GoTypeInferenceEngine before building call graph
- Update test to pass typeEngine parameter

Passes 2a and 2b will be implemented in next commit.
- Pass 2a: Extract return types from indexed functions
  - Operates on callGraph.Functions (already indexed in Pass 1)
  - Stores return types in typeEngine
- Pass 2b: Extract variable assignments (parallel)
  - Parallel extraction using worker pool pattern
  - Thread-safe via typeEngine mutex
  - Processes all .go source files
- Update pass numbers in comments (3-pass → 5-pass)
- Add required imports: extraction, sync, atomic
- Both passes run only if typeEngine is not nil
- Add getReturnType() helper function
  - Checks node.ReturnType first (annotations)
  - Falls back to callGraph.GoTypeEngine for Go inferred types
- Update GetCallees: add return_type to source object
- Update GetCallers: add return_type to target and caller objects
- Add core package import to mcp/tools.go
- Return types now exposed for both Python and Go functions in MCP
- Verify all 5 passes execute without errors
- Test Pass 1: Function indexing
- Test Pass 2a: Return type extraction to GoTypeEngine
- Test Pass 2b: Variable assignment tracking
- Test Pass 3: Call site extraction
- Test Pass 4: Call target resolution
- Verify GoTypeEngine is attached to CallGraph
- Verify return types are correctly stored and retrievable
@shivasurya
shivasurya force-pushed the shiva/golang-pr16-integration-mcp branch from 1d9997a to d393b83 Compare February 16, 2026 21:13
@github-actions

Copy link
Copy Markdown

Code Pathfinder Security Scan

Pass Critical High Medium Low Info

No security issues detected.

Metric Value
Files Scanned 7
Rules 38

Powered by Code Pathfinder

@shivasurya
shivasurya merged commit 4a48edb into main Feb 16, 2026
5 checks passed
@shivasurya
shivasurya deleted the shiva/golang-pr16-integration-mcp branch February 16, 2026 21:14
shivasurya added a commit that referenced this pull request Feb 16, 2026
…ype tracking (PR-17) (#540)

## Summary
This PR implements **Pattern 1b: Variable-based method resolution** for Go call graphs. Method calls like `user.Save()` are now resolved using variable type information from the type inference engine (PR-14/PR-15/PR-16).

## Changes

### 1. Enhanced `resolveGoCallTarget` Function
- **Updated signature**: Added `typeEngine` and `callGraph` parameters
- **New Pattern 1b**: Variable method resolution
  - Looks up variable type from `typeEngine` scope
  - Handles pointer types (`*User` → `User`)
  - Verifies method exists in `callGraph.Functions`
  - Prioritizes import resolution over variable resolution
  
**Resolution order**:
1. ✅ Import-based resolution (existing)
2. ✅ **Variable-based resolution (NEW)**
3. ✅ Same-package function calls
4. ✅ Builtin functions

### 2. Pointer Type Handling
Correctly strips pointer prefix for method lookup:
- Variable type: `*models.User` → Method FQN: `models.User.Save`
- Variable type: `pkg.Config` → Method FQN: `pkg.Config.Validate`

### 3. Backward Compatibility
- New parameters are optional (can be `nil`)
- Falls back to previous behavior when `typeEngine` is not provided
- All existing tests updated to pass `nil` for compatibility

## Testing

### Unit Tests (7 test cases)
```go
TestResolveGoCallTarget_VariableMethod:
✅ Resolve user.Save() to User.Save
✅ Resolve pointer variable (*User).Save
✅ Fail when method doesn't exist
✅ Fail when variable not in scope
✅ Fallback to import when typeEngine is nil
✅ Prioritize import over variable
✅ Resolve config.Validate() with return type
```

### Integration Test
```go
TestBuildGoCallGraph_MethodResolution:
✅ End-to-end resolution through BuildGoCallGraph
✅ Variable bindings from PR-15
✅ Method calls resolved correctly
✅ Edges and reverse edges created
✅ Uses all_type_patterns.go fixture
```

## Quality Metrics
- ✅ **Build**: `gradle buildGo` - SUCCESS
- ✅ **Tests**: `gradle testGo` - ALL PASS (29 packages)
- ✅ **Lint**: `gradle lintGo` - 0 issues
- ✅ **Coverage**: No regression

## Impact

**Before PR-17**:
```go
user.Save()          // ❌ Unresolved (import not found)
config.Validate()    // ❌ Unresolved (import not found)
```

**After PR-17**:
```go
user.Save()          // ✅ Resolved to models.User.Save
config.Validate()    // ✅ Resolved to pkg.Config.Validate
```

**Expected improvement**: 85-90% call resolution rate (as specified in PR-17 document)

## Dependencies
- **Stacked on**: #539 (PR-16: Integration & MCP)
- **Depends on**: #537 (PR-14), #538 (PR-15), #539 (PR-16)

## Code Quality
- **LoC**: ~150 (as specified)
- **Files changed**: 2 files (go_builder.go, go_builder_test.go)
- No code bloat - focused, minimal changes
- Comprehensive test coverage
- Well-documented with clear comments

🤖 Generated with Claude Code
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request go Pull requests that update go code

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant