roast-ai 0.4.8 → 0.4.10
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.gitignore +1 -0
- data/.rubocop.yml +1 -0
- data/Gemfile +6 -7
- data/Gemfile.lock +15 -3
- data/README.md +9 -5
- data/dsl/demo/Gemfile +4 -0
- data/dsl/demo/Gemfile.lock +120 -0
- data/dsl/demo/cogs/local.rb +15 -0
- data/dsl/demo/simple_external_cog.rb +17 -0
- data/dsl/less_simple.rb +112 -0
- data/dsl/plugin-gem-example/.gitignore +8 -0
- data/dsl/plugin-gem-example/Gemfile +13 -0
- data/dsl/plugin-gem-example/Gemfile.lock +178 -0
- data/dsl/plugin-gem-example/lib/other.rb +17 -0
- data/dsl/plugin-gem-example/lib/plugin_gem_example.rb +5 -0
- data/dsl/plugin-gem-example/lib/simple.rb +15 -0
- data/dsl/plugin-gem-example/lib/version.rb +10 -0
- data/dsl/plugin-gem-example/plugin-gem-example.gemspec +28 -0
- data/dsl/prototype.rb +25 -0
- data/dsl/scoped_executors.rb +28 -0
- data/dsl/simple.rb +5 -7
- data/dsl/simple_chat.rb +12 -0
- data/dsl/step_communication.rb +24 -0
- data/examples/grading/README.md +46 -0
- data/examples/grading/analyze_coverage/prompt.md +52 -0
- data/examples/grading/calculate_final_grade.rb +64 -0
- data/examples/grading/format_result.rb +61 -0
- data/examples/grading/generate_grades/prompt.md +105 -0
- data/examples/grading/generate_recommendations/output.txt +17 -0
- data/examples/grading/generate_recommendations/prompt.md +60 -0
- data/examples/grading/read_dependencies/prompt.md +15 -0
- data/examples/grading/verify_mocks_and_stubs/prompt.md +12 -0
- data/examples/grading/verify_test_helpers/prompt.md +53 -0
- data/examples/grading/workflow.md +5 -0
- data/examples/grading/workflow.yml +28 -0
- data/lib/roast/dsl/cog/config.rb +36 -0
- data/lib/roast/dsl/cog/input.rb +30 -0
- data/lib/roast/dsl/cog/output.rb +24 -0
- data/lib/roast/dsl/cog/registry.rb +39 -0
- data/lib/roast/dsl/cog/stack.rb +22 -0
- data/lib/roast/dsl/cog/store.rb +29 -0
- data/lib/roast/dsl/cog.rb +91 -0
- data/lib/roast/dsl/cog_input_context.rb +9 -0
- data/lib/roast/dsl/cog_input_manager.rb +47 -0
- data/lib/roast/dsl/cogs/chat.rb +78 -0
- data/lib/roast/dsl/cogs/cmd.rb +132 -0
- data/lib/roast/dsl/cogs/execute.rb +46 -0
- data/lib/roast/dsl/cogs/graph.rb +53 -0
- data/lib/roast/dsl/config_context.rb +9 -0
- data/lib/roast/dsl/config_manager.rb +96 -0
- data/lib/roast/dsl/execution_context.rb +9 -0
- data/lib/roast/dsl/execution_manager.rb +137 -0
- data/lib/roast/dsl/workflow.rb +113 -0
- data/lib/roast/error.rb +7 -0
- data/lib/roast/errors.rb +3 -3
- data/lib/roast/graph/edge.rb +25 -0
- data/lib/roast/graph/node.rb +40 -0
- data/lib/roast/graph/quantum_edge.rb +27 -0
- data/lib/roast/graph/threaded_exec.rb +93 -0
- data/lib/roast/graph.rb +233 -0
- data/lib/roast/resources/api_resource.rb +2 -2
- data/lib/roast/resources/url_resource.rb +2 -2
- data/lib/roast/tools/apply_diff.rb +1 -1
- data/lib/roast/tools/ask_user.rb +1 -1
- data/lib/roast/tools/bash.rb +1 -1
- data/lib/roast/tools/cmd.rb +2 -2
- data/lib/roast/tools/coding_agent.rb +2 -2
- data/lib/roast/tools/grep.rb +1 -1
- data/lib/roast/tools/read_file.rb +1 -1
- data/lib/roast/tools/search_file.rb +1 -1
- data/lib/roast/tools/swarm.rb +1 -1
- data/lib/roast/tools/update_files.rb +2 -2
- data/lib/roast/tools/write_file.rb +1 -1
- data/lib/roast/tools.rb +1 -1
- data/lib/roast/value_objects/api_token.rb +1 -1
- data/lib/roast/value_objects/uri_base.rb +1 -1
- data/lib/roast/value_objects/workflow_path.rb +1 -1
- data/lib/roast/version.rb +1 -1
- data/lib/roast/workflow/base_workflow.rb +38 -2
- data/lib/roast/workflow/command_executor.rb +1 -1
- data/lib/roast/workflow/configuration_loader.rb +1 -1
- data/lib/roast/workflow/error_handler.rb +1 -1
- data/lib/roast/workflow/step_executor_registry.rb +1 -1
- data/lib/roast/workflow/step_loader.rb +1 -1
- data/lib/roast/workflow/workflow_executor.rb +1 -1
- data/lib/roast.rb +4 -3
- data/roast.gemspec +1 -0
- data/sorbet/config +3 -0
- data/sorbet/rbi/annotations/.gitattributes +1 -0
- data/sorbet/rbi/annotations/activesupport.rbi +495 -0
- data/sorbet/rbi/annotations/faraday.rbi +17 -0
- data/sorbet/rbi/annotations/minitest.rbi +119 -0
- data/sorbet/rbi/annotations/mocha.rbi +34 -0
- data/sorbet/rbi/annotations/rainbow.rbi +269 -0
- data/sorbet/rbi/annotations/webmock.rbi +9 -0
- data/sorbet/rbi/gems/marcel@1.1.0.rbi +239 -0
- data/sorbet/rbi/gems/{rack@2.2.17.rbi → rack@2.2.19.rbi} +55 -38
- data/sorbet/rbi/gems/{rexml@3.4.1.rbi → rexml@3.4.2.rbi} +284 -239
- data/sorbet/rbi/gems/ruby_llm@1.8.2.rbi +5703 -0
- data/sorbet/rbi/shims/lib/roast/dsl/cog_input_context.rbi +17 -0
- data/sorbet/rbi/shims/lib/roast/dsl/config_context.rbi +17 -0
- data/sorbet/rbi/shims/lib/roast/dsl/execution_context.rbi +17 -0
- data/sorbet/rbi/todo.rbi +7 -0
- metadata +84 -6
- data/lib/roast/dsl/executor.rb +0 -27
- data/package-lock.json +0 -6
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require_relative "lib/version"
|
|
4
|
+
|
|
5
|
+
Gem::Specification.new do |spec|
|
|
6
|
+
spec.name = "plugin-gem-example"
|
|
7
|
+
spec.version = Plugin::Gem::Example::VERSION
|
|
8
|
+
spec.authors = ["Sam Schmidt"]
|
|
9
|
+
spec.email = ["sam.schmidt@shopify.com"]
|
|
10
|
+
|
|
11
|
+
spec.summary = "TODO: Write a short summary, because RubyGems requires one."
|
|
12
|
+
spec.description = "TODO: Write a longer description or delete this line."
|
|
13
|
+
spec.homepage = "TODO: Put your gem's website or public repo URL here."
|
|
14
|
+
spec.license = "MIT"
|
|
15
|
+
spec.required_ruby_version = ">= 3.1.0"
|
|
16
|
+
|
|
17
|
+
spec.metadata["allowed_push_host"] = "TODO: Set to your gem server 'https://example.com'"
|
|
18
|
+
|
|
19
|
+
spec.metadata["homepage_uri"] = spec.homepage
|
|
20
|
+
spec.metadata["source_code_uri"] = "TODO: Put your gem's public repo URL here."
|
|
21
|
+
spec.metadata["changelog_uri"] = "TODO: Put your gem's CHANGELOG.md URL here."
|
|
22
|
+
|
|
23
|
+
# Uncomment to register a new dependency of your gem
|
|
24
|
+
spec.add_dependency("roast-ai")
|
|
25
|
+
|
|
26
|
+
# For more information and examples about making a new gem, check out our
|
|
27
|
+
# guide at: https://bundler.io/guides/creating_gem.html
|
|
28
|
+
end
|
data/dsl/prototype.rb
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
# typed: true
|
|
2
|
+
# frozen_string_literal: true
|
|
3
|
+
|
|
4
|
+
#: self as Roast::DSL::Workflow
|
|
5
|
+
|
|
6
|
+
config do
|
|
7
|
+
# TODO: make a way to do print_all on all and turn off printing on one
|
|
8
|
+
cmd(:echo) { print_all! }
|
|
9
|
+
cmd(:date) { print_stdout! }
|
|
10
|
+
chat { "" }
|
|
11
|
+
# TODO: add a way to apply config to a subset of named cog by pattern
|
|
12
|
+
# cmd(/^date.*/) { print_all! }
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
execute do
|
|
16
|
+
# Anonymous cog. Added to the stack directly and given an autogenerated key in cog storage
|
|
17
|
+
# Use for actions you do once and forget about, don't need configuration
|
|
18
|
+
cmd { |my| my.command = "touch tmp/#{SecureRandom.uuid}" }
|
|
19
|
+
|
|
20
|
+
# Named cog. Configuration for this specific instance will be looked up from config block
|
|
21
|
+
cmd(:echo) { |my| my.command = "echo 'Hello World!'" }
|
|
22
|
+
|
|
23
|
+
# Cogs can implement input coercion for simple return values
|
|
24
|
+
cmd(:date) { "date" }
|
|
25
|
+
end
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
# typed: true
|
|
2
|
+
# frozen_string_literal: true
|
|
3
|
+
|
|
4
|
+
#: self as Roast::DSL::Workflow
|
|
5
|
+
|
|
6
|
+
config do
|
|
7
|
+
cmd do
|
|
8
|
+
print_all!
|
|
9
|
+
end
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
execute(:capitalize_a_random_word) do
|
|
13
|
+
cmd(:word) { "shuf /usr/share/dict/words -n 1" }
|
|
14
|
+
cmd(:capitalize) do |my|
|
|
15
|
+
word = cmd(:word).out.strip
|
|
16
|
+
my.command = "sh"
|
|
17
|
+
my.args << "-c"
|
|
18
|
+
my.args << "echo '#{word}' | tr '[:lower:]' '[:upper:]'"
|
|
19
|
+
end
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
execute do
|
|
23
|
+
cmd(:before) { "echo '--> before'" }
|
|
24
|
+
execute { :capitalize_a_random_word }
|
|
25
|
+
execute { :capitalize_a_random_word }
|
|
26
|
+
execute { :capitalize_a_random_word }
|
|
27
|
+
cmd(:after) { "echo '--> after'" }
|
|
28
|
+
end
|
data/dsl/simple.rb
CHANGED
|
@@ -1,10 +1,8 @@
|
|
|
1
|
-
# typed:
|
|
1
|
+
# typed: false
|
|
2
2
|
# frozen_string_literal: true
|
|
3
3
|
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
# This is a dead simple workflow that calls two shell scripts
|
|
7
|
-
shell <<~SHELLSTEP
|
|
4
|
+
# This is a dead simple workflow that calls two commands
|
|
5
|
+
cmd <<~CMDSTEP
|
|
8
6
|
echo "I have no idea what's going on"
|
|
9
|
-
|
|
10
|
-
|
|
7
|
+
CMDSTEP
|
|
8
|
+
cmd "pwd"
|
data/dsl/simple_chat.rb
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
# typed: true
|
|
2
|
+
# frozen_string_literal: true
|
|
3
|
+
|
|
4
|
+
#: self as Roast::DSL::Workflow
|
|
5
|
+
|
|
6
|
+
# How do we pass information between steps?
|
|
7
|
+
# Demonstrate by passing result of a command output to another step
|
|
8
|
+
|
|
9
|
+
config do
|
|
10
|
+
cmd(:echo) { display! }
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
execute do
|
|
14
|
+
cmd(:ls) { "ls -al" }
|
|
15
|
+
cmd(:echo) do |my|
|
|
16
|
+
my.command = "echo"
|
|
17
|
+
# TODO: this is a bespoke output object for cmd, is there a generic one we can offer
|
|
18
|
+
first_line = cmd(:ls).out.split("\n").second
|
|
19
|
+
last_line = cmd(:ls).out.split("\n").last
|
|
20
|
+
my.args << first_line unless first_line.blank?
|
|
21
|
+
my.args << "\n---\n"
|
|
22
|
+
my.args << last_line if last_line != first_line && last_line.present?
|
|
23
|
+
end
|
|
24
|
+
end
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
# Test Grading Workflow
|
|
2
|
+
|
|
3
|
+
This workflow acts as a senior software engineer and testing expert to evaluate the quality of test files based on best practices and guidelines.
|
|
4
|
+
|
|
5
|
+
## Usage
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
# Run the grading workflow on a test file
|
|
9
|
+
roast execute examples/grading/workflow.yml path/to/your_test.rb
|
|
10
|
+
```
|
|
11
|
+
|
|
12
|
+
## How it Works
|
|
13
|
+
|
|
14
|
+
1. **read_dependencies**: Analyzes the test file and its dependencies
|
|
15
|
+
2. **run_coverage**: Executes the test with coverage tracking
|
|
16
|
+
3. **generate_grades**: Evaluates test quality across multiple dimensions
|
|
17
|
+
4. **verify_test_helpers**: Checks for proper test helper usage
|
|
18
|
+
5. **verify_mocks_and_stubs**: Ensures appropriate use of test doubles
|
|
19
|
+
6. **analyze_coverage**: Reviews code coverage metrics
|
|
20
|
+
7. **generate_recommendations**: Provides improvement suggestions
|
|
21
|
+
8. **calculate_final_grade**: Computes an overall grade (A-F scale)
|
|
22
|
+
9. **format_result**: Formats the final output
|
|
23
|
+
|
|
24
|
+
## Customization
|
|
25
|
+
|
|
26
|
+
Feel free to adapt this workflow to your testing environment:
|
|
27
|
+
|
|
28
|
+
- **Different test frameworks**: Modify `run_coverage.rb` to work with RSpec, Jest, pytest, etc.
|
|
29
|
+
- **Coverage tools**: Replace the coverage command with your preferred tool (SimpleCov, Istanbul, Coverage.py)
|
|
30
|
+
- **Grading criteria**: Adjust the prompts in each step to match your team's standards
|
|
31
|
+
|
|
32
|
+
## Example Output
|
|
33
|
+
|
|
34
|
+
```
|
|
35
|
+
========== TEST GRADE REPORT ==========
|
|
36
|
+
Test file: test/example_test.rb
|
|
37
|
+
|
|
38
|
+
FINAL GRADE:
|
|
39
|
+
Score: 85/100
|
|
40
|
+
Letter Grade: B
|
|
41
|
+
|
|
42
|
+
RECOMMENDATIONS:
|
|
43
|
+
- Add edge case testing for error conditions
|
|
44
|
+
- Improve test descriptions for clarity
|
|
45
|
+
- Consider extracting common setup to helper methods
|
|
46
|
+
```
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
<coverage_results>
|
|
2
|
+
<%= workflow.output["run_coverage"] %>
|
|
3
|
+
</coverage_results>
|
|
4
|
+
|
|
5
|
+
Analyze the results and score them on a scale of 1-10 using the following rubrics:
|
|
6
|
+
|
|
7
|
+
<line_coverage>
|
|
8
|
+
0-1: Critical failure (0-20% coverage) - Core functionality remains completely untested
|
|
9
|
+
2-3: Poor coverage (21-40%) - Major gaps; many key functions lack any testing
|
|
10
|
+
4-5: Inadequate coverage (41-60%) - Several important code paths are not executed
|
|
11
|
+
6-7: Moderate coverage (61-80%) - Notable gaps remain; some important functionality lacks coverage
|
|
12
|
+
8-9: Good coverage (81-95%) - Only minor or edge case code paths remain untested
|
|
13
|
+
10: Excellent coverage (96-100%)
|
|
14
|
+
</line_coverage>
|
|
15
|
+
|
|
16
|
+
<branch_coverage>
|
|
17
|
+
0-1: Critical failure (0-20% branch coverage) - Almost no conditional branches are tested
|
|
18
|
+
2-3: Poor coverage (21-40%) - Most conditional logic remains untested
|
|
19
|
+
4-5: Inadequate coverage (41-60%) - Many conditions are only tested for one outcome
|
|
20
|
+
6-7: Moderate coverage (61-80%) - Some conditions lack testing for all outcomes
|
|
21
|
+
8-9: Good coverage (81-95%) - Most conditions are tested for most outcomes
|
|
22
|
+
10: Excellent coverage (96-100%)
|
|
23
|
+
</branch_coverage>
|
|
24
|
+
|
|
25
|
+
<method_coverage>
|
|
26
|
+
0-1: Critical failure (0-20% method coverage) - Most or core functionality methods are untested
|
|
27
|
+
2-3: Poor coverage (21-40%) - Several public API methods remain untested
|
|
28
|
+
4-5: Inadequate coverage (41-60%) - Some important public methods lack tests
|
|
29
|
+
6-7: Moderate coverage (61-80%) - Notable gaps remain; some public methods may lack comprehensive testing
|
|
30
|
+
8-9: Good coverage (81-95%) - Nearly all public methods are tested; private methods are mostly covered via public method tests
|
|
31
|
+
10: Excellent coverage (96-100%)
|
|
32
|
+
</method_coverage>
|
|
33
|
+
|
|
34
|
+
RESPONSE FORMAT
|
|
35
|
+
You must respond in JSON format within <json> XML tags. Example:
|
|
36
|
+
|
|
37
|
+
<json>
|
|
38
|
+
{
|
|
39
|
+
"method_coverage": {
|
|
40
|
+
"score": "10",
|
|
41
|
+
"justification": "The source file has 100% method coverage, indicating all methods are being tested."
|
|
42
|
+
},
|
|
43
|
+
"line_coverage": {
|
|
44
|
+
"score": 10,
|
|
45
|
+
"justification": "The source file has 100% line coverage, indicating all executable lines are tested."
|
|
46
|
+
},
|
|
47
|
+
"branch_coverage": {
|
|
48
|
+
"score": 8,
|
|
49
|
+
"justification": "The source file has 80% branch coverage, indicating some branches need testing."
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
</json>
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
class CalculateFinalGrade < Roast::Workflow::BaseStep
|
|
4
|
+
WEIGHTS = {
|
|
5
|
+
test_helpers: 0.2,
|
|
6
|
+
mocks_and_stubs: 0.2,
|
|
7
|
+
readability: 0.2,
|
|
8
|
+
maintainability: 0.2,
|
|
9
|
+
effectiveness: 0.2,
|
|
10
|
+
}.freeze
|
|
11
|
+
|
|
12
|
+
def call
|
|
13
|
+
llm_analysis = workflow.output["generate_grades"]
|
|
14
|
+
|
|
15
|
+
weighted_sum = WEIGHTS.sum do |criterion, weight|
|
|
16
|
+
score = llm_analysis[criterion.to_s]["score"].to_f / 10.0
|
|
17
|
+
score * weight
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
{
|
|
21
|
+
final_score: {
|
|
22
|
+
weighted_score: weighted_sum,
|
|
23
|
+
letter_grade: calculate_letter_grade(weighted_sum),
|
|
24
|
+
},
|
|
25
|
+
rubric_scores: calculate_rubric_scores(llm_analysis),
|
|
26
|
+
}
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
private
|
|
30
|
+
|
|
31
|
+
def calculate_letter_grade(score)
|
|
32
|
+
case score
|
|
33
|
+
when 0.9..1.0
|
|
34
|
+
"A"
|
|
35
|
+
when 0.8...0.9
|
|
36
|
+
"B"
|
|
37
|
+
when 0.7...0.8
|
|
38
|
+
"C"
|
|
39
|
+
when 0.6...0.7
|
|
40
|
+
"D"
|
|
41
|
+
else
|
|
42
|
+
"F"
|
|
43
|
+
end
|
|
44
|
+
end
|
|
45
|
+
|
|
46
|
+
def calculate_rubric_scores(llm_analysis)
|
|
47
|
+
scores = {}
|
|
48
|
+
|
|
49
|
+
WEIGHTS.each_key do |criterion|
|
|
50
|
+
next 1 unless llm_analysis[criterion.to_s]
|
|
51
|
+
raw_score = llm_analysis[criterion.to_s]["score"].to_f
|
|
52
|
+
normalized_score = raw_score / 10.0
|
|
53
|
+
|
|
54
|
+
scores[criterion] = {
|
|
55
|
+
raw_value: raw_score,
|
|
56
|
+
score: normalized_score,
|
|
57
|
+
description: llm_analysis[criterion.to_s]["justification"],
|
|
58
|
+
weighted_score: normalized_score * WEIGHTS[criterion],
|
|
59
|
+
}
|
|
60
|
+
end
|
|
61
|
+
|
|
62
|
+
scores
|
|
63
|
+
end
|
|
64
|
+
end
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
class FormatResult < Roast::Workflow::BaseStep
|
|
4
|
+
RUBRIC = {
|
|
5
|
+
test_helpers: { description: "Test Helpers Usage", weight: 0.2 },
|
|
6
|
+
mocks_and_stubs: { description: "Mocks and Stubs Usage", weight: 0.2 },
|
|
7
|
+
readability: { description: "Test Readability", weight: 0.2 },
|
|
8
|
+
maintainability: { description: "Test Maintainability", weight: 0.2 },
|
|
9
|
+
effectiveness: { description: "Test Effectiveness", weight: 0.2 },
|
|
10
|
+
}.freeze
|
|
11
|
+
|
|
12
|
+
def call
|
|
13
|
+
append_to_final_output(<<~OUTPUT)
|
|
14
|
+
========== TEST GRADE REPORT ==========
|
|
15
|
+
Test file: #{workflow.file}
|
|
16
|
+
OUTPUT
|
|
17
|
+
|
|
18
|
+
format_results
|
|
19
|
+
append_to_final_output("\n\n")
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
private
|
|
23
|
+
|
|
24
|
+
def format_results
|
|
25
|
+
# With HashWithIndifferentAccess, we can simply access with either syntax
|
|
26
|
+
grade_data = workflow.output["calculate_final_grade"]
|
|
27
|
+
|
|
28
|
+
unless grade_data
|
|
29
|
+
return append_to_final_output("Error: Grading data not available. This may be because you're replaying the workflow from this step, but the previous step data is missing or not found in the selected session.")
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
format_grade(grade_data)
|
|
33
|
+
|
|
34
|
+
# Make sure rubric_scores exists before trying to iterate over it
|
|
35
|
+
unless grade_data[:rubric_scores]
|
|
36
|
+
return append_to_final_output("Error: Rubric scores data not available in the workflow output.")
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
append_to_final_output("RUBRIC SCORES:")
|
|
40
|
+
grade_data[:rubric_scores].each do |category, data|
|
|
41
|
+
# Safely access RUBRIC with a fallback for potentially missing categories
|
|
42
|
+
rubric_item = RUBRIC[category.to_sym] || { description: "Unknown Category", weight: 0 }
|
|
43
|
+
|
|
44
|
+
append_to_final_output(" #{rubric_item[:description]} (#{(rubric_item[:weight] * 100).round}% of grade):")
|
|
45
|
+
append_to_final_output(" Value: #{data[:raw_value] || "N/A"}")
|
|
46
|
+
append_to_final_output(" Score: #{data[:score] ? (data[:score] * 10).round : "N/A"}/10 - \"#{data[:description] || "No description available"}\"")
|
|
47
|
+
end
|
|
48
|
+
end
|
|
49
|
+
|
|
50
|
+
def format_grade(grade_data)
|
|
51
|
+
return append_to_final_output("\nError: Final grade data not available.") unless grade_data && grade_data[:final_score]
|
|
52
|
+
|
|
53
|
+
letter_grade = grade_data[:final_score][:letter_grade]
|
|
54
|
+
celebration_emoji = letter_grade == "A" ? "🎉" : ""
|
|
55
|
+
append_to_final_output(<<~OUTPUT)
|
|
56
|
+
\nFINAL GRADE:
|
|
57
|
+
Score: #{(grade_data[:final_score][:weighted_score] * 100).round}/100
|
|
58
|
+
Letter Grade: #{letter_grade} #{celebration_emoji}
|
|
59
|
+
OUTPUT
|
|
60
|
+
end
|
|
61
|
+
end
|
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
These are the key testing guidelines to consider in your evaluation:
|
|
2
|
+
|
|
3
|
+
- Tests should serve as specifications that define expected behaviors
|
|
4
|
+
- Tests should have descriptive names that clearly communicate intent
|
|
5
|
+
- Tests should focus on behavior rather than implementation details
|
|
6
|
+
- Excessive mocking/stubbing should be avoided in favor of testing real behavior
|
|
7
|
+
- Tests should be well-structured with minimal setup complexity
|
|
8
|
+
- Tests should be maintainable and not break when implementation details change
|
|
9
|
+
- Tests should cover edge cases and error conditions
|
|
10
|
+
- Tests should follow proper naming conventions and directory structure
|
|
11
|
+
- Tests should not modify the behaviour of the code being tested (e.g. making a private method public in tests)
|
|
12
|
+
|
|
13
|
+
Now consider the full transcript and evaluate the test being graded based on the following rubrics on a scale of 1-10:
|
|
14
|
+
|
|
15
|
+
<test_helpers>
|
|
16
|
+
0-1: Extremely poor helper usage - Helpers used incorrectly or inappropriately, making tests harder to understand
|
|
17
|
+
2-3: Poor helper usage - Helpers are poorly designed, tightly coupled to implementation, or used incorrectly
|
|
18
|
+
4-5: Basic helper usage - Helpers work but may be poorly organized or not reusable
|
|
19
|
+
6-7: Good helper usage - Helpers are well-designed and used appropriately
|
|
20
|
+
8-9: Very good helper usage - Helpers are well-factored, reusable, and make tests clearer
|
|
21
|
+
10: Excellent helper usage - Helpers are perfectly designed, highly reusable, and significantly improve test clarity and maintainability. Also give this score to tests that DO NOT use test helpers at all.
|
|
22
|
+
</test_helpers>
|
|
23
|
+
|
|
24
|
+
<mocks_and_stubs>
|
|
25
|
+
0-1: Extremely poor mocking - Mocks/stubs used incorrectly or excessively, completely hiding real behavior
|
|
26
|
+
2-3: Poor mocking - Heavy reliance on mocks that couple tests to implementation; mocks don't match real behavior
|
|
27
|
+
4-5: Basic mocking - Mocks used appropriately but may be overused or not match implementation exactly
|
|
28
|
+
6-7: Good mocking - Mocks used judiciously where needed; generally match implementation
|
|
29
|
+
8-9: Very good mocking - Minimal mocking focused on external dependencies; accurately reflects real behavior
|
|
30
|
+
10: Excellent mocking - Mocks used only where absolutely necessary (external APIs, etc); perfectly match real implementations; maintain loose coupling
|
|
31
|
+
</mocks_and_stubs>
|
|
32
|
+
|
|
33
|
+
<readability>
|
|
34
|
+
0-1: Extremely poor readability - Test purpose is impossible to understand; no structure or organization
|
|
35
|
+
2-3: Poor readability - Test names are vague or misleading; structure is confusing with no clear assertions
|
|
36
|
+
4-5: Basic readability - Structure is understandable but not optimized for clarity
|
|
37
|
+
6-7: Good readability - Structure is logical with clear assertions
|
|
38
|
+
8-9: Very readable - Well-organized with explicit, meaningful test names and assertions
|
|
39
|
+
10: Exceptionally readable - Test names serve as perfect specifications; elegant structure with context-providing descriptions; self-documenting with clear setup, execution, and verification phases
|
|
40
|
+
</readability>
|
|
41
|
+
|
|
42
|
+
<maintenability>
|
|
43
|
+
0-1: Extremely brittle - Tests are completely coupled to implementation details
|
|
44
|
+
2-3: Highly unmaintainable - Will require significant rework when code changes because of heavy coupling to implementation details
|
|
45
|
+
4-5: Somewhat maintainable - Some coupling to implementation details
|
|
46
|
+
6-7: Reasonably maintainable - Tests mostly focus on behavior over implementation; limited coupling to implementation details
|
|
47
|
+
8-9: Highly maintainable - Tests focus on behavior rather than implementation; changes to implementation should rarely break tests
|
|
48
|
+
10: Exceptionally maintainable - Tests purely focus on behavior and public interfaces; implementation can be completely refactored without breaking tests; well-factored test helpers and fixtures
|
|
49
|
+
</maintenability>
|
|
50
|
+
|
|
51
|
+
<effectiveness>
|
|
52
|
+
0-1: Ineffective - Don't validate actual behavior and could pass even if code is broken
|
|
53
|
+
2-3: Minimally effective - Only the most basic functionality validated. Many incorrect behaviors would not be caught
|
|
54
|
+
4-5: Partially effective - Only catch obvious issues but miss subtle bugs; limited validation of actual outcomes
|
|
55
|
+
6-7: Reasonably effective - Should catch most common bugs
|
|
56
|
+
8-9: Highly effective - Should catch nearly all bugs
|
|
57
|
+
10: Exceptionally effective - Should catch even subtle edge case bugs; validate both positive and negative cases
|
|
58
|
+
</effectiveness>
|
|
59
|
+
|
|
60
|
+
While grading, consider the following goals as being applicable across all rubrics:
|
|
61
|
+
|
|
62
|
+
SUBJECTIVE:
|
|
63
|
+
- Well-written: Organized, easy to understand, and follow best practices
|
|
64
|
+
- Real behavior: Validate what the code does rather than implementation details
|
|
65
|
+
- Isolated: Should not depend on external systems, services, or APIs. Note: The use of fixtures such as `shops(:snowdevil)` is expected and should not be penalized. The only exception is when the SUT is being loaded as a fixture unnecessarily when it could be instantiated directly.
|
|
66
|
+
|
|
67
|
+
OBJECTIVE
|
|
68
|
+
- Idempotent: Should be able to run repeatedly without affecting outcome or side effects.
|
|
69
|
+
- Deterministic: Should produce the same results across all runs and environments.
|
|
70
|
+
- No sleep: Does not include sleep calls or rely on timing for synchronization.
|
|
71
|
+
- Concurrent: Properly handles concurrent execution paths without errors.
|
|
72
|
+
- Timeless: Does not depend on the current date or time. Will not fail due to changes such as daylight savings or leap years. Specifically with regards to handling time, look for anti-patterns like `Time.current + 7.days.to_i`, which fails on DST changes. The correct approach is `7.days.from_now`.
|
|
73
|
+
|
|
74
|
+
VIOLATING ANY OBJECTIVE GOAL SHOULD RESULT IN AN OVERALL SCORE LESS THAN 5!
|
|
75
|
+
|
|
76
|
+
Provide a brief justification for each score, using a maximum of 1-3 sentences. (Note that specific recommendations for improvement are not needed at this step.)
|
|
77
|
+
|
|
78
|
+
You are acting as a stern and relentless striver for excellence in programming, so you must be highly critical. The point of this grading exercise is to facilitate substantial improvement, not just stroking the programmer's ego. Do not hesitate to give a failing overall score (0) for serious violations!
|
|
79
|
+
|
|
80
|
+
RESPONSE FORMAT: You must respond in JSON format within <json> XML tags.
|
|
81
|
+
|
|
82
|
+
<json>
|
|
83
|
+
{
|
|
84
|
+
"test_helpers": {
|
|
85
|
+
"score": 4,
|
|
86
|
+
"justification": "Helpers are used incorrectly in several places, reducing test maintainability and clarity. The assert_valid_record helper is being misused with hashes instead of model instances."
|
|
87
|
+
},
|
|
88
|
+
"mocks_and_stubs": {
|
|
89
|
+
"score": 4,
|
|
90
|
+
"justification": "Several mocks don't match the actual implementation, making tests brittle and potentially hiding production bugs. For example, mocking success: true when the service returns status: 'success'."
|
|
91
|
+
},
|
|
92
|
+
"readability": {
|
|
93
|
+
"score": 8,
|
|
94
|
+
"justification": "Test names clearly describe behavior being tested."
|
|
95
|
+
},
|
|
96
|
+
"maintainability": {
|
|
97
|
+
"score": 6,
|
|
98
|
+
"justification": "Tests mostly focus on behavior but have some coupling to implementation."
|
|
99
|
+
},
|
|
100
|
+
"effectiveness": {
|
|
101
|
+
"score": 7,
|
|
102
|
+
"justification": "Tests validate most expected behaviors and would catch common bugs."
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
</json>
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
========== TEST RECOMMENDATIONS ==========
|
|
2
|
+
<%- if response.recommendations.empty? -%>
|
|
3
|
+
No recommendations found.
|
|
4
|
+
<%- else -%>
|
|
5
|
+
<%- response.recommendations.each_with_index do |rec, index| -%>
|
|
6
|
+
Recommendation #<%= index + 1 %>:
|
|
7
|
+
Description: <%= rec.description %>
|
|
8
|
+
Impact: <%= rec.impact %>
|
|
9
|
+
Priority: <%= rec.priority %>
|
|
10
|
+
|
|
11
|
+
Code Suggestion:
|
|
12
|
+
|
|
13
|
+
<%= rec.code_suggestion %>
|
|
14
|
+
|
|
15
|
+
<%- end -%>
|
|
16
|
+
<%- end -%>
|
|
17
|
+
===========================================
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
Finally, based on the conversation transcript above, go ahead and provide specific, actionable recommendations that would most effectively improve the overall test score.
|
|
2
|
+
|
|
3
|
+
Focus on recommendations that would:
|
|
4
|
+
|
|
5
|
+
1. Increase coverage
|
|
6
|
+
2. Add more assertions where needed
|
|
7
|
+
3. Make the tests more maintainable or readable
|
|
8
|
+
4. Ensure tests serve as specifications by having clear, descriptive names
|
|
9
|
+
5. Reduce excessive mocking/stubbing that couples tests to implementation details
|
|
10
|
+
6. Improve test structure to reduce setup complexity
|
|
11
|
+
7. Ensure tests focus on behavior rather than implementation details
|
|
12
|
+
8. Ensure gaps in private methods are tested through public methods
|
|
13
|
+
9. Fix any issues with test helpers that are used incorrectly or unnecessarily
|
|
14
|
+
10. Improve efficiency by combining or deleting tests where appropriate (note that having more than one assertion per test is acceptable)
|
|
15
|
+
11. Fix any violations of the objective criteria (idempotency, determinism, etc.)
|
|
16
|
+
12. Be specific about edge cases that should be covered by tests. Write down in the recommendations which edge cases you are referring to.
|
|
17
|
+
13. Do not recommend the use of RSpec features like `let` for Minispec tests.
|
|
18
|
+
|
|
19
|
+
IF YOU IDENTIFY EDGE CASES, YOU MUST BE SPECIFIC ABOUT THEM IN THE RECOMMENDATIONS.
|
|
20
|
+
|
|
21
|
+
RESPONSE FORMAT: You must respond in JSON format inside <json> XML tags without additional commentary.
|
|
22
|
+
|
|
23
|
+
Example:
|
|
24
|
+
|
|
25
|
+
<json>
|
|
26
|
+
{
|
|
27
|
+
"recommendations": [
|
|
28
|
+
{
|
|
29
|
+
"description": "Add tests for uncovered method X",
|
|
30
|
+
"impact": "Would increase method coverage by Y%",
|
|
31
|
+
"priority": "High",
|
|
32
|
+
"code_suggestion": "def test_method_x_with_valid_input\n result = subject.method_x('valid_input')\n assert_equal expected_result, result\nend"
|
|
33
|
+
},
|
|
34
|
+
{
|
|
35
|
+
"description": "Fix time handling to avoid DST issues",
|
|
36
|
+
"impact": "Would make tests deterministic across DST changes",
|
|
37
|
+
"priority": "High",
|
|
38
|
+
"code_suggestion": "# Replace\nexpiry_time = Time.current + 7.days.to_i\n\n# With\nexpiry_time = 7.days.from_now"
|
|
39
|
+
},
|
|
40
|
+
{
|
|
41
|
+
"description": "Add edge case tests for the show action for when the parameter X is blank",
|
|
42
|
+
"impact": "Would improve test completeness and effectiveness",
|
|
43
|
+
"priority": "Medium",
|
|
44
|
+
"code_suggestion": "..."
|
|
45
|
+
},
|
|
46
|
+
{
|
|
47
|
+
"description": "Improve test descriptions to better serve as specifications",
|
|
48
|
+
"impact": "Would make tests more valuable as documentation",
|
|
49
|
+
"priority": "Medium",
|
|
50
|
+
"code_suggestion": "# Replace\ndef test_process\n\n# With\ndef test_process_returns_success_with_valid_input"
|
|
51
|
+
},
|
|
52
|
+
{
|
|
53
|
+
"description": "Replace implementation-focused mocks with behavior assertions",
|
|
54
|
+
"impact": "Would make tests less brittle and more maintainable",
|
|
55
|
+
"priority": "High",
|
|
56
|
+
"code_suggestion": "# Replace\nUserNotifier.expects(:notify).with(user, 'welcome')\n\n# With\nassert_sends_notification(user, 'welcome') do\n subject.process\nend"
|
|
57
|
+
}
|
|
58
|
+
]
|
|
59
|
+
}
|
|
60
|
+
</json>
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
Use the provided functions to find and read important dependencies of the provided test file named <%= workflow.file %>.
|
|
2
|
+
|
|
3
|
+
The first dependency you should always look for is the source file for the prime subject of the test (whatever class this test file is claiming to test). Use `read_file` to read the subject's source code into your conversation transcript, but only if it's not already there from a previous chat.
|
|
4
|
+
|
|
5
|
+
If you can identify other important application-level dependencies then read them too.
|
|
6
|
+
How many extra dependencies to research is left to your discretion, but ALWAYS make sure you have the subject under test (SUT) in your context before responding.
|
|
7
|
+
|
|
8
|
+
Once you are finished using tool functions, respond with the relative path to the source file of the SUT inside <sut> tags. IMPORTANT: Include the full relative path from the project root, including any directory prefixes like lib/, app/, etc.
|
|
9
|
+
|
|
10
|
+
Example:
|
|
11
|
+
|
|
12
|
+
If you are told to find the dependencies of `test/services/country_db_interface_test.rb`,
|
|
13
|
+
then you would use the functions as explained above and ultimately respond with `<sut>app/services/country_db_interface.rb</sut>`
|
|
14
|
+
|
|
15
|
+
If the file is found at `lib/roast/workflow/workflow_initializer.rb`, respond with `<sut>lib/roast/workflow/workflow_initializer.rb</sut>` (include the lib/ prefix)
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
Find places in the provided test code where stubbing and mocking are used. Search for the corresponding implementation source code of those dependencies elsewhere in the codebase to validate that the stub or mock matches the implementation that it is doubling. Use the tool functions provided to find and read the dependencies.
|
|
2
|
+
|
|
3
|
+
Once you've found the dependencies, verify that any mocks and stubs accurately reflect the real implementation. If there are discrepancies, list them out alphabetically with:
|
|
4
|
+
|
|
5
|
+
1. The name of the mocked/stubbed method
|
|
6
|
+
2. What the mock/stub expects in terms of arguments and/or return values
|
|
7
|
+
3. What the actual implementation actually takes as arguments and returns
|
|
8
|
+
4. Suggestions for fixing the discrepancy
|
|
9
|
+
|
|
10
|
+
Note: If there are no discrepancies, do not summarize those that accurately reflect their real implementations in the codebase, just respond "All mocks and stubs verified."
|
|
11
|
+
|
|
12
|
+
IMPORTANT: There's absolutely no need for you to waste time grepping for methods/functions that you know belong to testing libraries such as Mocha's `expects` and `stubs`. Only search for the implementation of things that are stubbed and/or mocked in the test to verify whether the test code matches the implementation code.
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
Now identify custom test helpers used in this test for the following purpose:
|
|
2
|
+
|
|
3
|
+
1. Analyzing if they are used correctly
|
|
4
|
+
2. Understanding test code that has had significant chunks of implementation abstracted away into helpers
|
|
5
|
+
3. Fully understanding custom assertions that are not included by default in Ruby on Rails or part of your base knowledge
|
|
6
|
+
|
|
7
|
+
Your grep tool function is vital for this work. It provides 4 lines of context before and after the matching line.
|
|
8
|
+
|
|
9
|
+
For example, if you call `grep(string: "def assert_sql")`, the output will include:
|
|
10
|
+
|
|
11
|
+
```
|
|
12
|
+
.test/support/helpers/sql_assertions.rb-101- end
|
|
13
|
+
.test/support/helpers/sql_assertions.rb-102- result
|
|
14
|
+
.test/support/helpers/sql_assertions.rb-103- end
|
|
15
|
+
.test/support/helpers/sql_assertions.rb-104-
|
|
16
|
+
.test/support/helpers/sql_assertions.rb:105: def assert_sql(*patterns_to_match, **kwargs, &block)
|
|
17
|
+
.test/support/helpers/sql_assertions.rb-106- mysql_only_test!
|
|
18
|
+
.test/support/helpers/sql_assertions.rb-107-
|
|
19
|
+
.test/support/helpers/sql_assertions.rb-108- result = T.let(nil, T.nilable(T::Boolean))
|
|
20
|
+
.test/support/helpers/sql_assertions.rb-109- counter = ActiveRecord::SQLCounter.new(**kwargs)
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
Unfortunately, many test helper methods are undocumented. In those cases (like the example above) the pre-context will be junk. However, there are a number of helper methods that do have very specific and narrow use cases, and those do tend to be well-documented. In those cases, you should use `read_file` to be able to read the full documentation.
|
|
24
|
+
|
|
25
|
+
For example, here is the result of calling `grep(string: "def assert_sql_events")`
|
|
26
|
+
|
|
27
|
+
```
|
|
28
|
+
.test/support/helpers/externals_helper.rb-93- # @example Logs events in the list that did not occur
|
|
29
|
+
.test/support/helpers/externals_helper.rb-94- # expected_queries = { "Shop Load" => 1, "User Load" => 1 }
|
|
30
|
+
.test/support/helpers/externals_helper.rb-95- # # Fails and reports that User Load occured 0 times instead of expected 1
|
|
31
|
+
.test/support/helpers/externals_helper.rb-96- # assert_sql_events(expected_queries) { Shop.current_or_find(shop.id) }
|
|
32
|
+
.test/support/helpers/externals_helper.rb:97: def assert_sql_events(expected_events, &block)
|
|
33
|
+
.test/support/helpers/externals_helper.rb-98- mysql_only_test!
|
|
34
|
+
.test/support/helpers/externals_helper.rb-99-
|
|
35
|
+
.test/support/helpers/externals_helper.rb-100- mysql_events = ExternalsCollector.new(&block).events
|
|
36
|
+
.test/support/helpers/externals_helper.rb-101- .select { |e| e.first == :mysql }
|
|
37
|
+
```
|
|
38
|
+
|
|
39
|
+
Notice that the documentation for the `assert_sql_events` method is cutoff. Use your `read_file` tool function to get the whole test helper source code and gain better understanding of how it is intended to be used, with the side benefit of also being able to see how it is implemented.
|
|
40
|
+
|
|
41
|
+
Note: You will undoubtedly already be familiar with some of Minitest and RSpec's built-in helpers. There is no need to search for those, since they are packaged as gems you won't find them anyway.
|
|
42
|
+
|
|
43
|
+
DO NOT FORGET TO PREPEND `def` TO YOUR QUERY TO FIND A METHOD DEFINITION INSTEAD OF USAGES, otherwise you may bring back a very large and useless result set!!!
|
|
44
|
+
|
|
45
|
+
Once you are done understanding the custom test helpers used in the test file, analyze and report on whether it seems like any of the helpers are:
|
|
46
|
+
|
|
47
|
+
1. Used incorrectly
|
|
48
|
+
2. Used unnecessarily
|
|
49
|
+
3. Any other problem related to the use of helper methods
|
|
50
|
+
|
|
51
|
+
Where possible, use your best judgment to make recommendations for how to fix problems that you find, but ONLY related to test helpers.
|
|
52
|
+
|
|
53
|
+
Note: You are only being used to help find problems so it is not necessary to report on correct usage of helpers or to make positive comments.
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
As a senior software engineer and testing expert, evaluate the quality of this test file based on guidelines that will be subsequently provided.
|
|
2
|
+
|
|
3
|
+
Next I will now provide the source code of the test that we will be analyzing, and then step you through a series of analysis activities, before finally asking you to provided a final report.
|
|
4
|
+
|
|
5
|
+
# <%= file %> <%= File.read(file) %>
|