rewrite icon indicating copy to clipboard operation
rewrite copied to clipboard

Yaml `new DeleteKey("$.*")` leads to two cycles if followed by `new MergeYaml`

Open timtebeek opened this issue 1 year ago • 1 comments

This test fails with the Expected recipe to complete in 1 cycle, but took 2 cycles. Each individual recipe would pass its own equivalent test, so this is a minimal subset required to fail the test.

Also this test no longer fails if the JSON matcher passed to DeleteKey is $.x rather than $.*. So there is clearly something different about how DeleteKey operates when asked to remove all root entries rather than the only root entry.

class CycleTest implements RewriteTest {

    @Test
    void testCycles() {
        rewriteRun(
            spec -> spec.recipe(
                new CompositeRecipe(
                    List.of(
                        new DeleteKey("$.*"),
                        new MergeYaml("$", "foo: bar", null, "test.yml", null)
                    )
                )
            ),
            yaml(
                """
                x: y
                """,
                """
                foo: bar
                """,
                spec -> spec.path("test.yml")
            )
        );
    }
}

Slack Message

timtebeek avatar Jan 26 '24 17:01 timtebeek

I think I remember having to allow this recipe to use two cycles in many tests. As this is a pretty frequently used recipe, it would be great if we could fix this.

knutwannheden avatar Jan 26 '24 18:01 knutwannheden