Fix attachments never being sent with the message
Uploading an image showed the chip and then did nothing: the file was stored but never reached the model. Two causes, both in the composer template. The chips live in #attachments, and each carries the hidden file_ids input that binds it to the message. That container sat OUTSIDE the <form>, with an `hx-include="#attachments"` on a hidden <div> inside the form meant to pull it back in. That attribute only has an effect on the element issuing the request -- on a child of it, it does nothing. So the form serialised content and nothing else, and post_message saw no file_ids at all. Fixed by putting #attachments inside the form, where the inputs are submitted because they are in the form, rather than because of an attribute that has to be wired correctly. The file input stays outside, since inside it would submit an empty file part on every message. Second: /chat preselected models[0] rather than the model a new chat would actually use. With a vision model set as the default and a non-vision one first in the admin ordering, the composer showed the wrong model, sent the wrong model, and told the user images *would* be sent when they would not. It now resolves through default_model(), the same path /start uses. Every server-side test passed throughout, because the bug was entirely in the wiring between template and browser. Added tests that serialise the rendered form the way a browser does -- every named input inside <form> -- and assert file_ids is among them and the image reaches the model as a content part. Verified they fail with the old markup restored, then pass again. Confirmed end to end against gemma4-e4b-q8: given a drawing, it replied "Left: Green Circle / Right: Orange Triangle". 220 tests, ruff clean. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -660,3 +660,54 @@ def test_moving_returns_to_the_filtered_view(client: TestClient, db, registered)
|
||||
follow_redirects=False,
|
||||
)
|
||||
assert response.headers["location"] == "/admin/models?filter=enabled&page=2"
|
||||
|
||||
|
||||
def test_the_new_chat_composer_preselects_the_default_model(
|
||||
client: TestClient, db, registered
|
||||
):
|
||||
"""It must match what /start would actually pick. Showing a different model
|
||||
also mis-reports whether images will be sent."""
|
||||
connection = _connection(db)
|
||||
db.add_all(
|
||||
[
|
||||
Model(connection_id=connection.id, model_id="first-in-order", position=0),
|
||||
Model(connection_id=connection.id, model_id="the-default", position=7),
|
||||
]
|
||||
)
|
||||
db.commit()
|
||||
settings_store.update(db, {"default_model": "the-default"})
|
||||
|
||||
page = client.get("/chat").text
|
||||
assert 'value="the-default"' in page
|
||||
assert '<option value="the-default"\n selected' in page or (
|
||||
'value="the-default"' in page and "selected" in page
|
||||
)
|
||||
# And the hidden field the composer submits carries it too.
|
||||
assert 'name="model_id" value="the-default"' in page
|
||||
|
||||
|
||||
def test_the_composer_respects_an_explicit_model_query(client: TestClient, db, registered):
|
||||
connection = _connection(db)
|
||||
db.add_all(
|
||||
[
|
||||
Model(connection_id=connection.id, model_id="default-one", position=0),
|
||||
Model(connection_id=connection.id, model_id="asked-for", position=1),
|
||||
]
|
||||
)
|
||||
db.commit()
|
||||
settings_store.update(db, {"default_model": "default-one"})
|
||||
|
||||
page = client.get("/chat?model=asked-for").text
|
||||
assert 'name="model_id" value="asked-for"' in page
|
||||
|
||||
|
||||
def test_the_vision_warning_follows_the_preselected_model(client: TestClient, db, registered):
|
||||
connection = _connection(db)
|
||||
db.add(
|
||||
Model(
|
||||
connection_id=connection.id, model_id="blind-model", position=0,
|
||||
capabilities_json={"vision": False},
|
||||
)
|
||||
)
|
||||
db.commit()
|
||||
assert "has no vision" in client.get("/chat").text
|
||||
|
||||
Reference in New Issue
Block a user