-
Notifications
You must be signed in to change notification settings - Fork 0
Add spec files for mars components #10
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
01cce0c
55691c4
8cfa020
886661c
d6e78f5
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,9 @@ | ||
| { | ||
| "agentCanUpdateSnapshot": true, | ||
| "terminals": [ | ||
| { | ||
| "name": "Show env", | ||
| "command": "env" | ||
| } | ||
| ] | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -7,6 +7,7 @@ | |
| /spec/reports/ | ||
| /tmp/ | ||
|
|
||
| .idea/ | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. don't commit it, maybe add it to your personal |
||
| # rspec failure tracking | ||
| .rspec_status | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -17,3 +17,12 @@ Style/StringLiterals: | |
|
|
||
| Style/StringLiteralsInInterpolation: | ||
| EnforcedStyle: double_quotes | ||
|
|
||
| RSpec/MultipleExpectations: | ||
| Enabled: false | ||
|
|
||
| RSpec/ExampleLength: | ||
| Enabled: false | ||
|
|
||
| RSpec/VerifiedDoubleReference: | ||
| Enabled: false | ||
|
Comment on lines
+20
to
+28
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. why? |
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,86 @@ | ||
| # frozen_string_literal: true | ||
|
|
||
| RSpec.describe Mars::Agent do | ||
| describe "#initialize" do | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't this the initialize method needs to be tested |
||
| it "initializes with a name" do | ||
| agent = described_class.new(name: "TestAgent") | ||
| expect(agent.name).to eq("TestAgent") | ||
| end | ||
|
|
||
| it "accepts options parameter" do | ||
| options = { model: "gpt-4", temperature: 0.7 } | ||
| agent = described_class.new(name: "TestAgent", options: options) | ||
| expect(agent.name).to eq("TestAgent") | ||
| end | ||
|
|
||
| it "accepts tools parameter as an array" do | ||
| tool1 = instance_double("Tool1") | ||
| tool2 = instance_double("Tool2") | ||
| tools = [tool1, tool2] | ||
| agent = described_class.new(name: "TestAgent", tools: tools) | ||
| expect(agent.name).to eq("TestAgent") | ||
| end | ||
|
|
||
| it "accepts a single tool and converts it to an array" do | ||
| tool = instance_double("Tool") | ||
| agent = described_class.new(name: "TestAgent", tools: tool) | ||
| expect(agent.name).to eq("TestAgent") | ||
| end | ||
|
|
||
| it "accepts schema parameter" do | ||
| schema = { type: "object", properties: {} } | ||
| agent = described_class.new(name: "TestAgent", schema: schema) | ||
| expect(agent.name).to eq("TestAgent") | ||
| end | ||
|
|
||
| it "accepts all parameters together" do | ||
| tool = instance_double("Tool") | ||
| agent = described_class.new( | ||
| name: "CompleteAgent", | ||
| options: { model: "gpt-4" }, | ||
| tools: [tool], | ||
| schema: { type: "object" } | ||
| ) | ||
| expect(agent.name).to eq("CompleteAgent") | ||
| end | ||
| end | ||
|
|
||
| describe "#name" do | ||
| it "returns the agent name" do | ||
| agent = described_class.new(name: "MyAgent") | ||
| expect(agent.name).to eq("MyAgent") | ||
| end | ||
| end | ||
|
|
||
| describe "#run" do | ||
| let(:agent) { described_class.new(name: "TestAgent") } | ||
| let(:mock_chat) { instance_double("Chat") } | ||
|
|
||
| it "delegates to chat.ask with the input" do | ||
| allow(agent).to receive(:chat).and_return(mock_chat) | ||
| allow(mock_chat).to receive(:ask).with("test input").and_return("response") | ||
|
|
||
| result = agent.run("test input") | ||
|
|
||
| expect(result).to eq("response") | ||
| expect(mock_chat).to have_received(:ask).with("test input") | ||
| end | ||
|
Comment on lines
+60
to
+67
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. everything is so mocked that I'm not sure these tests add value at all |
||
|
|
||
| it "passes different inputs to chat.ask" do | ||
| allow(agent).to receive(:chat).and_return(mock_chat) | ||
| allow(mock_chat).to receive(:ask).and_return("response") | ||
|
|
||
| agent.run("first input") | ||
| agent.run("second input") | ||
|
|
||
| expect(mock_chat).to have_received(:ask).with("first input") | ||
| expect(mock_chat).to have_received(:ask).with("second input") | ||
| end | ||
| end | ||
|
|
||
| describe "inheritance" do | ||
| it "inherits from Mars::Runnable" do | ||
| expect(described_class.ancestors).to include(Mars::Runnable) | ||
| end | ||
| end | ||
|
Comment on lines
+81
to
+85
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't think we need to test this |
||
| end | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,75 @@ | ||
| # frozen_string_literal: true | ||
|
|
||
| RSpec.describe Mars::Aggregator do | ||
| describe "#initialize" do | ||
| it "initializes with a default name" do | ||
| aggregator = described_class.new | ||
| expect(aggregator.name).to eq("Aggregator") | ||
| end | ||
|
|
||
| it "initializes with a custom name" do | ||
| aggregator = described_class.new("CustomAggregator") | ||
| expect(aggregator.name).to eq("CustomAggregator") | ||
| end | ||
| end | ||
|
|
||
| describe "#name" do | ||
| it "returns the aggregator name" do | ||
| aggregator = described_class.new("MyAggregator") | ||
| expect(aggregator.name).to eq("MyAggregator") | ||
| end | ||
| end | ||
|
|
||
| describe "#run" do | ||
| let(:aggregator) { described_class.new } | ||
|
|
||
| context "when called without a block" do | ||
| it "joins inputs with newlines" do | ||
| inputs = %w[first second third] | ||
| result = aggregator.run(inputs) | ||
| expect(result).to eq("first\nsecond\nthird") | ||
| end | ||
|
|
||
| it "handles empty array" do | ||
| result = aggregator.run([]) | ||
| expect(result).to eq("") | ||
| end | ||
|
|
||
| it "handles single input" do | ||
| result = aggregator.run(["single"]) | ||
| expect(result).to eq("single") | ||
| end | ||
|
|
||
| it "handles numeric inputs" do | ||
| inputs = [1, 2, 3] | ||
| result = aggregator.run(inputs) | ||
| expect(result).to eq("1\n2\n3") | ||
| end | ||
| end | ||
|
|
||
| context "when called with a block" do | ||
| it "executes the block and returns its value" do | ||
| result = aggregator.run(["ignored"]) { "block result" } | ||
| expect(result).to eq("block result") | ||
| end | ||
|
|
||
| it "ignores the inputs when block is given" do | ||
| inputs = %w[first second] | ||
| result = aggregator.run(inputs) { "custom aggregation" } | ||
| expect(result).to eq("custom aggregation") | ||
| end | ||
|
|
||
| it "can perform custom aggregation logic" do | ||
| inputs = [1, 2, 3, 4, 5] | ||
| result = aggregator.run(inputs) { inputs.sum } | ||
| expect(result).to eq(15) | ||
| end | ||
| end | ||
| end | ||
|
|
||
| describe "inheritance" do | ||
| it "inherits from Mars::Runnable" do | ||
| expect(described_class.ancestors).to include(Mars::Runnable) | ||
| end | ||
| end | ||
| end |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,71 @@ | ||
| # frozen_string_literal: true | ||
|
|
||
| RSpec.describe Mars::Exit do | ||
| describe "#initialize" do | ||
| it "initializes with a default name" do | ||
| exit_node = described_class.new | ||
| expect(exit_node.name).to eq("Exit") | ||
| end | ||
|
|
||
| it "initializes with a custom name" do | ||
| exit_node = described_class.new(name: "CustomExit") | ||
| expect(exit_node.name).to eq("CustomExit") | ||
| end | ||
| end | ||
|
|
||
| describe "#name" do | ||
| it "returns the exit name" do | ||
| exit_node = described_class.new(name: "MyExit") | ||
| expect(exit_node.name).to eq("MyExit") | ||
| end | ||
| end | ||
|
|
||
| describe "#run" do | ||
| let(:exit_node) { described_class.new } | ||
|
|
||
| it "returns the input unchanged" do | ||
| input = "test input" | ||
| result = exit_node.run(input) | ||
| expect(result).to eq(input) | ||
| end | ||
|
|
||
| it "works with string inputs" do | ||
| result = exit_node.run("hello") | ||
| expect(result).to eq("hello") | ||
| end | ||
|
|
||
| it "works with numeric inputs" do | ||
| result = exit_node.run(42) | ||
| expect(result).to eq(42) | ||
| end | ||
|
|
||
| it "works with array inputs" do | ||
| input = [1, 2, 3] | ||
| result = exit_node.run(input) | ||
| expect(result).to eq(input) | ||
| end | ||
|
|
||
| it "works with hash inputs" do | ||
| input = { key: "value" } | ||
| result = exit_node.run(input) | ||
| expect(result).to eq(input) | ||
| end | ||
|
|
||
| it "works with nil input" do | ||
| result = exit_node.run(nil) | ||
| expect(result).to be_nil | ||
| end | ||
|
|
||
| it "returns the exact same object (not a copy)" do | ||
| input = "test" | ||
| result = exit_node.run(input) | ||
| expect(result).to be(input) | ||
| end | ||
| end | ||
|
|
||
| describe "inheritance" do | ||
| it "inherits from Mars::Runnable" do | ||
| expect(described_class.ancestors).to include(Mars::Runnable) | ||
| end | ||
| end | ||
| end |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
don't commit this, maybe you can add it to your personal
~/.gitignore