aboutsummaryrefslogtreecommitdiffstats
path: root/test_llamachat.py
diff options
context:
space:
mode:
Diffstat (limited to 'test_llamachat.py')
-rwxr-xr-xtest_llamachat.py64
1 files changed, 64 insertions, 0 deletions
diff --git a/test_llamachat.py b/test_llamachat.py
index 71a2c35..8fb7a0e 100755
--- a/test_llamachat.py
+++ b/test_llamachat.py
@@ -3773,6 +3773,69 @@ def test_skill_parts():
print("ok skill parts")
+def test_oneshot_skill_persists_until_new():
+ """A loaded skill survives a one-shot reply and is cleared by New.
+
+ One-shot used to drop skills when the reply finished, which made the
+ loaded-skill chip flash and vanish. The chip is the indicator that a
+ skill is active, so it must stay until the user clears it or starts a
+ new conversation.
+ """
+ os.environ.setdefault("QT_QPA_PLATFORM", "offscreen")
+ from PySide6.QtWidgets import QApplication
+
+ from llamachat import backend as _backend
+ from llamachat import config as _config
+ from llamachat import models as _models
+ from llamachat.ui import ChatWindow
+
+ app = QApplication.instance() or QApplication([])
+
+ with tempfile.TemporaryDirectory() as tmp:
+ tmp = Path(tmp)
+ skill_dir = tmp / "skills"
+ (skill_dir / "handoff" / "SKILL.md").parent.mkdir(parents=True)
+ (skill_dir / "handoff" / "SKILL.md").write_text(
+ "---\nname: handoff\ndescription: prepare a session handoff.\n"
+ "---\n\n# handoff\nWrite the handoff.\n"
+ )
+
+ cfg = _config.load(tmp / "config.toml")
+ cfg.prompts_dir = tmp / "prompts"
+ cfg.db_path = tmp / "t.db"
+ cfg.skills_dir = skill_dir
+ cfg.skills_enabled = True
+ history = db.History(cfg.db_path)
+ client = _backend.MultiClient(cfg.providers, cfg.request_timeout)
+ presets = _config.parse_presets(cfg.presets_path)
+ store = _models.ModelStore(cfg.models_path)
+ window = ChatWindow(cfg, history, client, presets, store)
+
+ window.session_id = history.create_session("oneshot", "m")
+ text = window._load_skills_from_text("prepare a handoff please")
+ assert text == "prepare a handoff please"
+ assert "handoff" in window.loaded_skills
+ assert window.skill_chips, "a loaded skill must show a chip"
+
+ # A finished one-shot reply must keep the skill loaded until New.
+ window.assistant_message_id = history.add_message(
+ window.session_id, "assistant", "here is the handoff"
+ )
+ window.assistant_buffer = "here is the handoff"
+ window._on_stream_finished()
+ assert "handoff" in window.loaded_skills, "one-shot must keep the skill"
+ assert window.skill_chips, "the chip must stay after a one-shot reply"
+
+ # New drops the skill and the chip.
+ window.new_session()
+ assert window.loaded_skills == []
+ assert not window.skill_chips
+
+ window.close()
+ history.close()
+ print("ok oneshot skill persists until new")
+
+
if __name__ == "__main__":
test_presets()
test_real_presets()
@@ -3848,4 +3911,5 @@ if __name__ == "__main__":
test_skills_db()
test_skills_column_migration()
test_skill_parts()
+ test_oneshot_skill_persists_until_new()
print("\nall checks passed")