Skip to content

fix: preserve named edges in shortest path weight lookups - #256

Merged
rustedgrail merged 2 commits into
dagrejs:masterfrom
Aschenbath:codex/fix-graphlib-254
Nov 24, 2026
Merged

rustedgrail merged 2 commits into
dagrejs:masterfrom
Aschenbath:codex/fix-graphlib-254

Conversation

@Aschenbath

Copy link
Copy Markdown
Contributor

Fixes #254.

Pass the original edge to weightFn in Bellman-Ford and the negative-weight check in shortestPaths. Named edges now retain their labels, so the reported a -> b -> c path returns distance 0 instead of Infinity. Bellman-Ford calculates traversal endpoints separately, which also lets g.inEdges traverse directed edges in reverse while looking up their original labels.

Add 14 regression cases covering named and unnamed parallel edges, numeric and object labels, positive and negative weights, reverse and undirected traversal, unreachable nodes, and negative cycles. Before the fix, 12 of these cases failed; all 14 now pass. Type checking, lint, and the package build pass.

The full suite on Windows with Node 24 reports 273 passing tests and one existing platform failure: the ESM export smoke test imports an absolute Windows path instead of a file URL (ERR_UNSUPPORTED_ESM_URL_SCHEME). Both the original and updated bundles reproduce that import error, and both load with a file URL. Separate checks of the packed CJS, ESM, and two browser bundles pass on Node 18 and Node 24 (118 assertions per runtime).

This change was prepared with AI assistance.

@rustedgrail
rustedgrail merged commit 93a5cab into dagrejs:master Nov 24, 2026
1 check passed
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.

alg.bellmanFord() and alg.shortestPaths() strip edge.name before calling weightFn

2 participants