<commit_before>require 'fileutils'
require 'open3'
require 'pathname'
require 'json'
require 'cmd_common'

RSpec.describe 'murano status', :cmd, :needs_password do
  include_context "CI_CMD"

  before(:example) do
    @project_name = rname('statusTest')
    out, err, status = Open3.capture3(capcmd('murano', 'project', 'create', @project_name, '--save'))
    expect(err).to eq('')
    expect(out.chomp).to match(/^[a-zA-Z0-9]+$/)
    expect(status.exitstatus).to eq(0)
  end
  after(:example) do
    out, err, status = Open3.capture3(capcmd('murano', 'project', 'delete', @project_name))
    expect(out).to eq('')
    expect(err).to eq('')
    expect(status.exitstatus).to eq(0)
  end

  context "without ProjectFile" do
    before(:example) do
      FileUtils.cp_r(File.join(@testdir, 'spec/fixtures/syncable_content/.'), '.')
      FileUtils.move('assets','files')
      FileUtils.mkpath('specs')
      FileUtils.copy(File.join(@testdir, 'spec/fixtures/product_spec_files/lightbulb.yaml'), 'specs/resources.yaml')
    end

    it "status" do
      out, err, status = Open3.capture3(capcmd('murano', 'status'))
      expect(err).to eq('')
      # Two problems with this output.
      # 1: Order of files is not set
      # 2: Path prefixes could be different.
      olines = out.lines
      expect(olines[0]).to eq("Adding:\n")
      expect(olines[1..8]).to contain_exactly(
        a_string_matching(/ \+ A  .*routes\/manyRoutes\.lua/),
        a_string_matching(/ \+ A  .*routes\/manyRoutes\.lua:4/),
        a_string_matching(/ \+ A  .*routes\/manyRoutes\.lua:7/),
        a_string_matching(/ \+ A  .*routes\/singleRoute\.lua/),
        a_string_matching(/ \+ S  .*files\/icon\.png/),
        a_string_matching(/ \+ S  .*files\/index\.html/),
        a_string_matching(/ \+ S  .*files\/js\/script\.js/),
        a_string_matching(/ \+ M  .*modules\/table_util\.lua/),
      )
      expect(olines[9]).to eq("Deleteing:\n")
      expect(olines[10..12]).to contain_exactly(
        " - E  gateway_disconnect\n",
        " - E  gateway_connect\n",
        " - E  user_account\n",
      )
      expect(olines[13]).to eq("Changing:\n")
      expect(olines[14..15]).to contain_exactly(
        a_string_matching(/ M E  .*services\/devdata\.lua/),
        a_string_matching(/ M E  .*services\/timers\.lua/),
      )
      expect(status.exitstatus).to eq(0)
    end

    it "matches file path", :broken_on_windows do
      out, err, status = Open3.capture3(capcmd('murano', 'status', '**/icon.png'))
      expect(err).to eq('')
      expect(out.lines).to match([
        "Adding:\n",
        a_string_matching(/ \+ S  .*files\/icon\.png/),
        "Deleteing:\n",
        "Changing:\n",
      ])
      expect(status.exitstatus).to eq(0)
    end

    it "matches route", :broken_on_windows do
      out, err, status = Open3.capture3(capcmd('murano', 'status', '#put#'))
      expect(err).to eq('')
      expect(out.lines).to match([
        "Adding:\n",
        a_string_matching(/ \+ A  .*routes\/manyRoutes\.lua:4/),
        "Deleteing:\n",
        "Changing:\n",
      ])
      expect(status.exitstatus).to eq(0)
    end
  end

  context "with ProjectFile" do
    before(:example) do
      FileUtils.cp_r(File.join(@testdir, 'spec/fixtures/syncable_content/.'), '.')
      FileUtils.move('assets','files')
      FileUtils.mkpath('specs')
      FileUtils.copy(File.join(@testdir, 'spec/fixtures/product_spec_files/lightbulb.yaml'), 'specs/resources.yaml')
      FileUtils.copy(File.join(@testdir, 'spec/fixtures/ProjectFiles/only_meta.yaml'), 'test.murano')
    end

    it "status" do
      out, err, status = Open3.capture3(capcmd('murano', 'status'))
      expect(err).to eq('')<commit_msg>status of services is being inconsistent, so skipping for now.<commit_after>require 'fileutils'
require 'open3'
require 'pathname'
require 'json'
require 'cmd_common'

RSpec.describe 'murano status', :cmd, :needs_password do
  include_context "CI_CMD"

  before(:example) do
    @project_name = rname('statusTest')
    out, err, status = Open3.capture3(capcmd('murano', 'project', 'create', @project_name, '--save'))
    expect(err).to eq('')
    expect(out.chomp).to match(/^[a-zA-Z0-9]+$/)
    expect(status.exitstatus).to eq(0)
  end
  after(:example) do
    out, err, status = Open3.capture3(capcmd('murano', 'project', 'delete', @project_name))
    expect(out).to eq('')
    expect(err).to eq('')
    expect(status.exitstatus).to eq(0)
  end

  context "without ProjectFile" do
    before(:example) do
      FileUtils.cp_r(File.join(@testdir, 'spec/fixtures/syncable_content/.'), '.')
      FileUtils.move('assets','files')
      FileUtils.mkpath('specs')
      FileUtils.copy(File.join(@testdir, 'spec/fixtures/product_spec_files/lightbulb.yaml'), 'specs/resources.yaml')
    end

    it "status", :not_in_okami do
      out, err, status = Open3.capture3(capcmd('murano', 'status'))
      expect(err).to eq('')
      # Two problems with this output.
      # 1: Order of files is not set
      # 2: Path prefixes could be different.
      olines = out.lines
      expect(olines[0]).to eq("Adding:\n")
      expect(olines[1..8]).to contain_exactly(
        a_string_matching(/ \+ A  .*routes\/manyRoutes\.lua/),
        a_string_matching(/ \+ A  .*routes\/manyRoutes\.lua:4/),
        a_string_matching(/ \+ A  .*routes\/manyRoutes\.lua:7/),
        a_string_matching(/ \+ A  .*routes\/singleRoute\.lua/),
        a_string_matching(/ \+ S  .*files\/icon\.png/),
        a_string_matching(/ \+ S  .*files\/index\.html/),
        a_string_matching(/ \+ S  .*files\/js\/script\.js/),
        a_string_matching(/ \+ M  .*modules\/table_util\.lua/),
      )
      expect(olines[9]).to eq("Deleteing:\n")
      expect(olines[10..12]).to contain_exactly(
        " - E  gateway_disconnect\n",
        " - E  gateway_connect\n",
        " - E  user_account\n",
      )
      expect(olines[13]).to eq("Changing:\n")
      expect(olines[14..15]).to contain_exactly(
        a_string_matching(/ M E  .*services\/devdata\.lua/),
        a_string_matching(/ M E  .*services\/timers\.lua/),
      )
      expect(status.exitstatus).to eq(0)
    end

    it "matches file path", :broken_on_windows do
      out, err, status = Open3.capture3(capcmd('murano', 'status', '**/icon.png'))
      expect(err).to eq('')
      expect(out.lines).to match([
        "Adding:\n",
        a_string_matching(/ \+ S  .*files\/icon\.png/),
        "Deleteing:\n",
        "Changing:\n",
      ])
      expect(status.exitstatus).to eq(0)
    end

    it "matches route", :broken_on_windows do
      out, err, status = Open3.capture3(capcmd('murano', 'status', '#put#'))
      expect(err).to eq('')
      expect(out.lines).to match([
        "Adding:\n",
        a_string_matching(/ \+ A  .*routes\/manyRoutes\.lua:4/),
        "Deleteing:\n",
        "Changing:\n",
      ])
      expect(status.exitstatus).to eq(0)
    end
  end

  context "with ProjectFile" do
    before(:example) do
      FileUtils.cp_r(File.join(@testdir, 'spec/fixtures/syncable_content/.'), '.')
      FileUtils.move('assets','files')
      FileUtils.mkpath('specs')
      FileUtils.copy(File.join(@testdir, 'spec/fixtures/product_spec_files/lightbulb.yaml'), 'specs/resources.yaml')
      FileUtils.copy(File.join(@testdir, 'spec/fixtures/ProjectFiles/only_meta.yaml'), 'test.murano')
    end

    it "status", :not_in_okami do
      out, err, status = Open3.capture3(capcmd('murano', 'status'))
      expect(err).to eq('')
{'fraction_non_alphanumeric': 0.17803995173615766, 'fraction_numerical': 0.010457165839924922, 'mean_word_length': 2.8003056546102902, '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': '6504159', 'n_tokens_mistral': 2695, 'n_tokens_neox': 2554, 'n_words': 464}