fix(backend): 冻结 TOOLBOX 注册表为只读 MappingProxyType(CR-H7)

This commit is contained in:
Yaojia Wang
2026-07-08 10:41:15 +02:00
parent 5dd336b011
commit 25d48b7aa7
2 changed files with 18 additions and 1 deletions

View File

@@ -7,6 +7,7 @@
from __future__ import annotations
import pytest
from ww_agents import SPECS
from ww_skills import TOOLBOX, get_tool
@@ -105,3 +106,11 @@ def test_get_tool_resolves_known_and_unknown() -> None:
assert get_tool("brainstorm") is TOOLBOX["brainstorm"]
assert get_tool("worldbuilding") is TOOLBOX["worldbuilding"]
assert get_tool("does-not-exist") is None
def test_toolbox_registry_is_read_only() -> None:
# CR-H7注册表是单一真相源运行时变异注入/删除)须 fail-fast冻结为 MappingProxyType
with pytest.raises(TypeError):
TOOLBOX["injected"] = TOOLBOX["brainstorm"] # type: ignore[index]
with pytest.raises(TypeError):
del TOOLBOX["brainstorm"] # type: ignore[attr-defined]