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

Test the command parsing logic #32

Merged
merged 4 commits into from
Jun 29, 2019

Conversation

bryanburgers
Copy link
Contributor

Start adding some tests to Homu by testing the issue comment
command-parsing logic.

Take parse_commands and break it apart into two phases

  • Parsing phase
  • Execution phase

The parsing phase returns a list of commands with action names (ideally,
this would be a Rust enum, but to simulate that, we use action names on
a single class) that are returned regardless of the current state. So
for example, @bors retry will return a retry command regardless of
the current state of realtime.

The execution phase then inspects the list of commands and decides what
to do with them. So for example, the retry command will be skipped if
realtime == False.

This has the positive result of having a parsing phase that has no
side-effects, which makes it much easier to test. This can lead to
higher confidence that the code works as expected without the high cost
of testing in production and possibly disrupting the build flow.

This has the negative result of adding a lot of lines of code to achieve
command parsing, which we already do successfully without the tests.

@pietroalbini
Copy link
Member

Unfortunately I didn't get a chance to look at this and I will be really busy for the next few weeks, so it would be great if someone else can review this!

Here are some random notes about the command parsing and the testing:

  • In other projects (like highfive) we use pytest instead of the native unittest module. From my experience it's way better and it has more mindshare in the Python community: would you be ok changing the use of unittest with it?
  • One thing that the current command parser supports is the ability to add random text in the same line as an homu command, like @bors retry network error. Could you add support for it (if it doesn't work already) and a test?
    • One bad thing about that feature is the current parser then continues parsing the command, just ignoring the unknown words: @bors retry (yielding priority to the rollup) is actually parsed as @bors retry rollup which is not something anyone wants. When you implement the previous note can you add a test to ensure this doesn't happen anymore?

@pietroalbini pietroalbini removed their assignment Jun 7, 2019
@bryanburgers
Copy link
Contributor Author

Hey, no problem. Good luck with your exams!

Yeah, pytest is nice. I didn’t realize there was precedent. I’ll switch over.

I’ll see what I can do about the parse. Seems kinda fuzzy what we do and don’t want, so we’ll see.

@pietroalbini
Copy link
Member

I’ll see what I can do about the parse. Seems kinda fuzzy what we do and don’t want, so we’ll see.

The behavior I expect and would like is to parse until an invalid word is found, and then stop parsing that line. Dunno if the others have different opinions.

@Mark-Simulacrum
Copy link
Member

That behavior seems reasonable. If it's easier then I think going down the triagebot route with "must have terminator" is also fine (e.g., a period) -- it doesn't really hurt us all that much from a user experience point of view

@pietroalbini
Copy link
Member

One issue I could see with the terminator is that nobody is used to it with bors, and I'd like for this PR not to change the current workflow.

@bryanburgers
Copy link
Contributor Author

I agree about no terminators. That would confuse everybody at this point.

Do we want to test current functionality now, and introduce the order change in a future PR? Or make those parser changes now?

@Mark-Simulacrum
Copy link
Member

I agree that it's not ideal to have that behavior change, I just intended to say that I don't think it's the end of the world presuming we indicate the change by throwing errors and suggesting to users that they should insert the terminator as appropriate. But if we can do without, great -- bors/homu's syntax is certainly simpler than triagebot's.

Start adding some tests to Homu by testing the issue comment
command-parsing logic.

Take `parse_commands` and break it apart into two phases

* Parsing phase
* Execution phase

The parsing phase returns a list of commands with action names (ideally,
this would be a Rust enum, but to simulate that, we use action names on
a single class) that are returned regardless of the current state.  So
for example, `@bors retry` will return a `retry` command regardless of
the current state of `realtime`.

The execution phase then inspects the list of commands and decides what
to do with them. So for example, the `retry` command will be skipped if
`realtime == False`.

This has the positive result of having a parsing phase that has no
side-effects, which makes it much easier to test. This can lead to
higher confidence that the code works as expected without the high cost
of testing in production and possibly disrupting the build flow.

This has the negative result of adding a lot of lines of code to achieve
command parsing, which we already do successfully without the tests.
@bryanburgers
Copy link
Contributor Author

  • Switched to pytest
  • Updated parsing to stop at unknown words

@pietroalbini @Mark-Simulacrum

When parsing a @bors command, stop parsing when we reach any unknown
word. This enables commands like

    @bors retry (yielding priority to the rollup)

to include a description of why we retried (which gets put in the retry
log) without also setting `rollup`.

The only tricky bit to this is a command like

    @bors r=person 0123456789abcdef

where the commit sha is part of the `r=` command, and we need to parse
it that way.
Homu leaves self-approvals in comments, like

    <!-- @bors r=someone abcdef -->

and we need to make sure those still parse correctly.
Commands that started with the botname *and then a colon* were being
dropped, because the parser didn't recognize the command and didn't
continue. Fix this by explicitely allowing a colon after the botname.
@pietroalbini
Copy link
Member

Won't have time to properly review this for a while, sorry!

By the way, there is another edge case that would be awesome to solve: ignore all commands when the line starts with >, to hopefully catch quoted emails. Example: rust-lang/rust#61540 (comment)

Copy link
Member

@pietroalbini pietroalbini 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 so much!

@pietroalbini pietroalbini merged commit abd0083 into rust-lang:master Jun 29, 2019
@pietroalbini
Copy link
Member

Merged this early even if my last comment wasn't handled to unblock your other work. Opened an issue to track commands in quotes: #52

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.

None yet

3 participants