|
| 1 | +# frozen_string_literal: true |
| 2 | + |
| 3 | +RSpec.describe MARS::Rendering::Mermaid do |
| 4 | + it "renders a custom Runnable subclass as a box node" do |
| 5 | + step = Class.new(MARS::Runnable) do |
| 6 | + def run(input) = input |
| 7 | + end.new(name: "custom_step") |
| 8 | + |
| 9 | + mermaid = described_class.new(step) |
| 10 | + output = mermaid.render |
| 11 | + |
| 12 | + expect(output).to include("custom_step[custom_step]") |
| 13 | + end |
| 14 | + |
| 15 | + it "renders an AgentStep as a box node" do |
| 16 | + step = MARS::AgentStep.new(name: "my_agent") |
| 17 | + mermaid = described_class.new(step) |
| 18 | + output = mermaid.render |
| 19 | + |
| 20 | + expect(output).to include("my_agent[my_agent]") |
| 21 | + end |
| 22 | + |
| 23 | + it "renders a Gate as a diamond node" do |
| 24 | + gate = MARS::Gate.new( |
| 25 | + "my_gate", |
| 26 | + check: ->(_input) { :branch }, |
| 27 | + fallbacks: { |
| 28 | + branch: Class.new(MARS::Runnable) do |
| 29 | + def run(input) = input |
| 30 | + end.new(name: "branch_step") |
| 31 | + } |
| 32 | + ) |
| 33 | + |
| 34 | + mermaid = described_class.new(gate) |
| 35 | + output = mermaid.render |
| 36 | + |
| 37 | + expect(output).to include("my_gate{my_gate}") |
| 38 | + expect(output).to include("|branch|") |
| 39 | + end |
| 40 | + |
| 41 | + it "renders a Sequential workflow with subgraph" do |
| 42 | + step1 = MARS::AgentStep.new(name: "step1") |
| 43 | + step2 = MARS::AgentStep.new(name: "step2") |
| 44 | + workflow = MARS::Workflows::Sequential.new("pipeline", steps: [step1, step2]) |
| 45 | + |
| 46 | + mermaid = described_class.new(workflow) |
| 47 | + output = mermaid.render |
| 48 | + |
| 49 | + expect(output).to include("subgraph pipeline") |
| 50 | + expect(output).to include("step1[step1]") |
| 51 | + expect(output).to include("step2[step2]") |
| 52 | + end |
| 53 | + |
| 54 | + it "renders a Parallel workflow with aggregator" do |
| 55 | + step1 = MARS::AgentStep.new(name: "step1") |
| 56 | + step2 = MARS::AgentStep.new(name: "step2") |
| 57 | + workflow = MARS::Workflows::Parallel.new("parallel", steps: [step1, step2]) |
| 58 | + |
| 59 | + mermaid = described_class.new(workflow) |
| 60 | + output = mermaid.render |
| 61 | + |
| 62 | + expect(output).to include("subgraph parallel") |
| 63 | + expect(output).to include("step1[step1]") |
| 64 | + expect(output).to include("step2[step2]") |
| 65 | + expect(output).to include("parallel_aggregator") |
| 66 | + end |
| 67 | +end |
0 commit comments