Skip to content

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

@timtebeek

Description

@timtebeek

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.

import org.junit.jupiter.api.Test;
import org.openrewrite.config.CompositeRecipe;
import org.openrewrite.test.RewriteTest;

import java.util.List;

import static org.openrewrite.yaml.Assertions.yaml;

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

Slack Message

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    Status

    Done

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions