fix(test): track TERMINAL_CONFIG_ENV_MAP after env-sync consolidation (#42695)

`test_terminal_config_env_sync.py::_save_config_env_sync_keys()`
AST-scanned `hermes_cli/config.py:set_config_value` for a
`_config_to_env_sync = {...}` literal. The terminal-config env bridging
was consolidated onto the canonical `TERMINAL_CONFIG_ENV_MAP` (now read
via `terminal_config_env_var_for_key()`), so that literal no longer
exists and the scanner raised:

    AssertionError: Could not find `_config_to_env_sync = {...}` literal in source

failing 8 of 9 tests on main for every PR.

Read the live `TERMINAL_CONFIG_ENV_MAP` instead — the actual source of
truth `set_config_value` bridges through — mirroring its `terminal.cwd`
exclusion. Refresh the stale module docstring and the now-incorrect
error-message hints that still referenced `_config_to_env_sync`.

Verified: the suite goes green, and a mutation (dropping `docker_volumes`
from `TERMINAL_CONFIG_ENV_MAP`) still trips the pinned regression test,
so the drift guard retains its teeth.
This commit is contained in:
kshitij 2026-06-09 02:11:46 -07:00 committed by GitHub
parent f8adefdebf
commit 76f89d66de
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -7,9 +7,9 @@ at startup, by THREE separate code paths:
1. cli.py -> ``env_mappings`` dict (CLI / TUI startup)
2. gateway/run.py -> ``_terminal_env_map`` dict (gateway / messaging
platforms)
3. hermes_cli/config.py:save_config_value
-> ``_config_to_env_sync`` dict (one-shot when the
user runs ``hermes config set ``)
3. hermes_cli/config.py:set_config_value
-> bridges via the canonical ``TERMINAL_CONFIG_ENV_MAP``
(one-shot when the user runs ``hermes config set ``)
If any one of these is missing a key, the corresponding config.yaml setting
silently does nothing for that entry-point. This bug already shipped once
@ -87,14 +87,20 @@ def _gateway_env_map_keys() -> set[str]:
def _save_config_env_sync_keys() -> set[str]:
"""terminal config keys bridged by ``hermes config set foo bar``."""
"""terminal config keys bridged by ``hermes config set foo bar``.
``set_config_value`` no longer carries its own ``_config_to_env_sync``
dict it bridges through the canonical ``TERMINAL_CONFIG_ENV_MAP`` via
``terminal_config_env_var_for_key()`` (config.py), excluding ``cwd``
(handled separately). Read the live map so this test tracks the actual
source of truth that the config-set path uses, rather than a string
literal that the consolidation removed.
"""
from hermes_cli import config as hc_config
source = inspect.getsource(hc_config.set_config_value)
keys = _extract_dict_keys(source, "_config_to_env_sync")
# set_config_value uses fully-qualified ``terminal.foo`` keys; strip the
# prefix so we can compare against the other two maps which use bare
# leaf keys.
return {k.split(".", 1)[1] for k in keys if k.startswith("terminal.")}
# set_config_value bridges every TERMINAL_CONFIG_ENV_MAP key except
# terminal.cwd (see the ``key != "terminal.cwd"`` guard in
# set_config_value); mirror that exclusion here.
return {k for k in hc_config.TERMINAL_CONFIG_ENV_MAP if k != "cwd"}
# Keys present in cli.py env_mappings but intentionally absent from
@ -180,8 +186,8 @@ def test_save_config_set_supports_critical_bridged_keys():
missing = required - save_keys
assert not missing, (
f"`hermes config set terminal.X` doesn't sync these load-bearing "
f"keys to .env: {sorted(missing)}. Add them to _config_to_env_sync "
f"in hermes_cli/config.py:set_config_value."
f"keys to .env: {sorted(missing)}. Add them to TERMINAL_CONFIG_ENV_MAP "
f"in hermes_cli/config.py (set_config_value bridges through it)."
)