Slide 1

Slide 1 text

The test code generator using static analysis and LLM Hashino Mikiko (@mikiko_bridge)

Slide 2

Slide 2 text

Agenda - What is “omochi” ? - Motivation - Demo - Architecture - Future Works - Conclusion

Slide 3

Slide 3 text

What is “omochi” ? Detect RSpec files and methods that have not yet been created, and generate sample code for them. feature - List all methods which is not tested by RSpec - Integrate with CI(github action) - Automatically generate RSpec code template

Slide 4

Slide 4 text

What is “omochi” ? feature 1. List all methods which is not tested by RSpec "Verify File List: [\"app/controllers/content_controller.rb\"]" "specファイルなし" ======= RESULT: app/controllers/content_controller.rb ======= - index - show - destroy - edit - update

Slide 5

Slide 5 text

What is “omochi” ? feature 2. Integrate with CI(github action)

Slide 6

Slide 6 text

What is “omochi” ? feature 3. Automatically generate RSpec code template

Slide 7

Slide 7 text

Agenda - What is “omochi” ? - Motivation - Demo - Architecture - Future Works - Conclusion

Slide 8

Slide 8 text

Motivation Omochi confirmed that all methods in PR have RSpec. It is hard to find unverified method by reviewer Some methods don’t have RSpec in your PR.

Slide 9

Slide 9 text

Agenda - What is “omochi” ? - Demo - Architecture - Future Works - Conclusion

Slide 10

Slide 10 text

No content

Slide 11

Slide 11 text

Agenda - What is “omochi” ? - Demo - Architecture - Future Works - Conclusion

Slide 12

Slide 12 text

Architecture def local_diff_path ...省略 diff_command = 'git diff --diff-filter=d --name-only' diff_output, _diff_error, _diff_status = Open3.capture3(diff_command, chdir: '.') ...省略 diff_output.split("\n") end

Slide 13

Slide 13 text

Architecture def get_ast(diff_path) exprs = [] ast = Parser::CurrentRuby.parse(File.read(diff_path)) exprs << { ast: ast, filename: diff_path } end

Slide 14

Slide 14 text

Architecture

Slide 15

Slide 15 text

Architecture def dfs(node, filename, result) ...省略 case node.type when :def child_value = node.children[0] code = Unparser.unparse(node) result[child_value] = code end node.children.each { |child| dfs(child, filename, result) } end

Slide 16

Slide 16 text

Architecture def find_spec_file(diff_path) spec_path = File.join('spec', diff_path.gsub(/\.rb$/, '_spec.rb').gsub('app/', '')) File.exist?(spec_path) ? spec_path : nil end

Slide 17

Slide 17 text

Architecture def get_ast(diff_path) exprs = [] ast = Parser::CurrentRuby.parse(File.read(diff_path)) exprs << { ast: ast, filename: diff_path } end

Slide 18

Slide 18 text

Architecture def get_ast(diff_path) exprs = [] ast = Parser::CurrentRuby.parse(File.read(diff_path)) exprs << { ast: ast, filename: diff_path } end def dfs_describe(node, filename, def_name_arr) ...省略 case node.type when :send method_node = node.children[1] if node.children[1] == :describe def_name = node.children[2].children[0] # "Omochi::CLI" if !def_name.nil? && def_name.is_a?(String) def_name = get_pure_function_name(def_name) def_name_arr.push(def_name) end end end node.children.each { |child| dfs_describe(child, filename, def_name_arr) } def_name_arr end

Slide 19

Slide 19 text

Architecture def process_spec_file(diff_path, create_spec, perfect) ...省略 method_code = result[spec_def_name] puts '===================================================================' puts "#{spec_def_name} のテストを以下に表示します。 " create_spec_by_bedrock(method_code) end get_ignore_methods(diff_path).each do |def_name| result[def_name] = true if result.key?(def_name) end perfect = false if print_result(diff_path, result).size > 0 perfect end

Slide 20

Slide 20 text

Agenda - What is “omochi” ? - Demo - Architecture - Future Works - Conclusion

Slide 21

Slide 21 text

Future Works - Support request spec etc… - Write test codes for omochi

Slide 22

Slide 22 text

Agenda - What is “omochi” ? - Demo - Architecture - Future Works - Conclusion

Slide 23

Slide 23 text

Conclusion - Please commits to omochi !! - Let's use AST to solve problems using technology👍 https://github.com/mikik0/omochi blog GitHub