stack-service-base 0.0.44 → 0.0.45

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: f513209afafa48f7df545924f19a06541edba143db06d84ceb7c70dce5aa93e0
4
- data.tar.gz: b156c2d8f6a2ce4c45956e2ba355cef65b7cf7632a0766ef0df15d25642b7f86
3
+ metadata.gz: a8dd8e95b44e414e82e74ca8564e57ebcc7fe6b060c468fca14ed3f72d60e438
4
+ data.tar.gz: 9e856f0ba26407b178bdbef0293001c89f5d74e12f8cd50670e1002ac83d29db
5
5
  SHA512:
6
- metadata.gz: 71f7b87b85e3346893cf292f4c53a50c6184b19f97a87022c29376391d4fc05515b3577f14ac432d4b81d4fc98b75d50b5bff272bcace2c1a1ea1ad99257febb
7
- data.tar.gz: 706b34820618e70f2472a7940eb5f9249ece5daf014b2eca18a45f90cc6471409b13c8fdeab0b2b237c18db9285ef2c682f2ca6318c7f16cb225e9917183bd6b
6
+ metadata.gz: b79b0985c03a2c9613143c4c06fa9758b24dcc7fc73acb343666a4f10b64e0ace50b812189778b5f4f86232c863db1c4d2cf59423155a20841ed8cc9f25eb02c
7
+ data.tar.gz: be2a3866a0aa3b8278a28226551dd1c8ea6e445a366a52e10af7831808f085a64a7104d35a031d9be049579ac54d683954d8f0bdf3e5bfc45761afcbb83c2dbe
@@ -0,0 +1,217 @@
1
+ unless ENV['RUBYOPT'] =~ /ruby-debug-ide/ # if defined?(::DEBUGGER__)
2
+
3
+ ENV['RUBY_DEBUG_CHROME_PATH'] = ''
4
+ ENV['RUBY_DEBUG_PORT'] = '12000'
5
+
6
+ require 'debug/session'
7
+ require 'debug/server'
8
+ require 'debug/server_cdp'
9
+
10
+ module DebugSkipMissingSources
11
+ def get_source_code(path)
12
+ super
13
+ rescue Errno::ENOENT, Errno::ENOTDIR => e
14
+ DEBUGGER__.warn "Skipped missing source for Chrome breakpoint: #{path} (#{e.message})"
15
+ @src_map[path] ||= '' # keep DevTools happy even though the file is absent
16
+ end
17
+ end
18
+
19
+ DEBUGGER__::UI_CDP.prepend(DebugSkipMissingSources)
20
+
21
+ module FixedChromeUuid
22
+ def chrome_setup
23
+ @uuid = ENV['RUBY_DEBUG_CHROME_UUID'] || '12345678-1234-5678-9abc-def012345678'
24
+ @chrome_pid = DEBUGGER__::UI_CDP.setup_chrome(@local_addr.inspect_sockaddr, @uuid)
25
+ DEBUGGER__.warn <<~TXT
26
+ With Chrome browser, type the following URL in the address-bar:
27
+ devtools://devtools/bundled/inspector.html?v8only=true&panel=sources&noJavaScriptCompletion=true&ws=#{@local_addr.inspect_sockaddr}/#{@uuid}
28
+ TXT
29
+ end
30
+ end
31
+
32
+ DEBUGGER__::UI_TcpServer.prepend(FixedChromeUuid)
33
+
34
+
35
+ module SkipMissingRegexBreakpoints
36
+ def add_line_breakpoint(req, b_id, path)
37
+ return super if File.exist?(path)
38
+
39
+ DEBUGGER__.warn "Skipping breakpoint for missing source: #{path}"
40
+ send_response req, breakpointId: b_id, locations: []
41
+ # Returning keeps Chrome happy and avoids queuing the request
42
+ end
43
+ end
44
+
45
+ DEBUGGER__::UI_CDP.prepend(SkipMissingRegexBreakpoints)
46
+
47
+ module DebugKeepThreadsRunning
48
+ def stop_all_threads
49
+ DEBUGGER__.warn 'skip stop_all_threads (threads keep running)'
50
+ end
51
+
52
+ def restart_all_threads
53
+ DEBUGGER__.warn 'skip restart_all_threads (threads already running)'
54
+ end
55
+
56
+ def wait_command_loop
57
+ begin
58
+ super
59
+ rescue =>e
60
+ DEBUGGER__.warn "EXCEPTION wait_command_loop: #{e.message}"
61
+ retry
62
+ end
63
+ end
64
+ end
65
+
66
+ DEBUGGER__::Session.prepend(DebugKeepThreadsRunning)
67
+
68
+ module FixedCdpUuid
69
+ def send_chrome_response(req)
70
+ env_uuid = ENV['RUBY_DEBUG_CHROME_UUID'] || '12345678-1234-5678-9abc-def012345678'
71
+ @uuid = env_uuid if env_uuid # re-apply before every handshake
72
+ DEBUGGER__.warn "Chrome UUID: #{env_uuid} (#{req.inspect})"
73
+ super
74
+ end
75
+ end
76
+
77
+ DEBUGGER__::UI_CDP.prepend(FixedCdpUuid)
78
+ module DebugResetCdpCache
79
+ def reset_cdp_script_cache!
80
+ @scr_id_map = {}
81
+ @obj_map = {}
82
+ end
83
+ end
84
+
85
+ module DebugResetCdpOnHandshake
86
+ def send_chrome_response(req)
87
+ if req.match?(/^GET\s\/[\h]{8}-[\h]{4}-[\h]{4}-[\h]{4}-[\h]{12}\sHTTP\/1\.1/)
88
+ if defined?(::DEBUGGER__::SESSION) && ::DEBUGGER__::SESSION.respond_to?(:reset_cdp_script_cache!)
89
+ ::DEBUGGER__::SESSION.reset_cdp_script_cache!
90
+ end
91
+ end
92
+ super
93
+ end
94
+ end
95
+
96
+ DEBUGGER__::Session.prepend(DebugResetCdpCache)
97
+ DEBUGGER__::UI_CDP.prepend(DebugResetCdpOnHandshake)
98
+
99
+ module DebugPreloadSources
100
+ class << self
101
+ def register(*paths)
102
+ stash.concat(paths.flatten.map { |p| File.expand_path(p) })
103
+ stash.uniq!
104
+ end
105
+
106
+ def register_breakpoint(path, line, **opts)
107
+ bp_entries << [File.expand_path(path), Integer(line), opts]
108
+ p bp_entries
109
+ end
110
+
111
+ def each_source(&block) = stash.each(&block)
112
+ def each_breakpoint(&block) = bp_entries.each(&block)
113
+
114
+ private
115
+
116
+ def stash = (@stash ||= [])
117
+ def bp_entries = (@bp_entries ||= [])
118
+ end
119
+ end
120
+
121
+ module DebugPreloadSession
122
+ def announce_cdp_sources
123
+ ensure_preloaded_breakpoints
124
+ super if defined?(super)
125
+ ensure
126
+ push_cdp_sources_to_ui
127
+ end
128
+
129
+ private
130
+
131
+ def ensure_preloaded_breakpoints
132
+ @__preloaded_breakpoints ||= {}
133
+ DebugPreloadSources.each_breakpoint do |path, line, opts|
134
+ key = [path, line, opts]
135
+ next if @__preloaded_breakpoints[key]
136
+
137
+ begin
138
+ ::DEBUGGER__.add_line_breakpoint(path, line, **opts)
139
+ @__preloaded_breakpoints[key] = true
140
+ rescue Errno::ENOENT => e
141
+ DEBUGGER__.warn "Preload breakpoint skipped: #{path}:#{line} (#{e.message})"
142
+ end
143
+ end
144
+ end
145
+
146
+ def push_cdp_sources_to_ui
147
+ return unless @ui&.respond_to?(:fire_event)
148
+
149
+ DebugPreloadSources.each_source do |path|
150
+ next if @scr_id_map[path]
151
+ next unless File.file?(path)
152
+
153
+ source = File.read(path)
154
+ script_id = (@scr_id_map.size + 1).to_s
155
+ @scr_id_map[path] = script_id
156
+ @src_map[script_id] = source
157
+
158
+ @ui.fire_event 'Debugger.scriptParsed',
159
+ scriptId: script_id,
160
+ url: path,
161
+ startLine: 0,
162
+ startColumn: 0,
163
+ endLine: source.lines.count,
164
+ endColumn: 0,
165
+ executionContextId: 1,
166
+ hash: source.hash.inspect
167
+ end
168
+ end
169
+ end
170
+
171
+ module DebugPreloadHandshake
172
+ def send_chrome_response(request)
173
+ res = super
174
+ if request.match?(/^GET\s\/[\h]{8}-[\h]{4}-[\h]{4}-[\h]{4}-[\h]{12}\sHTTP\/1\.1/) &&
175
+ defined?(::DEBUGGER__::SESSION)
176
+ ::DEBUGGER__::SESSION.extend(DebugPreloadSession)
177
+ ::DEBUGGER__::SESSION.announce_cdp_sources
178
+ end
179
+ res
180
+ end
181
+ end
182
+
183
+ DEBUGGER__::UI_CDP.prepend(DebugPreloadHandshake)
184
+ # DEBUGGER__::Session.prepend(DebugPreloadSession)
185
+ # DEBUGGER__::UI_CDP.prepend(DebugPreloadHandshake)
186
+
187
+ DebugPreloadSources.register(
188
+ Dir[File.expand_path('../**/*')]
189
+ )
190
+
191
+ break_line_index = File.readlines(__FILE__).index{ _1. match?(/remote [d]ebugger default breakpoint/) }.to_i + 2
192
+ DEBUGGER__.warn "break_line_index: #{break_line_index}"
193
+
194
+ DebugPreloadSources.register_breakpoint File.expand_path(__FILE__), break_line_index
195
+
196
+ Thread.new do
197
+ DEBUGGER__.open open: 'chrome', nonstop: true
198
+
199
+ loop do
200
+ # remote debugger default breakpoint
201
+ sleep 1
202
+ end
203
+ end
204
+
205
+
206
+ unless ENV['RUBYOPT'] =~ /ruby-debug-ide/
207
+ # ENV['RUBY_DEBUG_PORT'] = '12345' #/run/user/1000/rdbg-54391
208
+ # require 'debug/open_nonstop'
209
+ # to connect
210
+ # rdbg -A
211
+ # rdbg --attach 12345
212
+ # Chrome Devtools https://github.com/ruby/debug/pull/334/files#diff-5fc3d0a901379a95bc111b86cf0090b03f857edfd0b99a0c1537e26735698453R55-R64
213
+ # rdbg target.rb -O chrome --port 1234
214
+ end
215
+
216
+
217
+ end
@@ -1,3 +1,3 @@
1
1
  module StackServiceBase
2
- VERSION = '0.0.44'
2
+ VERSION = '0.0.45'
3
3
  end
@@ -4,6 +4,7 @@ require 'stack-service-base/rack_helpers'
4
4
  require 'stack-service-base/open_telemetry'
5
5
  require 'stack-service-base/nats_service'
6
6
  require 'stack-service-base/sinatra_ext'
7
+ require 'stack-service-base/debugger'
7
8
 
8
9
  module StackServiceBase
9
10
  class << self
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: stack-service-base
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.44
4
+ version: 0.0.45
5
5
  platform: ruby
6
6
  authors:
7
7
  - Artyom B
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2025-10-01 00:00:00.000000000 Z
11
+ date: 2025-10-16 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rack
@@ -122,6 +122,20 @@ dependencies:
122
122
  - - ">="
123
123
  - !ruby/object:Gem::Version
124
124
  version: '0'
125
+ - !ruby/object:Gem::Dependency
126
+ name: debug
127
+ requirement: !ruby/object:Gem::Requirement
128
+ requirements:
129
+ - - ">="
130
+ - !ruby/object:Gem::Version
131
+ version: '0'
132
+ type: :runtime
133
+ prerelease: false
134
+ version_requirements: !ruby/object:Gem::Requirement
135
+ requirements:
136
+ - - ">="
137
+ - !ruby/object:Gem::Version
138
+ version: '0'
125
139
  - !ruby/object:Gem::Dependency
126
140
  name: rake
127
141
  requirement: !ruby/object:Gem::Requirement
@@ -218,6 +232,7 @@ files:
218
232
  - lib/stack-service-base/command_init.rb
219
233
  - lib/stack-service-base/command_line.rb
220
234
  - lib/stack-service-base/database.rb
235
+ - lib/stack-service-base/debugger.rb
221
236
  - lib/stack-service-base/fiber_pool.rb
222
237
  - lib/stack-service-base/logging.rb
223
238
  - lib/stack-service-base/nats_patch_1.rb