<commit_before>require File.expand_path("../../../base", __FILE__)

require 'vagrant/util/powershell'

describe Vagrant::Util::PowerShell do
  include_context "unit"

  after{ described_class.reset! }

  describe ".version" do
    before do
      allow(described_class).to receive(:executable)
        .and_return("powershell")
      allow(Vagrant::Util::Subprocess).to receive(:execute)
    end

    after do
      described_class.version
    end

    it "should execute powershell command" do
      expect(Vagrant::Util::Subprocess).to receive(:execute).with("powershell", any_args)
    end

    it "should use the default timeout" do
      expect(Vagrant::Util::Subprocess).to receive(:execute).with(any_args, hash_including(
        timeout: Vagrant::Util::PowerShell::DEFAULT_VERSION_DETECTION_TIMEOUT))
    end

    it "should use environment variable provided timeout" do
      with_temp_env("VAGRANT_POWERSHELL_VERSION_DETECTION_TIMEOUT" => "1") do
        expect(Vagrant::Util::Subprocess).to receive(:execute).with(any_args, hash_including(
          timeout: 1))
        described_class.version
      end
    end

    it "should use default timeout when environment variable value is invalid" do
      with_temp_env("VAGRANT_POWERSHELL_VERSION_DETECTION_TIMEOUT" => "invalid value") do
        expect(Vagrant::Util::Subprocess).to receive(:execute).with(any_args, hash_including(
          timeout: Vagrant::Util::PowerShell::DEFAULT_VERSION_DETECTION_TIMEOUT))
        described_class.version
      end
    end
  end

  describe ".executable" do
    before{ allow(Vagrant::Util::Platform).to receive(:wsl?).and_return(false) }

    context "when found in PATH" do
      before{ expect(Vagrant::Util::Which).to receive(:which).with("powershell").and_return(true) }

      it "should return powershell string" do
        expect(described_class.executable).to eq("powershell")
      end
    end

    context "when not found in PATH" do
      before{ expect(Vagrant::Util::Which).to receive(:which).with("powershell").and_return(nil) }

      it "should return nil" do
        expect(described_class.executable).to be_nil
      end

      context "when within WSL" do
        before{ expect(Vagrant::Util::Platform).to receive(:wsl?).and_return(true) }

        it "should check PATH with .exe extension" do
          expect(Vagrant::Util::Which).to receive(:which).with("powershell.exe")
          described_class.executable
        end

        it "should return powershell.exe when found" do
          expect(Vagrant::Util::Which).to receive(:which).with("powershell.exe").and_return(true)
          expect(described_class.executable).to eq("powershell.exe")
        end

        it "should return nil when not found" do
          expect(Vagrant::Util::Which).to receive(:which).with("powershell.exe").and_return(nil)
          expect(described_class.executable).to be_nil
        end
      end
    end
  end

  describe ".available?" do
    context "when powershell executable is available" do
      before{ expect(described_class).to receive(:executable).and_return("powershell") }

      it "should be true" do
        expect(described_class.available?).to be(true)
      end
    end

    context "when powershell executable is not available" do
      before{ expect(described_class).to receive(:executable).and_return(nil) }

      it "should be false" do
        expect(described_class.available?).to be(false)
      end
    end
  end

  describe ".execute" do
    before do
      allow(described_class).to receive(:validate_install!)
      allow(Vagrant::Util::Subprocess).to receive(:execute)
    end
<commit_msg>Clean up powershell tests and add test for full path check<commit_after>require File.expand_path("../../../base", __FILE__)

require 'vagrant/util/powershell'

describe Vagrant::Util::PowerShell do
  include_context "unit"

  after{ described_class.reset! }

  describe ".version" do
    before do
      allow(described_class).to receive(:executable)
        .and_return("powershell")
      allow(Vagrant::Util::Subprocess).to receive(:execute)
    end

    after do
      described_class.version
    end

    it "should execute powershell command" do
      expect(Vagrant::Util::Subprocess).to receive(:execute).with("powershell", any_args)
    end

    it "should use the default timeout" do
      expect(Vagrant::Util::Subprocess).to receive(:execute).with(any_args, hash_including(
        timeout: Vagrant::Util::PowerShell::DEFAULT_VERSION_DETECTION_TIMEOUT))
    end

    it "should use environment variable provided timeout" do
      with_temp_env("VAGRANT_POWERSHELL_VERSION_DETECTION_TIMEOUT" => "1") do
        expect(Vagrant::Util::Subprocess).to receive(:execute).with(any_args, hash_including(
          timeout: 1))
        described_class.version
      end
    end

    it "should use default timeout when environment variable value is invalid" do
      with_temp_env("VAGRANT_POWERSHELL_VERSION_DETECTION_TIMEOUT" => "invalid value") do
        expect(Vagrant::Util::Subprocess).to receive(:execute).with(any_args, hash_including(
          timeout: Vagrant::Util::PowerShell::DEFAULT_VERSION_DETECTION_TIMEOUT))
        described_class.version
      end
    end
  end

  describe ".executable" do
    before{ allow(Vagrant::Util::Platform).to receive(:wsl?).and_return(false) }

    context "when found in PATH" do
      before{ expect(Vagrant::Util::Which).to receive(:which).with("powershell").and_return(true) }

      it "should return powershell string" do
        expect(described_class.executable).to eq("powershell")
      end
    end

    context "when not found in PATH" do
      before{ expect(Vagrant::Util::Which).to receive(:which).with("powershell").and_return(nil) }

      it "should return nil" do
        expect(described_class.executable).to be_nil
      end

      context "when within WSL" do
        before do
          allow(Vagrant::Util::Which).to receive(:which).with(/powershell/).and_return(nil)
          expect(Vagrant::Util::Platform).to receive(:wsl?).and_return(true)
        end

        it "should check PATH with .exe extension" do
          expect(Vagrant::Util::Which).to receive(:which).with("powershell.exe")
          described_class.executable
        end

        it "should return powershell.exe when found" do
          expect(Vagrant::Util::Which).to receive(:which).with("powershell.exe").and_return(true)
          expect(described_class.executable).to eq("powershell.exe")
        end

        it "should return nil when not found" do
          expect(described_class.executable).to be_nil
        end

        it "should check for powershell with full path" do
          expect(Vagrant::Util::Which).to receive(:which).with(/Windows\/System32.+powershell.exe/)
          described_class.executable
        end
      end
    end
  end

  describe ".available?" do
    context "when powershell executable is available" do
      before{ expect(described_class).to receive(:executable).and_return("powershell") }

      it "should be true" do
        expect(described_class.available?).to be(true)
      end
    end

    context "when powershell executable is not available" do
      before{ expect(described_class).to receive(:executable).and_return(nil) }

      it "should be false" do
        expect(described_class.available?).to be(false)
      end
    end
  end

  describe ".execute" do
    before do
      allow(described_class).to receive(:validate_install!)
      allow(Vagrant::Util::Subprocess).to receive(:execute)
    end

{'fraction_non_alphanumeric': 0.11018186645426789, 'fraction_numerical': 0.0007964954201513341, 'mean_word_length': 3.354913294797688, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 7, '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': '7308618', 'n_tokens_mistral': 2267, 'n_tokens_neox': 2152, 'n_words': 501}