<commit_before>require './spec/env/global.rb'
require 'therubyracer'
require './spec/lib/temp_dir'

shared_context "kern" do
  before(:each) do
    reset_for_ctx
  end

  def reset_for_ctx
    res=system('rake build:world')
    raise "Could not run build:world" unless res
    @ctx = V8::Context.new
    @ctx.load "./products/#{ENV['PLATFORM']}/application.js"

    if ENV['RUBY_PLATFORM'] =~ /darwin/
      `killall phantomjs`
      `killall rspec`
    end
  end

  class V8::Context
    def dump variable
      json_res = self.eval %{
        JSON.stringify(#{variable});
      }

      return JSON.parse(json_res)
    end
  end

  #Execute flok binary with a command
  def flok args
    #Get path to the flok binary relative to this file
    bin_path = File.join(File.dirname(__FILE__), "../../bin/flok")

    #Now execute the command with a set of arguments
    return system("#{bin_path} #{args}")
  end

  #Create a new flok project, add the given user_file (an .rb file containing controllers, etc.)
  #and then retrieve a V8 instance from this project's application_user.js
  def flok_new_user user_controllers_src, service_config=nil, service_src=nil
    temp_dir = new_temp_dir
    Dir.chdir temp_dir do
      flok "new test"
      Dir.chdir "test" do
        #Put controllers in
        File.write './app/controllers/user_controller.rb', user_controllers_src
        File.write './config/services.rb', service_config if service_config
        File.write './app/services/service0.rb', service_src if service_src

        #Build
        unless flok "build" #Will generate drivers/ but we will ignore that
          raise "Build failed"
        end

        #Execute
        @driver = FakeDriverContext.new
        v8 = V8::Context.new(:with => @driver)
        @ctx = v8
        @driver.ctx = v8
        v8.eval %{
          //We must convert this to JSON because the fake driver will receive
          //a raw v8 object otherwise
          function if_dispatch(q) {
            if_dispatch_json(JSON.stringify(q));
          }
        }
        File.write "/Users/Seo/Desktop/dump.rb", File.read('./products/chrome/application_user.js') 
        v8.eval File.read('./products/chrome/application_user.js')
        return v8
      end
    end
  end

  #This supports if_dispatch interface and allows for sending information back via 
  #int_dispatch to the kernel. It is embededd into the v8 context environment
  class FakeDriverContext
    include RSpec::Matchers 

    attr_accessor :ctx
    def initialize
      @q = []  #Full queue, 2 dimensional all priority 
      @cq = nil #Contains only the current working priority
      @cp = nil #Contains the current priority
    end
<commit_msg>removed absolute path<commit_after>require './spec/env/global.rb'
require 'therubyracer'
require './spec/lib/temp_dir'

shared_context "kern" do
  before(:each) do
    reset_for_ctx
  end

  def reset_for_ctx
    res=system('rake build:world')
    raise "Could not run build:world" unless res
    @ctx = V8::Context.new
    @ctx.load "./products/#{ENV['PLATFORM']}/application.js"

    if ENV['RUBY_PLATFORM'] =~ /darwin/
      `killall phantomjs`
      `killall rspec`
    end
  end

  class V8::Context
    def dump variable
      json_res = self.eval %{
        JSON.stringify(#{variable});
      }

      return JSON.parse(json_res)
    end
  end

  #Execute flok binary with a command
  def flok args
    #Get path to the flok binary relative to this file
    bin_path = File.join(File.dirname(__FILE__), "../../bin/flok")

    #Now execute the command with a set of arguments
    return system("#{bin_path} #{args}")
  end

  #Create a new flok project, add the given user_file (an .rb file containing controllers, etc.)
  #and then retrieve a V8 instance from this project's application_user.js
  def flok_new_user user_controllers_src, service_config=nil, service_src=nil
    temp_dir = new_temp_dir
    Dir.chdir temp_dir do
      flok "new test"
      Dir.chdir "test" do
        #Put controllers in
        File.write './app/controllers/user_controller.rb', user_controllers_src
        File.write './config/services.rb', service_config if service_config
        File.write './app/services/service0.rb', service_src if service_src

        #Build
        unless flok "build" #Will generate drivers/ but we will ignore that
          raise "Build failed"
        end

        #Execute
        @driver = FakeDriverContext.new
        v8 = V8::Context.new(:with => @driver)
        @ctx = v8
        @driver.ctx = v8
        v8.eval %{
          //We must convert this to JSON because the fake driver will receive
          //a raw v8 object otherwise
          function if_dispatch(q) {
            if_dispatch_json(JSON.stringify(q));
          }
        }
        v8.eval File.read('./products/chrome/application_user.js')
        return v8
      end
    end
  end

  #This supports if_dispatch interface and allows for sending information back via 
  #int_dispatch to the kernel. It is embededd into the v8 context environment
  class FakeDriverContext
    include RSpec::Matchers 

    attr_accessor :ctx
    def initialize
      @q = []  #Full queue, 2 dimensional all priority 
      @cq = nil #Contains only the current working priority
      @cp = nil #Contains the current priority
    end

{'fraction_non_alphanumeric': 0.09135430401205501, 'fraction_numerical': 0.005274062912036165, 'mean_word_length': 2.570948217888366, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, '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': '1599637', 'n_tokens_mistral': 1608, 'n_tokens_neox': 1566, 'n_words': 501}