fix: address quality issues in ast-analysis, presentation, extractors, and cli#1790
Conversation
Impact: 16 functions changed, 14 affected
…ck acknowledged) Impact: 48 functions changed, 9 affected
…nowledged) Decomposes the highest-complexity functions across 7 independent single-language extractor files (sync.json phase 26): r, dart, groovy, csharp, elixir, scala, julia. Pure behavior-preserving decomposition — no extraction-logic changes. Resolution benchmark precision/recall/ TP/FP/FN confirmed byte-for-byte identical to baseline for all 7 languages. Impact: 22 functions changed, 29 affected
…/printBuildMetadata docs check acknowledged — pure internal decomposition of CLI output logic, no new features/languages/architecture changes; README/CLAUDE/ ROADMAP do not need updates. Impact: 5 functions changed, 2 affected
Impact: 2 functions changed, 3 affected
Greptile SummaryThis PR addresses quality issues from a GAUNTLET audit by extracting helpers, building dispatch tables, and adopting concrete types across
Confidence Score: 5/5Safe to merge — all changes are structural refactors with no business logic modifications; behavior is preserved throughout. Every changed file is a mechanical extraction: helpers pulled out of long functions, dispatch tables replacing switch/if-else cascades, and type declarations promoted from inline No files require special attention. Important Files Changed
Flowchart%%{init: {'theme': 'neutral'}}%%
flowchart TD
subgraph cfg-conditionals ["cfg-conditionals.ts (new shared helper)"]
processBranch["processBranch(condBlock, joinBlock, S, branchKind, label, runBranchBody)"]
B1[makeBlock] --> B2[addEdge condBlock→branchBlock]
B2 --> B3[runBranchBody → branchEnd]
B3 --> B4{branchEnd non-null?}
B4 -->|yes| B5[addEdge branchEnd→joinBlock fallthrough]
processBranch --> B1
end
subgraph callers ["Previously inlined 6+ times — now delegating"]
processIf -->|true branch| processBranch
processAlternative -->|else-if branch| processBranch
processAlternative -->|else branch| processBranch
processElifSiblings -->|elif true branch| processBranch
processElifSiblings -->|elif else branch| processBranch
end
subgraph audit-presentation ["presentation/audit.ts decomposition"]
renderAuditFunction --> renderFunctionHeader
renderAuditFunction --> renderHealthMetrics
renderAuditFunction --> renderThresholdBreaches
renderAuditFunction --> renderImpactSection
renderAuditFunction --> renderCallRefs_calls["renderCallRefs('Calls')"]
renderAuditFunction --> renderCallRefs_calledby["renderCallRefs('Called by')"]
renderAuditFunction --> renderRelatedTests
end
%%{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
subgraph cfg-conditionals ["cfg-conditionals.ts (new shared helper)"]
processBranch["processBranch(condBlock, joinBlock, S, branchKind, label, runBranchBody)"]
B1[makeBlock] --> B2[addEdge condBlock→branchBlock]
B2 --> B3[runBranchBody → branchEnd]
B3 --> B4{branchEnd non-null?}
B4 -->|yes| B5[addEdge branchEnd→joinBlock fallthrough]
processBranch --> B1
end
subgraph callers ["Previously inlined 6+ times — now delegating"]
processIf -->|true branch| processBranch
processAlternative -->|else-if branch| processBranch
processAlternative -->|else branch| processBranch
processElifSiblings -->|elif true branch| processBranch
processElifSiblings -->|elif else branch| processBranch
end
subgraph audit-presentation ["presentation/audit.ts decomposition"]
renderAuditFunction --> renderFunctionHeader
renderAuditFunction --> renderHealthMetrics
renderAuditFunction --> renderThresholdBreaches
renderAuditFunction --> renderImpactSection
renderAuditFunction --> renderCallRefs_calls["renderCallRefs('Calls')"]
renderAuditFunction --> renderCallRefs_calledby["renderCallRefs('Called by')"]
renderAuditFunction --> renderRelatedTests
end
Reviews (4): Last reviewed commit: "refactor: address warnings in benchmark ..." | Re-trigger Greptile |
Codegraph Impact Analysis120 functions changed → 98 callers affected across 26 files
|
| const data: AuditResult = auditData(target, customDbPath, opts); | ||
|
|
||
| if (outputResult(data, null, opts)) return; | ||
| if (outputResult(data as unknown as Record<string, unknown>, null, opts)) return; |
There was a problem hiding this comment.
Double cast bypasses well-typed
AuditResult
data as unknown as Record<string, unknown> is required only because outputResult takes a Record<string, unknown> parameter. Since AuditResult is now a concrete, exported interface, widening outputResult's signature to accept object would remove the escape hatch and let the type system verify callers. The cast is not a bug today, but it silently defeats the type improvements introduced elsewhere in this PR.
Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!
There was a problem hiding this comment.
Fixed — removed the double cast entirely. Turns out it wasn't load-bearing: AuditResult assigns cleanly to outputResult's Record<string, any> parameter without any cast (verified with tsc --noEmit). Widening outputResult to accept object would be a good follow-up but touches ~20 call sites across the presentation layer that use the same as unknown as Record<string, unknown> pattern (queries-cli/impact.ts, path.ts, inspect.ts, overview.ts, triage.ts, owners.ts, exports.ts) — out of scope for this PR, which is limited to ast-analysis/presentation/extractors/cli. Filed #1803 for the repo-wide signature widening.
| levels: Record<number, ImpactLevelEntry[]>; | ||
| }; | ||
| health: { | ||
| cognitive: number; | ||
| cyclomatic: number; | ||
| maxNesting: number; | ||
| maintainabilityIndex: number | null; | ||
| halstead: HalsteadMetrics | null; | ||
| loc: number; | ||
| sloc: number; | ||
| commentLines: number; | ||
| thresholdBreaches: string[]; | ||
| }; | ||
| riskScore: number; | ||
| complexityNotes: string[]; | ||
| sideEffects: string[]; | ||
| health: AuditHealthMetrics; | ||
| riskScore: number | null; | ||
| complexityNotes: string | null; | ||
| sideEffects: string | null; | ||
| } |
There was a problem hiding this comment.
AuditFunctionEntry field types corrected from incorrect prior declarations
callees/callers change from string[] to Array<{name, kind, file, line}>, and relatedTests from string[] to Array<{file: string}>. These are corrections — the actual runtime values were always objects — but any external consumer of codegraph audit --json that treated these as string arrays will silently break. Worth calling out in release notes if the JSON output is considered a public API.
There was a problem hiding this comment.
Acknowledged, but verified this is not an actual behavior/output change. I traced callees/callers/relatedTests back through features/audit.ts history (e.g. commit 4a6787e) — they were always populated with SymbolRef[] and {file}[] objects at runtime; only the TS declaration was wrong. Since codegraph audit --json was already emitting objects (never strings), no external consumer that actually inspected the real output could have relied on the incorrect string-array shape, so no release-note callout is needed here — the JSON contract itself hasn't changed, just the type-checker's understanding of it.
|
Addressed Claude's/Greptile's review feedback:
|
…nfo (#1790) printNativeVersionInfo now takes a resolved NativeAddon directly instead of re-invoking loadNative() and asserting it non-null. isNativeAvailable() and loadNative() are two independent code paths; if they ever diverge the assertion would crash instead of degrading gracefully. Impact: 2 functions changed, 2 affected
AuditResult assigns cleanly to outputResult's Record<string, any> parameter without a cast; the `as unknown as Record<string, unknown>` was dead weight left over from before AuditResult was a concrete type. Impact: 1 functions changed, 1 affected
…is naming (#1791) * refactor: address warnings in benchmark tracer tooling Split loader-hooks.mjs's instrumentSource (cognitive 34, cyclomatic 22) into single-purpose matcher/tracker helpers. Extract the duplicated line-scanning loop shared by native-tracer.sh's trace_rust/trace_swift/ trace_dart/trace_zig into a parameterized inject_trace_calls plus small maybe_close_context/maybe_close_finally_scope/maybe_inject_declaration/ instrument_one_file helpers, and rename the LANG variable to TRACE_LANG so it no longer clobbers the POSIX locale env var inherited by every spawned compiler toolchain. Log lua-tracer.lua's swallowed pcall error to stderr so a genuine fixture failure is visible instead of looking like a silent successful trace. Impact: 17 functions changed, 11 affected * refactor: address warnings in ast-analysis and extractors/helpers naming (docs check acknowledged) Impact: 12 functions changed, 36 affected * fix: use compgen -G for glob expansion in inject_trace_calls (#1791) Unquoted `for srcfile in $glob_pattern` word-splits before globbing, so a TMP_DIR containing a space would silently skip every file instead of instrumenting it. compgen -G expands the glob pattern as a single argument, avoiding the split. Also documents the concrete failure mode of calling a maybe_* helper outside the inject_trace_calls -> instrument_one_file chain. Impact: 1 functions changed, 5 affected
Summary
Address remaining quality issues from the Titan GAUNTLET audit across ast-analysis, presentation, extractors, cli, and scripts:
src/ast-analysis/visitor-utils.ts,cfg-conditionals.ts— dispatch table + processBranch dedupesrc/presentation/audit.ts— decomposerenderAuditFunction, adopt typedAuditResultexecute()incli/commands/info.tsintoprintEngineInfo/printNativeVersionInfo/printBuildMetadatatimeMedianhelper inscripts/token-benchmark.tsTitan Audit Context
Changes
src/ast-analysis/visitor-utils.ts,src/ast-analysis/visitors/cfg-conditionals.tssrc/features/audit.ts,src/presentation/audit.ts,src/types.tssrc/extractors/{r,dart,groovy,csharp,elixir,scala,julia}.tssrc/cli/commands/info.tsscripts/token-benchmark.tsMetrics Impact
Part of the quality-fix pass addressing GAUNTLET fail-level violations; see
generated/titan/report for full metrics.Test plan