Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 13 additions & 1 deletion lib/cmd_deploy.sh
Original file line number Diff line number Diff line change
Expand Up @@ -563,19 +563,31 @@ 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
run_remote_strut "$stack" "$env_name" "$remote_args"
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 <stack>-<env>-<color> project — target
# the active color, not the plain <stack>-<env> project (strut#384).
Expand Down
27 changes: 26 additions & 1 deletion tests/test_cmd_status_remote.bats
Original file line number Diff line number Diff line change
Expand Up @@ -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 ]
}
Expand Down
Loading