Skip to content

test(model): Fix the test for cyclic dependencies#11426

Merged
sschuberth merged 1 commit into
mainfrom
deps-comp-imps
Mar 20, 2026
Merged

test(model): Fix the test for cyclic dependencies#11426
sschuberth merged 1 commit into
mainfrom
deps-comp-imps

Conversation

@sschuberth
Copy link
Copy Markdown
Member

Please have a look at the individual commit messages for the details.

Comment thread model/src/main/kotlin/utils/DependencyGraphBuilder.kt Fixed
Comment thread model/src/main/kotlin/utils/DependencyHandler.kt Fixed
@codecov
Copy link
Copy Markdown

codecov Bot commented Feb 12, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 58.40%. Comparing base (fbdf7cb) to head (25d7468).
⚠️ Report is 1 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff            @@
##               main   #11426   +/-   ##
=========================================
  Coverage     58.40%   58.40%           
+ Complexity     1759     1758    -1     
=========================================
  Files           355      355           
  Lines         13219    13219           
  Branches       1314     1314           
=========================================
  Hits           7721     7721           
  Misses         5008     5008           
  Partials        490      490           
Flag Coverage Δ
funTest-external-tools 14.56% <ø> (-0.03%) ⬇️
funTest-no-external-tools 30.54% <ø> (ø)
test-ubuntu-24.04 42.44% <ø> (-0.02%) ⬇️
test-windows-2025 42.42% <ø> (-0.02%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

.build(checkReferences = false)

graph.nodes shouldHaveSize 6
graph.edges shouldHaveSize 5
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.

It could be nice to verify the actual edges here to demonstrate how the cycles are broken.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

While debugging this with PNPM-specific changes on top, it looks to be as if indeed the cycle is broken at the "wrong" place. I need to further investigate this; moving back to draft.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

as if indeed the cycle is broken at the "wrong" place.

This was fixed by #11575. I've added verification of the actual edges to the test now.

val depFoo = createDependency("org.foo", "foo", "1.2.0", dependencies = setOf(depCyc1))
val depCyc2 = createDependency("org.cyclic", "cyclic", "77.7", dependencies = setOf(depFoo))
// TODO: Enable this once the functionality to break cycles is fully implemented.
"deal with cycles in dependencies".config(enabled = false) {
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.

"deal with cycles" is so unspecific, how about also changing it to "break cycles"?

addDependencyToGraph(scopeName, it, transitive = true, processed)
if (it in processed) {
return@mapNotNullTo null
}
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.

In #11207 I had this problem with this change:

The second commit tries to fix that issue by breaking cycles in transitive dependencies. With that fix, the first stack overflow does not happena anymore, but then there is a stack overflow in the default implementation of DependencyHandler.areDependenciesEqual when it tries to compare the dependency subtrees when adding the nodes.

Is this somehow solved by the early returns you added in the first commit?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Is this somehow solved by the early returns you added in the first commit?

Yes, at least that fixed the stack overflow I was seeing in my PNPM experiments.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

there is a stack overflow in the default implementation of DependencyHandler.areDependenciesEqual

#11575 also added another safeguard in this regard.

Comment thread model/src/test/kotlin/utils/DependencyGraphBuilderTest.kt Outdated
@sschuberth sschuberth marked this pull request as draft February 12, 2026 12:04
@sschuberth sschuberth force-pushed the deps-comp-imps branch 3 times, most recently from 8400556 to 758eb13 Compare March 20, 2026 11:45
There is no cycle in the originally defined

    depCyc2 -> depFoo -> depCyc1

dependency chain. Doing so is actually not directly possible with the
recursively defined `PackageReference` class.

Solve that by using a primitive `DependencyHandler` that just uses
indexes to identify dependencies.

The test passes thanks to the fix recently made in 80edb57.

Signed-off-by: Sebastian Schuberth <sebastian@doubleopen.org>
@sschuberth sschuberth marked this pull request as ready for review March 20, 2026 11:49
@sschuberth sschuberth changed the title Dependency comparison improvements test(model): Fix the test for cyclic dependencies Mar 20, 2026
@sschuberth sschuberth enabled auto-merge (rebase) March 20, 2026 11:56
@sschuberth sschuberth merged commit 403c91c into main Mar 20, 2026
36 of 40 checks passed
@sschuberth sschuberth deleted the deps-comp-imps branch March 20, 2026 12:53
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.

3 participants