Skip to content

fix(model): preserve shortest breadth-first distances - #5106

Open
cangen185-sudo wants to merge 2 commits into
antvis:masterfrom
cangen185-sudo:codex/fix-bfs-shortest-distance
Open

cangen185-sudo wants to merge 2 commits into
antvis:masterfrom
cangen185-sudo:codex/fix-bfs-shortest-distance

Conversation

@cangen185-sudo

Copy link
Copy Markdown
Contributor

📝 Description

Preserve the first-discovered distance in Model.breadthFirstSearch and enqueue each discovered node once. In a graph with a → b, a → c, and b → c, the callback currently receives distance 2 for c, even though c is a direct neighbor of a. This also makes getSuccessors(a, { breadthFirst: true, distance: 1 }) omit c and isSuccessor return false for that distance.

Only assign a neighbor's distance and enqueue it when it has not already been discovered. FIFO discovery then keeps minimum hop counts through converging paths and cycles.

🖼️ Screenshot

Real-model regressions check callback order and distances, plus the public distance-filtered successor APIs.

💡 Motivation and Context

The previous traversal marked nodes visited when dequeuing but unconditionally rewrote every neighbor's distance while enqueuing. Another node on the same frontier could overwrite a shorter pending distance before its callback ran. The existing test asserted callback count only.

The change is confined to breadth-first discovery. Regressions also exercise incoming traversal, pruning, isolated nodes, and the depth-first search entry point.

🧩 Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • Test Case (changes that add missing tests or correct existing tests)

🔍 Self Check before Merge

  • I have read the CONTRIBUTING document.
  • I have added tests to cover my changes.
  • All new and existing tests passed. The focused suites below passed; the full repository suite was not run.

Validation on Windows, against master at 306eddb03fd5313d75d9a3ce084722f44475da01:

  • Before the fix: 3 of the first 6 new traversal tests failed, showing incorrect outgoing and incoming distances; pruning, isolation, and DFS controls passed.
  • Final model suite: 10 files, 241 tests passed, including 7 new real-model regressions.
  • tsc --noEmit, Biome on the new test file, and git diff --check passed.
  • Full-file Biome on src/model/model.ts reports the same 2 existing errors (import organization and formatting) and 7 warnings on both the exact upstream baseline and patched source. No unrelated formatting changes are included.

AI assistance: implementation and test drafting assisted by OpenAI Codex; the patch was reviewed and locally tested.

@codecov-commenter

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 83.78%. Comparing base (306eddb) to head (7e64204).

Additional details and impacted files

Impacted file tree graph

@@           Coverage Diff           @@
##           master    #5106   +/-   ##
=======================================
  Coverage   83.78%   83.78%           
=======================================
  Files         338      338           
  Lines       39416    39418    +2     
  Branches     8164     8168    +4     
=======================================
+ Hits        33023    33027    +4     
+ Misses       6369     6367    -2     
  Partials       24       24           
Flag Coverage Δ
x6 83.78% <100.00%> (+<0.01%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

Files with missing lines Coverage Δ
src/model/model.ts 86.16% <100.00%> (+0.21%) ⬆️
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

This branch has not been deployed

No deployments
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.

3 participants