Skip to content

Conversation

@shivasurya
Copy link
Owner

Summary

Complete Phase 2 PR #4: AST Extraction Features by creating the resolution package and completing the extraction package. This PR migrates ~2000 LOC from 6 files into a clean hierarchical structure while maintaining full backward compatibility.

New Package Structure

resolution/ Package (1,127 lines)

Consolidates all resolution logic for imports, callsites, and type inference:

  • imports.go (297 lines) - Import extraction with relative import resolution (from .. import module)
  • callsites.go (271 lines) - Call site extraction with full argument tracking
  • inference.go (155 lines) - Type inference engine managing function scopes and variable bindings
  • return_type.go (404 lines) - Return type analysis and class instantiation resolution

extraction/ Package (961 lines)

Completes the extraction layer for Python AST analysis:

  • attributes.go (540 lines) - Class attribute extraction with type inference integration
  • variables.go (421 lines) - Variable assignment extraction and type tracking

Backward Compatibility

All original files updated with wrapper functions and type aliases:

// imports.go - Simple wrapper
func ExtractImports(...) (*core.ImportMap, error) {
    return resolution.ExtractImports(...)
}

// type_inference.go - Type aliases
type TypeInferenceEngine = resolution.TypeInferenceEngine
type FunctionScope = resolution.FunctionScope

Note: return_type.go contains documentation only (no wrapper) due to signature changes requiring direct migration to resolution package.

Test Migration

Moved 10 test files to new packages with full updates:

  • resolution/ (7 files): imports_test.go, imports_relative_test.go, callsites_test.go, inference_test.go, return_type_test.go, return_type_class_test.go
  • extraction/ (3 files): attributes_simple_test.go, attributes_coverage_test.go, variables_test.go

All test fixtures and relative paths adjusted for new locations.

Build Verification

gradle buildGo - SUCCESS
gradle testGo - ALL PASSING (100% pass rate)
gradle lintGo - 0 issues

Files Changed (26 files, +2389/-2241 lines)

New Files

  • resolution/imports.go
  • resolution/callsites.go
  • resolution/inference.go
  • resolution/return_type.go
  • extraction/attributes.go
  • extraction/variables.go

Modified Files (Backward Compatibility)

  • imports.go → wrapper to resolution
  • callsites.go → wrapper to resolution
  • type_inference.go → type aliases to resolution
  • attribute_extraction.go → wrapper to extraction
  • variable_extraction.go → wrapper to extraction
  • return_type.go → documentation only
  • builder.go → updated all imports and calls

Test Migrations

  • 7 tests moved to resolution/
  • 3 tests moved to extraction/
  • 1 test kept in parent (import cycle prevention)

Breaking Changes

None for most users. Direct imports of functions continue to work through wrappers.

Only breaking change: Code directly using ExtractReturnTypes or ResolveClassInstantiation must update to:

import "github.com/shivasurya/code-pathfinder/sourcecode-parser/graph/callgraph/resolution"

resolution.ExtractReturnTypes(...)
resolution.ResolveClassInstantiation(...)

Dependencies

Built on top of:

Related

  • Implements specification: /Users/shiva/src/shivasurya/cpf_plans/pr-details/refactor/pr-04-ast-extraction.md
  • Part of Phase 2 refactoring plan

🤖 Generated with Claude Code

Co-Authored-By: Claude [email protected]

@safedep
Copy link

safedep bot commented Nov 15, 2025

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
Copy link

codecov bot commented Nov 15, 2025

Codecov Report

❌ Patch coverage is 80.17621% with 180 lines in your changes missing coverage. Please review.
✅ Project coverage is 78.23%. Comparing base (7ea3953) to head (e492089).
⚠️ Report is 4 commits behind head on main.

Files with missing lines Patch % Lines
...de-parser/graph/callgraph/extraction/attributes.go 75.49% 49 Missing and 13 partials ⚠️
...ode-parser/graph/callgraph/extraction/variables.go 70.05% 44 Missing and 12 partials ⚠️
...e-parser/graph/callgraph/resolution/return_type.go 84.87% 23 Missing and 8 partials ⚠️
...ode-parser/graph/callgraph/resolution/callsites.go 86.58% 6 Missing and 5 partials ⚠️
...ecode-parser/graph/callgraph/resolution/imports.go 92.00% 4 Missing and 4 partials ⚠️
sourcecode-parser/graph/callgraph/builder.go 85.71% 4 Missing and 1 partial ⚠️
sourcecode-parser/graph/callgraph/callsites.go 0.00% 2 Missing ⚠️
sourcecode-parser/graph/callgraph/imports.go 0.00% 2 Missing ⚠️
...ode-parser/graph/callgraph/attribute_extraction.go 0.00% 1 Missing ⚠️
...ourcecode-parser/graph/callgraph/type_inference.go 50.00% 1 Missing ⚠️
... and 1 more
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #375      +/-   ##
==========================================
- Coverage   79.85%   78.23%   -1.63%     
==========================================
  Files          78       83       +5     
  Lines        6886     6914      +28     
==========================================
- Hits         5499     5409      -90     
- Misses       1157     1266     +109     
- Partials      230      239       +9     

☔ 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 added a commit that referenced this pull request Nov 15, 2025
Improve test coverage for resolution/inference.go from 26% to >90%:

## New Test Coverage

### ResolveVariableType Function
- Test variable type resolution from function returns
- Test confidence decay calculation (1.0 * 0.8 * 0.95 = 0.76)
- Test with different base confidence levels
- Test with non-existent functions (returns nil)

### UpdateVariableBindingsWithFunctionReturns Function
- Test resolving "call:funcName" placeholders
- Test qualified function names (e.g., "logging.getLogger")
- Test module-level scope resolution
- Test function scope resolution with nested paths
- Test unresolved function calls (remain as placeholders)
- Test nil type handling (edge case, no panic)

## Test Scenarios Covered

1. **Simple name resolution**: call:create_user → myapp.controllers.create_user
2. **Qualified name resolution**: call:logging.getLogger → logging.getLogger
3. **Module-level scope**: No dots in FunctionFQN, append to module path
4. **Function scope**: Strip function name, add called function
5. **Non-existent returns**: Placeholder remains unchanged
6. **Nil type safety**: No panic on nil types

## Coverage Impact

Before: 28 missing lines in inference.go (26.31% coverage)
After: All critical paths covered (>90% coverage)

This addresses the coverage gap reported in PR #375 review.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <[email protected]>
Copy link
Owner Author

shivasurya commented Nov 16, 2025

Merge activity

  • Nov 16, 12:00 AM UTC: A user started a stack merge that includes this pull request via Graphite.
  • Nov 16, 12:05 AM UTC: Graphite rebased this pull request as part of a merge.
  • Nov 16, 12:06 AM UTC: @shivasurya merged this pull request with Graphite.

@shivasurya shivasurya changed the base branch from refactor/03-stdlib-taint to graphite-base/375 November 16, 2025 00:03
@shivasurya shivasurya changed the base branch from graphite-base/375 to main November 16, 2025 00:04
shivasurya and others added 2 commits November 16, 2025 00:05
…n package

Complete Phase 2 PR #4: AST Extraction Features (~2000 LOC migrated)

## New Packages Created

### resolution/
- imports.go (297 lines) - Import extraction and relative import resolution
- callsites.go (271 lines) - Call site extraction with argument tracking
- inference.go (155 lines) - Type inference engine with scope management
- return_type.go (404 lines) - Return type analysis and class instantiation

### extraction/
- attributes.go (540 lines) - Class attribute extraction with type inference
- variables.go (421 lines) - Variable assignment extraction and type tracking

## Backward Compatibility

Created type aliases and wrapper functions in original files:
- imports.go → calls resolution.ExtractImports
- callsites.go → calls resolution.ExtractCallSites
- type_inference.go → type aliases to resolution package
- attribute_extraction.go → calls extraction.ExtractClassAttributes
- variable_extraction.go → calls extraction.ExtractVariableAssignments
- return_type.go → documentation only (signatures changed)

## Test Migration

Moved 10 test files to new packages:
- 7 tests to resolution/ (imports, callsites, inference, return_type)
- 3 tests to extraction/ (attributes, variables)
- Updated all imports and package declarations
- Fixed type mismatches and relative paths
- All tests passing with 100% success rate

## Build Verification

- ✅ gradle buildGo - SUCCESS
- ✅ gradle testGo - ALL PASSING
- ✅ gradle lintGo - 0 issues

Related to PR #4 specification document

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <[email protected]>
Improve test coverage for resolution/inference.go from 26% to >90%:

## New Test Coverage

### ResolveVariableType Function
- Test variable type resolution from function returns
- Test confidence decay calculation (1.0 * 0.8 * 0.95 = 0.76)
- Test with different base confidence levels
- Test with non-existent functions (returns nil)

### UpdateVariableBindingsWithFunctionReturns Function
- Test resolving "call:funcName" placeholders
- Test qualified function names (e.g., "logging.getLogger")
- Test module-level scope resolution
- Test function scope resolution with nested paths
- Test unresolved function calls (remain as placeholders)
- Test nil type handling (edge case, no panic)

## Test Scenarios Covered

1. **Simple name resolution**: call:create_user → myapp.controllers.create_user
2. **Qualified name resolution**: call:logging.getLogger → logging.getLogger
3. **Module-level scope**: No dots in FunctionFQN, append to module path
4. **Function scope**: Strip function name, add called function
5. **Non-existent returns**: Placeholder remains unchanged
6. **Nil type safety**: No panic on nil types

## Coverage Impact

Before: 28 missing lines in inference.go (26.31% coverage)
After: All critical paths covered (>90% coverage)

This addresses the coverage gap reported in PR #375 review.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <[email protected]>
@shivasurya shivasurya force-pushed the refactor/04-ast-extraction branch from c36b4d1 to e492089 Compare November 16, 2025 00:05
@shivasurya shivasurya merged commit 480d8ff into main Nov 16, 2025
3 checks passed
@shivasurya shivasurya deleted the refactor/04-ast-extraction branch November 16, 2025 00:06
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 refactor

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants