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
+48
View File
@@ -684,3 +684,51 @@ def test_only_an_administrator_may_change_extraction(client, registered):
assert client.post("/admin/extraction", data={"max_upload_mb": "1"}).status_code == 403
assert client.post("/admin/extraction/search", data={}).status_code == 403
assert client.post("/admin/extraction/rebuild", data={}).status_code == 403
def test_deleting_a_chat_removes_the_files_it_held(
client: TestClient, db, chat_with_model
):
"""Deleting a Chat cascades to its message and attachment *rows* and leaves
every file on disk -- a generated image, an uploaded PDF -- with nothing that
will ever look at them again, since `sweep_orphans` only considers uploads
that were never attached.
`remove_files_for_chats` was written for this and was called from exactly one
place, the temporary-chat sweep. The delete button was not it. That is
`sharing.forget_principal` a third time: a correct helper, absent from the
path that needs it.
"""
client.post("/api/files", files={"file": ("a.png", png_bytes(), "image/png")})
attachment = db.scalar(select(Attachment))
path = files_service.stored_path(attachment.stored_name)
client.post(
f"/api/chats/{chat_with_model}/messages",
data={"content": "here", "file_ids": [attachment.id]},
)
assert path.exists()
client.delete(f"/api/chats/{chat_with_model}")
assert db.scalar(select(Attachment)) is None
assert not path.exists(), "the row went and the file stayed"
def test_delete_chats_is_what_every_path_uses(client: TestClient, db, chat_with_model):
"""One function, so the next thing that deletes a chat cannot forget. It has
to unlink *before* the rows go -- they are what says which files to remove."""
client.post("/api/files", files={"file": ("a.png", png_bytes(), "image/png")})
attachment = db.scalar(select(Attachment))
path = files_service.stored_path(attachment.stored_name)
client.post(
f"/api/chats/{chat_with_model}/messages",
data={"content": "here", "file_ids": [attachment.id]},
)
chat = db.get(Chat, chat_with_model)
assert chat_service.delete_chats(db, [chat]) == 1
db.commit()
assert not path.exists()
assert chat_service.delete_chats(db, []) == 0
assert chat_service.delete_chats(db, [None]) == 0