rails-profiler 0.25.0 → 0.27.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.
Files changed (32) hide show
  1. checksums.yaml +4 -4
  2. data/app/assets/builds/profiler.css +24 -0
  3. data/app/assets/builds/profiler.js +739 -31
  4. data/app/controllers/profiler/api/test_runner_controller.rb +115 -0
  5. data/app/controllers/profiler/api/tests_controller.rb +46 -0
  6. data/app/controllers/profiler/test_runner_controller.rb +11 -0
  7. data/app/views/profiler/test_runner/index.html.erb +1 -0
  8. data/config/routes.rb +10 -0
  9. data/lib/profiler/collectors/database_collector.rb +1 -1
  10. data/lib/profiler/collectors/test_collector.rb +75 -0
  11. data/lib/profiler/configuration.rb +12 -1
  12. data/lib/profiler/mcp/resources/failing_tests.rb +40 -0
  13. data/lib/profiler/mcp/resources/recent_console.rb +36 -0
  14. data/lib/profiler/mcp/resources/slow_tests.rb +45 -0
  15. data/lib/profiler/mcp/server.rb +122 -8
  16. data/lib/profiler/mcp/tools/clear_profiles.rb +3 -3
  17. data/lib/profiler/mcp/tools/get_profile_detail.rb +123 -1
  18. data/lib/profiler/mcp/tools/get_profile_mailers.rb +147 -0
  19. data/lib/profiler/mcp/tools/get_test_profile_detail.rb +126 -0
  20. data/lib/profiler/mcp/tools/query_console_profiles.rb +95 -0
  21. data/lib/profiler/mcp/tools/query_test_profiles.rb +109 -0
  22. data/lib/profiler/mcp/tools/run_tests.rb +112 -0
  23. data/lib/profiler/railtie.rb +13 -1
  24. data/lib/profiler/test_helpers/minitest_support.rb +39 -0
  25. data/lib/profiler/test_helpers/reporter.rb +121 -0
  26. data/lib/profiler/test_helpers/rspec_support.rb +33 -0
  27. data/lib/profiler/test_profiler.rb +140 -0
  28. data/lib/profiler/test_runner/discovery.rb +57 -0
  29. data/lib/profiler/test_runner/run_store.rb +120 -0
  30. data/lib/profiler/test_runner/runner.rb +106 -0
  31. data/lib/profiler/version.rb +1 -1
  32. metadata +22 -2
@@ -0,0 +1,106 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "run_store"
4
+ require_relative "discovery"
5
+
6
+ module Profiler
7
+ module TestRunner
8
+ class Runner
9
+ def self.start(files:, framework:)
10
+ run = Profiler::TestRunner.run_store.create(files: files, framework: framework)
11
+ spawn_async(run)
12
+ run
13
+ end
14
+
15
+ def self.kill(run_id)
16
+ run = Profiler::TestRunner.run_store.find(run_id)
17
+ return false unless run && run.pid && run.status == "running"
18
+
19
+ begin
20
+ Process.kill("TERM", run.pid)
21
+ Profiler::TestRunner.run_store.update(run_id, status: "killed", finished_at: Time.now)
22
+ true
23
+ rescue Errno::ESRCH
24
+ # Process already exited
25
+ false
26
+ end
27
+ end
28
+
29
+ private
30
+
31
+ def self.spawn_async(run)
32
+ Thread.new do
33
+ run_process(run)
34
+ rescue => e
35
+ Profiler::TestRunner.run_store.update(
36
+ run.id,
37
+ status: "error",
38
+ finished_at: Time.now
39
+ )
40
+ Profiler::TestRunner.run_store.append_output(run.id, "\n[Profiler] Error: #{e.message}\n")
41
+ end
42
+ end
43
+
44
+ def self.run_process(run)
45
+ cmd = build_command(run.files, run.framework)
46
+ env = build_env
47
+
48
+ Profiler::TestRunner.run_store.update(run.id, status: "running", started_at: Time.now)
49
+
50
+ IO.popen([env, *cmd, err: [:child, :out]], "r") do |io|
51
+ Profiler::TestRunner.run_store.update(run.id, pid: io.pid)
52
+
53
+ while (chunk = io.read(256))
54
+ break if chunk.empty?
55
+
56
+ Profiler::TestRunner.run_store.append_output(run.id, chunk)
57
+ end
58
+ end
59
+
60
+ exit_code = $?.exitstatus || 0
61
+ status = exit_code == 0 ? "passed" : "failed"
62
+
63
+ Profiler::TestRunner.run_store.update(
64
+ run.id,
65
+ status: status,
66
+ finished_at: Time.now,
67
+ exit_code: exit_code
68
+ )
69
+ end
70
+
71
+ def self.build_command(files, framework)
72
+ root = defined?(Rails) ? Rails.root.to_s : Dir.pwd
73
+ absolute_files = files.map { |f| File.join(root, f) }
74
+
75
+ case framework.to_sym
76
+ when :rspec
77
+ ["bundle", "exec", "rspec", "--format", "progress", "--color", *absolute_files]
78
+ when :minitest
79
+ ["bundle", "exec", "rails", "test", *absolute_files]
80
+ else
81
+ ["bundle", "exec", "rspec", "--format", "progress", "--color", *absolute_files]
82
+ end
83
+ end
84
+
85
+ BLOCKED_ENV_KEYS = %w[RAILS_ENV RACK_ENV DATABASE_URL SECRET_KEY_BASE].freeze
86
+
87
+ def self.build_env
88
+ base = ENV.to_h
89
+
90
+ # Inject env var overrides configured in the profiler — skip blocked keys
91
+ overrides = Profiler.env_override_store.all_overrides
92
+ overrides.each do |key, entry|
93
+ next if BLOCKED_ENV_KEYS.include?(key.upcase)
94
+ value = entry.is_a?(Hash) ? entry["value"] : entry
95
+ base[key] = value
96
+ end
97
+
98
+ # Ensure test environment regardless of overrides
99
+ base["RAILS_ENV"] = "test"
100
+ base["RACK_ENV"] = "test"
101
+
102
+ base
103
+ end
104
+ end
105
+ end
106
+ end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Profiler
4
- VERSION = "0.25.0"
4
+ VERSION = "0.27.0"
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rails-profiler
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.25.0
4
+ version: 0.27.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Sébastien Duplessy
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2026-06-01 00:00:00.000000000 Z
11
+ date: 2026-06-02 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -114,14 +114,18 @@ files:
114
114
  - app/controllers/profiler/api/jobs_controller.rb
115
115
  - app/controllers/profiler/api/outbound_http_controller.rb
116
116
  - app/controllers/profiler/api/profiles_controller.rb
117
+ - app/controllers/profiler/api/test_runner_controller.rb
118
+ - app/controllers/profiler/api/tests_controller.rb
117
119
  - app/controllers/profiler/api/toolbar_controller.rb
118
120
  - app/controllers/profiler/application_controller.rb
119
121
  - app/controllers/profiler/assets_controller.rb
120
122
  - app/controllers/profiler/profiles_controller.rb
123
+ - app/controllers/profiler/test_runner_controller.rb
121
124
  - app/views/layouts/profiler/application.html.erb
122
125
  - app/views/layouts/profiler/embedded.html.erb
123
126
  - app/views/profiler/profiles/index.html.erb
124
127
  - app/views/profiler/profiles/show.html.erb
128
+ - app/views/profiler/test_runner/index.html.erb
125
129
  - config/routes.rb
126
130
  - exe/profiler-mcp
127
131
  - lib/profiler.rb
@@ -142,6 +146,7 @@ files:
142
146
  - lib/profiler/collectors/mailer_collector.rb
143
147
  - lib/profiler/collectors/request_collector.rb
144
148
  - lib/profiler/collectors/routes_collector.rb
149
+ - lib/profiler/collectors/test_collector.rb
145
150
  - lib/profiler/collectors/view_collector.rb
146
151
  - lib/profiler/configuration.rb
147
152
  - lib/profiler/console_profiler.rb
@@ -158,10 +163,13 @@ files:
158
163
  - lib/profiler/mcp/body_formatter.rb
159
164
  - lib/profiler/mcp/file_cache.rb
160
165
  - lib/profiler/mcp/path_extractor.rb
166
+ - lib/profiler/mcp/resources/failing_tests.rb
161
167
  - lib/profiler/mcp/resources/n1_patterns.rb
168
+ - lib/profiler/mcp/resources/recent_console.rb
162
169
  - lib/profiler/mcp/resources/recent_jobs.rb
163
170
  - lib/profiler/mcp/resources/recent_requests.rb
164
171
  - lib/profiler/mcp/resources/slow_queries.rb
172
+ - lib/profiler/mcp/resources/slow_tests.rb
165
173
  - lib/profiler/mcp/server.rb
166
174
  - lib/profiler/mcp/tools/analyze_queries.rb
167
175
  - lib/profiler/mcp/tools/clear_profiles.rb
@@ -171,12 +179,17 @@ files:
171
179
  - lib/profiler/mcp/tools/get_profile_detail.rb
172
180
  - lib/profiler/mcp/tools/get_profile_dumps.rb
173
181
  - lib/profiler/mcp/tools/get_profile_http.rb
182
+ - lib/profiler/mcp/tools/get_profile_mailers.rb
183
+ - lib/profiler/mcp/tools/get_test_profile_detail.rb
174
184
  - lib/profiler/mcp/tools/list_env_vars.rb
185
+ - lib/profiler/mcp/tools/query_console_profiles.rb
175
186
  - lib/profiler/mcp/tools/query_jobs.rb
176
187
  - lib/profiler/mcp/tools/query_mailers.rb
177
188
  - lib/profiler/mcp/tools/query_profiles.rb
189
+ - lib/profiler/mcp/tools/query_test_profiles.rb
178
190
  - lib/profiler/mcp/tools/reset_all_env_vars.rb
179
191
  - lib/profiler/mcp/tools/reset_env_var.rb
192
+ - lib/profiler/mcp/tools/run_tests.rb
180
193
  - lib/profiler/mcp/tools/set_env_var.rb
181
194
  - lib/profiler/middleware/cors_middleware.rb
182
195
  - lib/profiler/middleware/profiler_middleware.rb
@@ -192,6 +205,13 @@ files:
192
205
  - lib/profiler/storage/redis_store.rb
193
206
  - lib/profiler/storage/sqlite_store.rb
194
207
  - lib/profiler/tasks/profiler.rake
208
+ - lib/profiler/test_helpers/minitest_support.rb
209
+ - lib/profiler/test_helpers/reporter.rb
210
+ - lib/profiler/test_helpers/rspec_support.rb
211
+ - lib/profiler/test_profiler.rb
212
+ - lib/profiler/test_runner/discovery.rb
213
+ - lib/profiler/test_runner/run_store.rb
214
+ - lib/profiler/test_runner/runner.rb
195
215
  - lib/profiler/version.rb
196
216
  homepage: https://git.duplessy.eu/sebastien/rails-profiler-gem
197
217
  licenses: