Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CloudSlang Prompts should no longer pop-up to end-users for inputs with value #1431

Merged
merged 6 commits into from
Jun 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,8 @@ public Map<String, Value> bindInputs(List<Input> inputs,
Set<SystemProperty> systemProperties,
List<Input> missingInputs,
boolean useEmptyValuesForPrompts,
Map<String, Prompt> prompts) {
Map<String, Prompt> prompts,
boolean isCslangPromptEnabled) {
Map<String, Value> resultContext = new LinkedHashMap<>();

// we do not want to change original context map
Expand All @@ -70,7 +71,7 @@ public Map<String, Value> bindInputs(List<Input> inputs,
input = overridePromptSettingIfExists(prompts, input);

bindInput(input, srcContext, actualPromptContext, resultContext,
systemProperties, missingInputs, useEmptyValuesForPrompts);
systemProperties, missingInputs, useEmptyValuesForPrompts, isCslangPromptEnabled);
}

return resultContext;
Expand All @@ -79,7 +80,7 @@ public Map<String, Value> bindInputs(List<Input> inputs,
private void bindInput(Input input, Map<String, ? extends Value> context,
Map<String, Value> promptContext, Map<String, Value> targetContext,
Set<SystemProperty> systemProperties, List<Input> missingInputs,
boolean useEmptyValuesForPrompts) {
boolean useEmptyValuesForPrompts, boolean isCslangPromptEnabled) {
Value value;

String inputName = input.getName();
Expand All @@ -104,15 +105,26 @@ private void bindInput(Input input, Map<String, ? extends Value> context,
}

if (input.hasPrompt()) {
if (useEmptyValuesForPrompts) {
if (isNull(value)) {
value = createEmptyValue(input);
if (!isCslangPromptEnabled) {
if (isNull(value) || isEmpty(value)) {
if (useEmptyValuesForPrompts) {
value = createEmptyValue(input);
} else if (isNull(promptValue)) {
resolvePromptExpressions(input, context, targetContext, systemProperties);
missingInputs.add(createMissingInput(input, value));
return;
}
}
} else {
if (useEmptyValuesForPrompts) {
if (isNull(value)) {
value = createEmptyValue(input);
}
} else if (isNull(promptValue)) {
resolvePromptExpressions(input, context, targetContext, systemProperties);
missingInputs.add(createMissingInput(input, value));
return;
}
} else if (isNull(promptValue)) {
resolvePromptExpressions(input, context, targetContext, systemProperties);

missingInputs.add(createMissingInput(input, value));
return;
}
} else if (input.isRequired() && isEmpty(value)) {
missingInputs.add(input);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -185,14 +185,16 @@ public void startExecutable(@Param(ScoreLangConstants.EXECUTABLE_INPUTS_KEY) Lis
Map<String, Value> magicVariables = magicVariableHelper.getGlobalContext(executionRuntimeServices);
List<Input> missingInputs = new ArrayList<>();
ReadOnlyContextAccessor context = new ReadOnlyContextAccessor(callArguments, magicVariables);
boolean isCslangPromptEnabled = executionRuntimeServices.getCslangPromptsEnabledFlag();
Map<String, Value> boundInputValues = inputsBinding.bindInputs(
newExecutableInputs,
context.getMergedContexts(),
promptedValues,
runEnv.getSystemProperties(),
missingInputs,
isTrue(useEmptyValuesForPrompts),
promptArguments);
promptArguments,
isCslangPromptEnabled);

boolean continueToNext = true;
if (systemContext.containsKey(ScoreLangConstants.USER_INTERRUPT)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -515,7 +515,7 @@ private Map<String, Value> bindInputs(List<Input> inputs, Map<String, Value> con
Map<String, Value> promptArgs,
Set<SystemProperty> systemProperties, List<Input> missingInputs) {
return inputsBinding.bindInputs(inputs, context, promptArgs, systemProperties, missingInputs,
false, new HashMap<>());
false, new HashMap<>(), true);
}

private Map<String, Value> bindInputs(List<Input> inputs, Map<String, Value> context) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -138,9 +138,11 @@ public void testStartWithInput() {
Map<String, Value> resultMap = new HashMap<>();
resultMap.put("input1", ValueFactory.create(5));

when(inputsBinding.bindInputs(eq(inputs), anyMap(), anyMap(), anySet(), anyList(), anyBoolean(), anyMap()))
when(inputsBinding
.bindInputs(eq(inputs), anyMap(), anyMap(), anySet(), anyList(), anyBoolean(), anyMap(), anyBoolean()))
.thenReturn(resultMap);
executableSteps.startExecutable(inputs, runEnv, new HashMap<String, Value>(),
executableSteps
.startExecutable(inputs, runEnv, new HashMap<String, Value>(),
new ExecutionRuntimeServices(), "", 2L, ExecutableType.FLOW, new SystemContext(), false);

Map<String, Value> opVars = runEnv.getStack().popContext().getImmutableViewOfVariables();
Expand Down Expand Up @@ -168,7 +170,8 @@ public void testBoundInputEvent() {
resultMap.put("input1", ValueFactory.create(inputs.get(0).getValue()));
resultMap.put("input2", ValueFactory.create(inputs.get(1).getValue()));

when(inputsBinding.bindInputs(eq(inputs), anyMap(), anyMap(), anySet(), anyList(), anyBoolean(), anyMap()))
when(inputsBinding
.bindInputs(eq(inputs), anyMap(), anyMap(), anySet(), anyList(), anyBoolean(), anyMap(), anyBoolean()))
.thenReturn(resultMap);
executableSteps.startExecutable(inputs, runEnv, new HashMap<String, Value>(),
runtimeServices, "dockerizeStep", 2L, ExecutableType.FLOW, new SystemContext(), false);
Expand Down