Module: Legion::Extensions::MindGrowth::Runners::IntegrationTester

Extended by:
IntegrationTester
Includes:
Helpers::Lex
Included in:
IntegrationTester
Defined in:
lib/legion/extensions/mind_growth/runners/integration_tester.rb

Constant Summary collapse

TICK_BUDGET_MS =
5000

Instance Method Summary collapse

Instance Method Details

#benchmark_tick(with_extension: nil, iterations: 5) ⇒ Object



43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
# File 'lib/legion/extensions/mind_growth/runners/integration_tester.rb', line 43

def benchmark_tick(with_extension: nil, iterations: 5, **)
  return { success: false, reason: :gaia_not_available } unless gaia_available?
  return { success: false, reason: :invalid_iterations, iterations: iterations } unless iterations.is_a?(Integer) && iterations >= 1

  timings = Array.new(iterations) do
    start = ::Process.clock_gettime(::Process::CLOCK_MONOTONIC)
    Legion::Gaia.heartbeat if Legion::Gaia.respond_to?(:heartbeat)
    finish = ::Process.clock_gettime(::Process::CLOCK_MONOTONIC)
    ((finish - start) * 1000).round(2)
  end

  {
    success:        true,
    with_extension: with_extension,
    iterations:     iterations,
    avg_ms:         (timings.sum / timings.size).round(2),
    max_ms:         timings.max,
    min_ms:         timings.min,
    within_budget:  timings.max <= TICK_BUDGET_MS
  }
rescue StandardError => e
  { success: false, reason: :benchmark_failed, error: e.message }
end

#test_extension_in_tick(ext_module:, runner_module:, fn:, phase:, test_args: {}) ⇒ Object

rubocop:disable Naming/MethodParameterName



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/legion/extensions/mind_growth/runners/integration_tester.rb', line 15

def test_extension_in_tick(ext_module:, runner_module:, fn:, phase:, test_args: {}, **) # rubocop:disable Naming/MethodParameterName
  return { success: false, reason: :gaia_not_available } unless gaia_available?

  runner_class = resolve_runner_class(ext_module, runner_module)
  return { success: false, reason: :runner_not_found } unless runner_class

  # Test 1: Method exists and is callable
  method_check = test_method_callable(runner_class, fn)
  return method_check unless method_check[:success]

  # Test 2: Method returns valid response hash
  response_check = test_valid_response(runner_class, fn, test_args)
  return response_check unless response_check[:success]

  # Test 3: Method completes within budget
  perf_check = test_performance(runner_class, fn, test_args)

  {
    success:         true,
    method_callable: method_check[:success],
    valid_response:  response_check[:success],
    performance:     perf_check,
    phase:           phase
  }
rescue StandardError => e
  { success: false, reason: :exception, error: e.message }
end