Module: Rubino::LLM::ScenarioLoader

Defined in:
lib/rubino/llm/scenario_loader.rb

Overview

Loads a fake-provider scenario YAML by name and returns the parsed event list. The fake provider drives a deterministic chunk/tool-call stream from these events so the UI and tool plumbing can be exercised without burning provider tokens.

Search order:

1. <Rubino.configuration.fake_scenarios_dir>/<name>.yml
2. <gem_root>/lib/rubino/llm/scenarios/<name>.yml

The YAML file must contain a top-level ‘events:` key with an array of event hashes — see scenarios/happy-path.yml for the shape.

Defined Under Namespace

Classes: NotFound

Constant Summary collapse

DEFAULT_DIR =
File.expand_path("scenarios", __dir__)

Class Method Summary collapse

Class Method Details

.build_not_found_message(name, scenarios_dir) ⇒ Object



55
56
57
58
# File 'lib/rubino/llm/scenario_loader.rb', line 55

def build_not_found_message(name, scenarios_dir)
  tried = [scenarios_dir, DEFAULT_DIR].compact.uniq.map { |d| File.join(d, "#{name}.yml") }
  "fake scenario '#{name}' not found. Tried:\n  #{tried.join("\n  ")}"
end

.configured_dirObject



46
47
48
49
50
51
52
53
# File 'lib/rubino/llm/scenario_loader.rb', line 46

def configured_dir
  cfg = Rubino.configuration
  return nil unless cfg.respond_to?(:dig)

  cfg.dig("fake_provider", "scenarios_dir") || cfg.dig("providers", "fake", "scenarios_dir")
rescue StandardError
  nil
end

.load(name, scenarios_dir: nil) ⇒ Object

Returns the array of event hashes under the YAML ‘events:` key. Raises NotFound when the scenario can’t be located under either path, citing both so the operator can fix the misconfiguration.

Raises:



28
29
30
31
32
33
34
35
# File 'lib/rubino/llm/scenario_loader.rb', line 28

def load(name, scenarios_dir: nil)
  dir = scenarios_dir || configured_dir
  path = resolve_path(name, dir)
  raise NotFound, build_not_found_message(name, dir) unless path

  data = YAML.safe_load_file(path, permitted_classes: [Symbol], aliases: true) || {}
  Array(data["events"] || data[:events])
end

.resolve_path(name, scenarios_dir) ⇒ Object



37
38
39
40
41
42
43
44
# File 'lib/rubino/llm/scenario_loader.rb', line 37

def resolve_path(name, scenarios_dir)
  filename = "#{name}.yml"
  [scenarios_dir, DEFAULT_DIR].compact.uniq.each do |dir|
    candidate = File.join(dir, filename)
    return candidate if File.file?(candidate)
  end
  nil
end