Skip to content

[FIX] Handle indices for Null Current Cell Correctly - #110

Merged
Avni2000 merged 4 commits into
mainfrom
99-wrong-cell-indexing-when-current-notebook-is-null
Feb 17, 2026
Merged

Avni2000 merged 4 commits into
mainfrom
99-wrong-cell-indexing-when-current-notebook-is-null

Conversation

@Avni2000

@Avni2000 Avni2000 commented Feb 17, 2026 •

Copy link
Copy Markdown
Owner
  • Fix auto-resolution indexing

closes #99

Summary by CodeRabbit

  • Bug Fixes

    • Improved handling of notebook conflicts when the current version is unavailable during merge operations, ensuring correct cell references in auto-resolution logic.
  • Tests

    • Added regression test for cell indexing in delete/modify conflict scenarios.

@Avni2000 Avni2000 linked an issue Feb 17, 2026 that may be closed by this pull request
@coderabbitai

coderabbitai Bot commented Feb 17, 2026 •

Copy link
Copy Markdown
Contributor
📝 Walkthrough

Walkthrough

The PR refactors cell index resolution in conflict auto-resolution by introducing a computed resolvedCellIndex that selects the correct cell based on whether the resolution came from current or incoming notebooks. A new test validates behavior when the current notebook is null.

Changes

Cohort / File(s) Summary
Conflict Resolution Logic
src/conflictDetector.ts
Adds resolvedCellIndex selection helper and getResolvedCellIndex function to replace direct references to currentCellIndex and incomingCellIndex across execution-count, outputs-cleared, and outputs-stripping auto-resolutions. Updates conflict descriptions to reference resolved indices.
Regression Test
src/tests/nullCurrentCellIndexing.test.ts
New test file validating cell indexing behavior in delete/modify conflicts where current notebook is null, asserting correct execution_count handling using incoming cell indices.
Test Registry
src/tests/registry.ts
Registers new regression test with id "regression_null_current_cell_indexing" to the TEST_GROUPS structure.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Poem

A rabbit hops through conflicts with glee, 🐰
Resolving cell indices with clarity!
When current is null, we take incoming's way,
Auto-resolutions work perfectly today!
No more confusion, just indexed delight,
Each cell finds its place, perfectly right!

🚥 Pre-merge checks | ✅ 2 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 50.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly identifies the main fix: correcting cell index handling when the current notebook is null, which is the primary purpose of all changes.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch 99-wrong-cell-indexing-when-current-notebook-is-null

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 and usage tips.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 | 🟡 Minor

Whitespace auto-resolution descriptions still use conflict.currentCellIndex directly.

Lines 484 and 499 reference conflict.currentCellIndex for the description string instead of using getResolvedCellIndex. When current is 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 mutate resolvedNotebook cells, 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 asserting autoResolvedCount for 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: Replace null as any with undefined for the current field.

The NotebookSemanticConflict.current field is typed as Notebook | undefined, not nullable. Using undefined directly 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 deleted

This avoids the as any type 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).

@Avni2000 Avni2000 changed the title [FIX] Uses incomingCellIndex instead of always using currentCellIndex [FIX] Handle indices for Null Current Cell Correctly Feb 17, 2026
@Avni2000
Avni2000 merged commit ad86188 into main Feb 17, 2026
5 checks passed
@Avni2000
Avni2000 deleted the 99-wrong-cell-indexing-when-current-notebook-is-null branch March 1, 2026 01:38
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.

Wrong cell indexing when current notebook is null

1 participant