#!/usr/bin/env bash
set -euo pipefail

repo_root="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"
cd "$repo_root"

export PATH="/opt/homebrew/bin:/usr/local/bin:$PATH"

for tool in fish nu; do
  if ! command -v "$tool" >/dev/null 2>&1; then
    echo "Missing required shell: $tool" >&2
    exit 1
  fi
done

if [[ ! -x /usr/bin/expect ]]; then
  echo "Missing required executable: /usr/bin/expect" >&2
  exit 1
fi

git ls-files --error-unmatch \
  ZenttyResources/shell-integration/fish/vendor_conf.d/zentty-shell-integration.fish \
  ZenttyResources/shell-integration/nushell/vendor/autoload/zentty.nu \
  >/dev/null

TEST_RUNNER_SWIFT_BACKTRACE=enable=no xcodebuild test \
  -scheme Zentty \
  -destination 'platform=macOS' \
  -only-testing:ZenttyLogicTests/AgentStatusSupportTests/test_fish_shell_integration_enables_wrapper_from_colon_delimited_wrapper_dirs \
  -only-testing:ZenttyLogicTests/AgentStatusSupportTests/test_fish_shell_integration_enables_wrapper_once_when_multiple_real_binaries_exist \
  -only-testing:ZenttyLogicTests/AgentStatusSupportTests/test_fish_shell_integration_exports_active_wrapper_directories_to_child_processes \
  -only-testing:ZenttyLogicTests/AgentStatusSupportTests/test_fish_shell_integration_autoloads_from_xdg_data_dirs_and_reports_typed_command \
  -only-testing:ZenttyLogicTests/AgentStatusSupportTests/test_fish_shell_integration_loads_and_executes_runtime_with_bypass \
  -only-testing:ZenttyLogicTests/AgentStatusSupportTests/test_fish_pane_context_signal_is_parseable_in_non_git_directory \
  -only-testing:ZenttyLogicTests/AgentStatusSupportTests/test_nu_shell_integration_autoloads_from_xdg_data_dirs_in_interactive_repl \
  -only-testing:ZenttyLogicTests/AgentStatusSupportTests/test_nu_shell_integration_does_not_enable_non_executable_wrapper_file \
  -only-testing:ZenttyLogicTests/AgentStatusSupportTests/test_nu_shell_integration_does_not_enable_wrapper_without_executable_real_binary \
  -only-testing:ZenttyLogicTests/AgentStatusSupportTests/test_nu_shell_integration_enables_wrapper_from_colon_delimited_wrapper_dirs \
  -only-testing:ZenttyLogicTests/AgentStatusSupportTests/test_nu_shell_integration_enables_wrapper_when_real_binary_is_symlink_to_executable \
  -only-testing:ZenttyLogicTests/AgentStatusSupportTests/test_nu_shell_integration_does_not_enable_wrapper_when_real_binary_symlink_target_not_executable \
  -only-testing:ZenttyLogicTests/AgentStatusSupportTests/test_nu_shell_integration_loads_when_no_wrappers_enable \
  -only-testing:ZenttyLogicTests/AgentStatusSupportTests/test_nu_shell_integration_loads_without_cant_convert_under_real_zentty_env \
  -only-testing:ZenttyLogicTests/AgentStatusSupportTests/test_nu_shell_integration_preserves_cd_and_reports_directory_change \
  -only-testing:ZenttyLogicTests/AgentStatusSupportTests/test_nu_shell_integration_reports_initial_working_directory_on_first_context \
  -only-testing:ZenttyLogicTests/AgentStatusSupportTests/test_nu_shell_integration_tags_codex_pre_execution_command \
  -only-testing:ZenttyLogicTests/AgentStatusSupportTests/test_nu_shell_integration_enables_wrapper_through_pre_prompt_hook_closure \
  -only-testing:ZenttyLogicTests/AgentStatusSupportTests/test_shell_integration_does_not_enable_amp_wrapper_when_wrapper_executable_is_missing \
  -only-testing:ZenttyLogicTests/ShellIntegrationSSHModernTests/test_fish_shell_integration_defines_ssh_wrapper_only_with_ssh_feature \
  -only-testing:ZenttyLogicTests/ShellIntegrationSSHModernTests/test_fish_shell_integration_ssh_cache_matches_whole_lines_only \
  -only-testing:ZenttyLogicTests/ShellIntegrationSSHModernTests/test_fish_shell_integration_ssh_env_forwards_term_and_environment \
  -only-testing:ZenttyLogicTests/ShellIntegrationSSHModernTests/test_fish_shell_integration_ssh_session_output_is_capturable \
  -only-testing:ZenttyLogicTests/ShellIntegrationSSHModernTests/test_fish_shell_integration_ssh_streams_piped_stdin \
  -only-testing:ZenttyLogicTests/ShellIntegrationSSHModernTests/test_fish_shell_integration_ssh_terminfo_alone_does_not_set_colorterm \
  -only-testing:ZenttyLogicTests/ShellIntegrationSSHModernTests/test_fish_shell_integration_ssh_terminfo_caches_permanent_failure \
  -only-testing:ZenttyLogicTests/ShellIntegrationSSHModernTests/test_fish_shell_integration_ssh_terminfo_does_not_cache_transient_failure \
  -only-testing:ZenttyLogicTests/ShellIntegrationSSHModernTests/test_fish_shell_integration_ssh_terminfo_falls_back_to_short_socket_directory \
  -only-testing:ZenttyLogicTests/ShellIntegrationSSHModernTests/test_fish_shell_integration_ssh_terminfo_falls_back_when_install_fails \
  -only-testing:ZenttyLogicTests/ShellIntegrationSSHModernTests/test_fish_shell_integration_ssh_terminfo_installs_and_caches_on_miss \
  -only-testing:ZenttyLogicTests/ShellIntegrationSSHModernTests/test_fish_shell_integration_ssh_terminfo_leaves_user_multiplexing_alone \
  -only-testing:ZenttyLogicTests/ShellIntegrationSSHModernTests/test_fish_shell_integration_ssh_terminfo_never_runs_user_remote_command_twice \
  -only-testing:ZenttyLogicTests/ShellIntegrationSSHModernTests/test_fish_shell_integration_ssh_terminfo_skips_install_for_non_default_session \
  -only-testing:ZenttyLogicTests/ShellIntegrationSSHModernTests/test_fish_shell_integration_ssh_terminfo_teardown_does_not_replay_user_arguments \
  -only-testing:ZenttyLogicTests/ShellIntegrationSSHModernTests/test_fish_shell_integration_ssh_terminfo_tears_down_control_master \
  -only-testing:ZenttyLogicTests/ShellIntegrationSSHModernTests/test_fish_shell_integration_ssh_terminfo_uses_cached_host \
  -only-testing:ZenttyLogicTests/ShellIntegrationSSHModernTests/test_fish_shell_integration_ssh_wrapper_survives_terminfo_only_features \
  -only-testing:ZenttyLogicTests/ShellIntegrationSSHModernTests/test_nu_shell_integration_ssh_cache_matches_whole_lines_only \
  -only-testing:ZenttyLogicTests/ShellIntegrationSSHModernTests/test_nu_shell_integration_ssh_env_forwards_term_and_environment \
  -only-testing:ZenttyLogicTests/ShellIntegrationSSHModernTests/test_nu_shell_integration_ssh_forwards_piped_stdin_with_ssh_features \
  -only-testing:ZenttyLogicTests/ShellIntegrationSSHModernTests/test_nu_shell_integration_ssh_forwards_piped_stdin_without_ssh_features \
  -only-testing:ZenttyLogicTests/ShellIntegrationSSHModernTests/test_nu_shell_integration_ssh_session_output_is_capturable \
  -only-testing:ZenttyLogicTests/ShellIntegrationSSHModernTests/test_nu_shell_integration_ssh_terminfo_alone_does_not_set_colorterm \
  -only-testing:ZenttyLogicTests/ShellIntegrationSSHModernTests/test_nu_shell_integration_ssh_terminfo_caches_permanent_failure \
  -only-testing:ZenttyLogicTests/ShellIntegrationSSHModernTests/test_nu_shell_integration_ssh_terminfo_does_not_cache_transient_failure \
  -only-testing:ZenttyLogicTests/ShellIntegrationSSHModernTests/test_nu_shell_integration_ssh_terminfo_falls_back_when_install_fails \
  -only-testing:ZenttyLogicTests/ShellIntegrationSSHModernTests/test_nu_shell_integration_ssh_terminfo_installs_and_caches_on_miss \
  -only-testing:ZenttyLogicTests/ShellIntegrationSSHModernTests/test_nu_shell_integration_ssh_terminfo_leaves_user_multiplexing_alone \
  -only-testing:ZenttyLogicTests/ShellIntegrationSSHModernTests/test_nu_shell_integration_ssh_terminfo_never_opens_control_master \
  -only-testing:ZenttyLogicTests/ShellIntegrationSSHModernTests/test_nu_shell_integration_ssh_terminfo_never_runs_user_remote_command_twice \
  -only-testing:ZenttyLogicTests/ShellIntegrationSSHModernTests/test_nu_shell_integration_ssh_terminfo_skips_install_for_non_default_session \
  -only-testing:ZenttyLogicTests/ShellIntegrationSSHModernTests/test_nu_shell_integration_ssh_terminfo_uses_cached_host \
  -only-testing:ZenttyLogicTests/ShellIntegrationSSHModernTests/test_nu_shell_integration_ssh_wrapper_passes_through_without_ssh_feature \
  -only-testing:ZenttyLogicTests/ShellIntegrationSSHModernTests/test_nu_shell_integration_ssh_wrapper_survives_terminfo_only_features
