Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

#1124 Reason explanation id ambiguity #1125

Merged

Conversation

seregamorph
Copy link
Contributor

@seregamorph seregamorph commented Feb 6, 2024

The solution proposal for #1124

Sample failure message:

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':app:reason'.
> A failure occurred while executing com.autonomousapps.tasks.ReasonTask$ExplainDependencyAdviceAction
   > Could not create an instance of type com.autonomousapps.tasks.ReasonTask$ExplainDependencyAdviceAction.
      > Coordinates ':lis' matches more than 1 dependency [:list, :list-default, :list-impl]

and at the same time it works if --id is specified as :list as it fully matches one of the dependencies full name.

Sample test cases explaining updated behavior. Consider a project with these project dependencies:

  • :list
  • :list:sublist
  • :list-default
  • :list-impl

and library dependencies

  • com.squareup.okio:okio-jvm:3.0.0
  • com.squareup.okio:okio:3.0.0
--id res message
:li Coordinates ':li' matches more than 1 dependency [:list, :list:sublist, :list-default, :list-impl]
:list You asked about the dependency ':list'
:list: You asked about the dependency ':list:sublist'
:list-d You asked about the dependency ':list-default'
com.squareup.okio:oki Coordinates 'com.squareup.okio:oki' matches more than 1 dependency [com.squareup.okio:okio-jvm:3.0.0, com.squareup.okio:okio:3.0.0]
com.squareup.okio:okio You asked about the dependency 'com.squareup.okio:okio:3.0.0
com.squareup.okio:okio: You asked about the dependency 'com.squareup.okio:okio:3.0.0
com.squareup.okio:okio:3.0.0 You asked about the dependency 'com.squareup.okio:okio:3.0.0
com.squareup.okio:okio- You asked about the dependency 'com.squareup.okio:okio-jvm:3.0.0

@seregamorph seregamorph changed the title #1124 Reason explanation ambiguity #1124 Reason explanation id ambiguity Feb 6, 2024
@autonomousapps
Copy link
Owner

Would you be willing to write a test that specifically exercises this new code?

@seregamorph
Copy link
Contributor Author

For unit testing it looks trivial, but perhaps you mean another type of test. This is my first submission here, so I'm not quite familiar with test approach in this project - please give a good reference what you mean :)

@seregamorph
Copy link
Contributor Author

Well, I see failed test and probably functionalTest jvm.BundleSpec can be a good candidate for enhancement?

@autonomousapps
Copy link
Owner

I think you could update JvmReasonSpec maybe. Most of the time, new tests can be written by copy/pasting other related tests and tweaking slightly.

@seregamorph
Copy link
Contributor Author

@autonomousapps can you please recheck the PR?

@seregamorph seregamorph force-pushed the reason-explain-ambiguity branch 2 times, most recently from 9304b6d to 956eccb Compare February 7, 2024 12:26
@seregamorph seregamorph marked this pull request as draft February 7, 2024 18:42
@seregamorph seregamorph marked this pull request as ready for review February 8, 2024 14:22
@seregamorph
Copy link
Contributor Author

seregamorph commented Feb 8, 2024

I've discovered one more related problem. The project submodules are represented with both first and second coordinates key segment. Consider sample module with dependencies that have keys in dependencyUsages.entries:

  • "demo-gradle-multi-module:list|:list"
  • "demo-gradle-multi-module:list:sublist|:list:sublist"

and the filter --id=demo-.

Old behavior: it will take first non-ordered, there is ambiguity. In my experiment it took

----------------------------------------
You asked about the dependency 'demo-gradle-multi-module:list'.
There is no advice regarding this dependency.
----------------------------------------

The new behavior:

* What went wrong:
Execution failed for task ':app:reason'.
> A failure occurred while executing com.autonomousapps.tasks.ReasonTask$ExplainDependencyAdviceAction
   > Coordinates 'demo-' matches more than 1 dependency [:list, :list:sublist]

Instead of ambiguity it throws failure. But the error message can be confusing: we were filtering by demo-*, got :list*.
But from my perspective it's not a new problem, it does not make it worse than it was and I'd say it's a succession behavior :)

WDYT?

@seregamorph
Copy link
Contributor Author

Do you still have concerns or just need more time for better validation of the change?

@autonomousapps
Copy link
Owner

Do you still have concerns or just need more time for better validation of the change?

Just more time. I've been underwater at work. Thanks for your patience.

@@ -253,6 +253,29 @@ abstract class ReasonTask @Inject constructor(
}

private fun wasFiltered(): Boolean = finalAdvice == null && unfilteredAdvice != null

internal companion object {
internal fun findFilteredDependencyKey(dependencies: Set<Map.Entry<String, Any>>, requestedId: String): String? {
Copy link
Owner

Choose a reason for hiding this comment

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

does this need to be internal instead of private?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

because of accessing from the unit test

import org.junit.jupiter.api.Assertions.assertThrows
import org.junit.jupiter.api.Test

class ReasonTaskTest {
Copy link
Owner

Choose a reason for hiding this comment

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

Thank you for this great unit test

@autonomousapps autonomousapps merged commit c08a991 into autonomousapps:main Feb 22, 2024
1 check passed
@seregamorph seregamorph deleted the reason-explain-ambiguity branch February 22, 2024 20:50
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.

None yet

2 participants