standard_audit 0.6.0 → 0.8.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -5,7 +5,9 @@ module StandardAudit
5
5
  :current_actor_resolver, :current_request_id_resolver,
6
6
  :current_ip_address_resolver, :current_user_agent_resolver,
7
7
  :current_session_id_resolver,
8
- :sensitive_keys, :metadata_builder,
8
+ :sensitive_keys, :sensitive_key_patterns,
9
+ :sensitive_key_exceptions, :filter_nested_metadata,
10
+ :metadata_builder, :before_checksum_hooks,
9
11
  :anonymizable_metadata_keys, :retention_days
10
12
 
11
13
  def initialize
@@ -43,7 +45,37 @@ module StandardAudit
43
45
  private_key certificate_chain
44
46
  ssn credit_card authorization
45
47
  ]
48
+ # Regexps matched against every metadata key name, in addition to the
49
+ # exact-match `sensitive_keys` list. This is the supported way to catch a
50
+ # family of keys: `/secret/i` redacts `client_secret`, `webhook_secret`,
51
+ # and `secret` alike.
52
+ #
53
+ # There is deliberately NO substring *mode* for `sensitive_keys` — see
54
+ # the note in MetadataFilter. Patterns are opt-in and per-app, which is
55
+ # the only safe shape for a rule applied to append-only rows.
56
+ @sensitive_key_patterns = []
57
+
58
+ # Key names (String/Symbol, exact) or Regexps that are never redacted,
59
+ # even when `sensitive_keys` or `sensitive_key_patterns` matches. Lets an
60
+ # app adopt a broad pattern while keeping the handful of real audit keys
61
+ # it would otherwise swallow, e.g.
62
+ # `sensitive_key_patterns = [/token/i]` with
63
+ # `sensitive_key_exceptions = %i[input_tokens output_tokens]`.
64
+ @sensitive_key_exceptions = []
65
+
66
+ # When true, redaction descends into nested Hashes (and Hashes inside
67
+ # Arrays), so `metadata: { stripe: { client_secret: … } }` is caught.
68
+ # Defaults to false: it changes what gets written, and audit rows are
69
+ # append-only. Reserved keys are never descended into.
70
+ @filter_nested_metadata = false
71
+
46
72
  @metadata_builder = nil
73
+
74
+ # Callables (or Symbols naming an AuditLog instance method) run on
75
+ # `before_create` AFTER the UUID is assigned and BEFORE the checksum is
76
+ # computed. See Configuration#before_checksum.
77
+ @before_checksum_hooks = []
78
+
47
79
  @anonymizable_metadata_keys = %i[email name ip_address]
48
80
 
49
81
  # Retention defaults from ENV so it can be set per-environment without a
@@ -63,6 +95,37 @@ module StandardAudit
63
95
  days&.positive? ? days : nil
64
96
  end
65
97
 
98
+ # Registers a hook to run between `assign_uuid` and `compute_checksum` on
99
+ # every audit write that instantiates a model.
100
+ #
101
+ # config.before_checksum { |log| log.scope = derive_scope(log) }
102
+ # config.before_checksum :backfill_organization_scope
103
+ #
104
+ # A hook may set a `CHECKSUM_FIELDS` member (`scope_gid`, `metadata`, …) and
105
+ # the row will still verify, because the checksum is computed afterwards.
106
+ # That is the whole point: before this existed, hosts had to register their
107
+ # own `before_create ..., prepend: true` to beat the gem's checksum
108
+ # callback, which is fragile ordering knowledge no host should need.
109
+ #
110
+ # Hooks accumulate and run in registration order. Each is rescued
111
+ # individually — a failing hook logs and is skipped; it never fails the
112
+ # audit write.
113
+ #
114
+ # A Symbol/String is sent to the AuditLog instance (use this for methods
115
+ # supplied by a concern mixed into the model). A callable is passed the
116
+ # instance.
117
+ #
118
+ # NOTE: batched writes (`StandardAudit.batch { … }` → `insert_all!`) never
119
+ # instantiate a model, so hooks do not run there. A batched writer that
120
+ # needs a derived column has to set it on the buffered attrs.
121
+ def before_checksum(hook = nil, &block)
122
+ hook ||= block
123
+ raise ArgumentError, "before_checksum needs a callable, a Symbol, or a block" if hook.nil?
124
+
125
+ @before_checksum_hooks << hook
126
+ hook
127
+ end
128
+
66
129
  def subscribe_to(pattern)
67
130
  @subscriptions << pattern
68
131
  end
@@ -0,0 +1,155 @@
1
+ module StandardAudit
2
+ # The single implementation of sensitive-key redaction for audit metadata.
3
+ #
4
+ # There used to be two: one in `StandardAudit.record` and one in
5
+ # `Subscriber#extract_metadata`. They had already diverged — the subscriber
6
+ # copy did not subtract `RESERVED_METADATA_KEYS`, so an app that (reasonably)
7
+ # added `:_tags` to `sensitive_keys` got the reserved key preserved on the
8
+ # `record` path and stripped on the `ActiveSupport::Notifications` path. Two
9
+ # copies of a security filter drifting apart is exactly the failure mode
10
+ # worth designing out, so both paths now call here.
11
+ #
12
+ # The divergence is resolved in favour of `record`'s behaviour: reserved keys
13
+ # are subtracted from the sensitive set and can never be filtered.
14
+ #
15
+ # == Matching
16
+ #
17
+ # A key is redacted when it matches `config.sensitive_keys` **exactly** (by
18
+ # name, string/symbol insensitive) or matches one of
19
+ # `config.sensitive_key_patterns` (Regexps, always applied), unless it is
20
+ # listed in `config.sensitive_key_exceptions` or is a reserved key.
21
+ #
22
+ # == Why there is no substring mode
23
+ #
24
+ # Matching `sensitive_keys` by substring instead of exactly is the obvious
25
+ # "fix" for `client_secret` not matching `:secret`, and it is a trap. Against
26
+ # the current default key list it would strip real audit content across the
27
+ # estate:
28
+ #
29
+ # :token => input_tokens, output_tokens (live LLM cost accounting),
30
+ # token_digest (rendered in a staff audit UI)
31
+ # :password => password_reset_sent_at, onepassword
32
+ # :authorization => authorization_endpoint
33
+ #
34
+ # Audit rows are append-only, so a bad default cannot be undone — the content
35
+ # is simply never written. `sensitive_key_patterns` is the supported tool
36
+ # instead: `/secret/i` solves the motivating `client_secret` case exactly,
37
+ # opt-in and per-app, and `rake standard_audit:sensitive_keys:dry_run` turns
38
+ # "is this rule safe for my data?" into a command rather than a guess.
39
+ class MetadataFilter
40
+ # Raised when metadata is neither nil nor hash-like. Deliberately a raise
41
+ # rather than a pass-through: this filter **fails closed**. An
42
+ # `ActionController::Parameters` is not a `Hash`, and letting an unrecognised
43
+ # object through unfiltered would write raw params — passwords included —
44
+ # into an append-only row. Pre-0.7.0 the same input blew up with
45
+ # `NoMethodError` on `#reject`, so raising preserves the outcome while
46
+ # naming the cause.
47
+ class UnfilterableMetadataError < ArgumentError; end
48
+
49
+ class << self
50
+ def call(metadata, config: StandardAudit.config)
51
+ new(config: config).call(metadata)
52
+ end
53
+ end
54
+
55
+ def initialize(config: StandardAudit.config)
56
+ @config = config
57
+ end
58
+
59
+ # Filters anything hash-like, not just `Hash` — `ActionController::Parameters`
60
+ # and other `each_pair`-able wrappers are filtered rather than waved
61
+ # through. `nil` passes (there is nothing to leak); anything else raises.
62
+ #
63
+ # Descends into nested Hashes (and Hashes inside Arrays) only when
64
+ # `config.filter_nested_metadata` is true. Reserved keys are preserved and
65
+ # their values are left entirely alone, **at every depth** — `_tags` and
66
+ # `_source` are gem-owned, not host payload, and immunity that held only at
67
+ # the top level would be a confusing half-guarantee.
68
+ def call(metadata)
69
+ return nil if metadata.nil?
70
+
71
+ unless hash_like?(metadata)
72
+ raise UnfilterableMetadataError,
73
+ "audit metadata must be nil or hash-like (got #{metadata.class}); " \
74
+ "refusing to write it unfiltered"
75
+ end
76
+
77
+ filtered = metadata.reject { |key, _| filter?(key) }
78
+ return filtered unless @config.filter_nested_metadata
79
+
80
+ filter_values(filtered)
81
+ end
82
+
83
+ # True when `key` would be redacted from metadata. Public so hosts (and the
84
+ # dry-run tooling) can ask the question without writing a row.
85
+ def filter?(key)
86
+ key = key.to_s
87
+
88
+ # `_tags` and `_source` are owned by EventSubscriber and are never
89
+ # stripped, even if a consumer lists them in `sensitive_keys`.
90
+ return false if StandardAudit::RESERVED_METADATA_KEYS.include?(key)
91
+ return false if exception?(key)
92
+
93
+ sensitive_keys.include?(key) || sensitive_key_patterns.any? { |pattern| pattern.match?(key) }
94
+ end
95
+
96
+ private
97
+
98
+ def hash_like?(value)
99
+ value.respond_to?(:each_pair) && value.respond_to?(:reject)
100
+ end
101
+
102
+ # Rewrites each value in place on the already-rejected copy. In place
103
+ # because `transform_values` is not guaranteed across every hash-like
104
+ # wrapper, whereas `[]=` is.
105
+ def filter_values(hash)
106
+ hash.each_pair do |key, value|
107
+ # Reserved subtree: immune at every depth, never descended into.
108
+ next if StandardAudit::RESERVED_METADATA_KEYS.include?(key.to_s)
109
+
110
+ replacement = filter_descendant(value)
111
+ hash[key] = replacement unless replacement.equal?(value)
112
+ end
113
+
114
+ hash
115
+ end
116
+
117
+ def filter_descendant(value)
118
+ if hash_like?(value)
119
+ filter_values(value.reject { |key, _| filter?(key) })
120
+ elsif value.is_a?(Array)
121
+ value.map { |element| filter_descendant(element) }
122
+ else
123
+ value
124
+ end
125
+ end
126
+
127
+ def sensitive_keys
128
+ @sensitive_keys ||= @config.sensitive_keys.map(&:to_s) - StandardAudit::RESERVED_METADATA_KEYS
129
+ end
130
+
131
+ # A String entry is read as a Regexp source, so the rake task (and a
132
+ # `SENSITIVE_KEY_PATTERNS` env var) can pass one through without eval.
133
+ def sensitive_key_patterns
134
+ @sensitive_key_patterns ||= Array(@config.sensitive_key_patterns).map do |pattern|
135
+ pattern.is_a?(Regexp) ? pattern : Regexp.new(pattern.to_s)
136
+ end
137
+ end
138
+
139
+ def exception?(key)
140
+ exact_exceptions.include?(key) || pattern_exceptions.any? { |pattern| pattern.match?(key) }
141
+ end
142
+
143
+ def exceptions
144
+ @exceptions ||= Array(@config.sensitive_key_exceptions).partition { |entry| entry.is_a?(Regexp) }
145
+ end
146
+
147
+ def pattern_exceptions
148
+ exceptions.first
149
+ end
150
+
151
+ def exact_exceptions
152
+ @exact_exceptions ||= exceptions.last.map(&:to_s)
153
+ end
154
+ end
155
+ end
@@ -0,0 +1,298 @@
1
+ require "cgi"
2
+ require "active_support/concern"
3
+
4
+ module StandardAudit
5
+ # Batch resolution of the GlobalID-backed `actor` / `target` / `scope`
6
+ # references on a page of audit rows, plus the per-row memo the readers
7
+ # consult.
8
+ #
9
+ # Why this exists: `AuditLog#actor` resolves `actor_gid` through
10
+ # `GlobalID::Locator.locate`, which is one query per row. Rendering N rows
11
+ # that each read `actor` and `target` issues O(N) lookups — an N+1 that
12
+ # Prosopite fails in every consuming app. Before this concern existed, apps
13
+ # worked around it by defining their own `preloaded_actor=` writer (or
14
+ # reaching into `@preloaded_actor` with `instance_variable_set`) and
15
+ # hand-rolling a per-type whitelist loader.
16
+ #
17
+ # == Memo semantics
18
+ #
19
+ # The memo is a Hash consulted with `key?`, not a pair of ivars checked with
20
+ # `defined?`. That distinction matters: a reference that was preloaded but
21
+ # whose record has since been deleted memoizes `nil`, and reads back as
22
+ # `nil` *without* falling through to a query. "Preloaded, and the answer is
23
+ # nothing" is therefore distinct from "not preloaded".
24
+ #
25
+ # `actor=` / `target=` / `scope=` populate the memo too, since the writer
26
+ # already holds the record. `reload` clears it.
27
+ #
28
+ # == Batched writes
29
+ #
30
+ # `StandardAudit.batch { ... }` flushes through `insert_all!` and never
31
+ # instantiates an AuditLog, so nothing in this concern runs on that path —
32
+ # neither the memo nor the writers. It is a no-op for batched writes by
33
+ # construction, not by accident.
34
+ module ReferencePreloading
35
+ extend ActiveSupport::Concern
36
+
37
+ # The GlobalID-backed reference columns. `scope` is preloadable but not in
38
+ # the default `refs:` set, since most read surfaces render actor/target
39
+ # only.
40
+ REFERENCES = %i[actor target scope].freeze
41
+
42
+ DEFAULT_REFS = %i[actor target].freeze
43
+
44
+ class_methods do
45
+ # Resolves the given references for a whole collection of audit logs in a
46
+ # fixed number of queries (one per distinct stored `*_type`), then
47
+ # memoizes the result on each row.
48
+ #
49
+ # AuditLog.preload_references(
50
+ # logs,
51
+ # refs: %i[actor target],
52
+ # only: [Account, Profile, Order],
53
+ # includes: { "Profile" => [:account], "Order" => [:user] }
54
+ # )
55
+ #
56
+ # [refs:] Which references to resolve. Defaults to `%i[actor target]`.
57
+ # [only:] Optional whitelist of permitted classes. See the note below —
58
+ # this is matched against the *stored type string*, so it is
59
+ # a stricter gate than `GlobalID::Locator`'s own `:only`.
60
+ # [includes:] Either a uniform Active Record `includes` spec applied to
61
+ # every type, or a per-type Hash keyed by class name String
62
+ # or Class constant (e.g. `{ "Profile" => [:account] }`).
63
+ # A Hash counts as per-type only when *every* key is a String
64
+ # or a Module; `{ account: :identifiers }` is therefore read
65
+ # as a uniform nested-includes spec, as you would expect.
66
+ #
67
+ # == Why `only:` is matched on the stored string
68
+ #
69
+ # `GlobalID::Locator`'s `:only` option is evaluated as
70
+ # `gid.model_class <= klass`, which means it *constantizes the stored
71
+ # type string before deciding whether it was allowed*. That is the wrong
72
+ # order for audit rows, whose type strings are historical: a class that
73
+ # has since been renamed or removed raises `NameError` rather than being
74
+ # filtered out. So this method filters on the stored `*_type` string
75
+ # first, by class name, and only then hands the surviving gids to
76
+ # `locate_many` (still passing `only:` as a second gate).
77
+ #
78
+ # The consequence is that `only:` does **not** expand to subclasses or
79
+ # to modules the way GlobalID's does — list every concrete class whose
80
+ # name you expect to see in `actor_type` / `target_type`. Deny-by-default
81
+ # is the safe direction for a whitelist.
82
+ #
83
+ # A reference whose type is not in `only:` memoizes `nil`, so it reads
84
+ # back as nil without a query rather than silently re-N+1ing.
85
+ #
86
+ # Returns the logs as an Array.
87
+ def preload_references(logs, refs: DEFAULT_REFS, only: nil, includes: nil)
88
+ logs = logs.to_a
89
+ return logs if logs.empty?
90
+
91
+ Array(refs).each do |ref|
92
+ ref = ref.to_sym
93
+ unless REFERENCES.include?(ref)
94
+ raise ArgumentError, "unknown audit reference #{ref.inspect} (expected one of #{REFERENCES.inspect})"
95
+ end
96
+
97
+ preload_one_reference(logs, ref, only: only, includes: includes)
98
+ end
99
+
100
+ logs
101
+ end
102
+
103
+ # Extracts the model id from a GlobalID string without resolving it:
104
+ # "gid://some-app/Account/123" => "123".
105
+ #
106
+ # Deliberately *not* `GlobalID.parse(gid)&.model_id`. Audit gids are
107
+ # historical and the rows are append-only, so a gid written by another
108
+ # app — or before this app was renamed — is a real, permanent row whose
109
+ # id must still be readable. Parsing it back through the locator
110
+ # machinery resolves against the *current* `GlobalID.app`, which is not
111
+ # what these rows are keyed on.
112
+ #
113
+ # This mirrors `URI::GID#set_model_components` exactly, minus the app
114
+ # check and the validations: drop any `?params` query, take everything
115
+ # after the model-name segment, split composite ids on "/", and
116
+ # `CGI.unescape` each part (`URI::GID.build` `CGI.escape`s them). Returns
117
+ # a String for a single-column primary key and an Array of Strings for a
118
+ # composite one, matching `GlobalID#model_id`.
119
+ def reference_model_id(gid)
120
+ return nil if gid.blank?
121
+
122
+ # "gid:" , "" , app , ModelName , <id segment(s)>
123
+ segment = gid.to_s.split("?", 2).first.to_s.split("/", 5)[4]
124
+ return nil if segment.blank?
125
+
126
+ parts = segment.split("/").reject(&:blank?).map { |part| CGI.unescape(part) }
127
+ return nil if parts.empty?
128
+
129
+ parts.length == 1 ? parts.first : parts
130
+ end
131
+
132
+ private
133
+
134
+ def preload_one_reference(logs, ref, only:, includes:)
135
+ gid_attr = :"#{ref}_gid"
136
+ type_attr = :"#{ref}_type"
137
+ allowed_names = only && Array(only).map { |klass| klass.is_a?(Module) ? klass.name : klass.to_s }
138
+
139
+ index = {}
140
+ unresolvable_types = []
141
+
142
+ logs.group_by { |log| log.public_send(type_attr) }.each do |type, type_logs|
143
+ # A blank `*_type` with a populated `*_gid` happens on historical and
144
+ # partially-backfilled rows. The per-row reader can still resolve
145
+ # those (the gid carries the model name), so mark the group
146
+ # unresolvable rather than memoizing nil — batching must never make a
147
+ # resolvable reference read back as nothing.
148
+ if type.blank?
149
+ unresolvable_types << type
150
+ next
151
+ end
152
+
153
+ # Not whitelisted: intentionally left out of the index so it memoizes
154
+ # nil (no query, now or later).
155
+ next if allowed_names && !allowed_names.include?(type)
156
+
157
+ gids = type_logs.filter_map { |log| log.public_send(gid_attr).presence }.uniq
158
+ next if gids.empty?
159
+
160
+ begin
161
+ locate_reference_records(gids, only: only, includes: includes_for(includes, type)).each do |record|
162
+ index[[type, normalized_record_key(record.id)]] = record
163
+ end
164
+ rescue NameError, ActiveRecord::StatementInvalid => e
165
+ # A historical type string that no longer constantizes, or a
166
+ # relation the current schema can't satisfy. Leave these rows
167
+ # *unmemoized* so the per-row reader behaves exactly as it did
168
+ # before preloading was attempted — memoizing nil here would
169
+ # silently rewrite behaviour on a bad `includes:`.
170
+ unresolvable_types << type
171
+ Rails.logger.warn("[StandardAudit] Could not preload #{ref} for type #{type.inspect}: #{e.class}: #{e.message}")
172
+ end
173
+ end
174
+
175
+ logs.each do |log|
176
+ type = log.public_send(type_attr)
177
+ next if unresolvable_types.include?(type)
178
+
179
+ log.write_preloaded_reference(
180
+ ref,
181
+ index[[type, reference_model_id(log.public_send(gid_attr))]]
182
+ )
183
+ end
184
+ end
185
+
186
+ # `ignore_missing: true` makes this a `where(id: ids)` instead of
187
+ # `find(ids)`, so a deleted record is simply absent from the result
188
+ # rather than raising — which is what lets a deleted reference memoize
189
+ # nil.
190
+ def locate_reference_records(gids, only:, includes:)
191
+ options = { ignore_missing: true }
192
+ options[:only] = only if only
193
+ options[:includes] = includes if includes
194
+
195
+ GlobalID::Locator.locate_many(gids, options)
196
+ end
197
+
198
+ # Mirrors how `GlobalID::Locator::BaseLocator#locate_many` keys its own
199
+ # result index, so composite primary keys line up with
200
+ # `reference_model_id`.
201
+ def normalized_record_key(id)
202
+ id.is_a?(Array) ? id.map(&:to_s) : id.to_s
203
+ end
204
+
205
+ def includes_for(includes, type)
206
+ return nil if includes.nil?
207
+ return includes unless per_type_includes?(includes)
208
+
209
+ entry = includes.find { |key, _| (key.is_a?(Module) ? key.name : key.to_s) == type }
210
+ entry&.last
211
+ end
212
+
213
+ # A Hash counts as a per-type mapping only when every key names a class.
214
+ # Symbol keys mean the caller passed an Active Record includes spec such
215
+ # as `{ account: :identifiers }`, which must be applied uniformly.
216
+ def per_type_includes?(includes)
217
+ includes.is_a?(Hash) &&
218
+ includes.any? &&
219
+ includes.keys.all? { |key| key.is_a?(String) || key.is_a?(Module) }
220
+ end
221
+ end
222
+
223
+ # Writers. `preloaded_actor = record_or_nil` is the supported way to hand a
224
+ # separately-resolved record to a log; `nil` means "resolved to nothing",
225
+ # not "clear the memo".
226
+ REFERENCES.each do |ref|
227
+ define_method(:"preloaded_#{ref}=") do |record|
228
+ write_preloaded_reference(ref, record)
229
+ end
230
+
231
+ define_method(:"#{ref}_preloaded?") do
232
+ reference_preloaded?(ref)
233
+ end
234
+
235
+ # `actor_model_id` / `target_model_id` / `scope_model_id` — the trailing
236
+ # gid segment, without needing the record.
237
+ define_method(:"#{ref}_model_id") do
238
+ self.class.reference_model_id(public_send(:"#{ref}_gid"))
239
+ end
240
+ end
241
+
242
+ # The memo itself. Public because `preload_references` writes through it
243
+ # from the class side; treat it as gem-internal — `preloaded_actor=` and
244
+ # `actor_preloaded?` are the supported surface.
245
+ def preloaded_references
246
+ @preloaded_references ||= {}
247
+ end
248
+
249
+ def reference_preloaded?(ref)
250
+ preloaded_references.key?(ref.to_sym)
251
+ end
252
+
253
+ # See `preloaded_references` — gem-internal, but public so the class-level
254
+ # preloader can reach it.
255
+ def write_preloaded_reference(ref, record)
256
+ preloaded_references[ref.to_sym] = record
257
+ end
258
+
259
+ # Drops the memo so the next read re-resolves from the (possibly changed)
260
+ # gid columns.
261
+ def reload(...)
262
+ @preloaded_references = nil
263
+ super
264
+ end
265
+
266
+ private
267
+
268
+ # The single-row fallback: identical to the pre-0.7.0 reader behaviour.
269
+ def locate_reference(ref)
270
+ gid = public_send(:"#{ref}_gid")
271
+ return nil if gid.blank?
272
+
273
+ GlobalID::Locator.locate(gid)
274
+ rescue ActiveRecord::RecordNotFound
275
+ nil
276
+ end
277
+
278
+ def read_reference(ref)
279
+ ref = ref.to_sym
280
+ return preloaded_references[ref] if preloaded_references.key?(ref)
281
+
282
+ locate_reference(ref)
283
+ end
284
+
285
+ def assign_reference(ref, record)
286
+ if record.nil?
287
+ public_send(:"#{ref}_gid=", nil)
288
+ public_send(:"#{ref}_type=", nil)
289
+ else
290
+ public_send(:"#{ref}_gid=", record.to_global_id.to_s)
291
+ public_send(:"#{ref}_type=", record.class.name)
292
+ end
293
+
294
+ write_preloaded_reference(ref, record)
295
+ record
296
+ end
297
+ end
298
+ end
@@ -8,9 +8,23 @@ require "standard_audit"
8
8
  # - Resets the Configuration via `StandardAudit.reset_configuration!` so
9
9
  # that mutations to `StandardAudit.config` (subscriptions, sensitive
10
10
  # keys, async flag, custom resolvers, etc.) do not bleed across specs.
11
- # Consumers that customise configuration must re-call
12
- # `StandardAudit.configure { |c| ... }` from a `before` hook in their
13
- # own suite if they need a non-default baseline.
11
+ #
12
+ # IMPORTANT declare your configuration as a baseline. The reset restores
13
+ # gem defaults, and the config object holds *behaviour*, not just data:
14
+ # `before_checksum_hooks` live there. A suite that installs this plugin
15
+ # without a baseline silently loses its write-time hooks after the first
16
+ # example, and the specs that would have caught it pass vacuously.
17
+ #
18
+ # So in `config/initializers/standard_audit.rb`, use:
19
+ #
20
+ # StandardAudit.configure(baseline: true) do |config|
21
+ # config.subscribe_to "myapp.**"
22
+ # config.before_checksum :backfill_scope
23
+ # end
24
+ #
25
+ # `reset_configuration!` replays that block onto the fresh Configuration,
26
+ # so every example starts from your app's real configuration. There is
27
+ # nothing to re-apply by hand in a `before` hook.
14
28
  #
15
29
  # The memoized `Subscriber` and `EventSubscriber` instances are *not*
16
30
  # torn down here — they are wired up at engine boot via initializers and