test: add tests for setup wizard personalization and system prompt builder
Cover _USE_CASE_PLUGINS mapping, _suggest_plugins side effects, _build_system_base output for all name/purpose combinations, and GeneralConfig.purpose round-trip. Also update CLAUDE.md with the testing workflow rule. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -88,3 +88,70 @@ def test_trim_to_budget_no_trim_when_under_budget():
|
||||
def test_trim_to_budget_empty_list():
|
||||
from pyra.chat.history import _trim_to_budget
|
||||
assert _trim_to_budget([], 1000) == []
|
||||
|
||||
|
||||
# ── _build_system_base tests ───────────────────────────────────────────────────
|
||||
|
||||
def test_build_system_base_default_identity():
|
||||
from pyra.chat.history import _build_system_base
|
||||
result = _build_system_base("User", "Pyra", "")
|
||||
assert "You are Pyra" in result
|
||||
assert "User" in result
|
||||
|
||||
|
||||
def test_build_system_base_custom_name_and_assistant():
|
||||
from pyra.chat.history import _build_system_base
|
||||
result = _build_system_base("Alice", "Aria", "")
|
||||
assert "You are Aria" in result
|
||||
assert "Alice" in result
|
||||
|
||||
|
||||
def test_build_system_base_no_purpose_omits_focus_block():
|
||||
from pyra.chat.history import _build_system_base
|
||||
result = _build_system_base("User", "Pyra", "")
|
||||
assert "primary purpose" not in result
|
||||
assert "not a general-purpose chatbot" not in result
|
||||
|
||||
|
||||
def test_build_system_base_with_purpose_includes_focus_block():
|
||||
from pyra.chat.history import _build_system_base
|
||||
result = _build_system_base("User", "Pyra", "manage my Nextcloud server")
|
||||
assert "primary purpose" in result
|
||||
assert "manage my Nextcloud server" in result
|
||||
assert "not a general-purpose chatbot" in result
|
||||
|
||||
|
||||
def test_build_system_base_always_includes_security_constraints():
|
||||
from pyra.chat.history import _build_system_base
|
||||
for purpose in ("", "manage servers"):
|
||||
result = _build_system_base("User", "Pyra", purpose)
|
||||
assert "vault" in result
|
||||
assert "shell commands" in result
|
||||
|
||||
|
||||
def test_build_for_api_uses_config_user_name(tmp_pyra_home, monkeypatch):
|
||||
monkeypatch.setattr("pyra.chat.history.load_context_for_session", lambda: "")
|
||||
from pyra.config.schema import PyraConfig, ProviderConfig, GeneralConfig
|
||||
from pyra.chat.history import ConversationHistory
|
||||
cfg = PyraConfig(
|
||||
ai=ProviderConfig(provider_id="lmstudio", model="gemma"),
|
||||
general=GeneralConfig(user_name="Alice", assistant_name="Aria", purpose=""),
|
||||
)
|
||||
h = ConversationHistory(cfg)
|
||||
system = h.build_for_api()[0]["content"]
|
||||
assert "Alice" in system
|
||||
assert "Aria" in system
|
||||
|
||||
|
||||
def test_build_for_api_uses_purpose(tmp_pyra_home, monkeypatch):
|
||||
monkeypatch.setattr("pyra.chat.history.load_context_for_session", lambda: "")
|
||||
from pyra.config.schema import PyraConfig, ProviderConfig, GeneralConfig
|
||||
from pyra.chat.history import ConversationHistory
|
||||
cfg = PyraConfig(
|
||||
ai=ProviderConfig(provider_id="lmstudio", model="gemma"),
|
||||
general=GeneralConfig(purpose="manage my home server"),
|
||||
)
|
||||
h = ConversationHistory(cfg)
|
||||
system = h.build_for_api()[0]["content"]
|
||||
assert "manage my home server" in system
|
||||
assert "primary purpose" in system
|
||||
|
||||
Reference in New Issue
Block a user