fix(cli): validate active_profile is a string in config.load (#13442) - #13446
Conversation
…rdware#13442) - Reject non-string active_profile values (lists, ints, booleans, tables) during config.load() - Set load_error to prevent commands from crashing with TypeError: unhashable type - Ensure write operations refuse to overwrite config when active_profile is invalid - Add comprehensive regression tests covering multiple non-string active_profile types and diagnostics
aryanorastar
left a comment
There was a problem hiding this comment.
The Python CLI change itself looks correct, and the platform test matrix is passing. I found two required repository-contract failures that should be fixed before approval:
-
PR Metadata Preflight is failing because the
fix:commit has noFailure-Class:declaration in the PR body. Please add exactly one accepted declaration, such asFailure-Class: noneif no failure class applies. -
Hygiene is failing because
sdks/python-cli/tests/test_config.pyhas a new blank line at EOF. Remove the extra blank line and rerun the required checks.
After these two mechanical fixes and a green rerun, I would be happy to re-review.
@aryanorastar Thanks for the quick review! I've removed the extra blank line at EOF in commit |
aryanorastar
left a comment
There was a problem hiding this comment.
Approved. The active_profile type validation is correctly implemented, preserves invalid configuration files by refusing overwrite, and has focused regression coverage for invalid TOML types and diagnostic commands. The author also fixed the repository-contract issues: Failure-Class: none is present and the trailing blank line is removed. The latest Python CLI and metadata checks pass.
|
Verified against
Good follow-through on the earlier review round. From my side this is ready to merge as-is. by AI on behalf of David — if you need David’s attention urgently, please @Git-on-my-level and escalate with |
Fixes #13442
Validates that
active_profilein the config file is a string duringconfig.load(). If a non-string value is present (such as a list, integer, boolean, or inline table from an otherwise valid TOML file),load_erroris populated andactive_profilefalls back to the default profile rather than crashing with unhandled runtime exceptions.Problem & Root Cause
At
main,config.load()readsactive = data.get("active_profile", DEFAULT_PROFILE_NAME)without validating its type.When a TOML configuration contains a valid TOML non-string scalar or collection (for instance,
active_profile = ["work"]oractive_profile = 42):Config.active_profilereceives the non-string object andConfig.load_errorremainsNone.config.get_profile(), the lookuptarget in self.profilescrashes withTypeError: unhashable type: 'list'.auth statusorconfig setabort with an unhandled traceback instead of reporting a clean diagnostic error.load_errorwas not set,save()does not refuse to overwrite, which could clobber or corrupt the user's repairable config file.Changes
sdks/python-cli/omi_cli/config.py:active_profile:'profiles' must be a tablein fix: handle non-table profiles in config.load #13349.Config.was_load_errorisTrue, sosave()refuses to overwrite and protects user configs.sdks/python-cli/tests/test_config.py:list,int,bool,dict).save()raisesPermissionErrorand refuses to overwrite whenactive_profilehas an invalid type.omi version,omi config path) continue to execute successfully whenactive_profileis invalid.Verification & Test Results
Ran test suite with
pytest tests/test_config.py:save()refusal against corrupt configuration.version,config path) remain functional.Product invariants affected
none
Failure class (fixes)
Failure-Class: none