test: add comprehensive coverage for cli, chat, renderer, dirs, install, paths
56 new tests covering previously untested modules: - test_cli.py: memory write/read/append/list + plugin enable/disable + daemon stubs (via CliRunner) - test_chat_history.py: ConversationHistory build_for_api, add_*/clear, _trim_to_budget - test_chat_renderer.py: render_text_response return values, void render_* functions - test_config_dirs.py: bootstrap idempotency, directory/template/vault/db creation - test_plugin_install.py: list_bundled_plugins, read_manifest, install_bundled_plugin - test_utils_paths.py: ensure_dir (nested, idempotent), safe_chmod Total: 171 → 227 passing tests. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,57 @@
|
||||
from pyra.security.injection import InjectionWarning
|
||||
|
||||
|
||||
def test_render_text_response_passthrough():
|
||||
from pyra.chat.renderer import render_text_response
|
||||
result = render_text_response("Hello world")
|
||||
assert result == "Hello world"
|
||||
|
||||
|
||||
def test_render_text_response_redacts_api_key():
|
||||
from pyra.chat.renderer import render_text_response
|
||||
# anthropic-style key
|
||||
result = render_text_response("key: sk-ant-api03-abcdefghijklmnopqrstuvwxyz123456")
|
||||
assert "sk-ant" not in result
|
||||
assert "[REDACTED]" in result
|
||||
|
||||
|
||||
def test_render_text_response_empty_string():
|
||||
from pyra.chat.renderer import render_text_response
|
||||
result = render_text_response("")
|
||||
assert result == ""
|
||||
|
||||
|
||||
def test_render_text_response_whitespace_only():
|
||||
from pyra.chat.renderer import render_text_response
|
||||
result = render_text_response(" ")
|
||||
assert result == " "
|
||||
|
||||
|
||||
def test_render_error_no_exception():
|
||||
from pyra.chat.renderer import render_error
|
||||
render_error("Something went wrong")
|
||||
|
||||
|
||||
def test_render_info_no_exception():
|
||||
from pyra.chat.renderer import render_info
|
||||
render_info("Informational message")
|
||||
|
||||
|
||||
def test_render_system_no_exception():
|
||||
from pyra.chat.renderer import render_system
|
||||
render_system("System message")
|
||||
|
||||
|
||||
def test_render_injection_warning_no_exception():
|
||||
from pyra.chat.renderer import render_injection_warning
|
||||
warnings = [InjectionWarning(pattern_label="instruction-override", matched_text="ignore all")]
|
||||
render_injection_warning(warnings)
|
||||
|
||||
|
||||
def test_render_injection_warning_multiple():
|
||||
from pyra.chat.renderer import render_injection_warning
|
||||
warnings = [
|
||||
InjectionWarning(pattern_label="instruction-override", matched_text="ignore"),
|
||||
InjectionWarning(pattern_label="jailbreak", matched_text="DAN mode"),
|
||||
]
|
||||
render_injection_warning(warnings)
|
||||
Reference in New Issue
Block a user