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

Fix DialogFlow tests and update to canonical sample format. #1210

Merged
merged 4 commits into from
Sep 27, 2018

Conversation

dzlier-gcp
Copy link
Member

DialogFlow tests are failing, and while fixing them I ran into many issues with the tests simply parsing the stdout content to verify things were working as intended.

With canonical samples, we are no longer formatting the samples as commandline executables, and instead of writing to stdout, we are returning the requested information directly, as that is more likely to be what users are looking for anyway. So I updated the DF samples to do so, and the tests to match.

@googlebot googlebot added the cla: yes This human has signed the Contributor License Agreement. label Sep 11, 2018
Copy link

@beccasaurus beccasaurus left a comment

Choose a reason for hiding this comment

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

We won't be accepting changes to ML API docs samples which remove the output response information, it's critical to the user's docs experience.

We can't accept this change.

@dzlier-gcp
Copy link
Member Author

More context on @Beccca 's response:

The issue is with deleting the System.out.println lines in the classes, as these are determined by the DPEs in collaboration with the product teams to demonstrate the format of the responses returned from the various API calls in the code snippets embedded in our documentation. When thinking about the canonical format, I interpreted the decision that "we no longer have to make CLI's/executables" to mean there was no need to write to stdout if the code is not an executable, but that wasn't the main reason for the write lines in the first place. I will be adding those back in.

The issue I wanted to resolve in this change was making the functions actually return something other than void, for 2 reasons:

  1. Unit tests that capture and regex match on stdout are brittle, prone to problems, and don't do much to verify that the call was actually successful, particularly when it's only matching on the manual string part and not on the content returned itself.
  2. Functions like "list_" and "get_" that return void are functionally useless for anything other than documentation - they can't be copied into a developer's project and used as-is, because they don't do anything actually useful in practice.

@dzlier-gcp dzlier-gcp force-pushed the master branch 2 times, most recently from ffc98db to 259c6c3 Compare September 11, 2018 18:32
@dzlier-gcp
Copy link
Member Author

Updated to return the System.out lines in the sample classes.

@dzlier-gcp dzlier-gcp dismissed beccasaurus’s stale review September 11, 2018 20:03

Requested changes made.

@dzlier-gcp dzlier-gcp added the kokoro:force-run Add this label to force Kokoro to re-run the tests. label Sep 11, 2018
@kokoro-team kokoro-team removed the kokoro:force-run Add this label to force Kokoro to re-run the tests. label Sep 11, 2018
*/
public static void listContexts(String sessionId, String projectId) throws Exception {
public static List<Context> listContexts(String sessionId, String projectId) throws Exception {
List<Context> contexts = Lists.newArrayList();
Copy link
Contributor

Choose a reason for hiding this comment

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

I think if we are aiming for the new format, the context tags need to be moved inside of the function and examples of the arguments need to be provided in comments to give the user additional context:

public static List<Context> listContexts(String sessionId, String projectId) throws Exception {
// [START dialogflow_list_contexts]
// String sessionId = "my-session-id"
// String projectId = "my-project-id"

List<Context> contexts = Lists.newArrayList();


Copy link
Member Author

Choose a reason for hiding this comment

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

What's your take on the return statement being inside vs outside the tags?

Copy link
Contributor

Choose a reason for hiding this comment

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

I'd say leave the return outside.

Copy link
Contributor

Choose a reason for hiding this comment

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

I think that sounds reasonable.

Copy link
Member Author

Choose a reason for hiding this comment

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

From the perspective of having these regions be copy-pastable by developers, though, I would think the function tag and return statement would be useful so that they could just plop the function into their code directly. They would basically have to write a function wrapper around the code anyway regardless

Copy link
Contributor

Choose a reason for hiding this comment

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

I see what you are saying, but I think the presumption is that they can copy paste the code into an existing code and get it working. Even if they copy the function as a whole they still have to create a class around it, so I don't think including the function signature really make's a significant impact.

Copy link
Member Author

Choose a reason for hiding this comment

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

hey every keystroke counts :)

Copy link
Contributor

Choose a reason for hiding this comment

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

I feel we should make sure this gets decided in the new rubric. (To have a solid answer going forward)

Copy link
Member Author

Choose a reason for hiding this comment

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

Agreed. I'd prefer to leave it as-is for now though for consistency.

@@ -104,48 +101,14 @@ public static void detectIntentKnowledge(
System.out.format(" - Answer: '%s'\n", answer.getAnswer());
System.out.format(" - Confidence: '%s'\n", answer.getMatchConfidence());
}

allKnowledgeAnswers.add(Tuple.of(text, sessionsClient
Copy link
Contributor

Choose a reason for hiding this comment

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

Another suggestion on the new sample guidelines is to explicitly define variables ahead of time, and avoid multiple nesting in function calls.

Copy link
Member Author

Choose a reason for hiding this comment

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

Updated to break out nested calls.

beccasaurus
beccasaurus previously approved these changes Sep 11, 2018
Copy link

@beccasaurus beccasaurus left a comment

Choose a reason for hiding this comment

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

I had submitted a Request changes – after chatting & agreeing that the println statements would return, I'm 'Approving' to remove the request!

Thanks for all of the thought that went into these changes to improve our code sample experience for developers 🙏

=> @nnegrey for full approval from our end

@dzlier-gcp dzlier-gcp force-pushed the master branch 3 times, most recently from a440107 to a588ef6 Compare September 12, 2018 18:55
@dzlier-gcp dzlier-gcp added the kokoro:force-run Add this label to force Kokoro to re-run the tests. label Sep 12, 2018
@kokoro-team kokoro-team removed the kokoro:force-run Add this label to force Kokoro to re-run the tests. label Sep 12, 2018
Copy link
Contributor

@nnegrey nnegrey left a comment

Choose a reason for hiding this comment

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

Mostly nit to match the naming to the API naming

@dzlier-gcp dzlier-gcp added the kokoro:force-run Add this label to force Kokoro to re-run the tests. label Sep 13, 2018
@kokoro-team kokoro-team removed the kokoro:force-run Add this label to force Kokoro to re-run the tests. label Sep 13, 2018
@dzlier-gcp dzlier-gcp added the kokoro:force-run Add this label to force Kokoro to re-run the tests. label Sep 17, 2018
@kokoro-team kokoro-team removed the kokoro:force-run Add this label to force Kokoro to re-run the tests. label Sep 17, 2018
@dzlier-gcp
Copy link
Member Author

Hi all, I'm having an issue with this that I'm not sure I should report to the DialogFlow team directly as an actual bug found by the Unit Tests.

For the tests in KnowledgeBaseManagementIT, particularly the testIntentKnowledge, it creates a KnowledgeBase based on the Storage Docs FAQ.

The test question used to be "Where is my data stored?", which is the second question in the Storage section. Half the time, it was interpreting that as "Is my data redundant?", the first question in that section. When I changed the test text to "Is my data redundant?", it always succeeded locally, but now it's having the same problem run with kokoro where it thinks the question is the other one half the time.

This seems like a potential API problem though, since the input text is an exact match for one of the questions. Should I file a bug with the team, or just make the test more forgiving?

@nnegrey
Copy link
Contributor

nnegrey commented Sep 17, 2018

I'd start by reaching out to DF team and see if something changed on the backend, this sounds like an API bug.

@dzlier-gcp
Copy link
Member Author

Created bug b/115888589, but there was no automatic assignee so I'll forward it to the dialogflow team to make sure they see it.

assertThat(answer.getAnswer()).contains("Cloud Storage");
}
}

Choose a reason for hiding this comment

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

Please cleanup the resources (remove the knowledge base) after the test.

Copy link
Member Author

Choose a reason for hiding this comment

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

This is done in the @After tearDown() method above, line 77.

Copy link
Contributor

@nnegrey nnegrey left a comment

Choose a reason for hiding this comment

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

LGTM

Thanks Dane!

@beccasaurus
Copy link

ping ~ what's the status of this? looks like we've got LGTMs :)

@dzlier-gcp
Copy link
Member Author

Ah, thanks for the ping, I missed the LGTM. I will update the branch and submit.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cla: yes This human has signed the Contributor License Agreement.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants