Repository navigation
Various fixes for PR #161 - #163
Conversation
- unmatchRow should only work when it has BOTH currentCell and incomingCell - if semantic conflicts were empty (eg. after auto resolve), the reorder UI would disappear w/o telling user. - changed to detect reordering too
…behavior - stripOutputs now also nulls execution_count on remaining (unresolvable) conflicts when autoResolveExecutionCount=true, matching the auto-resolved outputs-changed path - Rewrite misleading // BUG comment in settingsMatrix.test.ts (A3) as a regression guard comment — the code was already correct - Document the incoming-before-current tie-breaking order in compareByPosition - Tests: A11 in settingsMatrix verifies stripOutputs + autoResolveExecutionCount on remaining conflicts; logicRegression verifies detectReordering and computeReorderedRowIndexSet agree across reorder/shared-reorder/drift cases
📝 WalkthroughWalkthroughRefines auto-resolution behavior to null execution_count only when autoResolveExecutionCount is enabled, switches global-reorder detection to use detectReordering(cellMappings), simplifies the unmatch guard, and adds/updates extensive tests for reordering, unmatch behavior, and settings interactions. Changes
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Possibly related issues
Possibly related PRs
Poem
🚥 Pre-merge checks | ✅ 1 | ❌ 2❌ Failed checks (1 warning, 1 inconclusive)
✅ Passed checks (1 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 |
- reorderUnmatch.test.ts now targets the Alpha reorder row explicitly, verifies a second unmatch works after rematch, and documents the 09_reorder_* fixture index mapping in the final disk assertion. - reorderUnmatchApplyDisk.test.ts now runs with showBaseColumn=true, asserts split rows show the base-column "(unmatched cell)" placeholder while hiding Use Base, and uses All Current to verify the mixed current/delete accept-all path after unmatch. - logicRegression.test.ts now asserts the exact reordered set (intro not reordered; alpha/beta/gamma reordered) and replaces the shared-reorder detector stub with the real detectSemanticConflicts path driven by mocked Git version lookups.
There was a problem hiding this comment.
Actionable comments posted: 1
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (1)
src/tests/reorderUnmatchApplyDisk.test.ts (1)
131-147:⚠️ Potential issue | 🟡 MinorWait for the bulk accept to settle before verifying row content.
verifyAllConflictsMatchSide()reads the resolved state immediately after theAll Currentclick, but the test only waits forwaitForAllConflictsResolved()afterwards. On slower runs that can produce a transient mismatch instead of a real regression.💡 Suggested ordering
await page.locator('button:has-text("All Current")').click(); + const allResolved = await waitForAllConflictsResolved(page, 7000); + if (allResolved.total <= 0 || allResolved.resolved !== allResolved.total) { + throw new Error(`Expected all conflicts resolved, got ${allResolved.resolved}/${allResolved.total}`); + } const currentAcceptance = await verifyAllConflictsMatchSide(page, 'current'); if (currentAcceptance.mismatches.length > 0) { throw new Error( `Expected "All Current" to resolve split rows to current/delete correctly:\n${currentAcceptance.mismatches.join('\n')}` ); } if (currentAcceptance.matchCount !== 3 || currentAcceptance.deleteCount !== 1) { throw new Error( `Expected "All Current" after splitting Beta to resolve 3 rows to current and 1 to delete, got current=${currentAcceptance.matchCount}, delete=${currentAcceptance.deleteCount}` ); } - - const allResolved = await waitForAllConflictsResolved(page, 7000); - if (allResolved.total <= 0 || allResolved.resolved !== allResolved.total) { - throw new Error(`Expected all conflicts resolved, got ${allResolved.resolved}/${allResolved.total}`); - }🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@src/tests/reorderUnmatchApplyDisk.test.ts` around lines 131 - 147, The test reads resolved state too early: after clicking the 'All Current' button (locator 'button:has-text("All Current")') call waitForAllConflictsResolved(page, 7000) first and assert it reports resolved==total, then call verifyAllConflictsMatchSide(page, 'current') and perform the mismatches/matchCount/deleteCount assertions; this ensures the bulk accept has settled before inspecting rows and avoids transient failures.
🧹 Nitpick comments (1)
src/tests/logicRegression.test.ts (1)
824-828: Make this reorder assertion exact.
some(row => row.isReordered)still passes if only one affected row is flagged, so it won't catch a partial regression in the mapping-driven reorder path.♻️ Tighten the assertion
- assert.ok( - reorderNoSemanticRows.some(row => row.isReordered), - 'Expected isReordered flags even when semanticConflicts is empty but cellMappings show a reorder' - ); + assert.deepStrictEqual( + reorderNoSemanticRows.map(row => !!row.isReordered), + [true, true], + 'Expected both rows to stay marked as reordered when cellMappings show a reorder' + );🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@src/tests/logicRegression.test.ts` around lines 824 - 828, The current test uses reorderNoSemanticRows.some(row => row.isReordered) which can mask partial failures; update the assertion in the test that uses buildMergeRowsFromSemantic and reorderNoSemanticRows to check exact expected reorder flags instead of just any truthy. Identify which rows should be reordered (based on the input reorderNoSemanticConflict/cellMappings) and assert that all and only those rows have row.isReordered true—e.g., compute the expected boolean array or filter rows by the mapping and use every/strict equality to compare to reorderNoSemanticRows.map(r => r.isReordered) so partial mappings will fail the test.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@src/tests/logicRegression.test.ts`:
- Around line 627-646: The test is directly reassigning functions on the
namespace import gitIntegration (getThreeWayVersions, getCurrentBranch,
getMergeBranch) which will fail at runtime; replace those direct assignments
with a proper mock or injectable approach: e.g., use jest.mock for the module
and provide mock implementations for
getThreeWayVersions/getCurrentBranch/getMergeBranch, or use
jest.spyOn(gitIntegration,
'getThreeWayVersions').mockImplementation(...)/mockRestore() for each function
instead of (gitIntegration as any)= assignments, and similarly replace
restoration with mockRestore() (and for WebConflictPanel.createOrShow use
jest.spyOn(WebConflictPanel, 'createOrShow').mockImplementation(() => {
openedWebPanel = true }) and restore it after). Ensure you update the test
setup/teardown to call mockRestore() or jest.resetAllMocks() rather than
reassigning the namespace.
---
Outside diff comments:
In `@src/tests/reorderUnmatchApplyDisk.test.ts`:
- Around line 131-147: The test reads resolved state too early: after clicking
the 'All Current' button (locator 'button:has-text("All Current")') call
waitForAllConflictsResolved(page, 7000) first and assert it reports
resolved==total, then call verifyAllConflictsMatchSide(page, 'current') and
perform the mismatches/matchCount/deleteCount assertions; this ensures the bulk
accept has settled before inspecting rows and avoids transient failures.
---
Nitpick comments:
In `@src/tests/logicRegression.test.ts`:
- Around line 824-828: The current test uses reorderNoSemanticRows.some(row =>
row.isReordered) which can mask partial failures; update the assertion in the
test that uses buildMergeRowsFromSemantic and reorderNoSemanticRows to check
exact expected reorder flags instead of just any truthy. Identify which rows
should be reordered (based on the input reorderNoSemanticConflict/cellMappings)
and assert that all and only those rows have row.isReordered true—e.g., compute
the expected boolean array or filter rows by the mapping and use every/strict
equality to compare to reorderNoSemanticRows.map(r => r.isReordered) so partial
mappings will fail the test.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: 1a7205f2-a86b-4c4a-b4b6-acac0979f76f
📒 Files selected for processing (3)
src/tests/logicRegression.test.tssrc/tests/reorderUnmatch.test.tssrc/tests/reorderUnmatchApplyDisk.test.ts
| const originalGetThreeWayVersions = gitIntegration.getThreeWayVersions; | ||
| const originalGetCurrentBranch = gitIntegration.getCurrentBranch; | ||
| const originalGetMergeBranch = gitIntegration.getMergeBranch; | ||
| const originalCreateOrShow = WebConflictPanel.createOrShow; | ||
| let openedWebPanel = false; | ||
|
|
||
| try { | ||
| (conflictDetector as any).detectSemanticConflicts = async () => sharedReorderConflict; | ||
| (gitIntegration as any).getThreeWayVersions = async (filePath: string) => { | ||
| if (filePath !== normalizedConflictPath) { | ||
| return null; | ||
| } | ||
|
|
||
| return { | ||
| base: JSON.stringify(sharedReorderBase), | ||
| current: JSON.stringify(sharedReorderCurrent), | ||
| incoming: JSON.stringify(sharedReorderIncoming), | ||
| }; | ||
| }; | ||
| (gitIntegration as any).getCurrentBranch = async () => 'current'; | ||
| (gitIntegration as any).getMergeBranch = async () => 'incoming'; |
There was a problem hiding this comment.
🧩 Analysis chain
🌐 Web query:
In TypeScript/JavaScript modules, can test code safely reassign properties on import * as ns from "./module" namespace imports, or are namespace imports read-only in CommonJS and ESM?
💡 Result:
- In real ESM:
import * as ns from "./module"produces a Module Namespace Exotic Object that is not extensible and whose internal[[Set]]always returns false—sons.foo = ...,delete ns.foo, or defining/redefining exports via the namespace is not allowed (and typically throws aTypeErrorin strict mode). [1] - In Node.js when importing CommonJS via ESM:
import * as m from "cjs"also exposes a Module Namespace Exotic Object (with at least adefaultexport pointing atmodule.exports, plus possibly detected named exports). That namespace wrapper is the ESM namespace object, so it’s still not something you can safely mutate via assignment. [2] - In CommonJS (using
requiredirectly):const ns = require("./module")just gives you whatevermodule.exportsis (often a plain object), which can be mutable—this is different from an ESM namespace import. [2] - In TypeScript transpiled to CJS: TS’s helper for
import * as nscommonly creates bindings withObject.defineProperty(... { get() { ... } })(getter-only), which likewise makes assignments likens.foo = ...fail at runtime. [3]
Practical takeaway: don’t rely on reassigning properties on a namespace import for tests. If you need to swap implementations, prefer your test framework’s module-mocking facilities or inject dependencies; if you truly need mutation, mutate an exported object’s internal state (e.g. export const config = { ... }) rather than trying to assign to ns.someExport. [1]
Sources:
[1] ECMAScript spec: Module Namespace Exotic Objects ([[Set]] returns false; not extensible) (tc39.es)
[2] Node.js ESM docs: “CommonJS Namespaces” and observing the Module Namespace Exotic Object via import * as m (nodejs.org)
[3] TypeScript docs (esModuleInterop) showing __createBinding using getter-based defineProperty (typescriptlang.org)
Citations:
- 1: https://tc39.es/ecma262/multipage/ordinary-and-exotic-objects-behaviours.html
- 2: https://nodejs.org/download/nightly/v20.0.0-nightly20230111384e1b5174/docs/api/esm.html
- 3: https://www.typescriptlang.org/tsconfig/esModuleInterop.html
🏁 Script executed:
# Check the import statement for gitIntegration in logicRegression.test.ts
rg -n "import.*gitIntegration" src/tests/logicRegression.test.ts | head -5
# Verify the exact lines flagged (627-646 and 710-712)
echo "=== Lines 627-646 ===" && sed -n '627,646p' src/tests/logicRegression.test.ts
echo "=== Lines 710-712 ===" && sed -n '710,712p' src/tests/logicRegression.test.tsRepository: Avni2000/MergeNB
Length of output: 1273
🏁 Script executed:
# Check for jest or test configuration that might affect module loading
fd -e config.js -e jest.config.ts -e package.json | xargs grep -l "jest\|test" 2>/dev/null | head -3
# Look at package.json test script and jest config
cat -n package.json | grep -A 10 '"test"' | head -15
# Check if jest config exists
ls -la jest.config.* 2>/dev/null || echo "No jest.config found"
# Check tsconfig to see if there's esModuleInterop or module settings affecting imports
cat -n tsconfig.json 2>/dev/null | grep -E '"module"|"esModuleInterop"'Repository: Avni2000/MergeNB
Length of output: 660
🏁 Script executed:
# Check if there's a sinon or other mock library available
rg -n "sinon|jest|mock|spy" package.json | head -5
# Check the actual test runner to understand the environment better
head -30 src/tests/runIntegrationTest.js 2>/dev/null || echo "File not found at expected path"
# Look at other tests to see if there's a pattern used elsewhere for mocking
rg -n "as any.*=.*async" src/tests/ --type ts | grep -v logicRegression | head -3Repository: Avni2000/MergeNB
Length of output: 91
🏁 Script executed:
# Find the test runner file
find . -name "runIntegrationTest.js" -o -name "runIntegrationTest.ts" 2>/dev/null
# Check if mocha is being used (common with `@types/mocha` dependency)
rg -n "mocha\|describe\|before\|after" src/tests/logicRegression.test.ts | head -5
# Look at the broader test structure
head -50 src/tests/logicRegression.test.ts | cat -nRepository: Avni2000/MergeNB
Length of output: 2703
🏁 Script executed:
# Check Node and TypeScript versions in package.json
rg -A 2 -B 2 '"node"|"typescript"' package.json | grep -E '"node"|"typescript"'
# Look for any test execution logs or CI config that shows if tests pass
fd -e "*.yml" -e "*.yaml" | xargs grep -l "test\|npm run test" 2>/dev/null | head -2
# Check tsconfig to see the exact module and target settings
cat tsconfig.json | grep -E '"module"|"target"|"esModuleInterop"'
# Check if there's evidence that this test actually runs (look for test output or skip markers)
rg -n "\.skip\|\.only\|pending" src/tests/logicRegression.test.ts | grep -E "627|710" || echo "No skip/only near flagged lines"Repository: Avni2000/MergeNB
Length of output: 163
Avoid stubbing gitIntegration by reassigning a namespace import.
import * as gitIntegration creates a read-only module namespace object in Node16 ESM. Assignments like (gitIntegration as any).getThreeWayVersions = ... violate module semantics and will fail at runtime, particularly under strict mode or with certain Node.js loaders, before the test assertions can run. The as any cast masks the TypeScript error but does not prevent the runtime failure.
Use dependency injection or a proper mocking library instead:
- Inject
gitIntegrationas a parameter and swap it in the test setup, or - Use a module mocking library (e.g.,
proxyquire,jest.mock, or similar) that properly handles namespace imports, or - Export a mutable object from
gitIntegrationthat tests can safely mutate (e.g.,export const config = { getThreeWayVersions: ... }).
Also applies to lines 710–712 (restore assignments).
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.
In `@src/tests/logicRegression.test.ts` around lines 627 - 646, The test is
directly reassigning functions on the namespace import gitIntegration
(getThreeWayVersions, getCurrentBranch, getMergeBranch) which will fail at
runtime; replace those direct assignments with a proper mock or injectable
approach: e.g., use jest.mock for the module and provide mock implementations
for getThreeWayVersions/getCurrentBranch/getMergeBranch, or use
jest.spyOn(gitIntegration,
'getThreeWayVersions').mockImplementation(...)/mockRestore() for each function
instead of (gitIntegration as any)= assignments, and similarly replace
restoration with mockRestore() (and for WebConflictPanel.createOrShow use
jest.spyOn(WebConflictPanel, 'createOrShow').mockImplementation(() => {
openedWebPanel = true }) and restore it after). Ensure you update the test
setup/teardown to call mockRestore() or jest.resetAllMocks() rather than
reassigning the namespace.
There was a problem hiding this comment.
The module system is CJS not ESM. No need. Also, we're using mocha, not Jest
There was a problem hiding this comment.
@Avni2000, you're right — in a CommonJS output environment, TypeScript compiles import * as ns into a mutable require()-based object, so direct property reassignment like (gitIntegration as any).getThreeWayVersions = ... is perfectly valid at runtime. The read-only restriction only applies to native ESM module namespace objects. And noted on Mocha — the Jest-specific advice was entirely inapplicable. I apologize for the noise.
✏️ Learnings added
Learnt from: Avni2000
Repo: Avni2000/MergeNB PR: 163
File: src/tests/logicRegression.test.ts:627-646
Timestamp: 2026-03-07T02:53:54.416Z
Learning: In Avni2000/MergeNB, the test infrastructure uses Mocha (not Jest) and TypeScript is compiled to CommonJS. Because of this, `import * as ns from '...'` namespace imports are mutable plain objects at runtime, so direct property reassignment like `(ns as any).foo = mockFn` in test setup/teardown is safe and intentional. Do not flag this pattern as a runtime safety issue.
Note: Learnings are effective only in the context of similar code segments. To apply general coding guidelines, please configure review instructions. You can manage existing learnings in the app.
🧠 Learnings used
Learnt from: CR
Repo: Avni2000/MergeNB PR: 0
File: AGENTS.md:0-0
Timestamp: 2026-02-03T02:45:32.680Z
Learning: Applies to src/**/resolver.ts : Use the `merge-nb.findConflicts` command as the single unified entry point to find notebooks with merge conflicts (both textual and semantic) and bring up the conflict resolution panel
Learnt from: Avni2000
Repo: Avni2000/MergeNB PR: 0
File: :0-0
Timestamp: 2026-02-04T23:12:05.322Z
Learning: In src/tests/vscodeIntegration.test.ts: The integration test has verification gaps: it never directly checks the outputs array content (only execution_count), uses getCellSource() normalization which masks source format inconsistencies (string vs array), and derives expected cell values from data-cell attributes containing original cells rather than from resolver output.
Learnt from: Avni2000
Repo: Avni2000/MergeNB PR: 0
File: :0-0
Timestamp: 2026-03-01T23:15:35.118Z
Learning: In src/web/client/**/*.tsx for MergeNB: When displaying cell reordering in the conflict resolution UI, use a simplified approach with arrows (showing direction and delta) and unmatch/rematch buttons that are ONLY visible for reordered cells. After unmatch, split the row into separate rows allowing manual selection and deletion. Avoid complex position badges or summary panels.
Learnt from: CR
Repo: Avni2000/MergeNB PR: 0
File: AGENTS.md:0-0
Timestamp: 2026-02-22T19:37:35.242Z
Learning: Applies to src/tests/**/*.ts : Run integration tests using vscode/test-electron to launch VS Code with merge-conflict repos
Learnt from: CR
Repo: Avni2000/MergeNB PR: 0
File: AGENTS.md:0-0
Timestamp: 2026-02-03T02:45:32.680Z
Learning: Applies to src/webview/**/*.{ts,tsx} : Provide a unified conflict resolution UI in `ConflictResolverPanel` webview supporting both textual and semantic conflict resolution with 3-way diff view
Learnt from: Avni2000
Repo: Avni2000/MergeNB PR: 155
File: src/web/client/MergeRow.tsx:309-312
Timestamp: 2026-03-03T07:05:27.507Z
Learning: In tests that interact with the CodeMirror editor, implement getResolvedEditorValue() to read the editor content directly from the CodeMirror instance (e.g. .cm-content.textContent) or via page.evaluate() that accesses the editor state, rather than reading a data-resolved-content DOM attribute. This avoids exposing full cell content in the DOM and prevents per-keystroke attribute updates, improving test isolation and security. Apply this pattern to all test files under src/tests or similarly named test suites that exercise the editor content.
Learnt from: CR
Repo: Avni2000/MergeNB PR: 0
File: AGENTS.md:0-0
Timestamp: 2026-02-22T19:37:35.242Z
Learning: Applies to **/*.ts : Detect merge conflicts in Jupyter notebooks using UU (both-modified) status from Git
Learnt from: CR
Repo: Avni2000/MergeNB PR: 0
File: AGENTS.md:0-0
Timestamp: 2026-02-22T19:37:35.242Z
Learning: Use Playwright helpers (integrationUtils.ts) for browser automation during conflict UI interaction testing
Learnt from: CR
Repo: Avni2000/MergeNB PR: 0
File: AGENTS.md:0-0
Timestamp: 2026-02-22T19:37:35.242Z
Learning: Applies to **/*.tsx : Implement cell-level diffing—show side-by-side or inline diffs for conflicting cells, not raw JSON lines
Learnt from: CR
Repo: Avni2000/MergeNB PR: 0
File: AGENTS.md:0-0
Timestamp: 2026-02-22T19:37:35.242Z
Learning: Use content-based cell matching algorithm (cellMatcher.ts) for 3-way merge logic
Learnt from: CR
Repo: Avni2000/MergeNB PR: 0
File: AGENTS.md:0-0
Timestamp: 2026-02-22T19:37:35.242Z
Learning: Applies to src/tests/registry.ts : Organize integration tests into groups in src/tests/registry.ts and add new tests there
Learnt from: CR
Repo: Avni2000/MergeNB PR: 0
File: AGENTS.md:0-0
Timestamp: 2026-02-22T19:37:35.242Z
Learning: Use LCS-based text diffing with inline change detection (diffUtils.ts) for conflict comparison
Summary by CodeRabbit
Bug Fixes
Refactor
Tests