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

feat: Scripted client nullable replies #121

Merged
merged 2 commits into from
Sep 27, 2024
Merged

Conversation

sminez
Copy link
Collaborator

@sminez sminez commented Sep 27, 2024

Support not replying to every prompt in a scripted client prompt-sequence.

Currently, prompting-client.scripted accepts scripts which have a top-level "prompt-filter" and a "prompts" list, which is a list of json objects with two mandatory fields: "prompt-filter" and "reply". The scripted client expects relevant prompts to match the filters specified in the "prompts" list in order, and for each one, immediately sends back the accompanying reply.

However, to write a spread test which mimics the create_multiple_actioned_by_other_pid integration test, we need to be able to attempt multiple writes (and check that those attempts occurred as expected), and then on a subsequent attempt, reply with a rule which then actions the previous prompts as well.

The docs update and new test data cover the new supported syntax for a prompt-sequence.

Tracked internally by https://warthogs.atlassian.net/browse/UDENG-4782

@@ -95,14 +99,25 @@ impl TypedPromptFilter {
}
}

/// Override the default handling for a missing key in being parsed as `None` so that only an
/// explicit value of `null` is accepted.
fn explicit_null<'de, T, D>(de: D) -> Result<Option<T>, D::Error>
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is what allows us to distinguish the field being explicitly specified as null vs simply being omitted. (The default behaviour of serde when deserializing into an Option<T> field is to treat both the same).

This is adapted form the example shown here in order to emit an error in the case of a missing field rather than parsing into an Option<Option<T>> and having to handle the validation explicitly after the struct has been deserialized.

Copy link
Member

@olivercalder olivercalder left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks great, thank you for addressing this so quickly!

@sminez sminez merged commit 83f63df into main Sep 27, 2024
9 checks passed
@sminez sminez deleted the scripted-client-nullable-replies branch September 27, 2024 22:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants