<commit_before>require 'debugger'
require 'selenium-webdriver'
require_relative 'selenium_adapter'

NUM_EDITS = 500

################################################################################
# Helpers for generating random edits
################################################################################
def js_get_random_edit(driver)
  return driver.execute_script "return parent.writer.getRandomOp();"
end

################################################################################
# Helpers
################################################################################
def check_consistency(driver)
  writer_delta = driver.execute_script "return parent.writer.getDelta().toString();"
  reader_delta = driver.execute_script "return parent.reader.getDelta().toString();"
  raise "Writer: #{writer_delta}\nReader: #{reader_delta}" unless writer_delta == reader_delta
end

################################################################################
# WebDriver setup
################################################################################
puts "Usage: ruby _browserdriver_ _editor_url_" unless ARGV.length == 2
browserdriver = ARGV[0].to_sym
editor_url = ARGV[1]
driver = Selenium::WebDriver.for browserdriver
driver.manage.timeouts.implicit_wait = 10
driver.get editor_url
editors = driver.find_elements(:class, "editor-container")
writer, reader = editors
driver.switch_to.frame(driver.find_element(:tag_name, "iframe"))
writer = driver.find_element(:id, "scribe-container")
adapter = SeleniumAdapter.new driver, writer

################################################################################
# Fuzzer logic
################################################################################
NUM_EDITS.times do |i|
   puts i if i % 10 == 0
   random_edit = js_get_random_edit(driver)
   adapter.op_to_selenium(random_edit)
   check_consistency(driver)
end
<commit_msg>Loading in tandem-core checkpoint.<commit_after>require 'debugger'
require 'execjs'
require 'selenium-webdriver'
require_relative 'selenium_adapter'

src = File.read('../../../bin/src/tandem-core.js')
src.prepend("window = {};")
c = V8::Context.new
c.eval(src)
debugger
puts c.eval('window.Delta')
abort

NUM_EDITS = 500

################################################################################
# Helpers for generating random edits
################################################################################
def js_get_random_edit(driver)
  return driver.execute_script "return parent.writer.getRandomOp();"
end

################################################################################
# Helpers
################################################################################
def check_consistency(driver)
  writer_delta = driver.execute_script "return parent.writer.getDelta().toString();"
  reader_delta = driver.execute_script "return parent.reader.getDelta().toString();"
  raise "Writer: #{writer_delta}\nReader: #{reader_delta}" unless writer_delta == reader_delta
end

################################################################################
# WebDriver setup
################################################################################
puts "Usage: ruby _browserdriver_ _editor_url_" unless ARGV.length == 2
browserdriver = ARGV[0].to_sym
editor_url = ARGV[1]
driver = Selenium::WebDriver.for browserdriver
driver.manage.timeouts.implicit_wait = 10
driver.get editor_url
editors = driver.find_elements(:class, "editor-container")
writer, reader = editors
driver.switch_to.frame(driver.find_element(:tag_name, "iframe"))
writer = driver.find_element(:id, "scribe-container")
adapter = SeleniumAdapter.new driver, writer

################################################################################
# Fuzzer logic
################################################################################
NUM_EDITS.times do |i|
   puts i if i % 10 == 0
   random_edit = js_get_random_edit(driver)
   adapter.op_to_selenium(random_edit)
   check_consistency(driver)
end

{'fraction_non_alphanumeric': 0.39676214196762144, 'fraction_numerical': 0.00572851805728518, 'mean_word_length': 9.297435897435898, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1986706', 'n_tokens_mistral': 1020, 'n_tokens_neox': 939, 'n_words': 197}