diff --git a/lib/cmd_deploy.sh b/lib/cmd_deploy.sh index 7b297d4..8ced835 100644 --- a/lib/cmd_deploy.sh +++ b/lib/cmd_deploy.sh @@ -563,12 +563,20 @@ cmd_status() { local env_file="$CMD_ENV_FILE" local env_name="$CMD_ENV_NAME" local services="$CMD_SERVICES" - validate_env_file "$env_file" + local json_flag="$CMD_JSON" # Prefer remote execution for stacks that map to a VPS host, so status # reflects the real remote containers instead of the (empty) local daemon. + # Check this before validating the env file: a topology-only stack + # (VPS_HOST/host layer supplied entirely via strut.conf [stacks]/[hosts], + # no base per-env file on disk) is a valid config for this read-only + # command and shouldn't hard-fail before we even know we're dispatching + # remote. if should_dispatch_remote; then local remote_args="status" + if [ -n "$json_flag" ]; then + remote_args="$remote_args --json" + fi if [ -n "$services" ]; then remote_args="$remote_args --services $services" fi @@ -576,6 +584,10 @@ cmd_status() { return $? fi + # Local path: we're not dispatching remote, so an explicitly-requested but + # missing env file (e.g. a typo'd --env) must still fail loudly here. + validate_env_file "$env_file" + # Local path: query the local Docker daemon and show where we're looking. # Blue-green stacks run under a -- project — target # the active color, not the plain - project (strut#384). diff --git a/tests/test_cmd_status_remote.bats b/tests/test_cmd_status_remote.bats index 3defece..c3a2505 100644 --- a/tests/test_cmd_status_remote.bats +++ b/tests/test_cmd_status_remote.bats @@ -191,8 +191,33 @@ EOF [[ "$output" == *"full"* ]] } -@test "cmd_status: fails gracefully when env file missing" { +@test "cmd_status: --json flag forwarded to remote" { + export VPS_HOST="vps.example.com" + export CMD_JSON="--json" + + run cmd_status + [ "$status" -eq 0 ] + [[ "$output" == *"--json"* ]] +} + +# strut#501: a topology-only stack (VPS_HOST supplied entirely via +# strut.conf [stacks]/[hosts], no base per-env file on disk) is a valid, +# read-only-command-friendly config — matches cmd_health's tolerance below. +# Previously cmd_status hard-failed here instead of dispatching remote. +@test "cmd_status: dispatches via SSH when env file is missing but VPS_HOST is set" { export CMD_ENV_FILE="$TEST_TMP/nonexistent.env" + export VPS_HOST="vps.example.com" + + run cmd_status + [ "$status" -eq 0 ] + [[ "$output" == *"ssh"* ]] + [[ "$output" == *"status"* ]] +} + +@test "cmd_status: fails gracefully when env file is missing and VPS_HOST is empty" { + export CMD_ENV_FILE="$TEST_TMP/nonexistent.env" + export VPS_HOST="" + run cmd_status [[ "$output" == *"not found"* ]] || [ "$status" -ne 0 ] }