Fix: Create tests for issue #2 #7

Merged
tymurbaniak merged 1 commits from claude/issue-6 into main 2026-03-23 15:10:21 +00:00
Owner

Summary

Adds a dedicated regression test suite for the stale-closure bug fixed in issue #2 (PR #3).

What was the bug (issue #2)?

The createPathSegment function in Graph.tsx built breadcrumb onClick handlers that closed over the graphsPath variable captured at render time. After further navigation, that closure became stale: findIndex returned -1 and splice(0) wiped the entire breadcrumb array, making all breadcrumbs disappear.

The fix (commit eb3a23a) switched to the functional updater form of setGraphsPath so findIndex always runs against the current state.

What this PR adds

A new describe block "Stale-closure regression (issue #2)" in e2e/breadcrumb.spec.ts with four targeted tests:

  1. Root breadcrumb remains functional after navigating three levels deep — navigates 3 levels and clicks the root; before the fix this triggered the stale closure and cleared all breadcrumbs.
  2. Level-1 breadcrumb resolves correctly when clicked from level 3 — the exact scenario that surfaced the bug: clicking a segment whose closure was two renders old.
  3. Successive back-clicks each trim exactly one breadcrumb level — verifies that clicking level-2, then level-1, then root each trims exactly one segment rather than wiping the array.
  4. Clicking the active (last) breadcrumb does not alter the path — guards against an off-by-one edge case where slice(0, 0) could clear the array.

All four tests would fail against the pre-fix code and pass against the fixed code.

Closes #6

## Summary Adds a dedicated regression test suite for the stale-closure bug fixed in issue #2 (PR #3). ### What was the bug (issue #2)? The `createPathSegment` function in `Graph.tsx` built breadcrumb `onClick` handlers that closed over the `graphsPath` variable captured at render time. After further navigation, that closure became stale: `findIndex` returned `-1` and `splice(0)` wiped the entire breadcrumb array, making all breadcrumbs disappear. The fix (commit `eb3a23a`) switched to the functional updater form of `setGraphsPath` so `findIndex` always runs against the *current* state. ### What this PR adds A new `describe` block **"Stale-closure regression (issue #2)"** in `e2e/breadcrumb.spec.ts` with four targeted tests: 1. **Root breadcrumb remains functional after navigating three levels deep** — navigates 3 levels and clicks the root; before the fix this triggered the stale closure and cleared all breadcrumbs. 2. **Level-1 breadcrumb resolves correctly when clicked from level 3** — the exact scenario that surfaced the bug: clicking a segment whose closure was two renders old. 3. **Successive back-clicks each trim exactly one breadcrumb level** — verifies that clicking level-2, then level-1, then root each trims exactly one segment rather than wiping the array. 4. **Clicking the active (last) breadcrumb does not alter the path** — guards against an off-by-one edge case where `slice(0, 0)` could clear the array. All four tests would fail against the pre-fix code and pass against the fixed code. Closes #6
tymurbaniak added 1 commit 2026-03-23 15:08:14 +00:00
The fix in issue #2 resolved a stale-closure bug in createPathSegment where
onClick captured graphsPath at render time; after further navigation findIndex
returned -1 and splice(0) wiped the entire breadcrumb array.

New test suite 'Stale-closure regression (issue #2)' covers:
- Root breadcrumb remains functional after navigating three levels deep
- Level-1 breadcrumb resolves correctly when clicked from level 3
- Successive back-clicks each trim exactly one breadcrumb level
- Clicking the currently active breadcrumb does not alter the path

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
tymurbaniak merged commit ee9a55f4e6 into main 2026-03-23 15:10:21 +00:00
tymurbaniak deleted branch claude/issue-6 2026-03-23 15:10:22 +00:00
Sign in to join this conversation.