#!/usr/bin/env bash set -euo pipefail SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)" source "$SCRIPT_DIR/../harness/helpers.sh" source "$SCRIPT_DIR/../harness/mock-nas.sh" require_root setup_test_env trap teardown_test_env EXIT # Start the mock NAS so rclone can connect via SFTP start_mock_nas # Generate a default config pointing at the mock NAS gen_config # Start warpgate and wait for full startup start_warpgate wait_for_log_line "Supervision active" 60 # Send SIGINT (Ctrl-C equivalent) to trigger orderly shutdown kill -INT "$WARPGATE_PID" # Wait for the process to exit wait_for_exit "$WARPGATE_PID" 30 # Verify exit code 0 (graceful shutdown) wait "$WARPGATE_PID" 2>/dev/null code=$? if [[ "$code" -ne 0 ]]; then echo "FAIL: expected exit code 0, got $code" >&2 exit 1 fi # Verify shutdown log messages appeared in correct order assert_log_contains "Signal received, shutting down" assert_log_order "Signal received, shutting down" "Write-back queue drained" # Verify the FUSE mount was removed assert_not_mounted # Verify no orphan rclone processes remain assert_no_orphan_rclone echo "PASS: $(basename "$0" .sh)"