Skip to content

fix(focus,find): fix relationship type case, empty CalledBy/Imports, stale API#68

Merged
greynewell merged 2 commits intomainfrom
fix/focus-find-rel-types-and-cache
Apr 8, 2026
Merged

fix(focus,find): fix relationship type case, empty CalledBy/Imports, stale API#68
greynewell merged 2 commits intomainfrom
fix/focus-find-rel-types-and-cache

Conversation

@greynewell
Copy link
Copy Markdown
Contributor

@greynewell greynewell commented Apr 8, 2026

Summary

Three commands (focus, find) were silently broken due to relationship type case mismatches and stale code paths.

Relationship type case (all three)

The Supermodel API returns relationship types in lowercase (calls, imports, defines_function, declares_class) but the handlers used uppercase literals. This caused:

  • supermodel focus <file>Imports and Called by sections always empty; --types never returned results
  • supermodel find <symbol>Callers, Callees, and Defined in always empty

filePath property lookup (focus, find)

callerNode.Prop("file", "path") missed the actual property name filePath used by Function nodes, causing caller file paths to appear as empty () in focus output and empty file fields in find JSON output.

Stale getGraph implementations (focus, find)

Both packages had their own getGraph that:

  1. Created a zip archive before checking cache (wasted time even on cache hits)
  2. Called the deprecated client.Analyze endpoint instead of AnalyzeShards

Now both delegate to analyze.GetGraph(), which uses git fingerprinting for ~1ms cache checks and the current AnalyzeShards endpoint.

Other

  • Removed nil dereference risk in find/handler.go defFile assignment
  • Removed dead newAPIClient wrapper from focus/zip.go
  • Updated tests to use lowercase relationship types

Test plan

  • supermodel focus internal/analyze/handler.go shows non-empty Imports and Called by sections
  • supermodel find GetGraph shows non-empty Callers, Callees, Defined in fields
  • go test ./internal/find/... ./internal/focus/... passes

🤖 Generated with Claude Code

Summary by CodeRabbit

  • Refactor

    • Simplified graph retrieval flow for more efficient analysis.
    • Standardized relationship type handling across find/focus features.
    • Improved property lookups for more accurate results.
  • Chores

    • Removed unused helpers and imports.
    • Added generated metadata artifacts for build tooling.

All API relationship types are lowercase (calls, imports, defines_function,
declares_class) but focus and find used uppercase literals, causing:

- focus: Imports and CalledBy sections always empty
- focus: Type extraction (--types flag) never returned results
- find: Callers, callees, and defined_in always empty

Also fixed:
- callerFile lookup used "file"/"path" props; Function nodes store their
  file in "filePath" — causes empty file in CalledBy output
- find/handler.go: nil dereference on defFile lookup when StartNode missing
- focus/getGraph and find/getGraph: created zip before checking cache and
  called the old client.Analyze endpoint; now delegate to analyze.GetGraph()
  which uses git fingerprinting for fast cache hits and AnalyzeShards
- Removed dead newAPIClient wrapper from focus/zip.go

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@coderabbitai
Copy link
Copy Markdown

coderabbitai bot commented Apr 8, 2026

Caution

Review failed

The pull request is closed.

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 0fff4e0d-1db3-4638-8b5e-cf22877ac62e

📥 Commits

Reviewing files that changed from the base of the PR and between 10b53c1 and 3c55536.

📒 Files selected for processing (10)
  • internal/find/doc.graph.go
  • internal/find/handler.graph.go
  • internal/find/handler_test.graph.go
  • internal/find/integration_test.graph.go
  • internal/find/zip.graph.go
  • internal/find/zip_test.graph.go
  • internal/focus/doc.graph.go
  • internal/focus/handler.graph.go
  • internal/focus/zip.go
  • internal/focus/zip.graph.go

Walkthrough

Graph relation type strings were normalized from uppercase to lowercase and node property lookups were adjusted. Local ZIP/cache/getGraph logic was removed in favor of delegating to analyze.GetGraph. Multiple build-ignored generated .graph.go metadata files were added; no new runtime APIs introduced. (50 words)

Changes

Cohort / File(s) Summary
Generated metadata files
internal/find/doc.graph.go, internal/find/handler.graph.go, internal/find/handler_test.graph.go, internal/find/integration_test.graph.go, internal/find/zip.graph.go, internal/find/zip_test.graph.go, internal/focus/doc.graph.go, internal/focus/handler.graph.go, internal/focus/zip.graph.go
Added build-ignored (//go:build ignore) generated artifacts documenting dependency/call graphs. No executable code or API surface changes.
Find handler
internal/find/handler.go
Changed graph relation type checks to lowercase ("calls", "contains_call", "defines_function", "defines", "declares_class"). Adjusted caller/callee and definition node property lookups (use ("filePath","file","path") variants). Removed inline zip/hash/cache/ui spinner; getGraph now calls analyze.GetGraph. Removed internal/cache import; added internal/analyze.
Find tests
internal/find/handler_test.go
Updated test fixtures to use lowercase relation Type values so tests align with handler logic.
Focus handler
internal/focus/handler.go
Normalized relation type strings to lowercase, fixed caller file property lookups ("filePath","file","path"), removed fallback that scanned all Function nodes (now relies on relationships), and switched getGraph to analyze.GetGraph (removed local zip/cache).
Focus zip removal
internal/focus/zip.go
Deleted full ZIP creation and helper logic (createZip, isGitRepo, gitArchive, walkZip) and removed unused newAPIClient helper. No exported symbols were removed.

Sequence Diagram(s)

sequenceDiagram
    participant CLI as "cmd/<command>"
    participant Handler as "internal/*/handler.go"
    participant Analyze as "internal/analyze (Analyze API)"
    participant Zip as "local zip/cache (removed)"

    CLI->>Handler: Run command (e.g., find/focus)
    Handler->>Analyze: analyze.GetGraph(ctx, cfg, dir, force)
    Analyze-->>Handler: graph data (nodes/relations)
    Handler->>Handler: process relations (calls, defines, imports)
    Note over Zip,Handler: previously Handler -> Zip -> cache -> Analyze flow removed
Loading

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~45 minutes

Possibly related PRs

Suggested reviewers

  • jonathanpopham

Poem

Lowercase whispers in the graph tonight,
Handlers hand off work with tidy light.
Zips retired, the analyzer takes the stage,
Relations hum cleaner on every page. ✨🛠️

🚥 Pre-merge checks | ✅ 2 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 40.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately captures the main fix: relationship type case corrections and handling of empty sections/stale API usage in focus and find commands.
Description check ✅ Passed The description covers all required template sections (What, Why, Test plan) with clear explanations of the three main bug categories and their fixes, though test plan items are incomplete checkboxes.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/focus-find-rel-types-and-cache

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
internal/find/handler_test.go (1)

200-203: ⚠️ Potential issue | 🟡 Minor

Test helper makeGraph() still uses uppercase "CALLS"

Heads up! The makeGraph() helper on line 201 still uses uppercase "CALLS":

{ID: "r1", Type: "CALLS", StartNode: "fn3", EndNode: "fn1"},

The tests using this helper (TestSearch_BasicMatch, TestSearch_CaseInsensitive, etc.) still pass because they don't assert on Callers/Callees fields. But this inconsistency could trip someone up later if they add a test that does check those fields.

Consider updating to lowercase for consistency with the API and the other test fixtures in this file:

Proposed fix
 	Relationships: []api.Relationship{
-		{ID: "r1", Type: "CALLS", StartNode: "fn3", EndNode: "fn1"},
+		{ID: "r1", Type: "calls", StartNode: "fn3", EndNode: "fn1"},
 	},
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@internal/find/handler_test.go` around lines 200 - 203, Update the test helper
makeGraph() so the Relationship Type uses lowercase "calls" (i.e., set
Relationships: []api.Relationship{{ID: "r1", Type: "calls", StartNode: "fn3",
EndNode: "fn1"}}) to match the API and other fixtures; modify the
api.Relationship.Type value in makeGraph() and run the tests (including
TestSearch_BasicMatch and TestSearch_CaseInsensitive) to ensure nothing else
relies on the uppercase value.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@internal/find/handler.graph.go`:
- Line 29: The call-graph metadata is stale: update the generated metadata so it
reflects that getGraph now calls analyze.GetGraph(); regenerate the call-graph
metadata file (the handler.graph.go metadata) using the project's call-graph
generation tool/command so the entry becomes "getGraph → analyze.GetGraph()"
instead of the old "getGraph → Analyze". After regenerating, commit the updated
metadata file.

---

Outside diff comments:
In `@internal/find/handler_test.go`:
- Around line 200-203: Update the test helper makeGraph() so the Relationship
Type uses lowercase "calls" (i.e., set Relationships: []api.Relationship{{ID:
"r1", Type: "calls", StartNode: "fn3", EndNode: "fn1"}}) to match the API and
other fixtures; modify the api.Relationship.Type value in makeGraph() and run
the tests (including TestSearch_BasicMatch and TestSearch_CaseInsensitive) to
ensure nothing else relies on the uppercase value.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 0186f061-18db-4206-8c76-03bde52dcb3d

📥 Commits

Reviewing files that changed from the base of the PR and between 10b76ed and 10b53c1.

📒 Files selected for processing (13)
  • internal/find/doc.graph.go
  • internal/find/handler.go
  • internal/find/handler.graph.go
  • internal/find/handler_test.go
  • internal/find/handler_test.graph.go
  • internal/find/integration_test.graph.go
  • internal/find/zip.graph.go
  • internal/find/zip_test.graph.go
  • internal/focus/doc.graph.go
  • internal/focus/handler.go
  • internal/focus/handler.graph.go
  • internal/focus/zip.go
  • internal/focus/zip.graph.go
💤 Files with no reviewable changes (1)
  • internal/focus/zip.go

// Run → printMatches internal/find/handler.go:120
// Run → ParseFormat internal/ui/output.go:24
// getGraph ← Run internal/find/handler.go:36
// getGraph → Analyze internal/api/client.go:41
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟡 Minor

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
# Description: Verify what getGraph calls in the refactored handler.go

# Look for the getGraph function implementation and its call sites
rg -A 10 'func getGraph' internal/find/handler.go

Repository: supermodeltools/cli

Length of output: 233


Regenerate the call-graph metadata file.

The metadata at line 29 is stale. Your code actually does what the PR says—getGraph now calls analyze.GetGraph() instead of the old deprecated endpoint. I verified the actual code:

func getGraph(ctx context.Context, cfg *config.Config, dir string, force bool) (*api.Graph, error) {
	g, _, err := analyze.GetGraph(ctx, cfg, dir, force)
	return g, err
}

Perfect. But the generated metadata file still shows the old call path (getGraph → Analyze). Since this is an auto-generated documentation file, just regenerate it with whatever tool/command creates it, and it'll reflect the current call graph.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@internal/find/handler.graph.go` at line 29, The call-graph metadata is stale:
update the generated metadata so it reflects that getGraph now calls
analyze.GetGraph(); regenerate the call-graph metadata file (the
handler.graph.go metadata) using the project's call-graph generation
tool/command so the entry becomes "getGraph → analyze.GetGraph()" instead of the
old "getGraph → Analyze". After regenerating, commit the updated metadata file.

focus/zip.go was entirely dead code after getGraph() was replaced with
analyze.GetGraph(). golangci-lint flagged createZip, skipDirs, isGitRepo,
gitArchive, walkZip as unused. Delete the file.

Also run goimports on modified files to satisfy formatting check.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@greynewell greynewell merged commit 525fe68 into main Apr 8, 2026
6 of 7 checks passed
greynewell added a commit that referenced this pull request Apr 8, 2026
The focus package had zero test coverage. New tests cover:
- pathMatches() helper (exact, suffix, dot-slash prefix)
- extract() core logic: file lookup, imports BFS, functions/callees,
  CalledBy population, self-call exclusion
- Relationship type case regression guard: verifies uppercase rel types
  (DEFINES_FUNCTION, CALLS) do not match, confirming the #68 fix
- render() for both JSON and markdown output formats

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
greynewell added a commit that referenced this pull request Apr 8, 2026
The focus package had zero test coverage. New tests cover:
- pathMatches() helper (exact, suffix, dot-slash prefix)
- extract() core logic: file lookup, imports BFS, functions/callees,
  CalledBy population, self-call exclusion
- Relationship type case regression guard: verifies uppercase rel types
  (DEFINES_FUNCTION, CALLS) do not match, confirming the #68 fix
- render() for both JSON and markdown output formats

Co-authored-by: Claude Sonnet 4.6 <noreply@anthropic.com>
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