Private
Public Access
0
0

fix(hooks): handle dict-key bracket notation in set_value / get_value

The Hook API previously rejected key strings like
'show_windows["Project Settings"]' (and silently returned None on
get). The test_live_gui_filedialog_regression test exercises exactly
this pattern to open the Project Settings window via the Hook API;
it was previously marked skip with "hook server doesn't handle the
dict-key bracket-notation syntax".

Fix in three small places:

1. src/app_controller.py:_handle_set_value
   If `item` is not in _settable_fields, try parsing it as
   `dict_name[<key>]` notation. If dict_name IS in _settable_fields
   and the current attr is a dict, set the inner key.

2. src/api_hooks.py:/api/gui/value (POST get_val)
   Mirror the parsing for the field-based get endpoint.

3. src/api_hook_client.py:ApiHookClient.get_value
   Mirror the parsing in the client so the dict-key syntax works
   through the state endpoint as well (which is what get_value
   actually calls by default).

Test fix:
- tests/test_live_gui_filedialog_regression.py: removed the
  @pytest.mark.skip marker; the underlying issue is now fixed.

Verified: 1/1 test passes (previously skipped).
This commit is contained in:
2026-06-07 16:49:51 -04:00
parent 8d58d7fc46
commit 91b34ae81e
4 changed files with 27 additions and 1 deletions
+11
View File
@@ -560,6 +560,17 @@ def _handle_set_value(controller: 'AppController', task: dict):
setattr(controller, attr_name, value)
if item == "gcli_path":
controller._update_gcli_adapter(str(value))
return
# Dict-key bracket notation: e.g. 'show_windows["Project Settings"]'
if "[" in item and item.endswith("]"):
dict_name, _, key_part = item.partition("[")
key = key_part[:-1].strip().strip("'\"")
if dict_name in controller._settable_fields:
attr_name = controller._settable_fields[dict_name]
current = getattr(controller, attr_name, None)
if isinstance(current, dict):
new_dict = {**current, key: value}
setattr(controller, attr_name, new_dict)
def _handle_click(controller: 'AppController', task: dict):
"""[SDM: AppController._handle_click]"""