Skip to content

fix: mermaid graph connectivity + method chain order + closure body attribution - #46

Merged
hungpham10 merged 6 commits into
mainfrom
fix/mermaid-graph-connectivity
Oct 9, 2026
Merged

hungpham10 merged 6 commits into
mainfrom
fix/mermaid-graph-connectivity

Conversation

@hungpham10

Copy link
Copy Markdown
Owner

Summary

Fix 3 issues in mermaid flow graph:

1. Graph connectivity

structural_edges() adds rule marker -> terminator/block-end (RETURN, BRANCH_END, SWITCH_END).

  • if c { return None; } -> IF_TRUE -> RETURN orphan fixed
  • Switch case return -> SWITCH_END connected
  • Loop break/continue -> BRANCH_END edge added

Result: binary_graph_for from 1 orphan + 2 unreachable -> 0 orphan / 0 unreachable.

2. Method chain order

fix_call_edge_order() tracks call stack (CALL_ENTER/EXIT) to reverse edges.

  • a.b().c() emit pre-order but runtime runs c -> b -> a. Edges reversed for correct execution order.
  • binary_graph_for: bin_base -> load becomes load -> bin_base
  • new_with_storage: Ok -> Search::new becomes Search::new -> Ok

3. Closure body attribution

Cross-region edge (same parent call, different child regions):

  • x.clone().unwrap_or_else(|| { ... }) body anchored to unwrap_or_else, not after x.clone().
  • Before: name_store.clone() -> CachedStorage::wrap becomes unwrap_or_else -> CachedStorage::wrap

4. Bonus: into_var + label improvements

  • tag_into_var() assigns to outermost call (map_err/load_all_symbols) not innermost (read).
  • sanitize(): truncate 80 chars + '...', shorten external call label to last segment.

All existing tests pass (11 mermaid + 44 extract + 104 graph + 8 mcp).

…ttribution

1. structural_edges(): thêm rule cho marker→terminator/block-end (RETURN, BRANCH_END,
   SWITCH_END) để khắc phục node orphan (nổi rời graph) khi thân nhánh if/loop/switch
   chỉ chứa marker.

2. control_flow(): fix_call_edge_order() tính scope call theo stack CALL_ENTER/EXIT,
   đảo cạnh cho đúng runtime:
   - Nested call: con chạy trước cha (a.b().c() → c → b → a).
   - Cross-region (closure body): neo vào call owner (unwrap_or_else) thay vì nối
     tuần tự sau receiver (name_store.clone).
   - Thoát vùng call sang marker điều khiển: neo vào call cha ngoài cùng.

3. common.rs tag_into_var(): gán into_var vào call NGOÀI CÙNG (produce giá trị)
   thay vì call trong cùng — sửa biến gán method chain (self.x = storage.read().load_id()
   → gán cho load_id/map_err, không phải read).

4. mermaid.rs sanitize(): truncate 80 ký tự + '…' suffix; rút gọn label external call
   lấy segment cuối (map_err thay vì full chain).

Test: all mermaid/graph/extract/mcp tests pass.
@coderabbitai

coderabbitai Bot commented Oct 9, 2026 •

Copy link
Copy Markdown

Important

  • 🔍 Trigger review

This repository does not receive automatic reviews because it has fewer than 10 stars.

⚙️ Run configuration
  • Configuration used: Organization UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 42c0a55d-32ab-478d-b520-2f0cff374b24
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

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

hungpham10 and others added 3 commits October 9, 2026 03:01
node_style() shortened external-call labels to the last dot-segment, so the
outer call of a chain (whose CallRecord name is the whole chain text) rendered
as just "ok" instead of "open_from_config(root).await.ok". Node identity was
right; only the label was misleading.

Replace the segment-shortening with whitespace collapsing (newline + indent ->
single space) so the full chain stays readable, and sanitize() still caps at
80 chars with '…' for extreme cases.

Before: c6[["ok · L1100 · ext"]]
After:  c6[["codegraph_extract::BinaryGraph::open_from_config(root) .await .ok · L1100 · ext"]]

Tests: 11 mermaid + 39 extract lib + 104 graph all pass.
@codspeed

codspeed Bot commented Oct 9, 2026 •

Copy link
Copy Markdown

Merging this PR will not alter performance

✅ 38 untouched benchmarks


Comparing fix/mermaid-graph-connectivity (962b122) with main (2f504c4)

Open in CodSpeed

2 vấn đề cốt lõi trong flowchart control-flow:

1. RETURN/THROW/BREAK/CONTINUE bị nối vào BRANCH_END/SWITCH_END
   Rule marker->marker cũ cho phép moi edge, nen 'if c { return None; }'
   ve thanh IF_TRUE -> RETURN -> BRANCH_END -> tail: trong nhu return xong
   van chay tiep. Gio terminator KHONG con ra edge nao (no đói la dead-end
   đúng nghia), va false-path duoc dieu huong QUA BRANCH_END
   (cond -> BRANCH_END -> tail) de node merge khong bi orphan.
   Tuong tu cho SWITCH_END: case 'A => return' neo SWITCH_END vao case
   vua mo thay vi vao RETURN.

2. Method chain render nguoc thu tu thuc thi
   Chain emit PRE-ORDER (call ngoai cung truoc, call trong sau) nen mermaid
   ve 'bin_base -> ExtractConfig::load' va 'ok -> open_from_config'. Viết lai
   control_flow(): dung cay frame tu cap CALL_ENTER/CALL_EXIT roi phat lai
   POST-ORDER (con truoc, cha sau) qua execution_order(). Node + canh tuan tu
   tu do da dung runtime ma khong can va canh sau nay.

   Thay the fix_call_edge_order() (cach ve cu gay 6 orphan o
   new_with_storage) bang cach sap lai node.

Ket qua (0 orphan / 0 unreachable, chi con dead-end la node cuoi):
  binary_graph_for : RETURN khong con noi toi BRANCH_END
                     load -> bin_base, open_from_config -> ok
  new_with_storage : x.clone -> make -> unwrap_or_else (closure body giua)
                     storage.clone -> Search::new -> ... -> Ok (Ok dung cuoi)
  main            : giu nguyen 0 orphan / 0 unreachable
  rebuild         : giu nguyen

Test: +4 test moi (15/15 mermaid pass), 104 graph, 39 extract lib.
@codecov-commenter

codecov-commenter commented Oct 9, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 98.33333% with 4 lines in your changes missing coverage. Please review.
✅ Project coverage is 78.21%. Comparing base (2f504c4) to head (962b122).
⚠️ Report is 1 commits behind head on main.

Files with missing lines Patch % Lines
crates/codegraph-api/src/mermaid.rs 98.68% 3 Missing ⚠️
crates/codegraph-extract/src/languages/common.rs 91.66% 1 Missing ⚠️

❌ Your patch status has failed because the patch coverage (98.33%) is below the target coverage (100.00%). You can increase the patch coverage or adjust the target coverage.

Additional details and impacted files
@@            Coverage Diff             @@
##             main      #46      +/-   ##
==========================================
+ Coverage   78.10%   78.21%   +0.11%     
==========================================
  Files          96       96              
  Lines       23299    23490     +191     
==========================================
+ Hits        18197    18373     +176     
- Misses       5102     5117      +15     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@hungpham10
hungpham10 merged commit 2098651 into main Oct 9, 2026
22 checks passed
@hungpham10
hungpham10 deleted the fix/mermaid-graph-connectivity branch October 9, 2026 06:24
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.

2 participants