Module: Textus::Doctor

Defined in:
lib/textus/doctor.rb,
lib/textus/doctor/check.rb,
lib/textus/doctor/check/hooks.rb,
lib/textus/doctor/check/schemas.rb,
lib/textus/doctor/check/audit_log.rb,
lib/textus/doctor/check/sentinels.rb,
lib/textus/doctor/check/templates.rb,
lib/textus/doctor/check/illegal_keys.rb,
lib/textus/doctor/check/manifest_files.rb,
lib/textus/doctor/check/policy_ambiguity.rb,
lib/textus/doctor/check/handler_allowlist.rb,
lib/textus/doctor/check/schema_violations.rb,
lib/textus/doctor/check/intake_registration.rb,
lib/textus/doctor/check/legacy_intake_fields.rb,
lib/textus/doctor/check/unowned_schema_fields.rb

Overview

Health check for a Textus store. Returns a JSON-friendly Hash envelope with an ‘issues` array and a summary. Each issue is a Hash with `code`, `level`, `subject`, `message`, and optionally `fix`.

Defined Under Namespace

Classes: Check

Constant Summary collapse

LEVELS =
%w[error warning info].freeze
DOCTOR_CHECK_TIMEOUT_SECONDS =
2
CHECKS =
[
  Check::ManifestFiles,
  Check::Schemas,
  Check::Templates,
  Check::Hooks,
  Check::IntakeRegistration,
  Check::IllegalKeys,
  Check::Sentinels,
  Check::AuditLog,
  Check::UnownedSchemaFields,
  Check::SchemaViolations,
  Check::PolicyAmbiguity,
  Check::HandlerAllowlist,
  Check::LegacyIntakeFields,
].freeze
ALL_CHECKS =
CHECKS.map(&:name_key).freeze

Class Method Summary collapse

Class Method Details

.run(store, checks: nil) ⇒ Object



31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
# File 'lib/textus/doctor.rb', line 31

def run(store, checks: nil)
  selected_keys = checks ? Array(checks).map(&:to_s) : ALL_CHECKS
  unknown = selected_keys - ALL_CHECKS
  unless unknown.empty?
    raise UsageError.new(
      "unknown doctor check: #{unknown.first}. Valid checks: #{ALL_CHECKS.join(", ")}",
    )
  end

  selected = CHECKS.select { |c| selected_keys.include?(c.name_key) }
  issues = selected.flat_map { |c| c.new(store).call }
  issues.concat(run_registered_checks(store))

  summary = LEVELS.to_h { |l| [l, issues.count { |i| i["level"] == l }] }
  {
    "protocol" => Textus::PROTOCOL,
    "ok" => summary["error"].zero?,
    "issues" => issues,
    "summary" => summary,
  }
end