Files that outlived the chats that held them, and a page that led with its footnotes

The second audit pass. Four things, and the first two were reported.

The Prompts page put a screen of variables and a screen of preview above
the editor, so the tabs began two screens down and switching one had to
drag the whole page to be any use -- and on a short tab it could not drag
far enough, leaving the panel stranded above a screenful of nothing.
Editor first, reference after, bar sticky. Custom themes were three fixed
slots: fifty-seven empty colour boxes on a fresh instance and no way to
make a fourth theme. One block per theme plus a blank one, colours behind
a disclosure. Both measured rather than argued about -- rendered through
TestClient and driven under headless Chromium, where the tab bar moved
385->642px before and does not move now, and the themes page went from
5495px to 2820px.

Asking where generated images go found the other two. Deleting a chat
cascades to the attachment rows and leaves every file on disk; the helper
written for exactly that was called from one place, and it was not the
delete button, a schedule's chat, a helper's chat or deleting an account.
Underneath it, `claim` bound message_id and never chat_id, so anything
picked before a chat existed kept an empty chat_id forever -- which six
readers filter on, so those files were also unnamed in the prompt,
unopenable in the canvas, and invisible to the one caller the cleanup had.

And folders nest now. The route has handled parent_id since folders
existed, with a cycle guard and a depth cap the move path never applied;
the sidebar has always drawn a tree. Nothing could ask for one.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
This commit is contained in:
2026-08-07 13:20:59 +02:00
parent 3afbccba81
commit c4aff999ba
25 changed files with 814 additions and 104 deletions
+75
View File
@@ -361,3 +361,78 @@ def test_the_settings_form_posts_at_a_route_that_serves_patch(
folder = _folder(db, "Errands")
assert client.post(f"/api/folders/{folder.id}", data={"name": "x"}).status_code == 405
assert client.patch(f"/api/folders/{folder.id}", data={"name": "x"}).status_code == 204
# --- Nesting, which had no control ---------------------------------------------
def folders_service_create(client, name: str, *, parent: str = "") -> str:
"""Make a folder through the route and return its id."""
data = {"name": name}
if parent:
data["parent_id"] = parent
client.post("/api/folders", data=data)
from lembas.db.session import session_scope
with session_scope() as db:
return db.scalar(select(Folder).where(Folder.name == name)).id
def test_a_folder_can_be_put_inside_another(client: TestClient, db, registered):
"""`parent_id` has been handled at the route since folders existed, with a
cycle guard and a depth cap, and `partials/_folder.html` has always recursed
to draw the tree. Nothing anywhere submitted it, so the README advertised
"arbitrarily nested" folders that could not be nested."""
outer = folders_service_create(client, "Outer")
inner = folders_service_create(client, "Inner")
client.patch(f"/api/folders/{inner}", data={"parent_id": outer})
assert db.get(Folder, inner).parent_id == outer
def test_the_settings_page_offers_the_move(client: TestClient, db, registered):
"""And offers only moves the route will accept -- a picker listing a folder
that would be refused is a control that looks like it works."""
outer = folders_service_create(client, "Outer")
inner = folders_service_create(client, "Inner")
client.patch(f"/api/folders/{inner}", data={"parent_id": outer})
page = client.get(f"/folders/{outer}").text
assert 'name="parent_id"' in page
# Its own child is not offered: that move is the cycle the route refuses.
assert f'value="{inner}"' not in page
assert f'value="{outer}"' not in page, "a folder cannot be its own parent"
def test_a_folder_cannot_be_moved_into_its_own_subtree(client: TestClient, db, registered):
outer = folders_service_create(client, "Outer")
inner = folders_service_create(client, "Inner")
client.patch(f"/api/folders/{inner}", data={"parent_id": outer})
refused = client.patch(f"/api/folders/{outer}", data={"parent_id": inner})
assert refused.status_code == 400
assert db.get(Folder, outer).parent_id is None
def test_moving_respects_the_depth_cap(client: TestClient, db, registered):
"""`create_folder` has always applied MAX_DEPTH; the move path never did, so
a three-deep subtree could be dropped under a six-deep folder and build a
tree the recursive sidebar template was never meant to draw. It went
unnoticed because nothing could submit `parent_id` at all."""
from lembas.api.folders import MAX_DEPTH
chain = []
parent = ""
for index in range(MAX_DEPTH):
made = folders_service_create(client, f"L{index}", parent=parent)
chain.append(made)
parent = made
loose = folders_service_create(client, "Loose")
child = folders_service_create(client, "LooseChild", parent=loose)
assert db.get(Folder, child).parent_id == loose
# `loose` is two tall; the deepest folder is already at the cap.
refused = client.patch(f"/api/folders/{loose}", data={"parent_id": chain[-1]})
assert refused.status_code == 400
assert db.get(Folder, loose).parent_id is None