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

@ -239,17 +239,30 @@ def start_script(name: str, params: Optional[dict] = None) -> dict:
script_config = AVAILABLE_SCRIPTS[name]
service = script_config["service_name"]
parameters = script_config.get("parameters", [])
# Write parameters to env file if script has one configured
# A misspelled parameter would otherwise be dropped, and the script run with its default.
unknown = sorted(set(params or {}) - {i["name"] for i in parameters})
if unknown:
return {
"success": False,
"error": f"Unknown parameters for script '{name}': {', '.join(unknown)}",
}
# Always write the env file: the service cannot start without it, and a file left by an interrupted run must
# not choose the parameters.
env_file = script_config.get("env_file")
if env_file and params:
if env_file:
values = {key: value for key, value in (params or {}).items() if value}
for parameter in parameters:
if parameter["type"] == "branch" and not values.get(parameter["name"]):
# upgrade.sh upgrades the current branch when it is not given one.
values[parameter["name"]] = get_current_branch() or "release"
try:
with open(env_file, "w") as f:
for key, value in params.items():
if value: # Only write non-empty values
# Convert param name to uppercase for env var
env_name = key.upper()
f.write(f"{env_name}={value}\n")
for key, value in values.items():
# Convert param name to uppercase for env var
f.write(f"{key.upper()}={value}\n")
except OSError as e:
return {
"success": False,