fix(graph2md): writeGraphData uses zero lineCount when startLine absent#103
fix(graph2md): writeGraphData uses zero lineCount when startLine absent#103greynewell merged 2 commits intomainfrom
Conversation
writeGraphData computed lineCount only when startLine > 0 && endLine > 0. For nodes without a startLine (API returns 0), the condition was false and lineCount remained 0, so the graph visualisation data showed lc=0 even though the same node's frontmatter correctly computed line_count=endLine (using effectiveStart=1). Fix: mirror the effectiveStart=1 defaulting used by all frontmatter writers — if endLine > 0 but startLine <= 0, treat startLine as 1. Adds TestGraphDataLineCountMissingStartLine to catch the regression. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
WalkthroughThis PR fixes how graph nodes calculate their line counts. Previously, it required both Changes
Estimated code review effort🎯 2 (Simple) | ⏱️ ~12 minutes Possibly related PRs
Suggested reviewers
Poem
🚥 Pre-merge checks | ✅ 3✅ Passed checks (3 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Comment |
goimports rejects manually aligned spaces; use single space. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 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/archdocs/graph2md/graph2md_test.go`:
- Line 223: The test ignores the error returned by os.ReadDir(outDir) (entries,
_ := os.ReadDir(outDir)); update the graph2md_test.go test to capture the error
(entries, err := os.ReadDir(outDir)), check err != nil and fail early with a
clear message (e.g., t.Fatalf("ReadDir(%s) failed: %v", outDir, err)) so
subsequent assertions (like checking for function markdown files) don't mask the
real I/O failure.
🪄 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: 16e04f55-46b5-4c52-ac72-c198b06d2733
📒 Files selected for processing (2)
internal/archdocs/graph2md/graph2md.gointernal/archdocs/graph2md/graph2md_test.go
| } | ||
|
|
||
| // Find the function's markdown file | ||
| entries, _ := os.ReadDir(outDir) |
There was a problem hiding this comment.
Handle ReadDir errors explicitly.
At Line 223, the error is ignored. If directory read fails, the test may fail later with a less useful message (“function markdown file not found”) instead of the real I/O error.
Suggested fix
- entries, _ := os.ReadDir(outDir)
+ entries, err := os.ReadDir(outDir)
+ if err != nil {
+ t.Fatalf("ReadDir: %v", err)
+ }📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
| entries, _ := os.ReadDir(outDir) | |
| entries, err := os.ReadDir(outDir) | |
| if err != nil { | |
| t.Fatalf("ReadDir: %v", err) | |
| } |
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.
In `@internal/archdocs/graph2md/graph2md_test.go` at line 223, The test ignores
the error returned by os.ReadDir(outDir) (entries, _ := os.ReadDir(outDir));
update the graph2md_test.go test to capture the error (entries, err :=
os.ReadDir(outDir)), check err != nil and fail early with a clear message (e.g.,
t.Fatalf("ReadDir(%s) failed: %v", outDir, err)) so subsequent assertions (like
checking for function markdown files) don't mask the real I/O failure.
Summary
writeGraphDatacomputedlineCountonly whenstartLine > 0 && endLine > 0startLine(value is 0), the condition was false andlineCountstayed 0lcfield in the embedded graph visualisation JSON was therefore 0 (or absent viaomitempty) for these nodeswriteFunctionFrontmatter,writeFileFrontmatter, etc.) already defaultedstartLineto 1 when it was missing — producing the correctline_countin the markdowneffectiveStart=1logic inwriteGraphDataso the graph JSON data is consistent with the frontmatter textTest plan
TestGraphDataLineCountMissingStartLine: function node withendLine=50, nostartLine— verifieslc=50ingraph_dataJSONTestLineCountMissingStartLine(frontmatter text) still passesgo test ./internal/archdocs/graph2md/...passesgo build ./...passes🤖 Generated with Claude Code
Summary by CodeRabbit
Bug Fixes
Tests