feat(cli): add live demo mode (#302)

This commit is contained in:
Elliot Chen
2026-06-23 20:11:23 +08:00
committed by GitHub
parent 62e50ab725
commit 1ea44ca548
5 changed files with 332 additions and 3 deletions
@@ -23,6 +23,18 @@ def test_demo_help_exposes_cinematic_mode() -> None:
assert "--cinematic" in _strip_ansi(result.stdout)
def test_demo_help_exposes_live_mode() -> None:
app = typer.Typer()
demo_command.register(app)
result = CliRunner().invoke(app, ["demo", "--help"], terminal_width=120)
help_text = _strip_ansi(result.stdout)
assert result.exit_code == 0
assert "--live" in help_text
assert "--server-url" in help_text
def test_collect_playable_story_prompts_for_memory_then_query(monkeypatch) -> None:
prompts: list[tuple[str, str]] = []
replies = iter(
@@ -102,5 +114,75 @@ def test_plain_demo_prints_custom_story(monkeypatch) -> None:
assert "episode-demo.md" in printed_text
def test_live_demo_flow_calls_server_and_builds_story() -> None:
story = build_demo_story(
"I love climbing in Yosemite every spring.",
"Where do I like to climb?",
)
calls: list[tuple[str, str, dict[str, object] | None]] = []
def fake_request(
method: str,
path: str,
*,
base_url: str,
json_body: dict[str, object] | None = None,
timeout_seconds: float,
) -> dict[str, object]:
calls.append((method, path, json_body))
assert base_url == "http://server.test"
assert timeout_seconds == 3.0
if path == "/health":
return {"status": "ok"}
if path == "/api/v1/memory/add":
return {"message_count": 1, "status": "accumulated"}
if path == "/api/v1/memory/flush":
return {"message_count": 1, "status": "extracted"}
if path == "/api/v1/memory/search":
return {
"data": {
"episodes": [
{
"id": "alice_ep_20260623_0001",
"episode": "Alice loves climbing in Yosemite every spring.",
"summary": "Alice climbs in Yosemite every spring.",
"subject": "Yosemite climbing",
"score": 0.82,
"atomic_facts": [
{
"id": "alice_af_20260623_0001",
"content": (
"Alice loves climbing in Yosemite every spring."
),
"score": 0.91,
}
],
}
]
}
}
raise AssertionError(f"unexpected request: {method} {path}")
live_story = demo_command._run_live_demo_flow(
story,
base_url="http://server.test",
request_json=fake_request,
timeout_seconds=3.0,
)
assert [path for _, path, _ in calls] == [
"/health",
"/api/v1/memory/add",
"/api/v1/memory/flush",
"/api/v1/memory/search",
]
add_body = calls[1][2]
assert add_body is not None
assert add_body["session_id"] == "everos-demo-live"
assert live_story.answer == "Alice loves climbing in Yosemite every spring."
assert live_story.source_filename == "episode:alice_ep_20260623_0001"
assert live_story.fact_filename == "fact:alice_af_20260623_0001"
def _strip_ansi(value: str) -> str:
return re.sub(r"\x1b\[[0-?]*[ -/]*[@-~]", "", value)