Skip to content

Instantly share code, notes, and snippets.

@noahd1
Created August 15, 2025 02:35
Show Gist options
  • Select an option

  • Save noahd1/784c1f55de10637e97da923ed17f16f9 to your computer and use it in GitHub Desktop.

Select an option

Save noahd1/784c1f55de10637e97da923ed17f16f9 to your computer and use it in GitHub Desktop.
Report coverage for a single file and a single line given a directory of Qlty jsonl files
require 'json'
if ARGV.length != 2
puts "Usage: ruby jsonl-line-reader.rb <directory> <path:line_number>"
exit 1
end
directory = ARGV[0]
target_arg = ARGV[1]
if target_arg =~ /^(.*):(\d+)$/
target_file_subpath = $1
target_line_number = $2.to_i
target_line_index = target_line_number - 1
else
puts "Error: Second argument must be in the format PATH:LINE_NUMBER"
exit 1
end
# Counters for summary
found_count = 0
covered_count = 0
uncovered_count = 0
omitted_count = 0
unexpected_line_count = 0
Dir.glob(File.join(directory, "*.jsonl")).each do |filename|
File.foreach(filename) do |line|
doc = JSON.parse(line)
next unless doc["path"] && doc["path"].include?(target_file_subpath)
found_count += 1
if doc["hits"].is_a?(Array)
if doc["hits"].length <= target_line_index
unexpected_line_count += 1
next
end
value = doc["hits"][target_line_index]
if value == "-1"
omitted_count += 1
elsif value == "0"
uncovered_count += 1
elsif value.to_i > 0
covered_count += 1
end
else
raise "hits key missing or not an array."
end
end
end
# Print summary
puts "\nSummary:"
puts "Total times path found: #{found_count}"
puts "Total times line considered covered: #{covered_count}"
puts "Total times line considered uncovered: #{uncovered_count}"
puts "Total times line considered omitted: #{omitted_count}"
puts "Total times with unexpected line count: #{unexpected_line_count}"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment