Starting a Controller script writes its env file every time and rejects unknown parameters

The upgrade service reads BRANCH from /tmp/wrolpi-upgrade.env, which upgrade.sh removes when it finishes.  The
Controller wrote that file only when a request had parameters, so starting an upgrade without a branch (the simple UI
sends no body when the field is empty) left the service unable to start, while the API answered success.  A request
like {"branch": "master"} was accepted with the key ignored, the same way.

Now the env file is always written, and a missing branch is the current one, as upgrade.sh chooses; a file left by an
interrupted run no longer chooses it.  Unknown parameters and unknown request keys are errors.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Roland 2026-10-25 20:11:19 -06:00
parent eb82489426
commit 3e54731534
No known key found for this signature in database
GPG key ID: 1BA620CE6C9A4680
4 changed files with 74 additions and 8 deletions

View file

@ -101,6 +101,16 @@ class TestScriptsStartEndpoint:
assert response.status_code == 400
assert "already running" in response.json()["detail"].lower()
def test_scripts_start_rejects_unknown_body_keys(self, test_client):
"""Parameters go in `params`; a body like {"branch": ...} is an error, not an upgrade of some other
branch."""
with mock.patch("controller.lib.scripts.is_docker_mode", return_value=False), \
mock.patch("controller.lib.scripts.get_script_status", return_value={"running": False}), \
mock.patch("subprocess.Popen") as popen:
response = test_client.post("/api/scripts/upgrade/start", json={"branch": "master"})
assert response.status_code == 422
popen.assert_not_called()
class TestScriptsOutputEndpoint:
"""Tests for /api/scripts/{name}/output endpoint."""