Skip to content

feat(go): Replace hardcoded stdlib set with GoImportResolver struct (PR-09)#557

Merged
shivasurya merged 1 commit intomainfrom
shiva/go-stdlib-support-pr09
Feb 25, 2026
Merged

feat(go): Replace hardcoded stdlib set with GoImportResolver struct (PR-09)#557
shivasurya merged 1 commit intomainfrom
shiva/go-stdlib-support-pr09

Conversation

@shivasurya
Copy link
Owner

Summary

  • Replaced the static goStdlibSet() hardcoded map with a dynamic GoImportResolver struct that uses StdlibLoader.ValidateStdlibImport() for version-aware, registry-backed stdlib detection
  • Added ImportType enum (ImportUnknown, ImportStdlib, ImportThirdParty, ImportLocal) and public methods ClassifyImport / ResolveImports for structured import classification
  • Implemented offline heuristic fallback (isStdlibImportFallback) for cases where no StdlibLoader is available — packages with no domain separator (.) in their path and not prefixed with internal/ are classified as stdlib
  • Removed hardcoded StdlibPackages assertions from TestBuildGoModuleRegistry and deleted TestGoStdlibSet; added 10 new TestGoImportResolver_* tests covering nil registry, fallback heuristic, loader delegation, local module detection, relative paths, and batch resolution

Changes

sast-engine/graph/callgraph/resolution/go_imports.go

  • Removed goStdlibSet() function (~124 lines of hardcoded map)
  • Removed registry.StdlibPackages = goStdlibSet() call from BuildGoModuleRegistry
  • Added ImportType enum with four constants
  • Added GoImportResolver struct with NewGoImportResolver constructor
  • Added isStdlibImport, isStdlibImportFallback, ClassifyImport, ResolveImports methods

sast-engine/graph/callgraph/resolution/go_imports_test.go

  • Removed TestGoStdlibSet test
  • Removed hardcoded StdlibPackages assertions from TestBuildGoModuleRegistry
  • Added mockResolutionStdlibLoader in-package mock implementing StdlibLoaderInterface
  • Added 10 new tests: TestGoImportResolver_NilRegistry, TestGoImportResolver_isStdlibImportFallback, TestGoImportResolver_isStdlibImport_WithLoader, TestGoImportResolver_isStdlibImport_NilLoader_FallsBackToHeuristic, TestGoImportResolver_ClassifyImport_Stdlib, TestGoImportResolver_ClassifyImport_ThirdParty, TestGoImportResolver_ClassifyImport_Local_RelativePath, TestGoImportResolver_ClassifyImport_Local_SameModule, TestGoImportResolver_ResolveImports, TestGoImportResolver_ResolveImports_Empty

Test plan

  • All 10 new TestGoImportResolver_* tests pass
  • Existing TestBuildGoModuleRegistry still passes
  • TestExtractGoImports still passes (uses empty StdlibPackages map)
  • No hardcoded stdlib package list remains in the resolver
  • Nil registry / nil loader cases handled without panics
  • Local module detection works for both relative paths and same-module prefix imports

🤖 Generated with Claude Code

@shivasurya shivasurya added enhancement New feature or request go Pull requests that update go code refactor labels Feb 25, 2026
@shivasurya shivasurya self-assigned this Feb 25, 2026
@shivasurya shivasurya added enhancement New feature or request go Pull requests that update go code refactor labels Feb 25, 2026
@safedep
Copy link

safedep bot commented Feb 25, 2026

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 Feb 25, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 83.32%. Comparing base (fc68795) to head (899ef90).
⚠️ Report is 1 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #557      +/-   ##
==========================================
- Coverage   83.36%   83.32%   -0.04%     
==========================================
  Files         143      143              
  Lines       17820    17782      -38     
==========================================
- Hits        14855    14817      -38     
  Misses       2426     2426              
  Partials      539      539              

☔ 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.

Copy link
Owner Author

shivasurya commented Feb 25, 2026

Merge activity

@shivasurya shivasurya force-pushed the shiva/go-stdlib-support-pr09 branch from 0c91e04 to 8ea75ed Compare February 25, 2026 03:52
@shivasurya shivasurya force-pushed the shiva/go-stdlib-support-pr08 branch from 5b74685 to e50cbf2 Compare February 25, 2026 03:52
@shivasurya shivasurya changed the base branch from shiva/go-stdlib-support-pr08 to graphite-base/557 February 25, 2026 03:55
@shivasurya shivasurya changed the base branch from graphite-base/557 to main February 25, 2026 03:56
…PR-09)

Replaced the hardcoded `goStdlibSet()` function with a dynamic `GoImportResolver`
struct that uses `StdlibLoader.ValidateStdlibImport()` for version-aware stdlib
detection, with a heuristic fallback (no domain separator in path) when no loader
is available. Added `ImportType` enum (ImportStdlib, ImportThirdParty, ImportLocal)
and `ClassifyImport`/`ResolveImports` methods. Updated tests: removed
`TestGoStdlibSet` and hardcoded `StdlibPackages` assertions, added 10 new
`TestGoImportResolver_*` tests covering nil registry, fallback heuristic, loader
delegation, and full import classification.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@shivasurya shivasurya force-pushed the shiva/go-stdlib-support-pr09 branch from 8ea75ed to 899ef90 Compare February 25, 2026 03:57
@github-actions
Copy link

Code Pathfinder Security Scan

Pass Critical High Medium Low Info

No security issues detected.

Metric Value
Files Scanned 2
Rules 38

Powered by Code Pathfinder

@shivasurya shivasurya merged commit b28db49 into main Feb 25, 2026
5 checks passed
@shivasurya shivasurya deleted the shiva/go-stdlib-support-pr09 branch February 25, 2026 03:58
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.

1 participant