Class: Tng::UI::GoUISession
- Inherits:
-
Object
- Object
- Tng::UI::GoUISession
- Defined in:
- lib/tng/ui/go_ui_session.rb
Overview
Ruby wrapper for calling go-ui binary
Instance Method Summary collapse
-
#display_error(message) ⇒ Object
Display error message using standard output (fallback for simple messages).
-
#display_info(message) ⇒ Object
Display info message.
-
#display_list(title, items) ⇒ Object
Display list of items.
-
#display_warning(message) ⇒ Object
Display warning message.
-
#initialize ⇒ GoUISession
constructor
A new instance of GoUISession.
- #running? ⇒ Boolean
-
#show_about ⇒ Object
Show about screen.
-
#show_audit_results(audit_result, _audit_type) ⇒ Object
Show audit results.
-
#show_auth_error(message = "Authentication failed") ⇒ Object
Show authentication error.
-
#show_auth_warning(missing_items = "") ⇒ String
Show authentication warning.
-
#show_banner(version) ⇒ Object
Show welcome banner.
-
#show_clipboard_success(command) ⇒ Object
Show clipboard success message.
-
#show_clone_menu ⇒ Object
Returns: "1", "2", "all", "back".
-
#show_clones(file_path, results) ⇒ Object
Show clone detection results.
-
#show_config_error(missing) ⇒ Object
Show configuration error.
-
#show_config_missing(missing_items) ⇒ Object
Show missing configuration.
- #show_dead_code_results(file_path, results_json) ⇒ Object
-
#show_goodbye ⇒ Object
Show goodbye message.
-
#show_help(version) ⇒ Object
Show help.
- #show_list_view(title, items) ⇒ Object
-
#show_menu ⇒ Object
Show main menu and return selected choice Returns: "tests", "stats", "about", "exit".
-
#show_no_items(item_type) ⇒ Object
Show 'no items found' message.
-
#show_post_generation_menu(file_path, run_command) ⇒ String
Show post-generation menu.
-
#show_post_install(version) ⇒ Object
Show post-install message.
- #show_progress(title) ⇒ Object
-
#show_ruby_test_type_menu ⇒ Object
Returns: "model", "service", "job", "lib", "utility", "other", "back".
- #show_spinner(message) ⇒ Object
-
#show_stats(stats_data) ⇒ Object
Show user statistics.
- #show_system_status(status) ⇒ Object
-
#show_test_results(title, passed, failed, errors, total, results = []) ⇒ Object
Show test results.
-
#show_test_type_menu(mode = "test") ⇒ Object
Returns: "controller", "model", "service", "other", "back".
-
#show_trace_results(trace_file_path) ⇒ Object
Show symbolic trace results.
- #start ⇒ Object
- #stop ⇒ Object
Constructor Details
#initialize ⇒ GoUISession
Returns a new instance of GoUISession.
11 12 13 14 |
# File 'lib/tng/ui/go_ui_session.rb', line 11 def initialize @binary_path = find_go_ui_binary @running = false end |
Instance Method Details
#display_error(message) ⇒ Object
Display error message using standard output (fallback for simple messages)
440 441 442 |
# File 'lib/tng/ui/go_ui_session.rb', line 440 def display_error() system(@binary_path, "auth-error", "--message", , "--title", "Error") end |
#display_info(message) ⇒ Object
Display info message
451 452 453 |
# File 'lib/tng/ui/go_ui_session.rb', line 451 def display_info() puts end |
#display_list(title, items) ⇒ Object
Display list of items
456 457 458 459 |
# File 'lib/tng/ui/go_ui_session.rb', line 456 def display_list(title, items) puts title items.each { |item| puts " - #{item}" } end |
#display_warning(message) ⇒ Object
Display warning message
445 446 447 448 |
# File 'lib/tng/ui/go_ui_session.rb', line 445 def display_warning() # Re-using auth-error for now but with different color/prefix if possible, or just puts if binary doesn't support generic warning puts end |
#running? ⇒ Boolean
24 25 26 |
# File 'lib/tng/ui/go_ui_session.rb', line 24 def running? @running end |
#show_about ⇒ Object
Show about screen
188 189 190 191 192 |
# File 'lib/tng/ui/go_ui_session.rb', line 188 def show_about system(@binary_path, "about") rescue StandardError => e puts "About error: #{e.message}" end |
#show_audit_results(audit_result, _audit_type) ⇒ Object
Show audit results
253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 |
# File 'lib/tng/ui/go_ui_session.rb', line 253 def show_audit_results(audit_result, _audit_type) # Always use the unified audit-results command which handles both issues and behaviours command = "audit-results" # Send full result object via temp file to avoid CLI argument limits data_json = JSON.generate(audit_result) input_path = _create_temp_file("go_ui_audit", ".json") File.write(input_path, data_json) puts "Audit results file: #{input_path}" if ENV["TNG_KEEP_TMP"] == "1" system(@binary_path, command, "--file", input_path) rescue StandardError => e puts "Audit results error: #{e.message}" ensure _cleanup_temp_file(input_path) unless ENV["TNG_KEEP_TMP"] == "1" end |
#show_auth_error(message = "Authentication failed") ⇒ Object
Show authentication error
326 327 328 329 330 |
# File 'lib/tng/ui/go_ui_session.rb', line 326 def show_auth_error( = "Authentication failed") system(@binary_path, "auth-error", "--message", ) rescue StandardError => e puts "Auth error: #{e.message}" end |
#show_auth_warning(missing_items = "") ⇒ String
Show authentication warning
350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 |
# File 'lib/tng/ui/go_ui_session.rb', line 350 def show_auth_warning(missing_items = "") output_file = Tempfile.new(["go_ui_auth", ".txt"]) output_path = output_file.path output_file.close data = { missing_items: missing_items } data_json = JSON.generate(data) pid = spawn(@binary_path, "auth-warning", "--data", data_json, out: output_path) Process.wait(pid) result = File.read(output_path).strip result.empty? ? "cancel" : result rescue StandardError => e puts "Auth warning error: #{e.message}" "cancel" ensure output_file&.unlink end |
#show_banner(version) ⇒ Object
Show welcome banner
334 335 336 337 338 |
# File 'lib/tng/ui/go_ui_session.rb', line 334 def (version) system(@binary_path, "banner", "--version", version) rescue StandardError => e puts "Banner error: #{e.message}" end |
#show_clipboard_success(command) ⇒ Object
Show clipboard success message
223 224 225 |
# File 'lib/tng/ui/go_ui_session.rb', line 223 def show_clipboard_success(command) system(@binary_path, "clipboard-success", "--command", command) end |
#show_clone_menu ⇒ Object
Returns: "1", "2", "all", "back"
83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 |
# File 'lib/tng/ui/go_ui_session.rb', line 83 def output_path = _create_temp_file("go_ui_clone_menu", ".json") begin system(@binary_path, "clone-menu", "--output", output_path) return "back" unless File.exist?(output_path) && File.size(output_path) > 0 choice = File.read(output_path).strip choice.empty? ? "back" : choice rescue StandardError "back" ensure _cleanup_temp_file(output_path) end end |
#show_clones(file_path, results) ⇒ Object
Show clone detection results
281 282 283 284 285 286 287 288 289 290 291 292 |
# File 'lib/tng/ui/go_ui_session.rb', line 281 def show_clones(file_path, results) data = { file_path: file_path, matches: results[:matches] } data_json = JSON.generate(data) input_path = _create_temp_file("go_ui_clones", ".json") File.write(input_path, data_json) system(@binary_path, "clones", "--file", input_path) rescue StandardError => e puts "Clones results error: #{e.message}" ensure _cleanup_temp_file(input_path) end |
#show_config_error(missing) ⇒ Object
Show configuration error
196 197 198 199 200 201 |
# File 'lib/tng/ui/go_ui_session.rb', line 196 def show_config_error(missing) data_json = JSON.generate({ missing: missing }) system(@binary_path, "config-error", "--data", data_json) rescue StandardError => e puts "Config error: #{e.message}" end |
#show_config_missing(missing_items) ⇒ Object
Show missing configuration
372 373 374 375 376 377 378 |
# File 'lib/tng/ui/go_ui_session.rb', line 372 def show_config_missing(missing_items) data = { missing_items: Array(missing_items) } data_json = JSON.generate(data) system(@binary_path, "config-missing", "--data", data_json) rescue StandardError => e puts "Config missing error: #{e.message}" end |
#show_dead_code_results(file_path, results_json) ⇒ Object
294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 |
# File 'lib/tng/ui/go_ui_session.rb', line 294 def show_dead_code_results(file_path, results_json) parsed = JSON.parse(results_json) # Rust returns {"file": "...", "dead_code": [...]} issues = parsed["dead_code"] || [] data = { file: file_path, dead_code: issues.map do |issue| { type: issue["type"], line: issue["line"], message: issue["message"], code: issue["code"], file: issue["file"] } end } input_path = _create_temp_file("go_ui_dead_code", ".json") File.write(input_path, JSON.generate(data)) system(@binary_path, "deadcode", "--file", input_path) rescue StandardError => e puts "Dead code results error: #{e.message}" ensure _cleanup_temp_file(input_path) end |
#show_goodbye ⇒ Object
Show goodbye message
341 342 343 344 345 |
# File 'lib/tng/ui/go_ui_session.rb', line 341 def show_goodbye system(@binary_path, "goodbye") rescue StandardError => e puts "Goodbye error: #{e.message}" end |
#show_help(version) ⇒ Object
Show help
390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 |
# File 'lib/tng/ui/go_ui_session.rb', line 390 def show_help(version) help_data = { title: "TNG - LLM-Powered Rails Test Generator", usages: [ { cmd: "bundle exec tng", desc: "Interactive mode" }, { cmd: "bundle exec tng --file=FILE --method=METHOD", desc: "Direct test generation" }, { cmd: "bundle exec tng --file=FILE --method=METHOD --audit", desc: "Direct audit mode" }, { cmd: "bundle exec tng --file=FILE --method=METHOD --trace", desc: "Symbolic trace mode" }, { cmd: "bundle exec tng --file=FILE --clones", desc: "Check for code duplicates" }, { cmd: "bundle exec tng --file=FILE --deadcode", desc: "Run dead code detection" }, ], features: [ "Controllers, Models, Services", "17+ other file types (Jobs, Helpers, Lib, Policies, etc.)", "Per-method test generation", "Code audit for issues & behaviors", "Symbolic execution traces", "Duplicate code detection (Clones)", "Dead code detection (Rust-powered)", "Searchable method lists" ], options: [ { flag: "-h, --help", desc: "Show this help message" }, { flag: "--file=PATH", desc: "Target file path (enables direct CLI mode)" }, { flag: "--method=NAME", desc: "Method name to generate test for" }, { flag: "--audit", desc: "Run audit mode instead of test generation" }, { flag: "--trace", desc: "Run symbolic trace mode" }, { flag: "--clones", desc: "Run clone detection mode" }, { flag: "--level=1|2|3|all", desc: "Set clone detection level (default: all)" }, { flag: "--deadcode", desc: "Run dead code detection" }, ], how_to: [ "Run 'bundle exec tng' for interactive mode", "Run 'tng [file] --clones' for duplicate detection", "Run 'tng [file] --deadcode' for dead code analysis", "Select Controller, Model, or Service to start", "Choose a method to generate/audit or select 'Check Duplicates'" ], footer: "" } system(@binary_path, "help-box", "--version", version, "--data", JSON.generate(help_data)) rescue StandardError => e puts "Help error: #{e.message}" end |
#show_list_view(title, items) ⇒ Object
100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 |
# File 'lib/tng/ui/go_ui_session.rb', line 100 def show_list_view(title, items) data_json = JSON.generate({ title: title, items: items }) output_path = _create_temp_file("go_ui_list", ".txt") begin system(@binary_path, "list-view", "--data", data_json, "--output", output_path) selected = File.read(output_path).strip selected.empty? ? "back" : selected rescue StandardError "back" ensure _cleanup_temp_file(output_path) end end |
#show_menu ⇒ Object
Show main menu and return selected choice Returns: "tests", "stats", "about", "exit"
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/tng/ui/go_ui_session.rb', line 30 def output_path = _create_temp_file("go_ui_menu", ".json") begin system(@binary_path, "menu", "--output", output_path) return "exit" unless File.exist?(output_path) && File.size(output_path) > 0 choice = File.read(output_path).strip choice.empty? ? "exit" : choice rescue StandardError "exit" ensure _cleanup_temp_file(output_path) end end |
#show_no_items(item_type) ⇒ Object
Show 'no items found' message
174 175 176 |
# File 'lib/tng/ui/go_ui_session.rb', line 174 def show_no_items(item_type) system(@binary_path, "no-items", "--type", item_type) end |
#show_post_generation_menu(file_path, run_command) ⇒ String
Show post-generation menu
207 208 209 210 211 212 213 214 215 216 217 218 219 |
# File 'lib/tng/ui/go_ui_session.rb', line 207 def (file_path, run_command) data_json = JSON.generate({ file_path: file_path, run_command: run_command }) output_path = _create_temp_file("go_ui_post_gen", ".txt") begin system(@binary_path, "post-generation-menu", "--data", data_json, "--output", output_path) choice = File.read(output_path).strip choice.empty? ? "back" : choice ensure _cleanup_temp_file(output_path) end end |
#show_post_install(version) ⇒ Object
Show post-install message
382 383 384 385 386 |
# File 'lib/tng/ui/go_ui_session.rb', line 382 def show_post_install(version) system(@binary_path, "post-install", "--version", version) rescue StandardError => e puts "Post install error: #{e.message}" end |
#show_progress(title) ⇒ Object
142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 |
# File 'lib/tng/ui/go_ui_session.rb', line 142 def show_progress(title) control_path = _create_temp_file("go_ui_progress", ".json") # Start progress in background (inherit TTY) pid = spawn(@binary_path, "progress", "--title", title, "--control", control_path) begin updater = ProgressUpdater.new(control_path) result = yield(updater) # Write completion status if result&.dig(:result, :error) # Error already written by updater.error else completion = { type: "complete", message: result&.dig(:message) || "Done!" } File.write(control_path, JSON.generate(completion)) end Process.wait(pid) result rescue StandardError => e error_data = { type: "error", message: "Error: #{e.message}" } File.write(control_path, JSON.generate(error_data)) Process.wait(pid) raise ensure _cleanup_temp_file(control_path) end end |
#show_ruby_test_type_menu ⇒ Object
Returns: "model", "service", "job", "lib", "utility", "other", "back"
66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 |
# File 'lib/tng/ui/go_ui_session.rb', line 66 def output_path = _create_temp_file("go_ui_ruby_test_type", ".json") begin system(@binary_path, "ruby-test-menu", "--output", output_path) return "back" unless File.exist?(output_path) && File.size(output_path) > 0 choice = File.read(output_path).strip choice.empty? ? "back" : choice rescue StandardError "back" ensure _cleanup_temp_file(output_path) end end |
#show_spinner(message) ⇒ Object
116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 |
# File 'lib/tng/ui/go_ui_session.rb', line 116 def show_spinner() control_path = _create_temp_file("go_ui_spinner", ".json") pid = spawn(@binary_path, "spinner", "--message", , "--control", control_path) begin result = yield status = { status: result&.dig(:success) ? "success" : "error", message: result&.dig(:message) || "Done!" } File.write(control_path, JSON.generate(status)) Process.wait(pid) result rescue StandardError => e status = { status: "error", message: e. } File.write(control_path, JSON.generate(status)) Process.wait(pid) raise ensure _cleanup_temp_file(control_path) end end |
#show_stats(stats_data) ⇒ Object
Show user statistics
180 181 182 183 184 185 |
# File 'lib/tng/ui/go_ui_session.rb', line 180 def show_stats(stats_data) stats_json = stats_data ? JSON.generate(stats_data) : "{}" system(@binary_path, "stats", "--data", stats_json) rescue StandardError => e puts "Stats error: #{e.message}" end |
#show_system_status(status) ⇒ Object
461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 |
# File 'lib/tng/ui/go_ui_session.rb', line 461 def show_system_status(status) data = { status: status[:status].to_s, message: status[:message], local_version: status[:gem_version], current_version: status[:current_version], user_base_url: status[:user_base_url], server_base_url: status[:server_base_url] } data_json = JSON.generate(data) input_path = _create_temp_file("go_ui_status", ".json") File.write(input_path, data_json) begin system(@binary_path, "system-status", "--file", input_path) rescue StandardError => e puts "System status error: #{e.message}" ensure _cleanup_temp_file(input_path) end end |
#show_test_results(title, passed, failed, errors, total, results = []) ⇒ Object
Show test results
234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 |
# File 'lib/tng/ui/go_ui_session.rb', line 234 def show_test_results(title, passed, failed, errors, total, results = []) data = { title: title, passed: passed, failed: failed, errors: errors, total: total, results: results } data_json = JSON.generate(data) system(@binary_path, "test-results", "--data", data_json) rescue StandardError => e puts "Test results error: #{e.message}" end |
#show_test_type_menu(mode = "test") ⇒ Object
Returns: "controller", "model", "service", "other", "back"
48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 |
# File 'lib/tng/ui/go_ui_session.rb', line 48 def (mode = "test") output_path = _create_temp_file("go_ui_test_type", ".json") begin system(@binary_path, "rails-test-menu", "--output", output_path, "--mode", mode) return "back" unless File.exist?(output_path) && File.size(output_path) > 0 choice = File.read(output_path).strip choice.empty? ? "back" : choice rescue StandardError "back" ensure _cleanup_temp_file(output_path) end end |
#show_trace_results(trace_file_path) ⇒ Object
Show symbolic trace results
272 273 274 275 276 |
# File 'lib/tng/ui/go_ui_session.rb', line 272 def show_trace_results(trace_file_path) system(@binary_path, "ruby-trace-results", "--file", trace_file_path) rescue StandardError => e puts "Trace results error: #{e.message}" end |
#start ⇒ Object
16 17 18 |
# File 'lib/tng/ui/go_ui_session.rb', line 16 def start @running = true end |
#stop ⇒ Object
20 21 22 |
# File 'lib/tng/ui/go_ui_session.rb', line 20 def stop @running = false end |