fix: remove redundant key normalization and defensive getattr in channel_prompts

- Remove double str() normalization in _resolve_channel_prompt since
  config bridging already handles numeric YAML key conversion
- Remove dead prompts.get(str(key)) fallback that could never match
  after keys were already normalized to strings
- Replace getattr(event, "channel_prompt", None) with direct attribute
  access since channel_prompt is a declared dataclass field
- Update test to verify normalization responsibility lives in config bridging
This commit is contained in:
Brenner Spear
2026-04-13 17:26:25 -07:00
committed by Teknium
parent 2fbdc2c8fa
commit 90a6336145
3 changed files with 15 additions and 9 deletions

View File

@@ -91,10 +91,19 @@ class TestResolveChannelPrompts:
adapter.config.extra = {"channel_prompts": {"100": "Research mode"}}
assert adapter._resolve_channel_prompt("100") == "Research mode"
def test_match_by_numeric_channel_id_key(self):
def test_numeric_yaml_keys_normalized_at_config_load(self):
"""Numeric YAML keys are normalized to strings by config bridging.
The resolver itself expects string keys (config.py handles normalization),
so raw numeric keys will not match — this is intentional.
"""
adapter = _make_adapter()
adapter.config.extra = {"channel_prompts": {100: "Research mode"}}
# Simulates post-bridging state: keys are already strings
adapter.config.extra = {"channel_prompts": {"100": "Research mode"}}
assert adapter._resolve_channel_prompt("100") == "Research mode"
# Pre-bridging numeric key would not match (bridging is responsible)
adapter.config.extra = {"channel_prompts": {100: "Research mode"}}
assert adapter._resolve_channel_prompt("100") is None
def test_match_by_parent_id(self):
adapter = _make_adapter()