From 5baee53534387ce9869b0570c78560f6205cc8b4 Mon Sep 17 00:00:00 2001 From: Amir Fathi Date: Fri, 21 Aug 2026 11:37:11 +0000 Subject: [PATCH] fix(test_scenario): stop apply_params_set writing NUM_NODES into cmd_args TestRun.param_space adds a "NUM_NODES" key to the action space whenever num_nodes is swept. apply_params_set has an explicit branch that assigns that value to new_tr.num_nodes, but the generic per-key loop above it also matches "NUM_NODES" and calls setattr(tdef.cmd_args, "NUM_NODES", value). Since CmdArgs uses ConfigDict(extra="allow"), that setattr does not raise: it silently creates a phantom NUM_NODES field on cmd_args that persists into cmd_args.model_dump() and any report reading it back. Skip "NUM_NODES" in the generic loop since the explicit branch below already owns it. Strengthens test_params_set, which exercised every num_nodes sweep shape but never asserted the field was absent from cmd_args. Fixes #943 Signed-off-by: Amir Fathi --- src/cloudai/_core/test_scenario.py | 4 ++++ tests/test_cloudaigym.py | 1 + 2 files changed, 5 insertions(+) diff --git a/src/cloudai/_core/test_scenario.py b/src/cloudai/_core/test_scenario.py index b8bdded3a..82315fb7d 100644 --- a/src/cloudai/_core/test_scenario.py +++ b/src/cloudai/_core/test_scenario.py @@ -217,6 +217,10 @@ def apply_params_set(self, action: dict[str, Any], env_params: dict[str, Any] | for key, value in full_action.items(): if key.startswith("extra_env_vars."): tdef.extra_env_vars[key[len("extra_env_vars.") :]] = value + elif key == "NUM_NODES": + # Handled below via new_tr.num_nodes; cmd_args has no such field, and CmdArgs' + # extra="allow" would otherwise let this create a phantom attribute on it. + continue else: attrs = key.split(".") obj = tdef.cmd_args diff --git a/tests/test_cloudaigym.py b/tests/test_cloudaigym.py index c1d8c3153..174e7049a 100644 --- a/tests/test_cloudaigym.py +++ b/tests/test_cloudaigym.py @@ -335,6 +335,7 @@ def test_params_set(setup_env: tuple[TestRun, Runner], num_nodes: int): assert new_tr.test.extra_env_vars[key[len("extra_env_vars.") :]] == value elif key == "NUM_NODES": assert new_tr.num_nodes == value + assert "NUM_NODES" not in cmd_args else: assert cmd_args[key] == value