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

[messages - elixir] Convert proto-based messages to json schema based messages #1952

Closed
wants to merge 14 commits into from

Conversation

WannesFransen1994
Copy link
Contributor

@WannesFransen1994 WannesFransen1994 commented Apr 14, 2022

Summary

Remove protobuf dependency and create modules based on json schema (manual parser). No validation of data in messages, that's done through acceptance testing.

Checklist:

  • Clean dependencies
  • Generate modules in generated folder
  • Adjust Make file & do integrations in CICD
  • See if compatibility testing kit is relevant
  • Adjust gherkin library as well and verify with acceptance testing there
  • Provide meaningful debug messages if applicable

@WannesFransen1994
Copy link
Contributor Author

Attempted a makefile adjustment, but seems that there's a problem with the messages generation. (based on the log)

==> cucumber_messages
Compiling 3 files (.ex)
Generated cucumber_messages app

@WannesFransen1994
Copy link
Contributor Author

Not that familiar with the whole monorepo build, but I've managed to make it work with adjusting the Makefile. Would love some pointers / reviews on the integration, specifically for

  1. manually copying the json schema files
  2. instead of adjusting the general gitignore - which caused an rsync conflict-, I've adjusted an ignore file here
  3. The CircleCI config integration file
  4. Instead of running the compiled binary with every file and verifying the output, I do this in the test suite (since starting an beam VM every time is expensive). Saves a lot of time though (would be even more if we ran this in parallel, though not sure it is worth the effort)

@WannesFransen1994 WannesFransen1994 marked this pull request as ready for review May 23, 2022 09:47
alias CucumberMessages.GherkinDocument.Feature.TableRow.TableCell, as: TableCellMessage
alias CucumberMessages.GherkinDocument.Tag, as: MessageTag
alias CucumberMessages.GherkinDocument.Scenario, as: MessageScenario
alias CucumberMessages.GherkinDocument.Step, as: StepMessage
Copy link
Contributor

Choose a reason for hiding this comment

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

@WannesFransen1994 is this document manually maintained? I see an inconsistency here: StepMessage where all the others are called Message*?

@@ -58,7 +58,15 @@ defmodule CucumberGherkin.AstBuilder do
Comment ->
loc = Token.get_location(token)
comment_message = %CommentMessage{location: loc, text: token.line.content}
# TODO: Normally your struct should default to an empty list instead of nil.
# Due to the limited converter in the messages library, we make a case clause and "catch" this unexpected `nil` value.
Copy link
Contributor

Choose a reason for hiding this comment

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

Is there an option to make the converter smarter? It's nice not to have to maintain this workaround "forever".

# case feature_message_acc.children do
# nil -> %{feature_message_acc | children: [child]}
# list -> %{feature_message_acc | children: list ++ [child]}
# end
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm actually not seeing the case statement; I'm not all that great at elixir, but the code you describe really isn't there?

alias CucumberMessages.GherkinDocument.Feature.TableRow, as: TableRowMessage
alias CucumberMessages.GherkinDocument.Scenario, as: ScenarioMessage
alias CucumberMessages.GherkinDocument.Step, as: StepMessage
alias CucumberMessages.GherkinDocument.TableRow, as: TableRowMessage
Copy link
Contributor

Choose a reason for hiding this comment

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

These are inconsistent with ast_builder.ex where you use Message as a prefix. I think it's easier to understand the code base if you stick to the same naming rules. Or is there a specific reason to deviate here?


# {:scenario, s} ->
# compile_scenario(m_acc, s, :feature_backgr_steps)
# end
Copy link
Contributor

Choose a reason for hiding this comment

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

What's the value of this comment block? It looks like it's preserving the old code, but once we're moved over, we have the old code in Git for historic reference. No need to keep a copy?

rm -rf lib/cucumber_messages/generated/*

.deps: setup_mix_and_get_dependencies update_proto_file compile_messages revert_proto_file
# .deps: setup_mix_and_get_dependencies update_proto_file compile_messages revert_proto_file
Copy link
Contributor

Choose a reason for hiding this comment

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

Remnant can be removed?

cat $<.bak | sed "s/package io.cucumber.messages/package cucumber_messages/" > $<
# update_proto_file: messages.proto
# mv $< $<.bak
# cat $<.bak | sed "s/package io.cucumber.messages/package cucumber_messages/" > $<
Copy link
Contributor

Choose a reason for hiding this comment

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

Remnant can be removed?

.PHONY: revert_proto_file
# revert_proto_file: messages.proto.bak
# mv messages.proto.bak messages.proto
# .PHONY: revert_proto_file
Copy link
Contributor

Choose a reason for hiding this comment

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

Remnant can be removed?

# metadata = %{definitions: nil, full_decoded: decoded, modules: [], parent: nil}
# list_of_modules = create_moduledata_structs(metadata, decoded)
# textual_modules = output_module(list_of_modules, [])
# write_files(textual_modules)
Copy link
Contributor

Choose a reason for hiding this comment

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

Remnant that can be removed?

# case create_moduledata_structs(empty_metadata, {name, child_member}) do
# %ModuleData{} = submodule -> submodule
# other -> raise "unexpected"
# end
Copy link
Contributor

Choose a reason for hiding this comment

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

Was this a remnant?

Copy link
Contributor

@aurelien-reeves aurelien-reeves left a comment

Choose a reason for hiding this comment

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

We pair today with @WannesFransen1994 to review the PR.
We noticed the following:

  • Please join the generated code for messages as part of the repo
  • We usually use the CCK as part of the messages high-level validation to make sure they serialize and deserialize as expected (you can take inspiration from ruby, perl, php, java or js implementation for that)
  • If you want to comply with request from Erik, you can copy the good/bad test data using make but keeping those ignored in the repo

Beside that: great job @WannesFransen1994! 👍Thanks a lot!

Comment on lines +20 to +22
# update_proto_file: messages.proto
# mv $< $<.bak
# cat $<.bak | sed "s/package io.cucumber.messages/package cucumber_messages/" > $<
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
# update_proto_file: messages.proto
# mv $< $<.bak
# cat $<.bak | sed "s/package io.cucumber.messages/package cucumber_messages/" > $<

@aurelien-reeves
Copy link
Contributor

PR now available in the dedicated repo here: cucumber/messages#29

@luke-hill luke-hill deleted the messages-elixir-proto-to-jsonschema branch August 15, 2023 11:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants