Fix the deploy step replay for a Python port

Review the AI's codeEasy10 min

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: true models set -e (or check=True), false models 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_error true, 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_error false, 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
Inputsimulate_deploy_exit([0, 0, 0], True)
Output[0, 3, 0]
Example 2
Inputsimulate_deploy_exit([0, 3, 0, 0], True)
Output[3, 2, 0]
Example 3
Inputsimulate_deploy_exit([0, 3, 0, 0], False)
Output[0, 4, 1]