<commit_before># typed: false
# frozen_string_literal: true

require "utils/analytics"
require "formula_installer"

describe Utils::Analytics do
  describe "::os_arch_prefix_ci" do
    context "when os_arch_prefix_ci is not set" do
      before do
        described_class.clear_os_arch_prefix_ci
      end

      it "returns OS_VERSION and prefix when HOMEBREW_PREFIX is a custom prefix" do
        allow(Hardware::CPU).to receive(:type).and_return(:intel)
        allow(Homebrew).to receive(:default_prefix?).and_return(false)
        arch = ", #{described_class.arch_label}" if described_class.arch_label.present?
        expected = "#{OS_VERSION}#{arch}, #{described_class.custom_prefix_label}"
        expect(described_class.os_arch_prefix_ci).to include(expected)
      end

      it "does not include prefix when HOMEBREW_PREFIX is the default prefix" do
        allow(Homebrew).to receive(:default_prefix?).and_return(true)
        expect(described_class.os_arch_prefix_ci).not_to include(described_class.custom_prefix_label)
      end

      it "includes CI when ENV['CI'] is set" do
        ENV["CI"] = "true"
        expect(described_class.os_arch_prefix_ci).to include("CI")
      end
    end
  end

  describe "::report_event" do
    let(:f) { formula { url "foo-1.0" } }
    let(:options) { FormulaInstaller.new(f).display_options(f) }
    let(:action)  { "#{f.full_name} #{options}".strip }

    context "when ENV vars is set" do
      it "returns nil when HOMEBREW_NO_ANALYTICS is true" do
        ENV["HOMEBREW_NO_ANALYTICS"] = "true"
        expect(described_class.report_event("install", action)).to be_nil
      end

      it "returns nil when HOMEBREW_NO_ANALYTICS_THIS_RUN is true" do
        ENV["HOMEBREW_NO_ANALYTICS_THIS_RUN"] = "true"
        expect(described_class.report_event("install", action)).to be_nil
      end
<commit_msg>Control for CPU type and Rosetta in `os_arch_prefix_ci` tests<commit_after># typed: false
# frozen_string_literal: true

require "utils/analytics"
require "formula_installer"

describe Utils::Analytics do
  describe "::os_arch_prefix_ci" do
    context "when os_arch_prefix_ci is not set" do
      before do
        described_class.clear_os_arch_prefix_ci
      end

      it "returns OS_VERSION and prefix when HOMEBREW_PREFIX is a custom prefix on intel" do
        allow(Hardware::CPU).to receive(:type).and_return(:intel)
        allow(Hardware::CPU).to receive(:in_rosetta2?).and_return(false)
        allow(Homebrew).to receive(:default_prefix?).and_return(false)
        expected = "#{OS_VERSION}, #{described_class.custom_prefix_label}"
        expect(described_class.os_arch_prefix_ci).to eq expected
      end

      it 'returns OS_VERSION, "ARM" and prefix when HOMEBREW_PREFIX is a custom prefix on arm' do
        allow(Hardware::CPU).to receive(:type).and_return(:arm)
        allow(Hardware::CPU).to receive(:in_rosetta2?).and_return(false)
        allow(Homebrew).to receive(:default_prefix?).and_return(false)
        expected = "#{OS_VERSION}, ARM, #{described_class.custom_prefix_label}"
        expect(described_class.os_arch_prefix_ci).to eq expected
      end

      it 'returns OS_VERSION, "Rosetta" and prefix when HOMEBREW_PREFIX is a custom prefix using Rosetta' do
        allow(Hardware::CPU).to receive(:type).and_return(:intel)
        allow(Hardware::CPU).to receive(:in_rosetta2?).and_return(true)
        allow(Homebrew).to receive(:default_prefix?).and_return(false)
        expected = "#{OS_VERSION}, Rosetta, #{described_class.custom_prefix_label}"
        expect(described_class.os_arch_prefix_ci).to eq expected
      end

      it "does not include prefix when HOMEBREW_PREFIX is the default prefix" do
        allow(Homebrew).to receive(:default_prefix?).and_return(true)
        expect(described_class.os_arch_prefix_ci).not_to include(described_class.custom_prefix_label)
      end

      it "includes CI when ENV['CI'] is set" do
        ENV["CI"] = "true"
        expect(described_class.os_arch_prefix_ci).to include("CI")
      end
    end
  end

  describe "::report_event" do
    let(:f) { formula { url "foo-1.0" } }
    let(:options) { FormulaInstaller.new(f).display_options(f) }
    let(:action)  { "#{f.full_name} #{options}".strip }

    context "when ENV vars is set" do
      it "returns nil when HOMEBREW_NO_ANALYTICS is true" do
        ENV["HOMEBREW_NO_ANALYTICS"] = "true"
        expect(described_class.report_event("install", action)).to be_nil
      end

      it "returns nil when HOMEBREW_NO_ANALYTICS_THIS_RUN is true" do
        ENV["HOMEBREW_NO_ANALYTICS_THIS_RUN"] = "true"
        expect(described_class.report_event("install", action)).to be_nil
      end

{'fraction_non_alphanumeric': 0.10634208840486867, 'fraction_numerical': 0.0014947683109118087, 'mean_word_length': 3.745694022289767, 'pattern_counts': {'":': 4, '<': 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': '6072322', 'n_tokens_mistral': 1555, 'n_tokens_neox': 1464, 'n_words': 329}