Skip to content

Conversation

pstreef
Copy link
Contributor

@pstreef pstreef commented Sep 10, 2025

What's changed?

This PR solves 2 issues:

  1. Result only returns the estimated time savings from the first recipe that made a change to a file. This change sums up the estimated time of all changes to a file (however, this still does not take occurrences into account).

  2. SourcesFileResults has rows for all recipes in the hierarchy for tracability. Because each of these rows has an estimated time savings (of the actual change) summing the column gives the wrong values. By only setting the value to the leaf recipe this column becomes sum-able.

What's your motivation?

Aligning the estimated time savings and making the results easier to understand

Anything in particular you'd like reviewers to focus on?

There might have been a good reason to only expose the first value in Result.

Anyone you would like to review specifically?

@jkschneider

Have you considered any alternatives or workarounds?

We could chose to only go forward with either solution, however I expect this will remain hard to explain.

Note: that this solution works around the problem that we do not have a number of occurrences per Recipe (stack) in Result . If we would have that occurrence count (which would be a non trivial change) we could give an actual value and not just assume 1 change by each recipe that made a change.

Any additional context

Checklist

  • I've added unit tests to cover both positive and negative cases
  • I've read and applied the recipe conventions and best practices
  • I've used the IntelliJ IDEA auto-formatter on affected files

This PR solves 2 issues:
1. Result only returns the estimated time savings from the first recipe that made a change to a file. This change sums up the estimated time of all changes to a file (however, this still does not take occurrences into account).

2. `SourcesFileResults` has rows for all recipes in the hierarchy for tracability. Because each of these rows has an estimated time savings (of the actual change) summing the column gives the wrong values. By only setting the value to the leaf recipe this column becomes sum-able.
@pstreef pstreef self-assigned this Sep 10, 2025
@pstreef pstreef moved this from In Progress to Ready to Review in OpenRewrite Sep 10, 2025
@pstreef pstreef marked this pull request as ready for review September 10, 2025 10:09
@@ -68,8 +73,7 @@ public Result(@Nullable SourceFile before, @Nullable SourceFile after, Collectio
if (recipesStack != null && !recipesStack.isEmpty()) {
Duration perOccurrence = recipesStack.get(recipesStack.size() - 1).getEstimatedEffortPerOccurrence();
if (perOccurrence != null) {
timeSavings = perOccurrence;
break;
timeSavings = timeSavings.plus(perOccurrence);
Copy link
Member

Choose a reason for hiding this comment

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

This fundamentally alters the intention of the calculation from only summing one of the recipes in the stack to each recipe in the stack contributing time savings. I think we intentionally did not design it this way.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Exactly, which is why I noted there might be a good reason for this in the description. Either way not summing these here is what introduces the difference in what SourcesFileResult summing (if done correctly) gives you. This is confusing people.

I think neither approach is "fully correct" because neither takes occurences into account, however, there currently isn't a viable mechanism to do that.

I wonder if so, why it was designed this way. Why are we picking the first? And nog the sum or the highest value?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Now re-reading what you said. We're not summing the recipes in 1 stack, but all the last (leaf) recipes in each stack. So that if multiple recipe (stacks) made a change to a file, we sum those estimated times up. Just like we would in the (corrected) SourcesFileResults

@github-project-automation github-project-automation bot moved this from Ready to Review to In Progress in OpenRewrite Sep 11, 2025
@@ -138,6 +142,10 @@ private static boolean subtreeChanged(Tree root, Map<UUID, Tree> beforeTrees) {
}.reduce(root, new AtomicBoolean(false)).get();
}

/** Sum of estimated time savings of all recipes that made changes to this source file.
Copy link
Member

Choose a reason for hiding this comment

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

nit: incorrectly formatted Javadoc.

@@ -129,6 +131,99 @@ void customEstimatedEffortForRecipeThatGeneratesSourceFiles() {
));
}

@Test
void summedEstimatedEffortForMultipleChangesToSameFile() {
Copy link
Member

Choose a reason for hiding this comment

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

nit: this test at nearly 100 lines is too complicated to really understand at a glance.

@jkschneider
Copy link
Member

It sounds like somewhere along the line SourcesFileResults may have changed in a way that it wasn't intended originally. For a recipe stack A -> B -> C there should only be a single row with a recipe column of C and parent recipe column of B.

@pstreef
Copy link
Contributor Author

pstreef commented Sep 11, 2025

It sounds like somewhere along the line SourcesFileResults may have changed in a way that it wasn't intended originally. For a recipe stack A -> B -> C there should only be a single row with a recipe column of C and parent recipe column of B.

Ok, so to solve the issue there we could remove the recursion altogether which adds the full stack. That solves 1 issue, but not the other. Do we want to keep the difference in the 2 summed estimated values?

@pstreef pstreef requested a review from jkschneider September 15, 2025 14:17
Copy link
Contributor

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

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

Some suggestions could not be made:

  • rewrite-groovy/src/main/java/org/openrewrite/groovy/GroovyParserVisitor.java
    • lines 471-471
    • lines 558-559

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: In Progress
Development

Successfully merging this pull request may close these issues.

3 participants