feat(go): third-party type resolution from vendor/GOMODCACHE#641
Open
shivasurya wants to merge 7 commits intomainfrom
Open
feat(go): third-party type resolution from vendor/GOMODCACHE#641shivasurya wants to merge 7 commits intomainfrom
shivasurya wants to merge 7 commits intomainfrom
Conversation
Adds GoThirdPartyLoader interface and GoThirdPartyLocalLoader that parses third-party Go packages from vendor/ or GOMODCACHE using tree-sitter. Extracts exported types, methods, fields, and functions into the same GoStdlibPackage format used by stdlib resolution. Integration: - Pattern 1b Check 2.5: validates method existence on third-party types between stdlib (Check 2) and promoted methods (Check 3) - Return type inference: inferTypeFromThirdPartyFunction for variable type bindings from third-party function calls - scan.go: InitGoThirdPartyLoader wired after stdlib loader init Validated: gorm.io/gorm.DB.Raw, gin.Context.Query resolve at 100% rate in integration tests with vendored source. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Fixes interface embedding resolution for types like posthog.Client which embeds EnqueueClient and io.Closer. Previously, only direct method_spec nodes were extracted — embedded interfaces were silently skipped, causing methods like Enqueue() and Close() to fall through to Check 4 (best-effort) instead of Check 2.5 (validated). Changes: - extractInterfaceMethods now captures type_elem → type_identifier and type_elem → qualified_type nodes as embedded interface names - flattenEmbeddedMethods resolves same-package embeds by looking up in pkg.Types (handles multi-level embedding recursively) - resolveWellKnownEmbeds handles cross-package stdlib embeds (io.Closer, io.Reader, io.Writer, fmt.Stringer, error) via hardcoded method table - Embeds field added to GoStdlibType for tracking Validated: posthog.Client.Enqueue() and .Close() now resolve via Check 2.5 from vendored source with 100% resolution rate. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
…ader
- Add disk cache layer to GoThirdPartyLocalLoader:
- Cache path: {userCacheDir}/code-pathfinder/go-thirdparty/{sha256(projectRoot)[:12]}/
- cache-index.json tracks version per module for invalidation on go.mod upgrades
- Cold run extracts via tree-sitter and writes JSON; warm run reads from disk (~5ms vs ~200ms)
- Version mismatch (go.mod bumped) triggers re-extraction automatically
- Reuse --refresh-rules flag to also flush go-thirdparty disk cache (no new CLI flag)
- InitGoThirdPartyLoader now accepts refreshCache bool; passed from scan.go refreshRules
- Update NewGoThirdPartyLocalLoader signature (add refreshCache bool param)
- Fix all call sites in tests and builder
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
SafeDep Report SummaryNo dependency changes detected. Nothing to scan. This report is generated by SafeDep Github App |
Code Pathfinder Security ScanNo security issues detected.
Powered by Code Pathfinder |
Codecov Report❌ Patch coverage is Additional details and impacted files@@ Coverage Diff @@
## main #641 +/- ##
========================================
Coverage 84.21% 84.21%
========================================
Files 161 162 +1
Lines 22719 23256 +537
========================================
+ Hits 19133 19586 +453
- Misses 2886 2936 +50
- Partials 700 734 +34 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
- godot: add trailing periods to 3 comments - tagliatelle: rename json tag cached_at → cachedAt (camelCase) - nilnil: introduce errPackageSourceNotFound sentinel; return it instead of (nil, nil) from getOrLoadPackage - unused: remove resolveEmbeddedFromExternal (dead code from PoC) - prealloc: preallocate fieldNames slice in test Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
…artyFunction
Registry (go_thirdparty_local_test.go):
- Add TestPackageCount, TestGoThirdPartyLocalGetType/GetFunction_NotFound
- Add TestGetType_PackageNotFound (errPackageSourceNotFound path)
- Add TestFindPackageSource_GOMODCACHE and _Subpackage (GOMODCACHE branch)
- Add TestLoadCacheIndex_InvalidJSON, TestWriteToDiskCache_NilDiskIndex
- Add TestIsExported_EmptyString, TestExtractMethodDecl_NoReceiverType
- Add TestInitDiskCache_NoGoMod
Extraction (go_variables_stdlib_test.go):
- Add mockThirdPartyLoader and 5 tests covering all paths of
inferTypeFromThirdPartyFunction (nil loader, unknown pkg, func not found,
error-only return, success)
Builder (go_version_test.go):
- Add TestInitGoThirdPartyLoader_{NilReg,NoDependencies,WithDependencies,RefreshCache}
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
- TestModuleKeyFor_NoMatch: fallback return importPath unchanged - TestLoadFromDiskCache_MissingFile: ReadFile error → nil - TestLoadFromDiskCache_WithLogger: debug log branch on cache hit - TestSaveCacheIndex_EmptyCacheDir: no-op when cacheDir is "" - TestWriteToDiskCache_WriteFailure: WriteFile error → log + return - TestInitDiskCache_MkdirAllFailure: MkdirAll failure → diskIndex stays nil - TestInitDiskCache_RefreshWithLogger: refreshCache=true with logger - TestExtractMethodDecl_UnexportedMethod: unexported methods skipped Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.



Summary
Adds foundational Go third-party type resolution: validated method calls on gorm, gin, grpc, and any other vendored/cached dependency — replacing the previous best-effort fallback.
What this PR delivers
GoThirdPartyLoaderinterface (core/types.go) — mirrorsGoStdlibLoader, reusesGoStdlibType/GoStdlibPackage(zero new types)GoThirdPartyLocalLoader(registry/go_thirdparty_local.go) — parses vendor/ or GOMODCACHE via tree-sitter; extracts exported types, methods, fields, functions; flattens embedded interface methods (same-package recursive + well-known cross-package io.Closer/io.Reader/etc.)builder/go_builder.go) — sits between Check 2 (stdlib) and Check 3 (promoted methods); validates third-party method calls against extracted metadataextraction/go_variables.go) —inferTypeFromThirdPartyFunction()infers return types from third-party constructors (e.g.gorm.Open → *gorm.DB){userCacheDir}/code-pathfinder/go-thirdparty/{sha256(projectRoot)[:12]}/withcache-index.jsonversion tracking; cold run ~50-200ms, warm run ~5ms; version mismatch triggers re-extraction--refresh-rulesintegration — reuses existing flag to also flush the go-thirdparty disk cache (no new flag)Resolution chain after this PR
PoC validation (from branch shiva/go-thirdparty-poc)
io.CloserandEnqueueClient)Test plan
TestDiskCacheWriteAndRead— cold run writes JSON, warm run reads from disk without vendor/TestCacheVersionMismatch— go.mod version bump triggers re-extractionTestRefreshCacheFlush—refreshCache=truewipes stale cache and re-extractsTestGormCheck25/TestGinSubpackageResolution— full pipeline integration testsgo test ./... -count=1)🤖 Generated with Claude Code