Skip to content

refactor(native): consolidate barrel-trace-with-fallback duplication in import_edges.rs - #2563

Merged
carlos-alm merged 1 commit into
mainfrom
fix/issue-2461
Aug 18, 2026
Merged

refactor(native): consolidate barrel-trace-with-fallback duplication in import_edges.rs#2563
carlos-alm merged 1 commit into
mainfrom
fix/issue-2461

Conversation

@carlos-alm

Copy link
Copy Markdown
Contributor

Summary

While fixing #2295 (consolidating TS's duplicate barrel-trace-with-fallback logic onto the shared traceBarrelTarget helper from #2071), found that the Rust native engine has the identical duplication pattern in crates/codegraph-core/src/domain/graph/builder/stages/import_edges.rs — and, unlike TS, had no shared helper at all to consolidate onto.

Three call sites each inlined the same "resolve through a barrel, falling back to the original file/name" pattern independently:

  • collect_symbol_lookup_pairs
  • emit_named_symbol_rows
  • emit_barrel_through_rows

Fix

Extracted trace_barrel_target(ctx, resolved_path, symbol_name) -> BarrelResolution, mirroring TS's traceBarrelTarget (src/domain/graph/builder/stages/resolve-imports.ts) exactly: returns the resolved barrel target when resolved_path is a barrel and resolution succeeds, otherwise falls back to resolved_path/symbol_name unchanged. Rewrote all three call sites to use it.

emit_barrel_through_rows needed a closer look: unlike the other two, it didn't previously have an is_barrel_file guard inline (redundant — the function's own top-level guard already established that) and treated "resolution failed" as an explicit early continue rather than a fallback. After routing through the shared helper (which never returns None, only the fallback identity), that case now flows through the same pre-existing actual_source == resolved_path self-reference check the function already used for a different purpose — same observable outcome, one fewer special case. Verified this is genuinely behavior-preserving by running the new emit_barrel_through_rows tests against both the original and refactored implementations with identical (all-passing) results.

Test plan

  • New tests for trace_barrel_target directly: falls back to identity for a non-barrel file, resolves through a barrel to the declaring file, falls back to identity when barrel resolution finds nothing
  • New tests for emit_barrel_through_rows (previously had no dedicated unit test — only exercised indirectly through the emit_edges_for_import orchestrator): emits an edge to the actual definition file, emits nothing when barrel resolution finds no target, skips a barrel that resolves back to itself
  • Revert-verified behavioral equivalence: temporarily restored the original three inline implementations (keeping the new tests) and confirmed the emit_barrel_through_rows tests still pass unchanged against the pre-refactor code — proving the refactor doesn't alter observable behavior
  • cargo test --lib (full suite) — 1094 passed (up from 1088, +6 new)
  • cargo clippy --lib -- -D warnings — clean
  • Rebuilt the native .node addon and ran tests/integration/build-parity.test.ts (native vs WASM cross-engine parity, including the monorepo-workspace fixture) — 12/12 passed
  • npm test (full suite) — 339 files, 5447 passed
  • npx tsc --noEmit — clean (no TS files changed by this PR)

Closes #2461

…in import_edges.rs

crates/codegraph-core/src/domain/graph/builder/stages/import_edges.rs
inlined the same "resolve through a barrel, falling back to the original
file/name" pattern independently in three places (collect_symbol_lookup_pairs,
emit_named_symbol_rows, emit_barrel_through_rows) -- the same class of
divergence-prone duplication #2295 consolidated on the TS side onto
traceBarrelTarget, but with no equivalent Rust helper to fall back on.

Extracts trace_barrel_target(ctx, resolved_path, symbol_name) mirroring
traceBarrelTarget's exact shape and rewrites all three call sites to use it.
emit_barrel_through_rows's prior explicit None-continue branch (barrel
resolution finds nothing) now flows through the same pre-existing
actual_source == resolved_path self-reference check the other two branches
already used -- verified behavior-preserving by running the new
emit_barrel_through_rows tests against both the original and refactored
implementations with identical results.

docs check acknowledged -- internal Rust refactor only, no new language
support, feature, or externally-visible behavior change to document.
@greptile-apps

greptile-apps Bot commented Aug 18, 2026

Copy link
Copy Markdown
Contributor

Greptile Summary

The PR consolidates duplicated native barrel-resolution fallback logic into trace_barrel_target while preserving parity with the TypeScript implementation.

  • Reuses the helper for symbol lookup, named-symbol edge emission, and barrel-through edge emission.
  • Adds focused coverage for successful resolution, identity fallback, unresolved exports, and self-referencing barrels.

Confidence Score: 5/5

The PR appears safe to merge with no actionable defects identified.

The shared helper preserves each call site's previous fallback semantics, and unresolved barrel exports still produce no through-edge because the existing self-reference check discards the identity fallback.

Important Files Changed

Filename Overview
crates/codegraph-core/src/domain/graph/builder/stages/import_edges.rs Extracts a shared barrel-target resolution helper, updates three equivalent call sites, and adds regression tests without introducing an actionable behavioral change.

Reviews (1): Last reviewed commit: "refactor(native): consolidate barrel-tra..." | Re-trigger Greptile

@carlos-alm
carlos-alm merged commit 108d81a into main Aug 18, 2026
34 checks passed
@carlos-alm
carlos-alm deleted the fix/issue-2461 branch August 18, 2026 07:05
@github-actions github-actions Bot locked and limited conversation to collaborators Aug 18, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Rust import_edges.rs has the same inline barrel-trace-with-fallback duplication #2295 fixes on the TS side

1 participant