fix(export): honor --functions for json and graphson formats - #2141
Conversation
exportJSON and exportGraphSON ignored opts.fileLevel entirely, always returning file-level (json) or a fixed all-kinds (graphson) shape regardless of --functions. dot/mermaid/graphml/neo4j already branched on fileLevel correctly. Closes #2136 Impact: 2 functions changed, 2 affected
Greptile SummaryThis PR fixes a longstanding bug where
Confidence Score: 5/5Safe to merge — the fix is a straightforward application of the branching pattern already proven across four other exporters, and all 35 export tests pass. The change adds a missing code path rather than touching existing behaviour. The new function-level branches use the same shared loaders and paginateResult plumbing as every other exporter, and the updated tests explicitly guard the corrected defaults. No files require special attention. Important Files Changed
Reviews (7): Last reviewed commit: "fix(export): align exportGraphSON functi..." | Re-trigger Greptile |
| const data = exportJSON(db, { fileLevel: false }); | ||
| expect(data.nodes.every((n) => n.kind !== 'file')).toBe(true); | ||
| expect(data.nodes.some((n) => n.name === 'doWork')).toBe(true); | ||
| expect(data.edges.some((e) => e.source === fn && e.target === fn2)).toBe(true); | ||
| }); |
There was a problem hiding this comment.
Missing
db.close() in the first new JSON test leaves an open in-memory database handle. Every surrounding test does close its db; this one should too.
| const data = exportJSON(db, { fileLevel: false }); | |
| expect(data.nodes.every((n) => n.kind !== 'file')).toBe(true); | |
| expect(data.nodes.some((n) => n.name === 'doWork')).toBe(true); | |
| expect(data.edges.some((e) => e.source === fn && e.target === fn2)).toBe(true); | |
| }); | |
| const data = exportJSON(db, { fileLevel: false }); | |
| expect(data.nodes.every((n) => n.kind !== 'file')).toBe(true); | |
| expect(data.nodes.some((n) => n.name === 'doWork')).toBe(true); | |
| expect(data.edges.some((e) => e.source === fn && e.target === fn2)).toBe(true); | |
| db.close(); | |
| }); |
There was a problem hiding this comment.
Fixed — added the missing db.close() to this test to match its sibling tests.
…s from v3.16.0 session - benchmark scripts are .ts, not .js; note npm run benchmark alias and git fetch --tags requirement for correct version labeling - warn against running registry prune --ttl 0 against the real global registry; recommend CODEGRAPH_REGISTRY_PATH isolation instead - warn about update-graph.sh hook contamination risk from scratch files with tracked extensions - recommend copying .codegraphrc.json aside before editing it in place and testing config-driven commands from a different cwd than the target - recommend full edge-set diffs (not just counts) for incremental rebuild verification — this is what caught #2138 in the v3.16.0 session
Codegraph Impact Analysis2 functions changed → 2 callers affected across 2 files
|
|
Addressed Greptile's review feedback:
|
…mats The function-level (--functions) branch retained pre-existing behavior that queried all non-file nodes independently of edges (including isolated nodes with no calls) and included every edge kind (inherits, implements, imports, etc.), not just calls. dot/mermaid/graphml/neo4j all already use loadFunctionLevelEdges for this scope. Now graphson does too, so all five function-level exporters agree on scope: calls edges only, nodes limited to those participating in at least one call. Impact: 1 functions changed, 2 affected
|
Follow-up fix pushed (2348999): the |
Summary
codegraph export -f json --functionsand-f graphson --functionssilently ignored the--functionsflag, always returning file-level output (json) or a fixed mixed-kind shape (graphson) — the only two of the six export formats that didn't branch onopts.fileLevel, unlikedot/mermaid/graphml/neo4jwhich already did.Found during
Dogfooding v3.16.0 — see #2136
Test plan
npx vitest run tests/graph/export.test.ts— 35/35 passing (added 3 new cases covering fileLevel vs functions for both formats)npx vitest run tests/integration/exports.test.ts tests/unit/index-exports.test.ts— 26/26 passingcodegraph export -f json --functionsand-f graphson --functionsnow produce distinct, correctly-scoped output against a real build