Skip to content

fix(DataMapper): Preserve sibling variable after choice - #3594

Open
pvillant wants to merge 1 commit into
KaotoIO:mainfrom
pvillant:fix/sibling-variable-choice-bug
Open

fix(DataMapper): Preserve sibling variable after choice#3594
pvillant wants to merge 1 commit into
KaotoIO:mainfrom
pvillant:fix/sibling-variable-choice-bug

Conversation

@pvillant

@pvillant pvillant commented Jul 31, 2026

Copy link
Copy Markdown
Contributor

Resolves: #3452

Screen.Recording.2026-07-31.at.10.49.11.mov

Summary by CodeRabbit

  • Bug Fixes

    • Preserved variable items when cleaning up stale mappings for a document.
    • Prevented valid mapping content from being removed during stale-mapping cleanup.
  • Tests

    • Added regression coverage to verify variable items remain intact.

@coderabbitai

coderabbitai Bot commented Jul 31, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

📝 Walkthrough

Walkthrough

removeStaleMappingsForDocument() now preserves VariableItem children during target-document cleanup. A regression test verifies that an inserted variable and the mapping child count remain unchanged.

Changes

Mapping cleanup

Layer / File(s) Summary
Preserve VariableItem children
packages/ui/src/services/mapping/mapping.service.ts, packages/ui/src/services/mapping/mapping.service.test.ts
Stale-mapping cleanup retains VariableItem nodes. A regression test verifies variable and child-count preservation.

Estimated code review effort: 2 (Simple) | ~10 minutes

Possibly related PRs

Suggested reviewers: igarashitm, mmelko, tplevko

Poem

A rabbit found a variable small,
Safe beside the mapping wall.
Cleanup came with pruning teeth,
But left that node and siblings beneath.
The tree stayed whole, from root to leaf.

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Linked Issues check ✅ Passed The code preserves VariableItem children and adds a regression test for issue #3452.
Out of Scope Changes check ✅ Passed All changes directly support preserving variables during stale-mapping cleanup.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly describes preserving a sibling variable after a choice selection, which is the primary change in the pull request.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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.

@sonarqubecloud

Copy link
Copy Markdown

@pvillant

Copy link
Copy Markdown
Contributor Author

@coderabbitai review

@coderabbitai

coderabbitai Bot commented Jul 31, 2026

Copy link
Copy Markdown
Contributor
✅ Action performed

Review finished.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@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.

🧹 Nitpick comments (1)
packages/ui/src/services/mapping/mapping.service.test.ts (1)

668-670: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Assert that cleanup retains the original VariableItem instance.

The current find() check passes if cleanup replaces variable with a new item that has the same name. Assert reference identity so the test detects loss of VariableItem state.

Proposed assertion
-      const retained = parentItem.children.find((c) => c instanceof VariableItem && c.name === 'myVar');
-      expect(retained).toBeDefined();
+      expect(parentItem.children).toContain(variable);
+      expect(variable.parent).toBe(parentItem);
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@packages/ui/src/services/mapping/mapping.service.test.ts` around lines 668 -
670, Update the cleanup assertion in the test around parentItem.children to
verify that the retained entry is the original VariableItem instance, not merely
an item with the same name; capture or reuse the pre-cleanup variable reference
and assert reference identity while preserving the existing children-length
check.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Nitpick comments:
In `@packages/ui/src/services/mapping/mapping.service.test.ts`:
- Around line 668-670: Update the cleanup assertion in the test around
parentItem.children to verify that the retained entry is the original
VariableItem instance, not merely an item with the same name; capture or reuse
the pre-cleanup variable reference and assert reference identity while
preserving the existing children-length check.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 599809fc-8170-4363-8a99-4e18ad25d189

📥 Commits

Reviewing files that changed from the base of the PR and between dab84fd and 484c0c2.

📒 Files selected for processing (2)
  • packages/ui/src/services/mapping/mapping.service.test.ts
  • packages/ui/src/services/mapping/mapping.service.ts

@pvillant
pvillant requested a review from a team July 31, 2026 09:47
@pvillant
pvillant marked this pull request as ready for review July 31, 2026 09:47

@igarashitm igarashitm left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Fix LGTM 👍

However the screencast reveals a bug, when choice selection is made to dataValue after variable creation, the dataValue node gets an expand button at left despite of being string leaf field. Could you either:

  • Fix it together if it's trivial
  • File an issue otherwise

@igarashitm

Copy link
Copy Markdown
Member

Also, this assertion improvement sounds nice to have and low hanging - #3594 (review)

@igarashitm

Copy link
Copy Markdown
Member

Verified this "expand button on leaf field" issue reproduces without variable creation #3594 (review)

Interestingly, if I reproduce it after creating a variable, then remove the variable, the button disappears.

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.

DataMapper: Variable node disappears when sibling choice is selected

2 participants