<commit_before>require 'test_helper'

module RVT
  class ConsoleSessionsControllerTest < ActionController::TestCase
    setup do
      PTY.stubs(:spawn).returns([StringIO.new, StringIO.new, Random.rand(20000)])
      @request.stubs(:remote_ip).returns('127.0.0.1')
    end

    test 'index is successful' do
      get :index      assert_response :success
    end

    test 'GET index creates new console session' do
      assert_difference 'ConsoleSession::INMEMORY_STORAGE.size' do
        get :index
      end
    end

    test 'PUT input validates for missing input' do
      get :index

      assert_not_nil console_session = assigns(:console_session)

      console_session.instance_variable_get(:@slave).stubs(:send_input).raises(ArgumentError)
      put :input, params: { id: console_session.pid, uid: console_session.uid }

      assert_response :unprocessable_entity
    end

    test 'PUT input sends input to the slave' do
      get :index

      assert_not_nil console_session = assigns(:console_session)

      console_session.expects(:send_input)
      put :input, params: { input: ' ', id: console_session.pid, uid: console_session.uid }
    end
<commit_msg>Fix editing artefact of assert_response<commit_after>require 'test_helper'

module RVT
  class ConsoleSessionsControllerTest < ActionController::TestCase
    setup do
      PTY.stubs(:spawn).returns([StringIO.new, StringIO.new, Random.rand(20000)])
      @request.stubs(:remote_ip).returns('127.0.0.1')
    end

    test 'index is successful' do
      get :index
      assert_response :success
    end

    test 'GET index creates new console session' do
      assert_difference 'ConsoleSession::INMEMORY_STORAGE.size' do
        get :index
      end
    end

    test 'PUT input validates for missing input' do
      get :index

      assert_not_nil console_session = assigns(:console_session)

      console_session.instance_variable_get(:@slave).stubs(:send_input).raises(ArgumentError)
      put :input, params: { id: console_session.pid, uid: console_session.uid }

      assert_response :unprocessable_entity
    end

    test 'PUT input sends input to the slave' do
      get :index

      assert_not_nil console_session = assigns(:console_session)

      console_session.expects(:send_input)
      put :input, params: { input: ' ', id: console_session.pid, uid: console_session.uid }
    end

{'fraction_non_alphanumeric': 0.0876527602191319, 'fraction_numerical': 0.009270965023177412, 'mean_word_length': 3.445692883895131, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 2, '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': '528248', 'n_tokens_mistral': 725, 'n_tokens_neox': 690, 'n_words': 178}