Skip to content

Conversation

@iransamarasekara
Copy link
Contributor

@iransamarasekara iransamarasekara commented Dec 16, 2025

Summary by CodeRabbit

  • Tests
    • Expanded test coverage for profile unification scenarios, including cascading merges, hierarchical unifications, multi-attribute matching with priority resolution, and application data merging validation.

✏️ Tip: You can customize this high-level summary in your review settings.

@CLAassistant
Copy link

CLAassistant commented Dec 16, 2025

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you all sign our Contributor License Agreement before we can accept your contribution.
0 out of 2 committers have signed the CLA.

❌ iransamarasekara
❌ Copilot
You have signed the CLA already but the status is still pending? Let us recheck it.

@coderabbitai
Copy link

coderabbitai bot commented Dec 16, 2025

Walkthrough

The PR adds a direct dependency on github.com/pkg/errors, expands test documentation with 10 new unification scenarios (10–19), and introduces a new integration test file covering advanced profile unification behaviors including cascading merges and multi-attribute matching.

Changes

Cohort / File(s) Summary
Dependency Management
go.mod
Moved github.com/pkg/errors from indirect to direct dependency in the require block.
Test Coverage Expansion
test/Unification_Scenarios.MD, test/integration/complex_unification_test.go
Added 10 new test scenarios (10–19) documenting complex unification behaviors. New integration test file implements these scenarios, validating cascading merges, deep hierarchies, multi-attribute matching, transitive unifications, application data merging, and rule reactivation across multiple profiles with setup and cleanup logic.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

  • Integration test file logic: Verify correctness of test setup (profile/schema/rule configuration), scenario implementations (merging conditions and assertions), and cleanup procedures.
  • Scenario coverage: Ensure all 10 new scenarios properly exercise the unification behavior documented in the matrix.
  • Data assertions: Confirm assertions validate merged profiles, attribute merging (emails, phones, traits, app data), and expected master/merged relationships.

Poem

🐰 Ten new tales of profiles that bind,
Cascading merges, hierarchies aligned!
Direct dependencies, tests refined—
Our unification dreams, clearly outlined! ✨

Pre-merge checks and finishing touches

❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Description check ⚠️ Warning The pull request has no description provided, missing all required template sections including Purpose, Goals, Approach, Automation tests, and Security checks. Add a comprehensive pull request description following the repository template, including Purpose, Goals, Approach, Automation tests details, and relevant sections.
✅ Passed checks (2 passed)
Check name Status Explanation
Title check ✅ Passed The title 'Add complex object unification tests' is clear and directly describes the main changes: new test scenarios and integration tests for profile unification.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.
✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

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.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 2

🧹 Nitpick comments (3)
test/Unification_Scenarios.MD (1)

59-68: Documentation looks good.

The new scenarios 10–19 are well documented and align with the integration tests. As a minor style note, "merge together" (lines 61, 62) could be shortened to just "merge" for conciseness.

test/integration/complex_unification_test.go (2)

138-151: Check errors from profile operations to catch failures early.

Ignoring errors from CreateProfile and GetProfile can hide infrastructure issues or service bugs. Consider using require.NoError for these critical operations.

-	prof1, _ := profileSvc.CreateProfile(p1, SuperTenantOrg)
+	prof1, err := profileSvc.CreateProfile(p1, SuperTenantOrg)
+	require.NoError(t, err, "Failed to create prof1")
 	time.Sleep(500 * time.Millisecond)
-	prof2, _ := profileSvc.CreateProfile(p2, SuperTenantOrg)
+	prof2, err := profileSvc.CreateProfile(p2, SuperTenantOrg)
+	require.NoError(t, err, "Failed to create prof2")

This pattern should be applied consistently across all test scenarios.


146-146: Consider polling-based waits for more reliable tests.

Fixed time.Sleep durations (e.g., 3 seconds) can cause flakiness under varying CI load. A polling approach that checks for the expected state with a timeout would be more robust. This is optional given the documented approach.

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between de1cf8c and 3ccf3c7.

📒 Files selected for processing (3)
  • go.mod (1 hunks)
  • test/Unification_Scenarios.MD (1 hunks)
  • test/integration/complex_unification_test.go (1 hunks)
🧰 Additional context used
🪛 LanguageTool
test/Unification_Scenarios.MD

[style] ~61-~61: ‘merge together’ might be wordy. Consider a shorter alternative.
Context: ...rofiles with different application data merge together. | App data from both profiles gets com...

(EN_WORDINESS_PREMIUM_MERGE_TOGETHER)


[style] ~62-~62: ‘merge together’ might be wordy. Consider a shorter alternative.
Context: ...ng email. | After update, both profiles merge together. | | 14 | Multiple Attributes Match...

(EN_WORDINESS_PREMIUM_MERGE_TOGETHER)

🔇 Additional comments (2)
test/integration/complex_unification_test.go (1)

564-572: Cleanup logic is well-structured.

Using t.Cleanup ensures resources are released even if tests fail. The cleanup order (rules → profiles → schema) is appropriate.

go.mod (1)

10-10: The github.com/pkg/errors package is directly imported in internal/system/utils/error_utils.go and properly marked as a direct dependency in go.mod. The promotion from indirect to direct is justified and correct.

Likely an incorrect or invalid review comment.

Comment on lines +100 to +127
_ = unificationSvc.AddUnificationRule(userIdRule, SuperTenantOrg)

emailRuleId := uuid.New().String()
emailRule := model.UnificationRule{
RuleId: emailRuleId,
TenantId: SuperTenantOrg,
RuleName: EmailBased,
PropertyName: "identity_attributes.email",
Priority: 1,
IsActive: true,
CreatedAt: time.Now().Unix(),
UpdatedAt: time.Now().Unix(),
}
_ = unificationSvc.AddUnificationRule(emailRule, SuperTenantOrg)

phoneRuleId := uuid.New().String()
phoneRule := model.UnificationRule{
RuleId: phoneRuleId,
TenantId: SuperTenantOrg,
RuleName: PhoneBased,
PropertyName: "identity_attributes.phone_number",
Priority: 2,
IsActive: true,
CreatedAt: time.Now().Unix(),
UpdatedAt: time.Now().Unix(),
}
_ = unificationSvc.AddUnificationRule(phoneRule, SuperTenantOrg)

Copy link

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟠 Major

Handle errors from unification rule setup.

Ignoring errors from AddUnificationRule can mask test setup failures, causing all subsequent tests to fail mysteriously. If rule creation fails, the tests will produce false negatives.

-	_ = unificationSvc.AddUnificationRule(userIdRule, SuperTenantOrg)
+	err = unificationSvc.AddUnificationRule(userIdRule, SuperTenantOrg)
+	require.NoError(t, err, "Failed to add user_id rule")

 	emailRuleId := uuid.New().String()
 	emailRule := model.UnificationRule{
 		RuleId:       emailRuleId,
 		TenantId:     SuperTenantOrg,
 		RuleName:     EmailBased,
 		PropertyName: "identity_attributes.email",
 		Priority:     1,
 		IsActive:     true,
 		CreatedAt:    time.Now().Unix(),
 		UpdatedAt:    time.Now().Unix(),
 	}
-	_ = unificationSvc.AddUnificationRule(emailRule, SuperTenantOrg)
+	err = unificationSvc.AddUnificationRule(emailRule, SuperTenantOrg)
+	require.NoError(t, err, "Failed to add email rule")

 	phoneRuleId := uuid.New().String()
 	phoneRule := model.UnificationRule{
 		RuleId:       phoneRuleId,
 		TenantId:     SuperTenantOrg,
 		RuleName:     PhoneBased,
 		PropertyName: "identity_attributes.phone_number",
 		Priority:     2,
 		IsActive:     true,
 		CreatedAt:    time.Now().Unix(),
 		UpdatedAt:    time.Now().Unix(),
 	}
-	_ = unificationSvc.AddUnificationRule(phoneRule, SuperTenantOrg)
+	err = unificationSvc.AddUnificationRule(phoneRule, SuperTenantOrg)
+	require.NoError(t, err, "Failed to add phone rule")
🤖 Prompt for AI Agents
In test/integration/complex_unification_test.go around lines 100 to 127, the
calls to unificationSvc.AddUnificationRule ignore returned errors during test
setup; change each call to capture the error and fail the test immediately if
non-nil (e.g., check the error and call t.Fatalf or use require.NoError with the
testing.T) so rule creation failures cause the test to stop with a clear message
instead of producing downstream false negatives.

Comment on lines +494 to +496
master1, _ := profileSvc.GetProfile(master1Id)
require.NotNil(t, master1, "Master1 should exist")
require.GreaterOrEqual(t, len(master1.MergedFrom), 4, "Master1 should have at least 3 children")
Copy link

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟡 Minor

Comment and assertion are inconsistent.

The comment says "at least 3 children" but the assertion checks >= 4. Clarify the expected count and align the comment with the assertion.

 		master1, _ := profileSvc.GetProfile(master1Id)
 		require.NotNil(t, master1, "Master1 should exist")
-		require.GreaterOrEqual(t, len(master1.MergedFrom), 4, "Master1 should have at least 3 children")
+		require.GreaterOrEqual(t, len(master1.MergedFrom), 3, "Master1 should have at least 3 children")
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
master1, _ := profileSvc.GetProfile(master1Id)
require.NotNil(t, master1, "Master1 should exist")
require.GreaterOrEqual(t, len(master1.MergedFrom), 4, "Master1 should have at least 3 children")
master1, _ := profileSvc.GetProfile(master1Id)
require.NotNil(t, master1, "Master1 should exist")
require.GreaterOrEqual(t, len(master1.MergedFrom), 3, "Master1 should have at least 3 children")
🤖 Prompt for AI Agents
In test/integration/complex_unification_test.go around lines 494 to 496, the
test comment and assertion disagree: the comment says "at least 3 children"
while the code asserts len(master1.MergedFrom) >= 4; make them consistent by
deciding the intended minimum (either 3 or 4) and updating either the numeric
comparison or the comment to match—if the expected minimum is 3 change the
assertion to require.GreaterOrEqual(t, len(master1.MergedFrom), 3, "...at least
3 children"), otherwise update the comment text to "at least 4 children".

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