rewrite icon indicating copy to clipboard operation
rewrite copied to clipboard

Support Postcondition in DeclarativeRecipe

Open amishra-u opened this issue 9 months ago • 2 comments

What problem are you trying to solve?

The Precondition feature in DeclarativeRecipe is great for filtering out files that are either unsupported or skipped for some other reasons. However, identifying which files a recipe can or cannot migrate isn’t always straightforward. Even if we define a precondition accurately, we might still encounter issues due to bugs in edit recipes or missing type attribution caused by parsing errors.

In such cases, a Postcondition feature would be extremely helpful. Since I know what the expected end state of the code should be, writing a recipe to validate that state is much more straightforward. If the postcondition is not met, I could simply discard the edits for that file.

Why this is important

Consider a scenario where I’m migrating a package with 1,000 files. If my recipe fails to correctly migrate even 10 of those files, running the build or tests post-migration could fail, halting the entire process. To continue, I’d need to manually fix the issues or update the recipe to handle those cases.

Having a Postcondition would allow me to automatically verify and discard edits in problematic files.

Describe the solution you'd like

A postcondition feature for DeclarativeRecipe similar to Precondition.

Are you interested in [contributing this feature to OpenRewrite]

Yes, but I’d appreciate feedback on this feature request before starting any work.

amishra-u avatar Apr 04 '25 17:04 amishra-u

@timtebeek @sambsnyd Please let me know if this make sense. I will work on it.

amishra-u avatar Apr 04 '25 17:04 amishra-u

I share your interest in adding wellness checks to the end of a recipe run and this speaks to that. One I've been thinking about how to implement is validating that dependency changes still lead to a classpath which provides all the types in use within the sources. Before we get to the point of adding anything to DeclarativeRecipe we should figure out what this looks like for a non-declarative recipe. In some cases it might just look like adding a search recipe to the end of a declarative recipe's recipe list, in which case no special framework support is required

sambsnyd avatar Apr 08 '25 00:04 sambsnyd

This issue is stale because it has not had any activity for 60 days. Remove question label or comment or this will be closed in two weeks. Issues may be reopened when there is renewed interest.

github-actions[bot] avatar Jul 28 '25 11:07 github-actions[bot]