bard-exception_notification 0.1.0 → 0.1.1

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: a24301e4be9951e47b9c36677feddb1e821b1f2ce800c9981267cea23c3b62a7
4
- data.tar.gz: 6ba33cc979646e6291832a1d7e00e78db3006773bda7dfcb25bd88d864eba420
3
+ metadata.gz: 353fd8c4eace3b5ba7cd5472113d701d9911e4b76162faecfdfc300f6ab46104
4
+ data.tar.gz: 9838422417dfaac9ecc11d901f61b9890f53c64b454138c05c46e637d6452eba
5
5
  SHA512:
6
- metadata.gz: 86e2d68724422b51e9851d22c940fb9a57b59539f70815eb200e3f0776bbdf91b1ceda1dfa8899e4433b07942ac4d6ef838c9aaca1b3ebfb185dcbccc000d814
7
- data.tar.gz: bd446d6a565fba957c8f82b4dadf318c78304c0ee56e1f182f672e07b252ba2172b96e92ba826bfc20910db6d5b26e70d6d175d1278d6d4756848e24fc8bb39b
6
+ metadata.gz: 897db35b4eda7a1dfd0efe4de4d04e3c4340b6bdfb3c9c0c3c4a9c6bfa490d38a208afa52730822ea9bab55e52dd4c1d82631963a4f2590a90db4e9f03568f46
7
+ data.tar.gz: ae8e67d64988a1c92b5d23055be4c747811ed6d56b83eaefd34ed0cc828c8bf2f944268c523d1e817ef1bd412584f93a486b72020a03987493d89e3e13f4ea01
data/CLAUDE.md CHANGED
@@ -20,7 +20,7 @@ A Rails engine gem that gives every BARD-managed Rails app the same exception_no
20
20
  - It adds `filter_parameters` for cookie/auth/session env keys so they show as `[FILTERED]` in emails, and ignores everything outside `Rails.env.production?`.
21
21
  - Job failures come from a `perform.active_job` notification subscriber, which fires only once retries are exhausted and never for discarded jobs.
22
22
  - The test route is prepended with a constraint on `Test::ENV_KEY`, an env key set only in-process, so it can't be reached over HTTP.
23
- - `lib/bard/exception_notification/test.rb` + `lib/tasks/exception_notification.rake` implement the end-to-end check. `Test.web` drives `Rails.application.call` with a mock request and inspects `exception_notifier.delivered`. It sets `ExceptionNotifier.testing_mode = true` so delivery failures raise instead of being only logged. The `test` task runs `web`, then `job`, then `rake`; `rake` goes last because it aborts by raising.
23
+ - `lib/bard/exception_notification/test.rb` + `lib/tasks/exception_notification.rake` implement the end-to-end check. `Test.web` drives `Rails.application.call` with a mock request and inspects `exception_notifier.delivered`. It sets `ExceptionNotifier.testing_mode = true` so delivery failures raise instead of being only logged. The `test` task runs `web`, `job`, and `rake`, and exits 0 when all three succeed. A rake notification needs an exception to escape a task, so `Test.rake` runs the hidden `exception_notification:test:raise` task in a child `bin/rails` process. That task registers a last `:bard_test_sent` lambda notifier, which prints `Test::SENT_MARKER` only if the notifiers before it delivered without raising. The parent then checks the child's output for that marker.
24
24
  - `app/` holds the engine's `TestsController` and `TestJob` (which inherits the host's `::ApplicationJob`).
25
25
 
26
26
  ## Specs
data/README.md CHANGED
@@ -56,9 +56,9 @@ This runs three checks in order:
56
56
 
57
57
  - `exception_notification:test:web` sends a request through the app's middleware stack to a test page that raises, then fails unless a notification was delivered. The page is reachable only from this task, never over HTTP. The request uses the host from `Rails.application.default_url_options`, so that host must be allowed by `config.hosts`.
58
58
  - `exception_notification:test:job` enqueues a job that raises. Its notification is sent once a worker runs the job and any retries configured by `ApplicationJob` are exhausted.
59
- - `exception_notification:test:rake` raises from the task itself, so the task exits with a failure after sending its notification.
59
+ - `exception_notification:test:rake` runs `bin/rails exception_notification:test:raise` in a child process, which fails by raising so that its notification goes out, and then checks that the notification was sent.
60
60
 
61
- The web and rake checks raise if the notification can't be delivered, instead of only logging the failure.
61
+ The command exits 0 once the web and rake notifications are sent and the job is enqueued. The web and rake checks fail if a notification is ignored or can't be delivered, instead of only logging the failure.
62
62
 
63
63
  ## Development
64
64
 
@@ -1,5 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require "open3"
4
+
3
5
  module Bard
4
6
  module ExceptionNotification
5
7
  class TestError < StandardError; end
@@ -7,6 +9,7 @@ module Bard
7
9
  module Test
8
10
  # Set only in-process, so no HTTP request can reach the test page.
9
11
  ENV_KEY = "bard.exception_notification.test"
12
+ SENT_MARKER = "exception_notification: sent"
10
13
 
11
14
  extend self
12
15
 
@@ -29,8 +32,17 @@ module Bard
29
32
  puts "job: enqueued #{TestJob}; its notification is sent once the job fails for good, after any retries ApplicationJob configures"
30
33
  end
31
34
 
35
+ # A rake notification needs an exception to escape a task, so it's raised in a child process to let this one exit 0.
32
36
  def rake
37
+ output, _status = Open3.capture2e(::Rails.root.join("bin/rails").to_s, "exception_notification:test:raise", chdir: ::Rails.root.to_s)
38
+ raise "The rake task's #{TestError} notification was not sent:\n#{output}" unless output.include?(SENT_MARKER)
39
+ puts "rake: sent a #{TestError} notification from a failing rake task"
40
+ end
41
+
42
+ # Registered last, this notifier runs only once the others have delivered without raising.
43
+ def raise_from_rake
33
44
  surface_delivery_failures!
45
+ ExceptionNotifier.register_exception_notifier(:bard_test_sent, ->(_exception, _options) { warn SENT_MARKER })
34
46
  raise TestError, message("rake")
35
47
  end
36
48
 
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Bard
4
4
  module ExceptionNotification
5
- VERSION = "0.1.0"
5
+ VERSION = "0.1.1"
6
6
  end
7
7
  end
@@ -15,9 +15,13 @@ namespace :exception_notification do
15
15
  Bard::ExceptionNotification::Test.job
16
16
  end
17
17
 
18
- desc "Send a test exception notification from a rake task"
18
+ desc "Send a test exception notification from a rake task that fails"
19
19
  task rake: :environment do
20
20
  Bard::ExceptionNotification::Test.rake
21
21
  end
22
+
23
+ task raise: :environment do
24
+ Bard::ExceptionNotification::Test.raise_from_rake
25
+ end
22
26
  end
23
27
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: bard-exception_notification
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Micah Geisel
@@ -83,7 +83,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
83
83
  - !ruby/object:Gem::Version
84
84
  version: '0'
85
85
  requirements: []
86
- rubygems_version: 4.0.20
86
+ rubygems_version: 4.0.6
87
87
  specification_version: 4
88
88
  summary: Shared exception_notification setup for BARD-managed Rails projects
89
89
  test_files: []