brainzlab 0.1.29 → 0.1.32

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 66b1827b6976d4cc3f0b16536eda54ac36ebc3fdba1f49369d93089198a99d73
4
- data.tar.gz: 6a5d234eb169b6401ff226fe0944006fc3fea60df64a574aeb86f98466fd7c7d
3
+ metadata.gz: 2c27f671d247f5b7274905767ed060ec3bfc90c7e2389b8fe117fb300c09a59b
4
+ data.tar.gz: 3af6ac68bd7042f00aa16defa1c68d170653a9b053fe98cb375760b6f72bc14a
5
5
  SHA512:
6
- metadata.gz: 2e958e58fdf83b5b472e3353a3f14b5b8d8a39315942eb74668735a2faefef9413d561b06b511bfff63fe2f633e8261320d3a8a7a25cf269ff0454283bfe6e36
7
- data.tar.gz: 7601dbd331048b5fc8dd184c218ce9605ef010efd47d5b51fbeee52506f692bd4bad768219a4b8ad95562e9e28a006696886643c492fae303008ae8ca8c2795f
6
+ metadata.gz: 571ec070d0ff6d1f3503245a6c0e201d4d81903fda8a0d6ddf316ae7148c4bee6deb93299b76e5fc22839747d9f827cbf68da46dc04cb7d01abf2685580fb647
7
+ data.tar.gz: 9af9570ce725917a5093a9efbc46f81b13c454bb044549057eb49e43fa717e2750d28d580db055171bcb7e9d4c2cc2173e283bb47e7154510a16f1c82ac2ee3e
data/CHANGELOG.md CHANGED
@@ -2,6 +2,18 @@
2
2
 
3
3
  All notable changes to this project will be documented in this file.
4
4
 
5
+ ## [0.1.31] - 2026-06-18
6
+
7
+ ### Fixed
8
+
9
+ - **Health-check Engine no longer auto-draws routes at all.** Any `routes.draw` (class-body in ≤0.1.29, or an initializer in 0.1.30) triggers Devise's `RouteSet#finalize!` patch → `Devise.configure_warden!`. When that runs before Warden's middleware is configured, apps with `devise_scope` routes crash with `NoMethodError: undefined method 'failure_app=' for nil`. The engine's routes were unused (consumers use their own `/up` probe), so the auto-draw is removed entirely. The health logic remains available via `HealthCheck.run`; apps can expose HTTP endpoints from their own routes (see the comment in `health_check.rb`).
10
+
11
+ ## [0.1.30] - 2026-06-18
12
+
13
+ ### Fixed
14
+
15
+ - **Health-check Engine route draw deferred to an initializer** (superseded by 0.1.31 — deferring wasn't enough, since the initializer still ran before Warden middleware).
16
+
5
17
  ## [0.1.25] - 2026-06-07
6
18
 
7
19
  ### Added
@@ -30,8 +30,12 @@ module BrainzLab
30
30
  end
31
31
  end
32
32
 
33
- # Add request context middleware (runs early)
34
- app.middleware.insert_after ActionDispatch::RequestId, BrainzLab::Rails::Middleware
33
+ # Add request context middleware. Gated on `enabled` so the kill switch
34
+ # (BRAINZLAB_SDK_ENABLED=false) fully removes it — it previously loaded
35
+ # unconditionally, so disabling didn't stop its session interference.
36
+ if BrainzLab.configuration.enabled
37
+ app.middleware.insert_after ActionDispatch::RequestId, BrainzLab::Rails::Middleware
38
+ end
35
39
 
36
40
  # Add DevTools middlewares if enabled
37
41
  if BrainzLab.configuration.devtools_enabled
@@ -220,16 +224,10 @@ module BrainzLab
220
224
  # Store request_id in thread local for log subscriber
221
225
  Thread.current[:brainzlab_request_id] = request_id
222
226
 
223
- # Capture session_id - access session to ensure it's loaded
224
- if request.session.respond_to?(:id)
225
- # Force session load by accessing it
226
- session_id = begin
227
- request.session.id
228
- rescue StandardError
229
- nil
230
- end
231
- context.session_id = session_id.to_s if session_id.present?
232
- end
227
+ # NOTE: session_id is captured AFTER @app.call (see below), never here.
228
+ # Forcing a session load on the way in — before the app's session
229
+ # middleware and any reset_session (login) — drops the session on
230
+ # cookie/active_record_store apps, causing login loops.
233
231
 
234
232
  # Capture full request info for Reflex
235
233
  context.request_method = request.request_method
@@ -276,6 +274,19 @@ module BrainzLab
276
274
 
277
275
  status, headers, response = @app.call(env)
278
276
 
277
+ # Capture session_id now that the app (and its session middleware) has
278
+ # run. Read it only if the session was already loaded — never force a
279
+ # load — so we never disturb the session lifecycle / Set-Cookie.
280
+ begin
281
+ rack_session = env['rack.session']
282
+ if rack_session && (!rack_session.respond_to?(:loaded?) || rack_session.loaded?)
283
+ sid = rack_session.respond_to?(:id) ? rack_session.id : nil
284
+ context.session_id = sid.to_s if sid && !sid.to_s.empty?
285
+ end
286
+ rescue StandardError
287
+ nil
288
+ end
289
+
279
290
  # Add breadcrumb for response
280
291
  BrainzLab::Reflex.add_breadcrumb(
281
292
  "Response #{status}",
@@ -254,16 +254,26 @@ module BrainzLab
254
254
  end
255
255
  end
256
256
 
257
- # Rails Engine for mounting health endpoints
257
+ # Rails Engine for the health endpoints.
258
+ #
259
+ # Routes are intentionally NOT auto-drawn at boot. Any `routes.draw`
260
+ # triggers Devise's RouteSet#finalize! patch, which calls
261
+ # Devise.configure_warden!; if that runs before Warden's middleware is
262
+ # configured (e.g. while another engine draws routes during early boot),
263
+ # apps with `devise_scope` routes crash with
264
+ # `NoMethodError: undefined method 'failure_app=' for nil`.
265
+ #
266
+ # The health logic is available directly via `HealthCheck.run`. To expose
267
+ # HTTP endpoints, draw them in your app's own routes (loaded at the correct
268
+ # boot phase), e.g.:
269
+ # namespace :health, module: "brain_z_lab/utilities/health_check" do
270
+ # get "/", to: "health#show"
271
+ # get "/live", to: "health#live"
272
+ # get "/ready", to: "health#ready"
273
+ # end
258
274
  if defined?(::Rails::Engine)
259
275
  class Engine < ::Rails::Engine
260
276
  isolate_namespace BrainzLab::Utilities::HealthCheck
261
-
262
- routes.draw do
263
- get '/', to: 'health#show'
264
- get '/live', to: 'health#live'
265
- get '/ready', to: 'health#ready'
266
- end
267
277
  end
268
278
  end
269
279
 
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module BrainzLab
4
- VERSION = '0.1.29'
4
+ VERSION = '0.1.32'
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: brainzlab
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.29
4
+ version: 0.1.32
5
5
  platform: ruby
6
6
  authors:
7
7
  - BrainzLab