Class: Space::Architect::GateEvaluator

Inherits:
Object
  • Object
show all
Defined in:
lib/space_architect/gate_evaluator.rb

Overview

Evaluates a single gate's captured output against its frozen expect block. Pure — no I/O. Mirrors GateLint's class shape.

GateEvaluator.call(stdout:, exit_code:, expect:) → Result result.pass? → Boolean result.reason → String (empty on pass, first failing matcher on fail)

Defined Under Namespace

Classes: Result

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.call(stdout:, exit_code:, expect:) ⇒ Object



15
# File 'lib/space_architect/gate_evaluator.rb', line 15

def self.call(stdout:, exit_code:, expect:) = new.call(stdout: stdout, exit_code: exit_code, expect: expect)

Instance Method Details

#call(stdout:, exit_code:, expect:) ⇒ Object



17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/space_architect/gate_evaluator.rb', line 17

def call(stdout:, exit_code:, expect:)
  e = (expect || {}).transform_keys(&:to_s)

  if e.key?("exit_code")
    expected = e["exit_code"]
    unless exit_code == expected
      return Result.new(pass: false, reason: "exit_code #{exit_code.inspect} != #{expected}")
    end
  end

  if (pattern = e["stdout_match"])
    unless Regexp.new(pattern).match?(stdout.to_s)
      return Result.new(pass: false, reason: "stdout did not match /#{pattern}/")
    end
  end

  if (thresh = e["threshold"])
    result = check_threshold(stdout.to_s, thresh.transform_keys(&:to_s))
    return result unless result.pass?
  end

  Result.new(pass: true, reason: "")
end