
- console:
    name: Console creation
    console_name: term
    doc: Opening the console
    key: $(test)_PASS
    steps:
        - open:
            protocol: terminal
            terminal_path: $(test_directory)
{% if os == "Linux" %}
        - writeln: echo "endOfOpen"
{% endif %}

- console:
    name: Console read_until with timeout
    console_name: term
    key: $(test)_PASS
    steps:
{% if os == "Linux" %}
        - read_until: {expected: endOfOpen, timeout: 5}
{% else %}
        - read_until: {expected: $(terminal_prompt), timeout: 5}
{% endif %}

- console:
    name: Console write
    console_name: term
    key: $(test)_PASS
    steps:
        - writeln: echo 0

- sleep:
    name: sleep item
    timeout: 1

- console:
    name: Console read_until immediate
    console_name: term
    key: $(test)_PASS
    steps:
{% if os == "Windows" %}
        - read_until: {expected: "echo 0", timeout: 0}
{% endif %}
        - read_until: {expected: "0", timeout: 0}

- console:
    name: Console write
    console_name: term
    key: $(test)_PASS
    steps:
        - writeln: echo "HelloConsole"

- console:
    name: Console read_until fail
    console_name: term
    key: $(test)_FAIL
    steps:
        - read_until: {expected: "Something never prints", timeout: 1}

- console:
    name: Console write
    console_name: term
    key: $(test)_PASS
    steps:
        - writeln: echo "HelloConsole"

- console:
    name: Console read_until no_fail
    console_name: term
    key: $(test)_PASS
    steps:
        - read_until: {expected: Something never prints, timeout: 1, no_fail: true}

- console:
    name: Console read_until muted
    console_name: term
    key: $(test)_PASS
    steps:
        - writeln: echo "HelloConsole"
{% if os == "Windows" %}
        - read_until: {expected: echo "HelloConsole", timeout: 1, mute: true}
{% endif %}
        - read_until: {expected: HelloConsole, timeout: 1, mute: true}

- console:
    name: Console read_until muted
    console_name: term
    key: $(test)_PASS
    steps:
        - writeln: echo "HelloConsole is PASS" && echo "endOfCmd"
{% if os == "Windows" %}
        - read_until: {expected: echo "endOfCmd", timeout: 1}
{% endif %}
        - read_until: {expected: endOfCmd, timeout: 1, process_result: "'Hello' in r'''$(result)''' and 'PASS' in r'''$(result)''' "}

{% if os == "Linux" %}
- console:
    name: Console runs on host (not the Flatpak sandbox)
    doc: Regression guard for the 0.2.1 Flatpak bug (term console spawned inside the sandbox instead of on the host). /.flatpak-info exists only inside the sandbox, so the host-only marker is emitted (and matched by read_until) ONLY when the shell really runs on the host. On a broken Flatpak the marker never appears, read_until times out and the item FAILS. The marker is built at runtime ($M) so it is never present in the command line itself. Passes on every other channel.
    console_name: term
    key: $(test)_PASS
    steps:
        - writeln: 'test -e /.flatpak-info && M=SANDBOX || M=HOST; echo "console_host_check_$M"'
        - read_until: {expected: console_host_check_HOST, timeout: 5}
{% endif %}

# --- read_until matching a list of values (succeeds on any) ---
- console:
    name: Console read_until list match any
    console_name: term
    key: $(test)_PASS
    steps:
        - writeln: echo "list_marker_B"
        - read_until: {expected: [list_marker_A, list_marker_B, list_marker_C], timeout: 5}

- console:
    name: Console read_until list no match
    console_name: term
    key: $(test)_FAIL
    steps:
        - read_until: {expected: [never_marker_A, never_marker_B], timeout: 1}

# --- read_until with regular expressions ---
- console:
    name: Console read_until regex
    console_name: term
    key: $(test)_PASS
    steps:
        - writeln: echo "regex_val_4242_end"
        - read_until: {expected: 'regex_val_\d+_end', regex: true, timeout: 5}

- console:
    name: Console read_until regex list any
    console_name: term
    key: $(test)_PASS
    steps:
        - writeln: echo "STATUS=ready"
        - read_until: {expected: ['ERR:.*', 'STATUS=(ready|busy)'], regex: true, timeout: 5}

- console:
    name: Console read_until regex no match
    console_name: term
    key: $(test)_FAIL
    steps:
        - read_until: {expected: 'never_\d{4}', regex: true, timeout: 1}

- console:
    name: Console closure
    execute_on_stop: true
    console_name: term
    key: $(test)_PASS
    steps:
        - close: term
