<commit_before>require "spec_helper"

describe Boulevard do
  it "has a version number" do
    expect(Boulevard::VERSION).not_to be nil
  end

  describe 'packaging and unpackaging' do
    let(:secret_key) { Boulevard::Crypt.generate_key }
    let(:code) { Base64.encode64(Random.new.bytes(rand(2**12) + 1)) }
    let(:unpackaged) { Boulevard.unpackage(secret_key, package) }

    describe 'with code' do
      let(:package) { Boulevard.package_code(secret_key, code) }

      it 'should round-trip it' do
        expect(unpackaged).to include code
      end
    end

    describe 'with a file' do
      make_temporary_directory

      let(:path) { file('something.rb', code) }

      let(:package) { Boulevard.package_file(secret_key, path) }

      it 'should round-trip it' do
        expect(unpackaged).to include code
      end
    end
  end

  describe 'running the code' do
    let(:secret_key) { Boulevard::Crypt.generate_key }

    context 'localy', type: :aruba do
      it 'runs the code from a file' do
        write_file 'local_script_runner', Boulevard.compile_host_code(secret_key, :local_script)

        code_package = Boulevard.package_code(
          secret_key,
          'print BoulevardRuntime.env[:message].reverse',
          message: 'hello world'
        )

        run "ruby local_script_runner '#{code_package}'"

        expect(last_command_started).to have_output 'hello world'.reverse
        expect(last_command_started).to be_successfully_executed
      end
    end

    context 'in the cloud'
  end<commit_msg>Improve test coverage<commit_after>require "spec_helper"

describe Boulevard do
  it "has a version number" do
    expect(Boulevard::VERSION).not_to be nil
  end

  describe 'packaging and unpackaging' do
    let(:secret_key) { Boulevard::Crypt.generate_key }
    let(:code) { Base64.encode64(Random.new.bytes(rand(2**12) + 1)) }
    let(:unpackaged) { Boulevard.unpackage(secret_key, package) }

    describe 'with code' do
      let(:package) { Boulevard.package_code(secret_key, code) }

      it 'should round-trip it' do
        expect(unpackaged).to include code
      end
    end

    describe 'with a file' do
      make_temporary_directory

      let(:path) { file('something.rb', code) }

      let(:package) { Boulevard.package_file(secret_key, path) }

      it 'should round-trip it' do
        expect(unpackaged).to include code
      end
    end
  end

  describe 'running the code' do
    let(:secret_key) { Boulevard::Crypt.generate_key }

    let(:script) do
      'print BoulevardRuntime.env[:message].reverse'
    end

    context 'localy', type: :aruba do
      before do
        write_file 'local_script_runner', Boulevard.compile_host_code(secret_key, :local_script)
      end

      context 'from a file' do
        let(:code_package) do
          write_file 'script.rb', script

          Boulevard.package_file(secret_key, 'tmp/aruba/script.rb', message: 'hello world')
        end

        it 'runs' do
          run "ruby local_script_runner '#{code_package}'"

          expect(last_command_started).to have_output 'hello world'.reverse
          expect(last_command_started).to be_successfully_executed
        end
      end

      context 'from a string' do
        let(:code_package) do
          Boulevard.package_code(secret_key, script, message: 'hello world')
        end

        it 'runs' do
          run "ruby local_script_runner '#{code_package}'"

          expect(last_command_started).to have_output 'hello world'.reverse
          expect(last_command_started).to be_successfully_executed
        end
      end
    end
  end
{'fraction_non_alphanumeric': 0.09662236987818383, 'fraction_numerical': 0.004429678848283499, 'mean_word_length': 2.8807733619763694, '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': '2722005', 'n_tokens_mistral': 1169, 'n_tokens_neox': 1072, 'n_words': 271}