Skip to content

fix: preserve deep taxonomy tree children#86

Merged
BhagyaAmarasinghe merged 2 commits into
mainfrom
fix-taxonomy-tree-nesting
Jun 15, 2026
Merged

fix: preserve deep taxonomy tree children#86
BhagyaAmarasinghe merged 2 commits into
mainfrom
fix-taxonomy-tree-nesting

Conversation

@BhagyaAmarasinghe

Copy link
Copy Markdown
Contributor

Summary

  • Fix taxonomy tree reconstruction so deep descendants are attached recursively instead of losing grandchildren when nodes are copied by value.
  • Add a regression test that builds a 5-level taxonomy path and verifies sorted level-4 leaves are preserved.

Why

The Formbricks taxonomy explorer depends on Hub returning the full tree. The previous reconstruction appended value copies before descendants were attached, so only shallow levels were visible in the UI.

Validation

  • go test ./internal/repository

@coderabbitai

coderabbitai Bot commented Jun 12, 2026

Copy link
Copy Markdown

Review Change Stack

Walkthrough

This PR refactors the taxonomy tree-building algorithm in buildTaxonomyTree. Previously, the function built a parent-pointer map and called a separate sorting helper. The new implementation constructs a childrenByParent lookup map once, locates the root node, and uses a new recursive attachTaxonomyChildren helper to populate the tree by assigning children from the map and sorting them stably by SortOrder and ID. A new test validates that the refactored logic correctly preserves deep multi-level child relationships.

🚥 Pre-merge checks | ✅ 3 | ❌ 2

❌ Failed checks (2 warnings)

Check name Status Explanation Resolution
Description check ⚠️ Warning The PR description includes a summary of changes and validation steps, but lacks the required 'How should this be tested?' section and most checklist items from the template. Add a detailed 'How should this be tested?' section with test instructions and check off the required checklist items, including build/test/lint commands and self-review confirmations.
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (3 passed)
Check name Status Explanation
Title check ✅ Passed The title 'fix: preserve deep taxonomy tree children' clearly and concisely summarizes the main change: fixing taxonomy tree reconstruction to preserve nested children.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

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


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

Choose a reason for hiding this comment

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

Actionable comments posted: 1

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

Inline comments:
In `@internal/repository/taxonomy_repository.go`:
- Around line 1056-1062: The code in buildTaxonomyTree silently drops any root
beyond the first by only setting root when root == nil and continuing, which
masks unexpected multi-root rows; instead keep the existing behavior of using
the first root but add a defensive log when another root is encountered: when
copyNode.ParentID == nil and root != nil, emit a warning (e.g.,
logger.Warn/Warnf) indicating multiple roots for the run and include identifying
info (run id / node id) rather than silently continuing; leave the initial set
root = &copyNode path unchanged.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: ASSERTIVE

Plan: Pro

Run ID: fc5037a7-dfca-44e8-9440-602602a6b1ed

📥 Commits

Reviewing files that changed from the base of the PR and between 4d165fb and a66adbf.

📒 Files selected for processing (2)
  • internal/repository/taxonomy_repository.go
  • internal/repository/taxonomy_repository_test.go

Comment thread internal/repository/taxonomy_repository.go

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

Fix the linting errors, other than that LGTM.

@BhagyaAmarasinghe BhagyaAmarasinghe added this pull request to the merge queue Jun 15, 2026
Merged via the queue into main with commit 9d175ee Jun 15, 2026
11 checks passed
@BhagyaAmarasinghe BhagyaAmarasinghe deleted the fix-taxonomy-tree-nesting branch June 15, 2026 10:52
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.

2 participants