From 21cfb264aab035cae43dfd11aa3a380959bcf6aa Mon Sep 17 00:00:00 2001 From: cjc0013 Date: Sat, 9 May 2026 07:58:20 -0400 Subject: [PATCH 1/2] Use declared ION variable names --- tools/run.py | 57 ++++++++++++++++++++++++++++++++++++---------------- 1 file changed, 40 insertions(+), 17 deletions(-) diff --git a/tools/run.py b/tools/run.py index 3dcbb3e..8dbd8d1 100755 --- a/tools/run.py +++ b/tools/run.py @@ -16,6 +16,41 @@ script = sys.argv[1] base_path = Path(f"scripts/{script}") +# --------------------------------------------------- +# Load script metadata +# --------------------------------------------------- +model_path = base_path / "model.json" +meta_path = base_path / "meta.json" + +if not model_path.exists(): + raise RuntimeError(f"Missing model.json in {base_path}") + +with open(model_path, "r", encoding="utf-8") as f: + model = json.load(f) + +meta = {} +if meta_path.exists(): + with open(meta_path, "r", encoding="utf-8") as f: + meta = json.load(f) + +output_format = meta.get("output_format") + + +def first_variable_name(model_key, fallback_name): + variables = model.get(model_key) or [] + if not variables: + return fallback_name + + name = variables[0].get("name") + if not name: + raise RuntimeError(f"First {model_key} entry in model.json is missing a name") + + return name + + +input_name = first_variable_name("inputVariables", "data_in") +output_name = first_variable_name("outputVariables", "data_out") + # --------------------------------------------------- # Load raw input (format-agnostic) # --------------------------------------------------- @@ -28,21 +63,9 @@ test_input = f.read() payload = { - "data_in": test_input + input_name: test_input } -# --------------------------------------------------- -# Load meta data (optional, for format hints) -# --------------------------------------------------- -meta_path = base_path / "meta.json" - -meta = {} -if meta_path.exists(): - with open(meta_path, "r", encoding="utf-8") as f: - meta = json.load(f) - -output_format = meta.get("output_format") - # --------------------------------------------------- # Headers # --------------------------------------------------- @@ -76,10 +99,10 @@ # --------------------------------------------------- # Validate output # --------------------------------------------------- -if "data_out" not in data: - raise RuntimeError(f"No data_out in response: {data}") +if output_name not in data: + raise RuntimeError(f"No {output_name} in response: {data}") -output = data["data_out"] +output = data[output_name] if output is None or (isinstance(output, str) and not output.strip()): raise RuntimeError("Script returned empty output") @@ -118,4 +141,4 @@ else: print(str(output)[:500]) -print(f"\n>>> Saved as tests/output.{output_format if output_format != 'Base64' else 'bin'}") \ No newline at end of file +print(f"\n>>> Saved as tests/output.{output_format if output_format != 'Base64' else 'bin'}") From 0eda2f4c5ddd46516005402a6d54f9a101cf4635 Mon Sep 17 00:00:00 2001 From: cjc0013 Date: Wed, 20 May 2026 18:33:17 -0400 Subject: [PATCH 2/2] Clean up model variable output handling --- tools/run.py | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/tools/run.py b/tools/run.py index 8dbd8d1..cb2c5b1 100755 --- a/tools/run.py +++ b/tools/run.py @@ -63,7 +63,7 @@ def first_variable_name(model_key, fallback_name): test_input = f.read() payload = { - input_name: test_input + input_name: test_input, } # --------------------------------------------------- @@ -99,10 +99,11 @@ def first_variable_name(model_key, fallback_name): # --------------------------------------------------- # Validate output # --------------------------------------------------- -if output_name not in data: - raise RuntimeError(f"No {output_name} in response: {data}") +output_key = output_name if output_name in data else "data_out" if "data_out" in data else None +if output_key is None: + raise RuntimeError(f"No {output_name} or data_out in response: {data}") -output = data[output_name] +output = data[output_key] if output is None or (isinstance(output, str) and not output.strip()): raise RuntimeError("Script returned empty output")