#!/usr/bin/env bash

# Test that raw tasks get interleave output even when task.output=prefix is set
# This ensures raw=true takes priority over task.output setting

cat <<EOF >mise.toml
[settings]
task.output = "prefix"

[tasks.normal]
run = 'echo normal task'

[tasks.raw_task]
raw = true
run = 'echo raw task output'

[tasks.interactive_task]
interactive = true
run = 'echo interactive task output'
EOF

# Normal task should use prefix output (from settings)
assert_contains "mise run normal" "[normal] normal task"

# Raw task should get interleave output mode, meaning stdout goes directly
# without the [task_name] prefix being applied to the actual output
assert "mise run raw_task" "raw task output"

# Verify stdout doesn't have the prefix (only check stdout, not stderr)
stdout_output=$(mise run raw_task 2>/dev/null)
if [[ $stdout_output == *"[raw_task]"* ]]; then
  echo "FAIL: raw task stdout should not have prefix"
  exit 1
fi
echo "SUCCESS: raw task stdout has no prefix"

# CLI and environment output overrides must not disable the inherited stdio
# required by raw and interactive tasks. They should resolve the same way as
# the equivalent task.output setting, including during a dry run.
for task in raw_task interactive_task; do
  assert_contains "mise run --output keep-order $task 2>&1" '$ echo'
  assert_not_contains "mise run --output keep-order $task 2>&1" "Finished in"
  assert_contains "MISE_TASK_OUTPUT=keep-order mise run $task 2>&1" '$ echo'
  assert_not_contains "MISE_TASK_OUTPUT=keep-order mise run $task 2>&1" "Finished in"
  assert_contains "mise run --output keep-order --dry-run $task 2>&1" '$ echo'
  assert_not_contains "mise run --output keep-order --dry-run $task 2>&1" "Finished in"
done
