Compare commits

...

1 Commits

Author SHA1 Message Date
Dizhan Xue
de8503b272 fix(rpc): treat a null section as absent when settings.set writes a key
The loader reads a null skillForge or skill_forge section as an absent
one, and skill block and unblock now agree. The settings writer did not:
_write_raw_key walked the dotted path with setdefault, which hands back
the stored null, and raised "blocked by non-object", so the settings
page could not change the skill blocklist of such a config.

A null section on the way to the key is now written as an empty object
under the spelling the file already uses. A section that is neither an
object nor null is still refused, and left as it is.
2026-10-12 11:40:33 +00:00
2 changed files with 29 additions and 2 deletions

View File

@ -781,9 +781,14 @@ def _write_raw_key(key: str, value: Any, *, merge: bool = False) -> dict:
node = raw
parts = key.split(".")
for p in parts[:-1]:
node = node.setdefault(_as_written(node, p), {})
if not isinstance(node, dict):
name = _as_written(node, p)
child = node.get(name)
# A null section is an absent one, the way the loader reads it.
if child is None:
child = node[name] = {}
elif not isinstance(child, dict):
raise ConfigValidationError(f"config path {key} blocked by non-object")
node = child
leaf = _as_written(node, parts[-1])
prev = node.get(leaf)
if merge:

View File

@ -1219,6 +1219,28 @@ async def test_settings_set_blocklist_is_a_raw_list(cfg):
await rpc_console.settings_set({"key": "skillForge.blocklist", "value": "codeword"})
@pytest.mark.parametrize("spelling", ["skillForge", "skill_forge"])
async def test_settings_set_blocklist_fills_a_null_section_under_its_spelling(cfg, spelling):
"""The loader reads a null section as an absent one; the write must agree."""
from raven.config.raven import load_raven_config
cfg.write_text(json.dumps({spelling: None}), encoding="utf-8")
await rpc_console.settings_set({"key": "skillForge.blocklist", "value": ["codeword"]})
assert _read(cfg) == {spelling: {"blocklist": ["codeword"]}}
assert load_raven_config(config_path=cfg).skill_forge.blocklist == ["codeword"]
async def test_settings_set_blocklist_refuses_a_non_object_section_and_keeps_it(cfg):
cfg.write_text(json.dumps({"skillForge": "codeword"}), encoding="utf-8")
with pytest.raises(ConfigValidationError, match="non-object"):
await rpc_console.settings_set({"key": "skillForge.blocklist", "value": ["codeword"]})
assert _read(cfg) == {"skillForge": "codeword"}
async def test_settings_set_media_speech_selection_merges(cfg):
await rpc_console.settings_set({"key": "tools.media.speech", "value": {"model": "tts-1", "quality": "high"}})
await rpc_console.settings_set({"key": "tools.media.speech", "value": {"model": "tts-2", "quality": ""}})