Standardize on the .agents/ directory (shared with project skills): phases/, user_stories/, reports/, screenshots/, validate.sh, and phase-sessions/ + pipeline.log all move to .agents/ (git mv preserves history; runtime artifacts move alongside). Updates every reference in AGENTS.md, README.md, .gitignore, app docstrings, and test story headers. Historical KB content in data/ and the runtime pipeline.log transcript are left untouched.
2.1 KiB
2.1 KiB
Story: Chat Survives a Refresh (localStorage)
Phase: 14_chat_persistence.md · E2E: tests/e2e/test_chat_persistence.py
Narrative
As a user, I want my conversation to survive a browser refresh and a trip to another page — the previous session should be waiting for me when I come back.
- Given I have asked a few questions
- When I refresh the page (or go to Sources and come back)
- Then the whole conversation is restored: my questions, Brain's answers (rendered markdown), the source chips, and deflected answers with their "Maybe try" chips — amber style included.
Acceptance criteria
- Conversation state (user + brain messages, with sources/deflection/
suggestions metadata) is stored in
localStorageunder a versioned key; user messages are saved when sent, brain answers when the turn completes. - On load, stored messages are re-rendered (markdown, source chips, deflected styling + maybe-try chips); the empty state is hidden when a conversation exists.
- "New chat" control (chat header) clears the stored conversation and returns to the empty state with suggestions.
- Storage failures (private mode / quota) degrade silently — chat still works, nothing throws.
- Size-bounded: oldest messages are dropped if the serialized conversation outgrows the quota budget.
- Unit + integration green,
app/coverage >90%, story E2E green in isolation, one--no-gpg-signcommit.
Playwright Mapping Rule
Test Scenario → tests/e2e/test_chat_persistence.py (mock LLM, seeded KB):
test_conversation_survives_reload— ask → answer with source chip →page.reload()→ both bubbles restored (text + chip href), empty state hidden.test_deflected_turn_restores_styling— off-topic question → deflected answer → reload → amber bubble + "Maybe try" chips back.test_new_chat_clears_conversation— with a conversation, "New chat" → messages gone, empty state + suggestions back, storage key cleared.test_persists_across_page_navigation— ask → go to Sources → back to/→ conversation still there.