Skip to content

Pass all messages through the event bus#1865

Merged
luke-hill merged 4 commits into
mainfrom
feature/messages-in-event-bus
May 26, 2026
Merged

Pass all messages through the event bus#1865
luke-hill merged 4 commits into
mainfrom
feature/messages-in-event-bus

Conversation

@brasmusson
Copy link
Copy Markdown
Contributor

Description

Make the MessageBuilder a mandatory formatter and let it pass the created message to the event bus. Users of the message stream then only have to register for on_envelope on the event bus to get the full message stream.

Previously only the messages produced by the gherkin library have been passed though the event bus. This change is a step to completely replace the event other than messages with messages.

After this change event users, mainly formatters, can be updated to use messages without having to inherit from MessageBuilder - which is a kind of hack - but to use the final design of registering for the message stream in the event bus.

When most or all event users have be updated to use message. Event producers can be change to produce messages instead. Then MessageBuilder need to be updated to not convert those messages from events. Finally MessageBuilder can be completely removed.

Type of change

Please delete options that are not relevant.

  • Refactoring (improvements to code design or tooling that don't change behaviour)

Please add an entry to the relevant section of CHANGELOG.md as part of this pull request.

Checklist:

Your PR is ready for review once the following checklist is
complete. You can also add some checks if you want to.

  • Tests have been added for any changes to behaviour of the code
  • New and existing tests are passing locally and on CI
  • bundle exec rubocop reports no offenses
  • RDoc comments have been updated
  • CHANGELOG.md has been updated

* Make the MessageBuilder a mandatory formatter and let it pass the
  created message to the event bus. Users of the message stream then
  only have to register for on_envelope on the event bus to get the
  full message stream.
@luke-hill
Copy link
Copy Markdown
Contributor

When most or all event users have be updated to use message. Event producers can be change to produce messages instead. Then MessageBuilder need to be updated to not convert those messages from events. Finally MessageBuilder can be completely removed.

I spoke with Rien about this on thursday. This is something I think is something we should do, but it sounds hard.

Step 1 I'm going to produce a mapping doc probably as an issue detailing which events map 1->1, which events don't map, and which messages don't have a mapping event source

* When a StepDefinitionRegistered event is fired, send also a
  StepDefinition message.
* Remove the handling of StepDefinitionRegistered event in the
  MessageBuilder.
Copy link
Copy Markdown
Contributor

@luke-hill luke-hill left a comment

Choose a reason for hiding this comment

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

Reviewed a couple of files (message/rerun), get that work.

The rest I will likely need some help with / pair review

step_definition = StepDefinition.new(@configuration.id_generator.new_id, self, string_or_regexp, proc_or_sym, options)
@step_definitions << step_definition
@configuration.notify :step_definition_registered, step_definition
@configuration.notify :envelope, step_definition.to_envelope
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Can we remove this out into a separate PR targeting the v11 migration branch

Comment thread lib/cucumber/runtime.rb
reports = [message_builder, summary_report] + formatters
reports << fail_fast_report if @configuration.fail_fast?
reports << publish_banner_printer unless @configuration.publish_quiet?
@report ||= Formatter::Fanout.new(reports)
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I start to think that what we see here is technical debt from the time before we started to use event i CucumberRuby. Then the formatters had a lot of methods beforeScenario, afterScenario, beforeStep etc. The Fanout was utility to "iterate" over all the formatters and call these methods, so the "runtime" called beforeScenario on the Fanout which resulted in that beforeScenario was called on each formatter.

Now when we are using events what is important is that the right formatters are created. When they are created they register for the events they are interested in on the event bus (they get the Configuration object which has the event bus passed to the initialize method). Then the get event from the event bus and do their job.

So the remaining purpose of the code here (which is call from line 77 self.visitor = report) is to create the right formatter. Summary_report we always want to create as the runtime uses it to determine the exit code. Now we always want to create the message builder so that is can listen to event and create message, send the to the event bus so that message users can get all messages from the event bus. Then we shall create the formatters specified by the cli options etc.

@luke-hill luke-hill merged commit c4e62e1 into main May 26, 2026
17 checks passed
@luke-hill luke-hill deleted the feature/messages-in-event-bus branch May 26, 2026 16:39
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