fix: reject negative process counts when scaling

A process count below zero was accepted and stored verbatim, leaving the scheduler to reject the value long after the command reported success. Counts below zero are now rejected, as are process tuples that omit a process type, across `ps:scale`, the `ps-set-scale` trigger and the `formation` key of `app.json`. A negative count persisted by an earlier version stays readable so it can be corrected with `ps:scale`.
This commit is contained in:
Jose Diaz-Gonzalez committed 2026-09-18 02:50:34 -04:00
1 parent 4fc19fe1bc
commit ffa2991abf
8 files changed
+292 -3

No files matched your search

+33
View File
@@ -58,6 +58,23 @@ teardown() {
assert_output_contains "cron: 1" 1
}
@test "(app-json) negative formation quantity" {
mkdir -p /var/lib/dokku/data/app-json/$TEST_APP
negative_formation_callback "$TEST_APP" /var/lib/dokku/data/app-json/$TEST_APP
run_plugn_trigger post-release-builder herokuish $TEST_APP dokku/$TEST_APP:latest
echo "output: $output"
echo "status: $status"
assert_failure
assert_output_contains "Invalid quantity for process type web in app.json: value must be zero or greater"
run /bin/bash -c "dokku --quiet ps:scale $TEST_APP"
output=$(echo "$output" | tr -s " ")
echo "output: ($output)"
echo "status: $status"
assert_output "web: 1"
}
persist_scale_callback_a() {
local APP="$1"
local APP_REPO_DIR="$2"
@@ -81,3 +98,19 @@ persist_scale_callback_b() {
echo "cron: python3 worker.py" >>"$APP_REPO_DIR/Procfile"
mv "$APP_REPO_DIR/app-5205b.json" "$APP_REPO_DIR/app.json"
}
negative_formation_callback() {
local APP="$1"
local APP_REPO_DIR="$2"
[[ -z "$APP" ]] && local APP="$TEST_APP"
cat >"$APP_REPO_DIR/app.json" <<EOF
{
"formation": {
"web": {
"quantity": -1
}
}
}
EOF
}
+71
View File
@@ -357,6 +357,77 @@ worker=1" >/var/lib/dokku/config/ps/$TEST_APP/scale
assert_output_contains "The --clear and --replace flags cannot be specified together"
}
@test "(ps:scale) invalid process counts" {
run /bin/bash -c "dokku ps:scale $TEST_APP web=-1"
echo "output: $output"
echo "status: $status"
assert_failure
assert_output_contains "Invalid count for process type web: value must be zero or greater"
run /bin/bash -c "dokku ps:scale --replace $TEST_APP web=1 worker=-2"
echo "output: $output"
echo "status: $status"
assert_failure
assert_output_contains "Invalid count for process type worker: value must be zero or greater"
run /bin/bash -c "dokku ps:scale $TEST_APP =1"
echo "output: $output"
echo "status: $status"
assert_failure
assert_output_contains "Missing process type for count 1"
run_plugn_trigger ps-set-scale $TEST_APP true false web=-1
echo "output: $output"
echo "status: $status"
assert_failure
assert_output_contains "Invalid count for process type web: value must be zero or greater"
run /bin/bash -c "dokku --quiet ps:scale $TEST_APP"
output=$(echo "$output" | tr -s " ")
echo "output: ($output)"
echo "status: $status"
assert_output "web: 1"
run /bin/bash -c "dokku ps:scale --skip-deploy $TEST_APP web=0"
echo "output: $output"
echo "status: $status"
assert_success
run /bin/bash -c "dokku --quiet ps:scale $TEST_APP"
output=$(echo "$output" | tr -s " ")
echo "output: ($output)"
echo "status: $status"
assert_output "web: 0"
}
@test "(ps:scale) repairing a negative process count" {
echo "web=-1
worker=2" >/var/lib/dokku/config/ps/$TEST_APP/scale
run /bin/bash -c "dokku --quiet ps:scale $TEST_APP"
output=$(echo "$output" | tr -s " ")
echo "output: ($output)"
echo "status: $status"
assert_success
assert_output $'web: -1\nworker: 2'
run_plugn_trigger ps-current-scale $TEST_APP
echo "output: $output"
echo "status: $status"
assert_success
run /bin/bash -c "dokku ps:scale --skip-deploy $TEST_APP web=1"
echo "output: $output"
echo "status: $status"
assert_success
run /bin/bash -c "dokku --quiet ps:scale $TEST_APP"
output=$(echo "$output" | tr -s " ")
echo "output: ($output)"
echo "status: $status"
assert_output $'web: 1\nworker: 2'
}
@test "(ps) handle windows newlines in procfile" {
run deploy_app python dokku@$DOKKU_DOMAIN:$TEST_APP procfile_line_endings_to_windows
echo "output: $output"