Skip to content

ShellInputProvider inputs are not consumed by ComponentFlow-based interactive components (e.g. ConfirmationInput, StringInput) #1383

Description

@Tountoun

When a command runs a ComponentFlow with two sequential steps and the test supplies two queued inputs via ShellInputProvider.Builder#withInput(String), the flow throws a NoSuchElementException on the second step's context key — regardless of the value supplied (tested with "y", "yes", "true").

Steps to reproduce

Command under test:

```java
@component
public class ExampleCommand {

private final ComponentFlow.Builder builder;

public ExampleCommand(ComponentFlow.Builder builder) {
    this.builder = builder;
}

@Command(name = "example")
public String example() {
    ComponentFlow flow = builder.clone().reset()
        .withStringInput("reason")
            .name("Reason:")
            .and()
        .withConfirmationInput("confirm")
            .name("Confirm?")
            .and()
        .build();

    ComponentFlow.ComponentFlowResult result = flow.run();
    boolean confirmed = result.getContext().get("confirm");
    return confirmed ? "Confirmed" : "Cancelled";
}

}
```

Test:

```java
@ShellTest
@ContextConfiguration(classes = ExampleApplication.class)
class ExampleCommandTest {

@Test
void testExample(@Autowired ShellTestClient client) throws Exception {
    ShellInputProvider provider = ShellInputProvider.providerFor("example")
        .withInput("some reason")
        .withInput("true")
        .build();

    ShellScreen screen = client.sendCommand(provider);

    ShellAssertions.assertThat(screen).containsText("Confirmed");
}

}
```

Expected behavior

The queued inputs are consumed sequentially by the ComponentFlow steps, and the flow completes with confirm = true.

Actual behavior

```
java.util.NoSuchElementException: Context does not contain key: confirm
at org.springframework.shell.jline.tui.component.context.BaseComponentContext.get(BaseComponentContext.java:44)
at ExampleCommand.example(ExampleCommand.java:...)
...
```

The exception is identical regardless of the value queued via withInput(...) (tried "y", "yes", "true"), which suggests the input is never reaching the ComponentFlow/ConfirmationInput reading mechanism at all, rather than being rejected as an invalid value.

Is ComponentFlow end-to-end testing currently expected to be unsupported in 4.0.3, or is there a recommended workaround I'm missing?

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    status/need-triageTeam needs to triage and take a first look

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions