Skip to content

refactor: unify call-ref and tests rendering format between audit and inspect commands#1900

Open
carlos-alm wants to merge 1 commit into
fix/issue-1771-dispatch-table-reference-edgesfrom
fix/issue-1772-dedupe-callref-tests-rendering
Open

refactor: unify call-ref and tests rendering format between audit and inspect commands#1900
carlos-alm wants to merge 1 commit into
fix/issue-1771-dispatch-table-reference-edgesfrom
fix/issue-1772-dedupe-callref-tests-rendering

Conversation

@carlos-alm

Copy link
Copy Markdown
Contributor

Summary

BEHAVIOR CHANGE: codegraph audit's Calls/Called by/Tests sections now match inspect.ts's richer format (same pattern as #1756's impact-level unification earlier in this batch).

  • audit.ts's renderCallRefs/renderRelatedTests and inspect.ts's renderExplainEdges (calls/called-by/tests portions) duplicated near-identical rendering with different formats: audit.ts's had no indent support, no "no edges" fallback, and unpluralized "Tests (N):"; inspect.ts's had all three.
  • Investigated downstream dependencies first: only one existing test exercises renderExplainEdges's text output and asserts on a format that didn't change; audit.test.ts only tests the data layer; codegraph query/context use entirely different renderers, untouched.
  • Extracted shared renderCallRefsSection/renderNoCallEdgesFallback/renderRelatedTestsSection into a new src/presentation/call-ref-sections.ts (following the impact-levels.ts pattern/location from Duplicate impact-level rendering logic: presentation/audit.ts vs presentation/queries-cli/impact.ts #1756), adopted in both call sites.

Closes #1772

Test plan

  • npm test — full suite green (3560 passed, 0 failed), zero test updates needed
  • npm run lint / npx tsc --noEmit — clean
  • Manual verification against this repo's own graph: no-edges case now shows the fallback message in audit (previously silent); populated case now byte-identical between audit/inspect; pluralization verified both ways (Tests (1 file): vs Tests (58 files):)

Stacked on #1898 (base branch fix/issue-1771-dispatch-table-reference-edges) — only the presentation diff is this issue's change.

… inspect commands

Extracts the duplicated "Calls"/"Called by"/"Tests" section rendering from
presentation/audit.ts's renderCallRefs/renderRelatedTests and
presentation/queries-cli/inspect.ts's renderExplainEdges into shared helpers
in the new presentation/call-ref-sections.ts (renderCallRefsSection,
renderNoCallEdgesFallback, renderRelatedTestsSection), following the same
pattern established by #1756's impact-levels.ts unification. inspect.ts's
richer format (indent-aware, "no call edges" fallback, singular/plural
"Tests" label) is adopted as canonical in both commands.

BEHAVIOR CHANGE: `codegraph audit`'s plain-text output (not --json/--ndjson)
now matches `codegraph audit --quick`/`codegraph explain` exactly for these
sections:
- Prints "(no call edges found -- may be invoked dynamically or via
  re-exports)" when a function has neither callers nor callees. Previously
  audit printed nothing in this case.
- "Tests (N):" is now "Tests (N file):"/"Tests (N files):" (singular/plural),
  matching explain's existing label.

No changes to `codegraph audit --quick`/`codegraph explain` output — inspect.ts
keeps its exact current format, just via the shared helper.

docs check acknowledged: this is an internal presentation-layer refactor (no
new command, language, or architecture change). CLAUDE.md's presentation/*.ts
catch-all row already covers the new shared helper file, matching the
precedent set by #1756's impact-levels.ts, which likewise did not get its own
table row.

Fixes #1772

Impact: 14 functions changed, 6 affected
@greptile-apps

greptile-apps Bot commented Jul 6, 2026

Copy link
Copy Markdown
Contributor

Greptile Summary

This PR extracts duplicated rendering helpers for "Calls", "Called by", and "Tests" sections from both audit.ts and inspect.ts into a new shared module src/presentation/call-ref-sections.ts, following the same pattern established by the impact-levels.ts extraction in #1756.

  • The three new exported functions (renderCallRefsSection, renderNoCallEdgesFallback, renderRelatedTestsSection) centralise formatting logic and add two behaviour improvements to codegraph audit: a "no call edges" fallback message now shows when both callers and callees are empty, and the Tests label is now correctly pluralised (Tests (1 file): vs Tests (N files):).
  • Both call sites pass TypeScript's type checker via structural compatibility between the new CallRefLike/RelatedTestRefLike interfaces and the underlying domain types.

Confidence Score: 5/5

Safe to merge — purely a presentation-layer refactor with no logic changes beyond the two intentionally documented behaviour improvements in audit.

All three changed files are in the presentation layer and touch only console output. The extracted helpers are structurally identical to the inline code they replace; the two behaviour additions (no-edges fallback and pluralised Tests label in audit) match what inspect already produced and are explicitly called out in the PR description. TypeScript compatibility is enforced by the structural interfaces, and the full test suite passes with zero test updates.

No files require special attention.

Important Files Changed

Filename Overview
src/presentation/call-ref-sections.ts New shared module — well-documented, correct interface definitions, sensible defaults for indent, and all three helpers guard against empty input before printing.
src/presentation/audit.ts Removes local renderCallRefs/renderRelatedTests and adopts the shared helpers; kindIcon import retained (still used in renderFunctionHeader); behaviour changes are intentional and documented.
src/presentation/queries-cli/inspect.ts Inline rendering loop in renderExplainEdges replaced by four shared-helper calls; formatting and fallback behaviour preserved exactly.

Flowchart

%%{init: {'theme': 'neutral'}}%%
flowchart TD
    A[audit.ts] -->|calls| D[renderCallRefsSection]
    A -->|calls| E[renderNoCallEdgesFallback]
    A -->|calls| F[renderRelatedTestsSection]
    B[inspect.ts] -->|calls| D
    B -->|calls| E
    B -->|calls| F
    D & E & F -->|defined in| C[call-ref-sections.ts]
    C -->|imports| G[domain/queries.ts kindIcon]
Loading
%%{init: {'theme': 'base', 'themeVariables': {"darkMode": true, "background": "#0d1117", "primaryColor": "#21262d", "primaryTextColor": "#e6edf3", "primaryBorderColor": "#8b949e", "lineColor": "#8b949e", "textColor": "#e6edf3", "edgeLabelBackground": "#161b22", "actorBkg": "#21262d", "actorBorder": "#8b949e", "actorTextColor": "#e6edf3", "actorLineColor": "#8b949e", "signalColor": "#8b949e", "signalTextColor": "#e6edf3", "noteBkgColor": "#373320", "noteBorderColor": "#d4a72c", "noteTextColor": "#f0e6c0", "labelBoxBkgColor": "#21262d", "labelBoxBorderColor": "#8b949e", "labelTextColor": "#e6edf3", "loopTextColor": "#e6edf3", "activationBkgColor": "#30363d", "activationBorderColor": "#8b949e"}}}%%
flowchart TD
    A[audit.ts] -->|calls| D[renderCallRefsSection]
    A -->|calls| E[renderNoCallEdgesFallback]
    A -->|calls| F[renderRelatedTestsSection]
    B[inspect.ts] -->|calls| D
    B -->|calls| E
    B -->|calls| F
    D & E & F -->|defined in| C[call-ref-sections.ts]
    C -->|imports| G[domain/queries.ts kindIcon]
Loading

Reviews (1): Last reviewed commit: "refactor: unify call-ref and tests rende..." | Re-trigger Greptile

@github-actions

github-actions Bot commented Jul 6, 2026

Copy link
Copy Markdown
Contributor

Codegraph Impact Analysis

14 functions changed6 callers affected across 3 files

  • renderImpactSection in src/presentation/audit.ts:69 (3 transitive callers)
  • renderAuditFunction in src/presentation/audit.ts:77 (2 transitive callers)
  • CallRefLike.name in src/presentation/call-ref-sections.ts:14 (0 transitive callers)
  • CallRefLike.kind in src/presentation/call-ref-sections.ts:15 (0 transitive callers)
  • CallRefLike.file in src/presentation/call-ref-sections.ts:16 (0 transitive callers)
  • CallRefLike.line in src/presentation/call-ref-sections.ts:17 (0 transitive callers)
  • RelatedTestRefLike.file in src/presentation/call-ref-sections.ts:22 (0 transitive callers)
  • RenderCallRefsSectionOpts.indent in src/presentation/call-ref-sections.ts:32 (0 transitive callers)
  • renderCallRefsSection in src/presentation/call-ref-sections.ts:46 (6 transitive callers)
  • RenderNoCallEdgesFallbackOpts.indent in src/presentation/call-ref-sections.ts:61 (0 transitive callers)
  • renderNoCallEdgesFallback in src/presentation/call-ref-sections.ts:70 (6 transitive callers)
  • RenderRelatedTestsSectionOpts.indent in src/presentation/call-ref-sections.ts:82 (0 transitive callers)
  • renderRelatedTestsSection in src/presentation/call-ref-sections.ts:92 (6 transitive callers)
  • renderExplainEdges in src/presentation/queries-cli/inspect.ts:484 (3 transitive callers)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant