Repository navigation
fix(export): add id-based join fields to file-level exportJSON edges - #2342
Conversation
…2144) File-level exportJSON edges use file path strings for source/target, which don't join against this same payload's nodes[].id the way function-level mode's numeric-id edges do. Fixing source/target directly would break existing codegraph export -f json consumers who read them as file paths today, so this adds sourceId/targetId (numeric, matching nodes[].id) alongside the existing fields instead — purely additive, giving consumers the same id-based join function-level mode already supports without changing the existing shape. docs check acknowledged. Impact: 1 functions changed, 2 affected
Greptile SummaryThe PR completes the file-level JSON edge fix by deriving additive
Confidence Score: 5/5The PR appears safe to merge. The previously reported join and DISTINCT-aggregation failures are no longer present, and no blocking failure remains. Important Files Changed
Flowchart%%{init: {'theme': 'neutral'}}%%
flowchart LR
E["Aggregated file-level edge<br/>source/target paths"] --> M["Map exported file paths<br/>to nodes[].id"]
M --> I["Add sourceId/targetId"]
I --> F["File endpoint: numeric node ID"]
I --> D["Directory endpoint: null"]
E --> P["Preserve source/target paths"]
Reviews (2): Last reviewed commit: "fix(export): resolve sourceId/targetId a..." | Re-trigger Greptile |
| let edges = db | ||
| .prepare(` | ||
| SELECT DISTINCT n1.file AS source, n2.file AS target, e.kind, e.confidence | ||
| SELECT DISTINCT n1.file AS source, n2.file AS target, n1.id AS sourceId, n2.id AS targetId, e.kind, e.confidence |
There was a problem hiding this comment.
When a cross-file edge connects function or symbol nodes, sourceId and targetId contain those raw endpoint IDs even though nodes contains only file nodes, causing the advertised ID-based join to fail; including the raw IDs in DISTINCT also expands formerly collapsed file-level edges into parallel rows.
Codegraph Impact Analysis1 functions changed → 2 callers affected across 2 files
|
…ndpoints (#2144 review) The previous fix pulled sourceId/targetId from the edge query's own n1.id/n2.id — but for a cross-file calls/receiver/etc. edge, those are the edge's ACTUAL endpoints (function/class/... nodes), not the file nodes this payload's nodes[] array contains. That both failed to resolve against nodes[].id for the common case and widened this query's DISTINCT aggregation, since different function-pairs between the same two files would produce separate rows instead of collapsing into one file-level edge. Fix: look sourceId/targetId up from the already-fetched file-kind nodes list by file path, entirely outside the SQL query, so the existing DISTINCT aggregation is untouched. null (not omitted) when an endpoint is a directory (contains edges), since directories have no entry in this file-only nodes[] array to resolve against. docs check acknowledged. Impact: 1 functions changed, 2 affected
Summary
Closes #2144
exportJSON's two modes produce edges with a differentsource/targetschema:edges[].source/targetare file path strings, which don't join against this same payload'snodes[].id.--functions):edges[].source/targetare numeric node IDs, matchingnodes[].id.Changing file-level's
source/targetto numeric IDs directly (matching function-level) would be a breaking change to the existingcodegraph export -f jsonoutput shape, which has real consumers relying on file paths there today — flagged in the issue as needing "a consistent identifier scheme... version/document the change since it affects the public JSON export shape."Fix
Purely additive: file-level edges now also carry
sourceId/targetId(numeric, matchingnodes[].id), alongside the existingsource/targetfile-path strings. Consumers who want the same id-based join function-level mode already supports can use the new fields; anyone readingsource/targetas file paths today is unaffected.Test plan
tests/graph/export.test.ts: file-level edges'sourceId/targetIdresolve againstnodes[].id, whilesource/targetremain file path strings.codegraph export -f json.npm testsuite passes (4607 tests, 287 files).npx tsc --noEmitandnpm run lintclean.