diff --git a/CHANGELOG.md b/CHANGELOG.md index 58be338..8bfc527 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -13,6 +13,7 @@ Design: `docs/one-card-for-a-set.md` (parts A and B). **A host changes nothing, - *A review is judged before any step is answered.* The lines a review has are read first, for every shape of process: a warning or an error stops the run there. The assistant asks for "validate fully" only for core's own streamed process, whose validate step stores nothing and comes back to the review; for any other process the step after the review may be the one that stores, and a review of such a process is passed only on its own lines. A review with no lines is not passed. (`ProcessCardRecordTest.aReviewWithAWarningOrAnErrorIsJudgedBeforeAnyStepIsAnswered`, `aReviewThatSaysNothingOfTheRecordsIsNotPassedAndOneThatAgreesIs`) - *A screen is passed only against the record of what the card displayed.* The stored proposal keeps, for every screen the card displayed, its texts and its inputs with the value shown. A screen that is not on that record (a step outside the process's list, such as an optional step), an input that is not on it, a screen the process changed while it ran (`processMetaDataAdjustment`) and every screen of a state-machine process stop the run. (`ProcessCardRecordTest.aScreenThatWasNeverOnTheCardIsNotPassed`, `aScreenTheProcessChangedWhileItRanIsNotPassed`) - *A job that was not read is not described.* A job the person may not read, one the application does not answer for, and one in an unknown state is reported as "its outcome could not be read", with the action FAILED; never as running or done. A status check cancels nothing. (`ProcessJobPathTest.aJobThatCannotBeReadIsNeverReportedAsRunningOrDone`, `aStatusCheckCancelsNothing`) + - *(Second review.) A review's own inputs and values are held to the card.* The review branch judged only the count and the lines: a review with an option whose value the process had changed after the card was made ("Mode: soft (its default)" on the card, "hard" in the process), or with a value to read, was passed, and the storing step ran with what the card never showed. A review is now held to the record of what the card displayed like any other screen, before it is passed or answered: such a run stops with nothing stored, and the card to go on with shows the values the process holds. `ProcessCardRecordTest.aReviewsOwnInputsAndValuesAreHeldToWhatTheCardShowed`, `aReviewWhoseOwnInputIsAsTheCardShowedItIsPassed`. - A run or a job still working after the wait is reported as "started and has not finished". The names a card shows are in the application's order, not the model's. Every input of every screen is on the card, also one left empty. - **No card for what cannot happen.** `create_record`, `update_record`, `delete_record` and a table's own bulk edit and bulk delete ask the application, as the person, what it tells their own screens about the table. A person who may not make that kind of change is told so plainly and gets no card. The confirmed change is still decided by the UI API (a permission that goes between the card and the confirmation is refused there, with the application's own answer). - UI API extension `assistant` 1.11.0 (additive): `AssistantActionV1.recordCount`, `records`, `recordsBefore` for a run over a set. diff --git a/docs/one-card-for-a-set.md b/docs/one-card-for-a-set.md index 3cf5d6e..8974a99 100644 --- a/docs/one-card-for-a-set.md +++ b/docs/one-card-for-a-set.md @@ -76,6 +76,13 @@ texts, its inputs with the value shown for each, and the inputs shown as left em 4. The review is passed only on evidence: lines that are fine and count all of the card's records. A review with no lines says nothing of what will happen to the records and is the person's to read. +**A review is a screen too.** Before a review is passed, and before it is answered with "validate", what the review screen has of its own +is held to the same record of what the card displayed as any other screen (`ProcessTools.screenDiffers`): a text the card did not +display, an input the card did not show or whose value is no longer the one the card showed (the process changed an option after the card +was made), a value to read, or records it lists, stops the run with nothing stored. The card to go on with shows the review's inputs with +the values the process holds now and its values to read. The records a review lists are the card's own only for a table's bulk edit or +bulk delete. A count and lines that agree with the card say nothing of an option; they do not pass a review by themselves. + A run whose card named no records always stops at a review: there is nothing on the card the review could be the same as. A card that validates every record ("validate fully") stops at the review again, as it says. diff --git a/qbit-assistant/src/main/java/com/kingsrook/qbits/assistant/tools/process/ProcessTools.java b/qbit-assistant/src/main/java/com/kingsrook/qbits/assistant/tools/process/ProcessTools.java index 4b3499a..2a6a5ee 100644 --- a/qbit-assistant/src/main/java/com/kingsrook/qbits/assistant/tools/process/ProcessTools.java +++ b/qbit-assistant/src/main/java/com/kingsrook/qbits/assistant/tools/process/ProcessTools.java @@ -1637,8 +1637,30 @@ public class ProcessTools // validated first where the process can, so that is known // //////////////////////////////////////////////////////////////////// String differs = mayStep ? reviewDiffers(process, run, state) : ""; + if(mayStep && (differs == null || VALIDATE_FIRST.equals(differs))) + { + ///////////////////////////////////////////////////////////////// + // a review is a screen too. What it has of its own (a text, // + // an input with its value, a value to read, records it lists) // + // is passed only against the record of what the card // + // displayed, like any other screen, and before any step is // + // answered: a count and lines that agree say nothing of an // + // option the process changed, or of a value the card never had // + ///////////////////////////////////////////////////////////////// + String own = screenDiffers(process, table, screen, state, run, true); + differs = own == null ? differs : own; + } if(differs != null && !VALIDATE_FIRST.equals(differs)) { + if(shows(screen)) + { + /////////////////////////////////////////////////////////////// + // the card the run comes back with shows what the review // + // shows now: its inputs with the values the process has, // + // and its values to read // + /////////////////////////////////////////////////////////////// + show(call, run, process, screen, state); + } run.review = call.clean(review(state)); run.canValidateFully = !Boolean.FALSE.equals(ValueUtils.getValueAsBoolean(state.get("supportsFullValidation"))) && !Boolean.TRUE.equals(ValueUtils.getValueAsBoolean(state.get("doFullValidation"))); run.differs = differs.isEmpty() ? null : differs; @@ -1654,7 +1676,7 @@ public class ProcessTools // before anything goes on // //////////////////////////////////////////////////////////////////// run.validated |= differs != null; - answerValues = new LinkedHashMap<>(); + answerValues = valuesFor(screen, run.values); answerValues.put("doFullValidation", differs != null); } else @@ -1668,7 +1690,7 @@ public class ProcessTools missing.add(field.getName()); } } - String differs = missing.isEmpty() && mayStep ? screenDiffers(process, table, screen, state, run) : null; + String differs = missing.isEmpty() && mayStep ? screenDiffers(process, table, screen, state, run, false) : null; if(!missing.isEmpty() || !mayStep || differs != null) { run.missing = missing; @@ -1728,8 +1750,18 @@ public class ProcessTools ** In a process whose steps are a state machine the order of the screens ** is the process's to choose as it runs: no screen with something to show ** is passed there. + ** + ** A review is held to the same record for what it has of its own, before + ** its count and lines can pass it ({@link #reviewDiffers}): a review with + ** an input whose value is not the card's, an input the card did not show, + ** or a value to read, comes back to the person. The records a review lists + ** are the card's own only for a table's bulk edit or bulk delete (the card + ** names its records and the values that change); for any other process + ** they are records as the process made them, which the card never showed. + ** + ** @param review whether the screen is a review *******************************************************************************/ - private String screenDiffers(QProcessMetaData process, QTableMetaData table, QFrontendStepMetaData screen, Map state, Run run) + private String screenDiffers(QProcessMetaData process, QTableMetaData table, QFrontendStepMetaData screen, Map state, Run run, boolean review) { if(!shows(screen)) { @@ -1756,7 +1788,7 @@ public class ProcessTools { return ("It shows values to read that were not known when the card was made."); } - if(listsRecords(screen)) + if(listsRecords(screen) && !(review && ProcessRunnability.isTableBulkAction(process))) { return ("It lists records that were not known when the card was made."); } @@ -1915,6 +1947,9 @@ public class ProcessTools ** 4. the review is passed only on evidence: lines that are fine and count ** all of the card's records. A review with no lines says nothing of ** what will happen to the records, and is the person's to read. + ** This judges the count and the lines only. What else a review screen has + ** (inputs, values to read, records) is judged by {@link #screenDiffers}, + ** which the caller asks before it passes a review or answers it. *******************************************************************************/ private static String reviewDiffers(QProcessMetaData process, Run run, Map state) { diff --git a/qbit-assistant/src/test/java/com/kingsrook/qbits/assistant/tools/process/ProcessCardRecordTest.java b/qbit-assistant/src/test/java/com/kingsrook/qbits/assistant/tools/process/ProcessCardRecordTest.java index 76bd731..d145410 100644 --- a/qbit-assistant/src/test/java/com/kingsrook/qbits/assistant/tools/process/ProcessCardRecordTest.java +++ b/qbit-assistant/src/test/java/com/kingsrook/qbits/assistant/tools/process/ProcessCardRecordTest.java @@ -66,7 +66,11 @@ import static org.assertj.core.api.Assertions.assertThat; ** - a review with an error and a warning in a process that is not core's ** streamed one, answered with "validate first" before its lines were read; ** - a review that counts the card's records and says nothing else; - ** - a screen the process changed while it ran. + ** - a screen the process changed while it ran; + ** - (second review) a review with an input whose value the process changed + ** after the card was made, and a review with a value to read: its count and + ** its lines agreed with the card, so it was passed, and the storing step + ** ran with the option the card never showed. *******************************************************************************/ class ProcessCardRecordTest extends BaseAssistantTest { @@ -77,6 +81,9 @@ class ProcessCardRecordTest extends BaseAssistantTest private static final String QUIET = "quietReview"; private static final String AGREED = "agreedReview"; private static final String REWRITE = "rewriteScreen"; + private static final String OPTION = "reviewWithAnOption"; + private static final String CHANGED = "reviewWithAChangedOption"; + private static final String IMPACT = "reviewWithAValueToRead"; private static final String PURGE_TEXT = "Everything in the archive is purged as well, permanently."; @@ -132,6 +139,30 @@ class ProcessCardRecordTest extends BaseAssistantTest .withStep(result())); } + /////////////////////////////////////////////////////////////////////// + // reviews that have something of their own: an option with a default // + // (which the preview of one of them changes), and a value to read // + /////////////////////////////////////////////////////////////////////// + for(Object[] reviewed : new Object[][] { { OPTION, "Option Review", FinePreview.class, true }, { CHANGED, "Changed Option", ChangingPreview.class, true }, + { IMPACT, "Impact Review", ChangingPreview.class, false } }) + { + QFrontendStepMetaData review = new QFrontendStepMetaData().withName("review").withLabel("Review").withComponent(new QFrontendComponentMetaData().withType(QComponentType.VALIDATION_REVIEW_SCREEN)); + if((Boolean) reviewed[3]) + { + review.withComponent(new QFrontendComponentMetaData().withType(QComponentType.EDIT_FORM)).withFormField(new QFieldMetaData("mode", QFieldType.STRING).withLabel("Mode").withDefaultValue("soft")); + } + else + { + review.withComponent(new QFrontendComponentMetaData().withType(QComponentType.VIEW_FORM)).withViewField(new QFieldMetaData("impact", QFieldType.STRING).withLabel("Impact")); + } + qInstance.addProcess(process((String) reviewed[0], (String) reviewed[1]).withTableName("blog_post").withMinInputRecords(1) + .withStep(new QBackendStepMetaData().withName("preview").withCode(new QCodeReference((Class) reviewed[2])) + .withInputData(new QFunctionInputMetaData().withRecordListMetaData(new QRecordListMetaData().withTableName("blog_post")))) + .withStep(review) + .withStep(new QBackendStepMetaData().withName("store").withCode(new QCodeReference(ProcessFixture.Work.class))) + .withStep(result())); + } + /////////////////////////////////////////////////////////////////////// // a step replaces a screen that is on the card by one of its own // /////////////////////////////////////////////////////////////////////// @@ -173,7 +204,7 @@ class ProcessCardRecordTest extends BaseAssistantTest protected void customizeConfig(AssistantQBitConfig config) { List reviewed = new ArrayList<>(ProcessFixture.REVIEWED); - reviewed.addAll(List.of(TIDY, RETAG, QUIET, AGREED, REWRITE)); + reviewed.addAll(List.of(TIDY, RETAG, QUIET, AGREED, REWRITE, OPTION, CHANGED, IMPACT)); config.withReviewedProcesses(reviewed); } @@ -186,7 +217,7 @@ class ProcessCardRecordTest extends BaseAssistantTest void grant() { ProcessFixture.grant(RUNNER); - for(String name : List.of(TIDY, RETAG, QUIET, AGREED, REWRITE)) + for(String name : List.of(TIDY, RETAG, QUIET, AGREED, REWRITE, OPTION, CHANGED, IMPACT)) { AssistantTestFixture.grant(RUNNER, name + ".hasAccess"); } @@ -273,6 +304,78 @@ class ProcessCardRecordTest extends BaseAssistantTest + /******************************************************************************* + ** A review is a screen too: what it has of its own is passed only against + ** the record of what the card displayed, however well its count and its + ** lines agree. The card said "Mode: soft (its default)" and the process + ** holds "hard" at the review: the run stops there, nothing is stored, and + ** going on is a new card that shows the value the process has. A review + ** with a value to read ("Also unpublishes 250 linked pages") stops the + ** same way and its card shows the value. + *******************************************************************************/ + @Test + @SuppressWarnings("unchecked") + void aReviewsOwnInputsAndValuesAreHeldToWhatTheCardShowed() throws Exception + { + ToolCallOutcome proposed = call(ProcessTools.RUN, Map.of("process", CHANGED, "recordIds", List.of("1", "2", "3"))); + assertThat(lines(proposed)).contains("Mode=soft (its default)"); + Map stopped = json(String.valueOf(confirm(proposed).get("message"))); + assertThat(stopped).containsEntry("status", "STOPPED_FOR_REVIEW").containsEntry("whyItCameBack", "\"Mode\" has a value the card did not show."); + assertThat(ProcessFixture.RAN).extracting(ran -> ran.get("step")).as("nothing was stored").doesNotContain("store"); + + ToolCallOutcome goOn = call(ProcessTools.RUN, Map.of("run", String.valueOf(stopped.get("run")))); + assertThat(lines(goOn)).as("the card to go on with shows what the process holds now").contains("Mode=hard").contains("Why it came back=\"Mode\" has a value the card did not show."); + assertThat(confirm(goOn)).containsEntry("status", AssistantPendingAction.STATUS_EXECUTED); + assertThat(ProcessFixture.RAN).as("and only then is it stored, with the value that card showed").anySatisfy(ran -> + { + assertThat(ran).containsEntry("step", "store"); + assertThat(String.valueOf(((Map) ran.get("values")).get("mode"))).isEqualTo("hard"); + }); + + ProcessFixture.RAN.clear(); + ToolCallOutcome impact = call(ProcessTools.RUN, Map.of("process", IMPACT, "recordIds", List.of("1", "2", "3"))); + assertThat(lines(impact)).as("the card has nothing of the value: it did not exist yet").noneMatch(line -> line.contains("250")); + Map read = json(String.valueOf(confirm(impact).get("message"))); + assertThat(read).containsEntry("status", "STOPPED_FOR_REVIEW").containsEntry("whyItCameBack", "It shows values to read that were not known when the card was made."); + assertThat(ProcessFixture.RAN).extracting(ran -> ran.get("step")).doesNotContain("store"); + assertThat(lines(call(ProcessTools.RUN, Map.of("run", String.valueOf(read.get("run")))))).contains("Impact=Also unpublishes 250 linked pages."); + } + + + + /******************************************************************************* + ** And a review whose own input has the value the card showed is passed on + ** the one confirmation: the default the card named, or the value the + ** person gave, which is the value the storing step then runs with. A value + ** given for a review's input that the process then changes comes back. + *******************************************************************************/ + @Test + @SuppressWarnings("unchecked") + void aReviewWhoseOwnInputIsAsTheCardShowedItIsPassed() throws Exception + { + Map byDefault = confirm(call(ProcessTools.RUN, Map.of("process", OPTION, "recordIds", List.of("1", "2", "3")))); + assertThat(byDefault).as(String.valueOf(byDefault.get("message"))).containsEntry("status", AssistantPendingAction.STATUS_EXECUTED); + assertThat(String.valueOf(byDefault.get("resultSummary"))).startsWith("Option Review finished"); + assertThat(ProcessFixture.RAN).extracting(ran -> ran.get("step")).contains("store"); + + ProcessFixture.RAN.clear(); + ToolCallOutcome given = call(ProcessTools.RUN, Map.of("process", OPTION, "recordIds", List.of("1", "2", "3"), "values", Map.of("mode", "firm"))); + assertThat(lines(given)).contains("Mode=firm"); + assertThat(confirm(given)).containsEntry("status", AssistantPendingAction.STATUS_EXECUTED); + assertThat(ProcessFixture.RAN).anySatisfy(ran -> + { + assertThat(ran).containsEntry("step", "store"); + assertThat(String.valueOf(((Map) ran.get("values")).get("mode"))).isEqualTo("firm"); + }); + + ProcessFixture.RAN.clear(); + Map overruled = json(String.valueOf(confirm(call(ProcessTools.RUN, Map.of("process", CHANGED, "recordIds", List.of("1", "2", "3"), "values", Map.of("mode", "firm")))).get("message"))); + assertThat(overruled).as("the person said firm, the process made it hard").containsEntry("status", "STOPPED_FOR_REVIEW").containsEntry("whyItCameBack", "\"Mode\" has a value the card did not show."); + assertThat(ProcessFixture.RAN).extracting(ran -> ran.get("step")).doesNotContain("store"); + } + + + /******************************************************************************* ** A screen the process changed while it ran (here: the text of a screen ** that is on the card) is not the screen the card displayed, and what it @@ -387,6 +490,27 @@ class ProcessCardRecordTest extends BaseAssistantTest + /******************************************************************************* + ** A preview that finds all three records fine, and changes what the review + ** after it has: an option of the review, and a value the review shows. + *******************************************************************************/ + public static class ChangingPreview implements BackendStep + { + /******************************************************************************* + ** + *******************************************************************************/ + @Override + public void run(RunBackendStepInput input, RunBackendStepOutput output) throws QException + { + output.addValue("recordCount", input.getRecords().size()); + output.addValue("mode", "hard"); + output.addValue("impact", "Also unpublishes 250 linked pages."); + output.addValue("validationSummary", new ArrayList<>(List.of(new ProcessSummaryLine(Status.OK, 3, "posts will be retagged.")))); + } + } + + + /******************************************************************************* ** One tool call of the person with no chat around it, logged. *******************************************************************************/