Validate training completion handoff
This commit is contained in:
@@ -37,6 +37,13 @@ def write_state(path: Path, payload: dict) -> None:
|
||||
temporary.replace(path)
|
||||
|
||||
|
||||
def load_completion_command(path: Path) -> list[str]:
|
||||
command = json.loads(path.read_text(encoding="utf-8"))
|
||||
if not isinstance(command, list) or not command or not all(isinstance(x, str) and x for x in command):
|
||||
raise ValueError("completion command must be a non-empty JSON list of non-empty strings")
|
||||
return command
|
||||
|
||||
|
||||
def main() -> int:
|
||||
parser = argparse.ArgumentParser()
|
||||
parser.add_argument("--container", required=True)
|
||||
@@ -64,9 +71,11 @@ def main() -> int:
|
||||
write_state(state_path, state)
|
||||
return 0
|
||||
if args.completion_command_json:
|
||||
command = json.loads(args.completion_command_json.read_text(encoding="utf-8"))
|
||||
if not isinstance(command, list) or not command or not all(isinstance(x, str) and x for x in command):
|
||||
try:
|
||||
command = load_completion_command(args.completion_command_json)
|
||||
except (OSError, json.JSONDecodeError, ValueError) as exc:
|
||||
state["status"] = "invalid_completion_command"
|
||||
state["completion_handoff_error"] = str(exc)
|
||||
write_state(state_path, state)
|
||||
return 4
|
||||
result = subprocess.run(command, check=False)
|
||||
|
||||
Reference in New Issue
Block a user