Repository navigation
[FIX] Handle indices for Null Current Cell Correctly - #110
Conversation
📝 WalkthroughWalkthroughThe PR refactors cell index resolution in conflict auto-resolution by introducing a computed Changes
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~25 minutes Poem
🚥 Pre-merge checks | ✅ 2 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing touches
🧪 Generate unit tests (beta)
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. Comment |
There was a problem hiding this comment.
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (1)
src/conflictDetector.ts (1)
484-484:⚠️ Potential issue | 🟡 MinorWhitespace auto-resolution descriptions still use
conflict.currentCellIndexdirectly.Lines 484 and 499 reference
conflict.currentCellIndexfor the description string instead of usinggetResolvedCellIndex. Whencurrentis null, this will produce a misleading cell number in the auto-resolved description (e.g., "cell 1" instead of the correct incoming-based index). Not a data-corruption bug since whitespace resolution doesn't mutateresolvedNotebookcells, but it's inconsistent with the rest of the function.Proposed fix
if (isWhitespaceOnlyDifference(currentSourceStr, incomingSourceStr)) { autoResolved = true; autoResolvedCount++; - autoResolvedDescriptions.push(`Whitespace-only change resolved (cell ${(conflict.currentCellIndex ?? 0) + 1})`); + autoResolvedDescriptions.push(`Whitespace-only change resolved (cell ${(getResolvedCellIndex(conflict) ?? 0) + 1})`); }Same for line 499:
if (isWhitespaceOnlyDifference(currentSource, incomingSource)) { autoResolved = true; autoResolvedCount++; - autoResolvedDescriptions.push(`Whitespace-only added cell resolved (cell ${(conflict.currentCellIndex ?? 0) + 1})`); + autoResolvedDescriptions.push(`Whitespace-only added cell resolved (cell ${(getResolvedCellIndex(conflict) ?? 0) + 1})`); }🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@src/conflictDetector.ts` at line 484, The auto-resolve description uses conflict.currentCellIndex directly causing wrong cell numbers when current is null; update both places that push whitespace-only messages (the autoResolvedDescriptions.push calls at the two mentioned spots) to compute the displayed index via getResolvedCellIndex(conflict) instead of using conflict.currentCellIndex, so the description reads the incoming-based index consistently with the rest of the function.
🧹 Nitpick comments (2)
src/tests/nullCurrentCellIndexing.test.ts (2)
100-136: Consider assertingautoResolvedCountfor completeness.The test verifies cell-level outcomes but doesn't assert that exactly 2 conflicts were auto-resolved (and 0 remain). Adding these checks would catch regressions where conflicts are silently skipped or double-counted.
+ assert.strictEqual(result.autoResolvedCount, 2, 'Both conflicts should be auto-resolved'); + assert.strictEqual(result.remainingConflicts.length, 0, 'No conflicts should remain'); + const cell0 = result.resolvedNotebook?.cells[0];🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@src/tests/nullCurrentCellIndexing.test.ts` around lines 100 - 136, Add assertions to verify the auto-resolution summary: assert that result.autoResolvedCount === 2 and result.remainingConflicts.length === 0 immediately after the console.log of auto-resolution result (referencing result.autoResolvedCount and result.remainingConflicts.length) and before or alongside the cell execution_count assertions in the nullCurrentCellIndexing test so the test fails if conflicts are skipped or double-counted.
76-83: Replacenull as anywithundefinedfor thecurrentfield.The
NotebookSemanticConflict.currentfield is typed asNotebook | undefined, not nullable. Usingundefineddirectly is both type-safe and semantically correct for simulating a delete/modify conflict where the current notebook is absent:current: undefined, // Simulate delete/modify conflict where current is deletedThis avoids the
as anytype bypass while maintaining the same test behavior since production code treats both null and undefined identically via falsy checks (lines 418–422 in conflictDetector.ts).🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@src/tests/nullCurrentCellIndexing.test.ts` around lines 76 - 83, The test creates a NotebookSemanticConflict with current set to `null as any` which bypasses types; change the object to use `current: undefined` so it matches the declared type `Notebook | undefined` on NotebookSemanticConflict.current and preserves the delete/modify simulation; update the test object literal where `current` is set and ensure any related assertions still pass (production code that checks falsy current in conflictDetector will behave the same).
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Outside diff comments:
In `@src/conflictDetector.ts`:
- Line 484: The auto-resolve description uses conflict.currentCellIndex directly
causing wrong cell numbers when current is null; update both places that push
whitespace-only messages (the autoResolvedDescriptions.push calls at the two
mentioned spots) to compute the displayed index via
getResolvedCellIndex(conflict) instead of using conflict.currentCellIndex, so
the description reads the incoming-based index consistently with the rest of the
function.
---
Nitpick comments:
In `@src/tests/nullCurrentCellIndexing.test.ts`:
- Around line 100-136: Add assertions to verify the auto-resolution summary:
assert that result.autoResolvedCount === 2 and result.remainingConflicts.length
=== 0 immediately after the console.log of auto-resolution result (referencing
result.autoResolvedCount and result.remainingConflicts.length) and before or
alongside the cell execution_count assertions in the nullCurrentCellIndexing
test so the test fails if conflicts are skipped or double-counted.
- Around line 76-83: The test creates a NotebookSemanticConflict with current
set to `null as any` which bypasses types; change the object to use `current:
undefined` so it matches the declared type `Notebook | undefined` on
NotebookSemanticConflict.current and preserves the delete/modify simulation;
update the test object literal where `current` is set and ensure any related
assertions still pass (production code that checks falsy current in
conflictDetector will behave the same).
closes #99
Summary by CodeRabbit
Bug Fixes
Tests