Module: Smith::Doctor::Checks::Persistence
- Defined in:
- lib/smith/doctor/checks/persistence.rb
Class Method Summary collapse
- .check_active_record(report) ⇒ Object
- .check_db_connection(report) ⇒ Object
- .check_model_registry_mode(report) ⇒ Object
- .check_ruby_llm_persistence(report) ⇒ Object
- .check_schema_presence(report) ⇒ Object
- .inspect_tables(report) ⇒ Object
- .ruby_llm_persistence_detected? ⇒ Boolean
- .run(report) ⇒ Object
- .verify_active_connection(report) ⇒ Object
Class Method Details
.check_active_record(report) ⇒ Object
17 18 19 20 21 22 23 24 |
# File 'lib/smith/doctor/checks/persistence.rb', line 17 def self.check_active_record(report) loaded = defined?(::ActiveRecord::Base) report.add( name: "persistence.active_record", status: loaded ? :pass : :fail, message: loaded ? "ActiveRecord available" : "ActiveRecord not available" ) end |
.check_db_connection(report) ⇒ Object
26 27 28 29 30 31 32 33 |
# File 'lib/smith/doctor/checks/persistence.rb', line 26 def self.check_db_connection(report) unless defined?(::ActiveRecord::Base) report.add(name: "persistence.db_connection", status: :skip, message: "DB check skipped — no ActiveRecord") return end verify_active_connection(report) end |
.check_model_registry_mode(report) ⇒ Object
56 57 58 |
# File 'lib/smith/doctor/checks/persistence.rb', line 56 def self.check_model_registry_mode(report) PersistenceRegistry.check(report, ::Smith.config.ruby_llm_model_registry) end |
.check_ruby_llm_persistence(report) ⇒ Object
35 36 37 38 39 40 41 42 43 |
# File 'lib/smith/doctor/checks/persistence.rb', line 35 def self.check_ruby_llm_persistence(report) detected = ruby_llm_persistence_detected? report.add( name: "persistence.ruby_llm_surface", status: detected ? :pass : :warn, message: detected ? "RubyLLM persistence surface detected" : "RubyLLM persistence surface not detected", detail: detected ? nil : "RubyLLM may be running in memory-only mode" ) end |
.check_schema_presence(report) ⇒ Object
45 46 47 48 49 50 51 52 53 54 |
# File 'lib/smith/doctor/checks/persistence.rb', line 45 def self.check_schema_presence(report) unless defined?(::ActiveRecord::Base) report.add( name: "persistence.schema_presence", status: :skip, message: "Schema check skipped — no ActiveRecord" ) return end inspect_tables(report) end |
.inspect_tables(report) ⇒ Object
80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 |
# File 'lib/smith/doctor/checks/persistence.rb', line 80 def self.inspect_tables(report) tables = ::ActiveRecord::Base.connection.tables known = tables.select { |t| %w[chats messages tool_calls].include?(t) } if known.any? report.add(name: "persistence.schema_presence", status: :pass, message: "RubyLLM tables found: #{known.join(", ")}") else report.add(name: "persistence.schema_presence", status: :warn, message: "No RubyLLM persistence tables detected (heuristic)", detail: "Expected tables like chats, messages, or tool_calls") end rescue StandardError => e report.add(name: "persistence.schema_presence", status: :warn, message: "Schema check inconclusive", detail: e.) end |
.ruby_llm_persistence_detected? ⇒ Boolean
72 73 74 75 76 77 78 |
# File 'lib/smith/doctor/checks/persistence.rb', line 72 def self.ruby_llm_persistence_detected? return false unless defined?(::RubyLLM::Chat) ::RubyLLM::Chat.ancestors.any? { |a| a.name&.include?("ActiveRecord") } rescue StandardError false end |
.run(report) ⇒ Object
9 10 11 12 13 14 15 |
# File 'lib/smith/doctor/checks/persistence.rb', line 9 def self.run(report) check_active_record(report) check_db_connection(report) check_ruby_llm_persistence(report) check_schema_presence(report) PersistenceRegistry.check(report, ::Smith.config.ruby_llm_model_registry) end |
.verify_active_connection(report) ⇒ Object
60 61 62 63 64 65 66 67 68 69 70 |
# File 'lib/smith/doctor/checks/persistence.rb', line 60 def self.verify_active_connection(report) active = ::ActiveRecord::Base.connection.active? report.add( name: "persistence.db_connection", status: active ? :pass : :fail, message: active ? "Database connection active" : "Database connection failed" ) rescue StandardError => e report.add(name: "persistence.db_connection", status: :fail, message: "Database connection failed", detail: e.) end |