#!/usr/bin/env bash
set -euo pipefail
# https://github.com/jdx/mise/discussions/6391

cat <<EOF >mise.toml
[tasks.fails]
run = '''
sleep 1;
echo "An error occurred!"
exit 1;
'''

[tasks.deponfails]
depends = ["fails"]
run = 'echo "This will not run because the dependency fails."'

[tasks.grouped]
run = [
    { task = "deponfails" }
]
EOF

# Test that task failure with dependencies does not hang
timeout 5s mise run grouped 2>&1 && exit_code=0 || exit_code=$?

# Check if it was a timeout (exit code 124)
if [ "$exit_code" -eq 124 ]; then
	echo "FAIL: Task hung after dependency failure (timeout reached)"
	exit 1
fi

# The command should fail with exit code 1
if [ "$exit_code" -ne 1 ]; then
	echo "Expected exit code 1, got $exit_code"
	exit 1
fi

echo "Test passed: task with failing dependency did not hang"
