<commit_before># frozen_string_literal: true

require "helpers"

# tests cli commands: built-in (help, version, commands, types, & conf)
class CLIBuiltinsTest < Minitest::Test
  include Aruba::Api
  include Helpers
  include Helpers::CLI

  def setup
    setup_aruba
  end

  def test_help
    # `kbsecret help` should always run, and should produce a "Usage:" output
    kbsecret "help", interactive: false do |stdout, _|
      assert_match(/Usage/, stdout)
    end
  end

  def test_version
    exp = "kbsecret version #{KBSecret::VERSION}."

    # `kbsecret version` should always run, and should produce KBSecret's current version
    kbsecret "version", interactive: false do |stdout, _|
      assert_equal exp, stdout.chomp
    end
  end

  def test_commands
    # `kbsecret commands` should always run
    kbsecret "commands"
  end

  def test_types
    # `kbsecret types` should always run, and should produce every type known to KBSecret
    kbsecret "types", interactive: false do |stdout, _|
      KBSecret::Record.record_types.each do |type|
        assert_includes stdout, type.to_s
      end
    end
  end

  def test_conf
    # with EDITOR unset, `kbsecret conf` should produce an error message
    delete_environment_variable "EDITOR"
    kbsecret "conf", interactive: false do |_, stderr|
      assert_match(/You need to set \$EDITOR/, stderr)
    end

    # with EDITOR set to `cat`, `kbsecret conf` should output the configuration
    set_environment_variable "EDITOR", "cat"
    kbsecret "conf", interactive: false do |stdout, _|
      assert_match(/:mount:/, stdout)
    end
  end
end<commit_msg>test/cli: Add note about moving conf test<commit_after># frozen_string_literal: true

require "helpers"

# tests cli commands: built-in (help, version, commands, types, & conf)
class CLIBuiltinsTest < Minitest::Test
  include Aruba::Api
  include Helpers
  include Helpers::CLI

  def setup
    setup_aruba
  end

  def test_help
    # `kbsecret help` should always run, and should produce a "Usage:" output
    kbsecret "help", interactive: false do |stdout, _|
      assert_match(/Usage/, stdout)
    end
  end

  def test_version
    exp = "kbsecret version #{KBSecret::VERSION}."

    # `kbsecret version` should always run, and should produce KBSecret's current version
    kbsecret "version", interactive: false do |stdout, _|
      assert_equal exp, stdout.chomp
    end
  end

  def test_commands
    # `kbsecret commands` should always run
    kbsecret "commands"
  end

  def test_types
    # `kbsecret types` should always run, and should produce every type known to KBSecret
    kbsecret "types", interactive: false do |stdout, _|
      KBSecret::Record.record_types.each do |type|
        assert_includes stdout, type.to_s
      end
    end
  end

  # TODO: move this to its own file (no longer a builtin)
  def test_conf
    # with EDITOR unset, `kbsecret conf` should produce an error message
    delete_environment_variable "EDITOR"
    kbsecret "conf", interactive: false do |_, stderr|
      assert_match(/You need to set \$EDITOR/, stderr)
    end

    # with EDITOR set to `cat`, `kbsecret conf` should output the configuration
    set_environment_variable "EDITOR", "cat"
    kbsecret "conf", interactive: false do |stdout, _|
      assert_match(/:mount:/, stdout)
    end
  end
end
{'fraction_non_alphanumeric': 0.08313253012048193, 'fraction_numerical': 0.0, 'mean_word_length': 3.416223404255319, 'pattern_counts': {'":': 0, '<': 5, '<?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': '741882', 'n_tokens_mistral': 1018, 'n_tokens_neox': 981, 'n_words': 356}