A temporary chat that keeps the model it was started on

The new-chat screen keeps its preselections in the query string, and the
three ways off it each rebuilt the URL with only their own key: the
Temporary button went to /chat?temporary=1, the model picker to
/chat?model=<id>, and /temp to /chat?temporary=1. So each undid the other,
and a temporary chat could only be started on the default model. The
folder from "New chat here" and the agent kind were dropped the same way.

chat_index now builds both URLs from one set of carried values and changes
only its own key; /temp keeps location.search when run on /chat.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-09-29 13:07:57 +00:00
co-authored by Claude Opus 5.5
parent cb8a223fa4
commit e65ea90fe6
8 changed files with 112 additions and 6 deletions
+55
View File
@@ -2,6 +2,8 @@
from __future__ import annotations
import html
import re
from datetime import UTC, datetime, timedelta
from fastapi.testclient import TestClient
@@ -100,6 +102,59 @@ def test_the_new_chat_screen_carries_the_flag(client: TestClient, db, registered
assert 'name="temporary"' in client.get("/chat?temporary=1").text
def _temporary_link(page: str) -> str:
match = re.search(r'href="([^"]*)"\s+aria-label="Temporary chat"', page)
assert match, "no temporary toggle on the page"
return html.unescape(match.group(1))
def _picker_url(page: str) -> str:
match = re.search(r'data-picker-navigate="([^"]*)"', page)
assert match, "no navigating model picker on the page"
return html.unescape(match.group(1))
def test_the_temporary_toggle_keeps_the_chosen_model(client: TestClient, db, registered):
"""Temporary chats could only be started on the default model: the toggle
linked to a bare `/chat?temporary=1`, so the model picked a moment before
was dropped."""
connection = _connection(db)
db.add(Model(connection_id=connection.id, model_id="other-model"))
db.commit()
on = _temporary_link(client.get("/chat?model=other-model").text)
assert "model=other-model" in on and "temporary=1" in on
assert 'name="model_id" value="other-model"' in client.get(on).text
off = _temporary_link(client.get(on).text)
assert "model=other-model" in off and "temporary" not in off
def test_choosing_a_model_keeps_the_temporary_flag(client: TestClient, db, registered):
"""The other half: the picker navigated to a bare `/chat?model=`, so
picking a model after the toggle quietly made the chat an ordinary one."""
connection = _connection(db)
db.add(Model(connection_id=connection.id, model_id="other-model"))
db.commit()
url = _picker_url(client.get("/chat?temporary=1").text)
assert url.endswith("model=")
page = client.get(url + "other-model").text
assert 'name="temporary"' in page
assert 'name="model_id" value="other-model"' in page
assert _picker_url(client.get("/chat").text) == "/chat?model="
def test_both_links_keep_the_folder(client: TestClient, db, registered):
_connection(db)
client.post("/api/folders", data={"name": "Quests"})
folder = db.scalar(select(Folder))
page = client.get(f"/chat?folder={folder.id}").text
assert f"folder={folder.id}" in _temporary_link(page)
assert f"folder={folder.id}" in _picker_url(page)
def test_starting_a_temporary_chat_sets_the_flag(client: TestClient, db, registered):
_connection(db)
client.post("/api/chats/start", data={"content": "hello", "temporary": "true"})