<commit_before>Describe 'native commands lifecycle' -tags 'Feature' {

    BeforeAll {
        $powershell = Join-Path -Path $PsHome -ChildPath "powershell"
    }

    It "native | ps | native doesn't block" {
        $iss = [initialsessionstate]::CreateDefault2();
        $rs = [runspacefactory]::CreateRunspace($iss)
        $rs.Open()

        $ps = [powershell]::Create()
        $ps.Runspace = $rs

        $ps.AddScript("& $powershell -noprofile -command '100;
            Start-Sleep -Seconds 100' |
            %{ if (`$_ -eq 100) { 'foo'; exit; }}").BeginInvoke()

        # waiting 30 seconds, because powershell startup time could be long on the slow machines,
        # such as CI
        Wait-UntilTrue { $rs.RunspaceAvailability -eq 'Available' } -timeout 30000 -interval 100 | Should Be $true

        $ps.Stop()
        $rs.ResetRunspaceState()
    }
}

Describe "Native Command Processor" -tags "Feature" {

    # If powershell receives a StopProcessing, it should kill the native process and all child processes<commit_msg>Add a test for chaining more than 2 native commands in pipeline (#4012)<commit_after>Describe 'native commands with pipeline' -tags 'Feature' {

    BeforeAll {
        $powershell = Join-Path -Path $PsHome -ChildPath "powershell"
    }

    It "native | ps | native doesn't block" {
        $iss = [initialsessionstate]::CreateDefault2();
        $rs = [runspacefactory]::CreateRunspace($iss)
        $rs.Open()

        $ps = [powershell]::Create()
        $ps.Runspace = $rs

        $ps.AddScript("& $powershell -noprofile -command '100;
            Start-Sleep -Seconds 100' |
            %{ if (`$_ -eq 100) { 'foo'; exit; }}").BeginInvoke()

        # waiting 30 seconds, because powershell startup time could be long on the slow machines,
        # such as CI
        Wait-UntilTrue { $rs.RunspaceAvailability -eq 'Available' } -timeout 30000 -interval 100 | Should Be $true

        $ps.Stop()
        $rs.ResetRunspaceState()
    }

    It "native | native | native should work fine" {

        if ($IsWindows) {
            $result = @(ping.exe | findstr.exe count | findstr.exe ping)
            $result[0] | Should Match "Usage: ping"
        } else {
            $result = @(ps aux | grep powershell | grep -v grep)
            $result[0] | Should Match "powershell"
        }
    }
}

Describe "Native Command Processor" -tags "Feature" {

    # If powershell receives a StopProcessing, it should kill the native process and all child processes
{'fraction_non_alphanumeric': 0.11955217912834866, 'fraction_numerical': 0.01879248300679728, 'mean_word_length': 2.4798331015299024, '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': '5015972', 'n_tokens_mistral': 790, 'n_tokens_neox': 711, 'n_words': 231}