Fix the deploy step replay for a Python port
Your task
An AI agent rewrote your Bash deploy script in Python. Bash with set -e stops at the first failing command, while Python's subprocess.run keeps going unless you pass check=True. To test the port's failure handling, you replay a list of step exit codes under both postures.
An assistant wrote simulate_deploy_exit(step_codes, abort_on_error). It is in the editor. It has a bug. Find it and fix it.
Input and output:
step_codes: the exit code of each deploy step, in order. Python reports a step killed by a signal as a negative code, such as-9.abort_on_error:truemodelsset -e(orcheck=True),falsemodels a port that ignores failures.- Return
[script_exit_code, steps_run, swallowed_failures].
Rules the tests check:
- A step fails when its code is anything other than 0.
- With
abort_on_errortrue, run the steps in order and stop at the first failing step. Return its code, the number of steps run including it, and 0. If no step fails, return[0, number of steps, 0]. - With
abort_on_errorfalse, every step runs and the script still exits 0. Return[0, number of steps, number of failing steps].
Examples
simulate_deploy_exit(step_codes: list[int], abort_on_error: bool) -> list[int]Example 1
Input
simulate_deploy_exit([0, 0, 0], True)Output
[0, 3, 0]Example 2
Input
simulate_deploy_exit([0, 3, 0, 0], True)Output
[3, 2, 0]Example 3
Input
simulate_deploy_exit([0, 3, 0, 0], False)Output
[0, 4, 1]