54 lines
1.6 KiB
Python
54 lines
1.6 KiB
Python
"""Tests for session persistence."""
|
|
|
|
from __future__ import annotations
|
|
|
|
from pathlib import Path
|
|
|
|
from openharness.api.usage import UsageSnapshot
|
|
from openharness.engine.messages import ConversationMessage, TextBlock
|
|
from openharness.services.session_storage import (
|
|
export_session_markdown,
|
|
load_session_snapshot,
|
|
save_session_snapshot,
|
|
)
|
|
|
|
|
|
def test_save_and_load_session_snapshot(tmp_path: Path, monkeypatch):
|
|
monkeypatch.setenv("OPENHARNESS_DATA_DIR", str(tmp_path / "data"))
|
|
project = tmp_path / "repo"
|
|
project.mkdir()
|
|
|
|
path = save_session_snapshot(
|
|
cwd=project,
|
|
model="claude-test",
|
|
system_prompt="system",
|
|
messages=[ConversationMessage(role="user", content=[TextBlock(text="hello")])],
|
|
usage=UsageSnapshot(input_tokens=1, output_tokens=2),
|
|
)
|
|
|
|
assert path.exists()
|
|
snapshot = load_session_snapshot(project)
|
|
assert snapshot is not None
|
|
assert snapshot["model"] == "claude-test"
|
|
assert snapshot["usage"]["output_tokens"] == 2
|
|
|
|
|
|
def test_export_session_markdown(tmp_path: Path, monkeypatch):
|
|
monkeypatch.setenv("OPENHARNESS_DATA_DIR", str(tmp_path / "data"))
|
|
project = tmp_path / "repo"
|
|
project.mkdir()
|
|
|
|
path = export_session_markdown(
|
|
cwd=project,
|
|
messages=[
|
|
ConversationMessage(role="user", content=[TextBlock(text="hello")]),
|
|
ConversationMessage(role="assistant", content=[TextBlock(text="world")]),
|
|
],
|
|
)
|
|
|
|
assert path.exists()
|
|
content = path.read_text(encoding="utf-8")
|
|
assert "OpenHarness Session Transcript" in content
|
|
assert "hello" in content
|
|
assert "world" in content
|