The audit module contains a small function that builds a summary from incoming events of different types using pattern matching. After a recent refactor, the results became unstable: some events disappear from the final list, and some fields in the collected items arrive in a form that the calling code does not expect.
Audit::EventShapeSummary.build(events) accepts an enumerable set of events.Hash with symbol keys.Hash must contain the keys:
:items — an array of normalized records in the original order;:counts — a hash with counters for the types "login", "purchase", "logout".{:type=>"login", :user_id=>String, :ip=>String};{:type=>"purchase", :user_id=>String, :amount_cents=>Integer, :currency=>String};{:type=>"logout", :user_id=>String}.:items, each normalized record must have the following form:
{:kind=>"login", :user_id=>..., :ip=>...};{:kind=>"purchase", :user_id=>..., :total_cents=>..., :currency=>...};{:kind=>"logout", :user_id=>...}.ruby audit_event_shape_summary.rb
login, purchase, logout events.:items structure with the expected field contract.:items and in :counts.:total_cents for purchases.3.3.0ruby, without Rails, without Fiber schedulerruby audit_event_shape_summary.rbUse line comments to explain the problem, its impact, the fix and how to test it.